Lumiera  0.pre.03
»edit your freedom«
duck-detector-extension-test.cpp
Go to the documentation of this file.
1 /*
2  DuckDetectorExtension(Test) - detecting support for extension points at compile time
3 
4  Copyright (C)
5  2017, 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"
21 #include "lib/util.hpp"
22 
23 #include <string>
24 
25 
26 namespace lib {
27 namespace meta{
28 namespace test{
29 
30  using std::string;
31 
32 
33  namespace { // test types and definitions to explore....
34 
35  void
36  fun (long)
37  { }
38 
39  int
40  fun (string, long)
41  {
42  return 12;
43  }
44 
45  void
46  fun ()
47  { }
48 
49 
50  class Cheesy
51  {
52  public:
53  double funny (char, char, string);
54  void funky() const;
55  short fuzzy (float, float);
56  llong fuzzy();
57  double fully;
58  };
59 
60  class Fishy
61  {
63  llong fuzzy();
64 
66  friend void fun (Fishy&);
67  };
68 
69 
70  }//(End) test definitions
71 
72 
73 
74 
75  /***********************************************************************************/
90  class DuckDetectorExtension_test : public Test
91  {
92 
95 
96  META_DETECT_FUNCTION (double, funny, (char, char, string));
97  META_DETECT_FUNCTION (llong, fuzzy, (void));
102  META_DETECT_MEMBER(funny);
103  META_DETECT_MEMBER(funky);
104  META_DETECT_MEMBER(fuzzy);
105  META_DETECT_MEMBER(fully);
109 
110 
111  void
112  run (Arg)
113  {
114  detect_freeFunctionADL_ExtensionPoint();
115  detect_memberFunctionVariations();
116  }
117 
118 
134  void
136  {
137  fun ();
138  fun (23);
139  fun ("FUN", 45);
140 
141  CHECK ( not HasExtensionPoint_funZ<long>::value );
142 
143  CHECK ( HasExtensionPoint_fun<long> ::value );
144  CHECK ( HasExtensionPoint_fun<long&> ::value );
145  CHECK ( HasExtensionPoint_fun<long&&> ::value );
146  CHECK ( HasExtensionPoint_fun<char> ::value );
147  CHECK ( HasExtensionPoint_fun<char&> ::value );
148  CHECK ( HasExtensionPoint_fun<char&&> ::value );
149  CHECK ( not HasExtensionPoint_fun<string> ::value );
150  CHECK ( not HasExtensionPoint_fun<void> ::value );
151 
152  CHECK ( not HasExtensionPoint_fun<Cheesy> ::value );
153  CHECK ( not HasExtensionPoint_fun<Fishy> ::value );
154  CHECK ( HasExtensionPoint_fun<Fishy&> ::value );
155  CHECK ( not HasExtensionPoint_fun<Fishy&&> ::value );
156  CHECK ( not HasExtensionPoint_fun<Fishy const&>::value );
157 
158  CHECK ( not HasExtensionPoint_fun<Fishy const&>::value );
159  }
160 
161 
171  void
173  {
174  CHECK ( HasFunSig_funny<Cheesy> ::value ); // explicit function signature detected
175  CHECK ( HasFunSig_funny<Cheesy const> ::value ); // const qualifier is irrelevant
176  CHECK ( not HasFunSig_funny<Cheesy const&> ::value ); // but reference does not work, obviously
177 
178  CHECK ( HasFunSig_fuzzy<Cheesy> ::value ); // explicit function signature detected, overload is irrelevant
179 
180  CHECK ( HasFunName_funny<Cheesy> ::value ); // function name detected (arguments irrelevant)
181  CHECK ( HasFunName_funky<Cheesy> ::value ); // detected irrespective of const modifier
182  CHECK ( not HasFunName_fuzzy<Cheesy> ::value ); // function name fuzzy *not* detected due to overload ambiguity
183  CHECK ( not HasFunName_fully<Cheesy> ::value ); // name fully is a member, not a function
184 
185  CHECK ( HasMember_funny<Cheesy> ::value ); // 'funny' is not only a function, it is also a member
186  CHECK ( HasMember_funky<Cheesy> ::value );
187  CHECK ( not HasMember_fuzzy<Cheesy> ::value ); // WARNING: member 'fuzzy' *not* detected due to overload ambiguity
188  CHECK ( HasMember_fully<Cheesy> ::value ); // 'fully' is not a function, but it is detected as member here
189 
190  CHECK ( not HasArglessFun_funny<Cheesy> ::value ); // there is no argument less function 'funny' (it takes arguments)
191  CHECK ( HasArglessFun_funky<Cheesy> ::value ); // but an argument-less 'funky'
192  CHECK ( HasArglessFun_fuzzy<Cheesy> ::value ); // and one of the 'fuzzy' overloads also takes no arguments
193 
194  CHECK ( not HasFunSig_fuzzy<Fishy> ::value ); // Fishy::fuzzy() is private and can thus never be detected
195  CHECK ( not HasFunSig_funny<Fishy> ::value ); // and no fun with Fishy beyond that...
196  CHECK ( not HasFunName_funny<Fishy> ::value );
197  CHECK ( not HasFunName_funky<Fishy> ::value );
198  CHECK ( not HasFunName_fuzzy<Fishy> ::value );
199  CHECK ( not HasFunName_fully<Fishy> ::value );
200  CHECK ( not HasMember_funny<Fishy> ::value );
201  CHECK ( not HasMember_funky<Fishy> ::value );
202  CHECK ( not HasMember_fuzzy<Fishy> ::value );
203  CHECK ( not HasMember_fully<Fishy> ::value );
204  CHECK ( not HasArglessFun_funny<Fishy> ::value );
205  CHECK ( not HasArglessFun_funky<Fishy> ::value );
206  CHECK ( not HasArglessFun_fuzzy<Fishy> ::value );
207  CHECK ( not HasFunSig_fuzzy<short> ::value );
208  }
209  };
210 
211 
213  LAUNCHER (DuckDetectorExtension_test, "unit meta");
214 
215 
216 
217 }}} // namespace lib::meta::test
Definition: run.hpp:40
#define META_DETECT_MEMBER(_NAME_)
Detector for a nested member (field or function).
#define META_DETECT_FUNCTION(_RET_TYPE_, _FUN_NAME_, _ARGS_)
Detector for a specific member function.
Implementation namespace for support and library code.
#define META_DETECT_FUNCTION_ARGLESS(_FUN_)
Detector for an argument-less member function with the given name.
Simplistic test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
#define META_DETECT_FUNCTION_NAME(_FUN_NAME_)
Detector for a member function with the given name.
#define META_DETECT_EXTENSION_POINT(_FUN_)
Detector for support of a free-function extension point.
Metaprogramming helpers to check for specific properties of a type in question.