Lumiera  0.pre.03
»edit your freedom«
test-helper-variadic-test.cpp
Go to the documentation of this file.
1 /*
2  TestHelperVariadic(Test) - verify variadic template diagnostics helper
3 
4  Copyright (C)
5  2014, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
19 #include "lib/test/run.hpp"
20 #include "lib/test/test-helper.hpp"
21 
22 
23 #include <iostream>
24 #include <utility>
25 #include <string>
26 #include <cmath>
27 
28 using std::string;
29 using std::cout;
30 
31 
32 namespace lib {
33 namespace test{
34 namespace test{
35 
36  namespace { // test fixture...
37 
38  class Interface
39  {
40  public:
41  Interface(){}
42  Interface(Interface const& o) { cout << "COPY.CT from "<<&o<<" !!!\n"; }
43  Interface(Interface const&& o) { cout << "MOVE.CT from "<<&o<<" !!!\n"; }
44 
45  Interface& operator= (Interface const& o) { cout << "COPY= from "<<&o<<" !!!\n"; return *this; }
46  Interface& operator= (Interface const&& o) { cout << "MOVE= from "<<&o<<" !!!\n"; return *this; }
47 
48  virtual ~Interface() { }
49  };
50 
51  class Impl
52  : public Interface
53  {
54  string s_;
55 
56  public:
57  Impl(string ss ="ZOMG") : s_(ss) { }
58  };
59 
60 
61  inline double
62  makeRvalue()
63  {
64  return atan2(0,-0.0);
65  }
66 
67 
68  }//(End) test fixture
69 
70 
71 
72 
73 
74 
75  /****************************************************************************/
90  class TestHelperVariadic_test : public Test
91  {
92 
93  virtual void
94  run (Arg)
95  {
96  double d = makeRvalue();
97  double const& cr = d;
98 
99  Impl obj;
100  Interface const& ref = obj;
101 
102  cout << "--no-arg--\n" << showVariadicTypes() <<"\n";
103  cout << "--reference--\n" << showVariadicTypes(d) <<"\n";
104  cout << "--value--\n" << showVariadicTypes(makeRvalue()) <<"\n";
105 
106  forwardFunction("two values", "foo", 42L); // displayed as char [4] const&, long &&
107  forwardFunction("references", d,cr,std::move(d)); // displayed as double&, double const&, double &&
108 
109  forwardFunction("baseclass", ref); // displayed as Interface const&
110  }
111 
112 
116  template<typename... ARGS>
117  void
118  forwardFunction (string id, ARGS&&... args)
119  {
120  cout << "--"<<id<<"--\n"
121  << showVariadicTypes (std::forward<ARGS>(args)...)
122  << "\n"
123  ;
124  }
125 
126  };
127 
128 
130  LAUNCHER (TestHelperVariadic_test, "unit common");
131 
132 
133 }}} // namespace lib::test::test
Definition: run.hpp:40
string showVariadicTypes()
helper for investigating a variadic argument pack
Implementation namespace for support and library code.
Target object to be instantiated as Singleton Allocates a variable amount of additional heap memory a...
Simplistic test class runner.
A collection of frequently used helper functions to support unit testing.
void forwardFunction(string id, ARGS &&... args)
this dummy simulates a typical variadic call which takes all arguments as &#39;&&&#39; for the purpose of "pe...