Lumiera  0.pre.03
»edit your freedom«
format-cout-test.cpp
Go to the documentation of this file.
1 /*
2  FormatCOUT(Test) - validate automatic string conversion in output
3 
4  Copyright (C) Lumiera.org
5  2016, 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 
30 #include "lib/p.hpp"
31 #include "lib/diff/gen-node.hpp"
32 
33 #include "lib/meta/util.hpp"
34 #include "lib/meta/trait.hpp"
35 #include "lib/format-cout.hpp"
36 
37 #include <string>
38 
39 using lib::P;
40 using lib::makeP;
41 using lib::diff::GenNode;
42 
43 using std::string;
44 
45 
46 namespace util {
47 namespace test {
48 
49  namespace { // test fixture
50 
52  class Reticent
53  {
54  uint neigh_ = 42;
55  };
56 
57 
63 
64  template<typename T>
66  template<typename T>
67  using BasicallyCString = std::is_convertible<T, const char*>;
68 
69 
70 #define SHOW_CHECK(_EXPR_) cout << STRINGIFY(_EXPR_) << "\t : " << (_EXPR_::value? "Yes":"No") << endl;
71 #define ANALYSE(_TYPE_) \
72  cout << "Type: " STRINGIFY(_TYPE_) " ......"<<endl; \
73  SHOW_CHECK (is_StringLike<_TYPE_>); \
74  SHOW_CHECK (BasicallyString<_TYPE_>); \
75  SHOW_CHECK (BasicallyCString<_TYPE_>); \
76  SHOW_CHECK (std::is_arithmetic<_TYPE_>); \
77  SHOW_CHECK (can_lexical2string<_TYPE_>); \
78  SHOW_CHECK (can_convertToString<_TYPE_>); \
79  SHOW_CHECK (use_StringConversion4Stream<_TYPE_>);
80 
81 
82  void
83  showTraits()
84  {
85  using CharLit = decltype("literal");
86  using CharPtr = const char*;
87  using StringPtr = string *;
88  using StringRef = string &;
89  using StringRRef = string &&;
90  using StrConstRef = string const&;
91  using GenNodePtr = GenNode*;
92  using GenNodeRef = GenNode&;
93  using GenNodeRRef = GenNode&&;
94 
95  ANALYSE (int);
96  ANALYSE (char);
97  ANALYSE (double);
98  ANALYSE (int64_t);
99  ANALYSE (string);
100  ANALYSE (StringPtr);
101  ANALYSE (StringRef);
102  ANALYSE (StringRRef);
103  ANALYSE (StrConstRef);
104  ANALYSE (CharLit);
105  ANALYSE (CharPtr)
106  ANALYSE (Reticent)
107  ANALYSE (P<Reticent>)
108  ANALYSE (GenNode)
109  ANALYSE (GenNodePtr)
110  ANALYSE (GenNodeRef)
111  ANALYSE (GenNodeRRef)
112  ANALYSE (P<GenNode>)
113  cout << "───────────────────────────╼━━━━━━━━━━╾───────────────────────────"<<endl;
114  }
115  }//(end)fixture
116 
117 
118 
119 
120  /***************************************************************************/
141  : public Test
142  {
143  void
144  run (Arg)
145  {
146  showTraits();
147 
148  auto silent = makeP<Reticent>();
149  auto chatty = makeP<GenNode>("Hui", "Buh");
150 
151  cout << "smart-ptr, no string conv..." << silent <<endl;
152  cout << "smart-ptr, custom conv......" << chatty <<endl;
153 
154  cout << "reference, no string conv..." << *silent <<endl;
155  cout << "reference, custom conv......" << *chatty <<endl;
156  cout << "pointer, custom conv......" << chatty.get() <<endl;
157 
158  chatty.reset();
159  cout << "smart-ptr, NULL pointee....." << chatty <<endl;
160  cout << "pointer, NULL pointee....." << chatty.get() <<endl;
161  }
162  };
163 
164  LAUNCHER (FormatCOUT_test, "unit common");
165 
166 
167 }} // namespace util::test
168 
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:49
Simple and lightweight helpers for metaprogramming and type detection.
types able to be lexically converted to string representation
Definition: trait.hpp:368
compare for unadorned base type, disregarding const and references
Definition: trait.hpp:329
Customised refcounting smart pointer.
when to use custom string conversions for output streams
Definition: trait.hpp:389
Simple test class runner.
Generic building block for tree shaped (meta)data structures.
Helpers for type detection, type rewriting and metaprogramming.
detect possibility of a conversion to string.
Definition: meta/util.hpp:172
P< X > makeP(ARGS &&... ctorArgs)
Helper to create and manage by lib::P.
Definition: p.hpp:144
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:80
detect various flavours of string / text data
Definition: trait.hpp:344
generic data element node within a tree
Definition: gen-node.hpp:231