Lumiera  0.pre.03
»edit your freedom«
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)
5  2009, 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"
23 #include "lib/meta/function.hpp"
24 #include "lib/format-cout.hpp"
25 
26 #include <functional>
27 #include <tuple>
28 
29 
30 namespace steam {
31 namespace control {
32 namespace test {
33 
34  using lib::test::showSizeof;
35  using lib::test::randTime;
36 
37  using lib::time::TimeVar;
38  using std::function;
39  using lib::meta::_Fun;
40  using lib::meta::Tuple;
41 
42 
43 
44 
45 
46 
47  namespace { // build a test dummy class....
48 
49  template<typename SIG>
50  struct _Tup
51  {
52  using Args = typename _Fun<SIG>::Args;
53  using Ret = typename _Fun<SIG>::Ret;
54  using Ty = Tuple<Args>;
55  };
56 
57 
58  template<typename SIG>
59  class TestClass
60  : public AcceptArgumentBinding< SIG // to derive the desired signature
61  , TestClass<SIG> // the target class providing the implementation
62  , typename _Tup<SIG>::Ty // base class to inherit from
63  >
64  {
65  using ATuple = typename _Tup<SIG>::Ty;
66  using RetType = typename _Tup<SIG>::Ret;
67 
68  public:
69 
70  RetType
71  bindArg (ATuple const& tuple)
72  {
73  static_cast<ATuple&> (*this) = tuple;
74  return RetType();
75  }
76  };
77 
78 
79  } // test-helper implementation
80 
81 
82 
83 
84 
85 
86  /*********************************************************/
92  class ArgumentTupleAccept_test : public Test
93  {
94 
95  virtual void
96  run (Arg)
97  {
98  TestClass<void()> testVoid;
99  TestClass<int(TimeVar,int)> testTime;
100 
101  testVoid.bind();
102  testTime.bind(randTime(),23);
103 
104  cout << showSizeof(testVoid) << endl;
105  cout << showSizeof(testTime) << endl;
106 
107  cout << std::get<0> (testTime) << endl;
108  CHECK (23 == std::get<1> (testTime));
109  }
110 
111  };
112 
113 
114 
116  LAUNCHER (ArgumentTupleAccept_test, "unit controller");
117 
118 
119 }}} // namespace steam::control::test
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
Definition: timevalue.hpp:232
Helper Template for Steam-Layer control::Command : mix in a bind(...) function.
Automatically use custom string conversion in C++ stream output.
typename BuildTupleType< TYPES >::Type Tuple
Build a std::tuple from types given as type sequence.
Definition: run.hpp:40
Mixin-templates providing arbitrary function call operators and argument binding functions.
Helper for uniform access to function signature types.
Definition: function.hpp:99
Steam-Layer implementation namespace root.
Metaprogramming with tuples-of-types and the std::tuple record.
Metaprogramming tools for transforming functor types.
Simplistic test class runner.
A collection of frequently used helper functions to support unit testing.
lib::time::Time randTime()
create a random but not insane Time value between 1s ...