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) Lumiera.org
5  2014, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
29 #include "lib/test/test-helper.hpp"
30 
31 
32 #include <iostream>
33 #include <utility>
34 #include <string>
35 #include <cmath>
36 
37 using std::string;
38 using std::cout;
39 
40 
41 namespace lib {
42 namespace test{
43 namespace test{
44 
45  namespace { // test fixture...
46 
47  class Interface
48  {
49  public:
50  Interface(){}
51  Interface(Interface const& o) { cout << "COPY.CT from "<<&o<<" !!!\n"; }
52  Interface(Interface const&& o) { cout << "MOVE.CT from "<<&o<<" !!!\n"; }
53 
54  Interface& operator= (Interface const& o) { cout << "COPY= from "<<&o<<" !!!\n"; return *this; }
55  Interface& operator= (Interface const&& o) { cout << "MOVE= from "<<&o<<" !!!\n"; return *this; }
56 
57  virtual ~Interface() { }
58  };
59 
60  class Impl
61  : public Interface
62  {
63  string s_;
64 
65  public:
66  Impl(string ss ="ZOMG") : s_(ss) { }
67  };
68 
69 
70  inline double
71  makeRvalue()
72  {
73  return atan2(0,-0.0);
74  }
75 
76 
77  }//(End) test fixture
78 
79 
80 
81 
82 
83 
84  /****************************************************************************/
99  class TestHelperVariadic_test : public Test
100  {
101 
102  virtual void
103  run (Arg)
104  {
105  double d = makeRvalue();
106  double& dr = d;
107 
108  Impl obj;
109  Interface const& ref = obj;
110 
111  cout << "--no-arg--\n" << showVariadicTypes() <<"\n";
112  cout << "--value--\n" << showVariadicTypes<double>(d) <<"\n";
113  cout << "--reference--\n" << showVariadicTypes<double&>(d) <<"\n";
114  cout << "--move--\n" << showVariadicTypes<double&&>(d) <<"\n";
115 
116  forwardFunction("two values", "foo", 42L); // passed as REF, MOV
117  forwardFunction("matched", d,dr,std::move(dr)); // passed as REF, REF, MOV
118 
119  forwardFunction<Interface const&>("baseclass", ref);
120  }
121 
122 
126  template<typename... ARGS>
127  void
128  forwardFunction (string id, ARGS&&... args)
129  {
130  // in reality here you'd invoke some factory(<std::forward<ARGS>(args)...)
131  //
132  cout << "--"<<id<<"--\n"
133  << showVariadicTypes<ARGS&&...>(args...)
134  << "\n"
135  ;
136  }
137 
138  };
139 
140 
142  LAUNCHER (TestHelperVariadic_test, "unit common");
143 
144 
145 }}} // namespace lib::test::test
Definition: run.hpp:49
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...
Simple 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...