Lumiera  0.pre.03
»edityourfreedom«
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
argument-tuple-accept-test.cpp
Go to the documentation of this file.
1 /*
2  ArgumentTupleAccept(Test) - verify synthesising a bind(...) function
3 
4  Copyright (C) Lumiera.org
5  2009, 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"
32 #include "lib/meta/function.hpp"
33 #include "lib/format-cout.hpp"
34 
35 #include <functional>
36 #include <tuple>
37 
38 
39 namespace proc {
40 namespace control {
41 namespace test {
42 
44  using lib::test::randTime;
45 
46  using lib::time::TimeVar;
47  using std::function;
48  using lib::meta::_Fun;
49  using lib::meta::Tuple;
50 
51 
52 
53 
54 
55 
56  namespace { // build a test dummy class....
57 
58  template<typename SIG>
59  struct _Tup
60  {
61  using Args = typename _Fun<SIG>::Args;
62  using Ret = typename _Fun<SIG>::Ret;
63  using Ty = Tuple<Args>;
64  };
65 
66 
67  template<typename SIG>
68  class TestClass
69  : public AcceptArgumentBinding< SIG // to derive the desired signature
70  , TestClass<SIG> // the target class providing the implementation
71  , typename _Tup<SIG>::Ty // base class to inherit from
72  >
73  {
74  using ATuple = typename _Tup<SIG>::Ty;
75  using RetType = typename _Tup<SIG>::Ret;
76 
77  public:
78 
79  RetType
80  bindArg (ATuple const& tuple)
81  {
82  static_cast<ATuple&> (*this) = tuple;
83  return RetType();
84  }
85  };
86 
87 
88  } // test-helper implementation
89 
90 
91 
92 
93 
94 
95  /*********************************************************/
101  class ArgumentTupleAccept_test : public Test
102  {
103 
104  virtual void
105  run (Arg)
106  {
107  TestClass<void()> testVoid;
108  TestClass<int(TimeVar,int)> testTime;
109 
110  testVoid.bind();
111  testTime.bind(randTime(),23);
112 
113  cout << showSizeof(testVoid) << endl;
114  cout << showSizeof(testTime) << endl;
115 
116  cout << std::get<0> (testTime) << endl;
117  CHECK (23 == std::get<1> (testTime));
118  }
119 
120  };
121 
122 
123 
125  LAUNCHER (ArgumentTupleAccept_test, "unit controller");
126 
127 
128 }}} // namespace proc::control::test
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
Definition: timevalue.hpp:142
Automatically use custom string conversion in C++ stream output.
string showSizeof(size_t siz, string name)
for printing sizeof().
Definition: test-helper.cpp:48
Definition: run.hpp:49
Mixin-templates providing arbitrary function call operators and argument binding functions.
Helper for uniform access to function signature types.
Definition: function.hpp:108
typename BuildTupleType< TYPES >::Type Tuple
Build a std::tuple from types given as type sequence.
Metaprogramming with tuples-of-types and the std::tuple record.
Helper Template for Proc-Layer control::Command : mix in a bind(...) function.
std::vector< string > & Arg
Definition: run.hpp:54
Metaprogramming tools for transforming functor types.
Simple test class runner.
LAUNCHER(ArgumentTupleAccept_test,"unit controller")
Register this test class...
A collection of frequently used helper functions to support unit testing.
Proc-Layer implementation namespace root.
Definition: id-scheme.hpp:63
lib::time::Time randTime()
create a random but not insane Time value