Lumiera  0.pre.03
»edit your freedom«
digxel-configurations-test.cpp
Go to the documentation of this file.
1 /*
2  DigxelConfigurations(Test) - verify predefined standard Digxel configurations
3 
4  Copyright (C)
5  2011, 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"
21 #include "lib/time/digxel.hpp"
22 #include "lib/format-cout.hpp"
23 #include "lib/error.hpp"
24 #include "lib/util.hpp"
25 
26 using LERR_(ASSERTION);
27 using util::typeStr;
28 
29 
30 namespace lib {
31 namespace time{
32 namespace test{
33 
34 
35 
36 
37 
38 
39  /*******************************************************************/
49  class DigxelConfigurations_test : public Test
50  {
51  virtual void
52  run (Arg)
53  {
54  verifyConfiguration<Digxel<int> > (123);
55  verifyConfiguration<Digxel<double>> (123.4567);
56  verifyConfiguration<SexaDigit > (42);
57  verifyConfiguration<SexaDigit > (-5);
58  verifyConfiguration<HexaDigit > (0xc);
59  verifyConfiguration<HexaDigit > (0x6f);
60  verifyConfiguration<CountVal > (-1234567890);
61 
62  verifySignum();
63  }
64 
65 
66  void
67  verifySignum()
68  {
69  Signum sig;
70  CHECK (1 == sig);
71 
72  sig = 123;
73  CHECK (1 == sig);
74  sig = -sig;
75  CHECK (-1 == sig);
76  sig += 98;
77  CHECK (+1 == sig);
78  CHECK (sig.show() == string(" "));
79  sig *= -1;
80  CHECK (sig.show() == string("-"));
81  }
82 
83 
84  template<class DIX, typename VAL>
85  void
86  verifyConfiguration (VAL testval)
87  {
88  DIX digxel;
89  CHECK (0 == digxel);
90  cout << typeStr(digxel) << "--empty--"<<digxel;
91 
92  digxel = testval;
93  cout << "--(val="<<testval<<")--"<<digxel;
94 
95  // verify buffer overrun protection
96  digxel = 123456789.12345;
97  string formatted;
98 #if false
99  VERIFY_ERROR (ASSERTION, formatted = digxel.show() ); // should trigger assertion
100  formatted = digxel.show(); // second time doesn't reformat
101  CHECK (formatted.length() == digxel.maxlen());
102  cout << "--(clipped)--"<< digxel;
103 #endif
104 
105  cout <<"|"<< endl;
106  }
107  };
108 
109 
111  LAUNCHER (DigxelConfigurations_test, "unit common");
112 
113 
114 
115 }}} // namespace lib::time::test
A self-contained numeric element for building structured numeric displays.
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:40
Implementation namespace for support and library code.
Simplistic test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A collection of frequently used helper functions to support unit testing.
Lumiera error handling (C++ interface).
special Digxel to show a sign.
Definition: digxel.hpp:318