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) Lumiera.org
5  2011, 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 #include "lib/test/test-helper.hpp"
30 #include "lib/time/digxel.hpp"
31 #include "lib/format-cout.hpp"
32 #include "lib/error.hpp"
33 #include "lib/util.hpp"
34 
35 #include <cstdlib>
36 
37 using LERR_(ASSERTION);
38 using util::isSameObject;
39 using util::typeStr;
40 using std::rand;
41 
42 
43 namespace lib {
44 namespace time{
45 namespace test{
46 
47 
48 
49 
50 
51 
52  /*******************************************************************/
62  class DigxelConfigurations_test : public Test
63  {
64  virtual void
65  run (Arg)
66  {
67  verifyConfiguration<Digxel<int> > (123);
68  verifyConfiguration<Digxel<double>> (123.4567);
69  verifyConfiguration<SexaDigit > (42);
70  verifyConfiguration<SexaDigit > (-5);
71  verifyConfiguration<HexaDigit > (0xc);
72  verifyConfiguration<HexaDigit > (0x6f);
73  verifyConfiguration<CountVal > (-1234567890);
74 
75  verifySignum();
76  }
77 
78 
79  void
80  verifySignum()
81  {
82  Signum sig;
83  CHECK (1 == sig);
84 
85  sig = 123;
86  CHECK (1 == sig);
87  sig = -sig;
88  CHECK (-1 == sig);
89  sig += 98;
90  CHECK (+1 == sig);
91  CHECK (sig.show() == string(" "));
92  sig *= -1;
93  CHECK (sig.show() == string("-"));
94  }
95 
96 
97  template<class DIX, typename VAL>
98  void
99  verifyConfiguration (VAL testval)
100  {
101  DIX digxel;
102  CHECK (0 == digxel);
103  cout << typeStr(digxel) << "--empty--"<<digxel;
104 
105  digxel = testval;
106  cout << "--(val="<<testval<<")--"<<digxel;
107 
108  // verify buffer overrun protection
109  digxel = 123456789.12345;
110  string formatted;
111 #if false
112  VERIFY_ERROR (ASSERTION, formatted = digxel.show() ); // should trigger assertion
113  formatted = digxel.show(); // second time doesn't reformat
114  CHECK (formatted.length() == digxel.maxlen());
115  cout << "--(clipped)--"<< digxel;
116 #endif
117 
118  cout <<"|"<< endl;
119  }
120  };
121 
122 
124  LAUNCHER (DigxelConfigurations_test, "unit common");
125 
126 
127 
128 }}} // 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:49
Implementation namespace for support and library code.
Simple 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:327
bool isSameObject(A const &a, B const &b)
compare plain object identity, bypassing any custom comparison operators.
Definition: util.hpp:372