Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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"
21#include "lib/time/digxel.hpp"
22#include "lib/format-cout.hpp"
23#include "lib/error.hpp"
24#include "lib/util.hpp"
25
26using LERR_(ASSERTION);
27using util::typeStr;
28
29
30namespace lib {
31namespace time{
32namespace 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
63 }
64
65
66 void
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
112
113
114
115}}} // namespace lib::time::test
digxel::CBuf show() const
Definition digxel.hpp:262
special Digxel to show a sign.
Definition digxel.hpp:318
A self-contained numeric element for building structured numeric displays.
Lumiera error handling (C++ interface).
#define LERR_(_NAME_)
Definition error.hpp:45
Automatically use custom string conversion in C++ stream output.
Implementation namespace for support and library code.
Test runner and basic definitions for tests.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
A collection of frequently used helper functions to support unit testing.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...