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)
5  2016, 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 
21 #include "lib/p.hpp"
22 #include "lib/diff/gen-node.hpp"
23 
24 #include "lib/meta/util.hpp"
25 #include "lib/meta/trait.hpp"
26 #include "lib/format-cout.hpp"
27 
28 #include <string>
29 
30 using lib::P;
31 using lib::makeP;
32 using lib::diff::GenNode;
33 
34 using std::string;
35 
36 
37 namespace util {
38 namespace test {
39 
40  namespace { // test fixture
41 
43  class Reticent
44  {
45  uint neigh_ = 42;
46  };
47 
48 
54 
55  template<typename T>
57  template<typename T>
58  using BasicallyCString = std::is_convertible<T, const char*>;
59 
60 
61 #define SHOW_CHECK(_EXPR_) cout << STRINGIFY(_EXPR_) << "\t : " << (_EXPR_::value? "Yes":"No") << endl;
62 #define ANALYSE(_TYPE_) \
63  cout << "Type: " STRINGIFY(_TYPE_) " ......"<<endl; \
64  SHOW_CHECK (is_StringLike<_TYPE_>); \
65  SHOW_CHECK (BasicallyString<_TYPE_>); \
66  SHOW_CHECK (BasicallyCString<_TYPE_>); \
67  SHOW_CHECK (std::is_arithmetic<_TYPE_>); \
68  SHOW_CHECK (can_lexical2string<_TYPE_>); \
69  SHOW_CHECK (can_convertToString<_TYPE_>); \
70  SHOW_CHECK (use_StringConversion4Stream<_TYPE_>);
71 
72 
73  void
74  showTraits()
75  {
76  using CharLit = decltype("literal");
77  using CharPtr = const char*;
78  using StringPtr = string *;
79  using StringRef = string &;
80  using StringRRef = string &&;
81  using StrConstRef = string const&;
82  using GenNodePtr = GenNode*;
83  using GenNodeRef = GenNode&;
84  using GenNodeRRef = GenNode&&;
85 
86  ANALYSE (int);
87  ANALYSE (char);
88  ANALYSE (double);
89  ANALYSE (int64_t);
90  ANALYSE (string);
91  ANALYSE (StringPtr);
92  ANALYSE (StringRef);
93  ANALYSE (StringRRef);
94  ANALYSE (StrConstRef);
95  ANALYSE (CharLit);
96  ANALYSE (CharPtr)
97  ANALYSE (Reticent)
98  ANALYSE (P<Reticent>)
99  ANALYSE (GenNode)
100  ANALYSE (GenNodePtr)
101  ANALYSE (GenNodeRef)
102  ANALYSE (GenNodeRRef)
103  ANALYSE (P<GenNode>)
104  cout << "───────────────────────────╼━━━━━━━━━━╾───────────────────────────"<<endl;
105  }
106  }//(end)fixture
107 
108 
109 
110 
111  /***************************************************************************/
132  : public Test
133  {
134  void
135  run (Arg)
136  {
137  showTraits();
138 
139  auto silent = makeP<Reticent>();
140  auto chatty = makeP<GenNode>("Hui", "Buh");
141 
142  cout << "smart-ptr, no string conv..." << silent <<endl;
143  cout << "smart-ptr, custom conv......" << chatty <<endl;
144 
145  cout << "reference, no string conv..." << *silent <<endl;
146  cout << "reference, custom conv......" << *chatty <<endl;
147  cout << "pointer, custom conv......" << chatty.get() <<endl;
148 
149  chatty.reset();
150  cout << "smart-ptr, NULL pointee....." << chatty <<endl;
151  cout << "pointer, NULL pointee....." << chatty.get() <<endl;
152  }
153  };
154 
155  LAUNCHER (FormatCOUT_test, "unit common");
156 
157 
158 }} // namespace util::test
159 
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:40
Simple and lightweight helpers for metaprogramming and type detection.
types able to be lexically converted to string representation
Definition: trait.hpp:373
compare for unadorned base type, disregarding const and references
Definition: trait.hpp:334
Customised refcounting smart pointer.
when to use custom string conversions for output streams
Definition: trait.hpp:394
Simplistic 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:163
P< X > makeP(ARGS &&... ctorArgs)
Helper to create and manage by lib::P.
Definition: p.hpp:135
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:71
detect various flavours of string / text data
Definition: trait.hpp:349
generic data element node within a tree
Definition: gen-node.hpp:222