Lumiera  0.pre.03
»edit your freedom«
time-basics-test.cpp
Go to the documentation of this file.
1 /*
2  TimeBasics(Test) - working with Lumiera's internal Time values
3 
4  Copyright (C) Lumiera.org
5  2008, 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/time/timevalue.hpp"
30 #include "lib/time/diagnostics.hpp"
31 #include "lib/format-cout.hpp"
32 #include "lib/util.hpp"
33 
34 #include <boost/lexical_cast.hpp>
35 #include <cstdlib>
36 
37 using boost::lexical_cast;
38 using util::isnil;
39 using std::rand;
40 
41 
42 namespace lib {
43 namespace test{
44 
45  using time::Time;
46  using time::TimeVar;
47  using time::FSecs;
48 
49 
50  /****************************************/
53  class TimeBasics_test : public Test
54  {
55  virtual void
56  run (Arg arg)
57  {
58  FSecs refval = isnil(arg)? 1 : lexical_cast<long> (arg[1]);
59 
60  Time org(refval);
61 
62  checkBasics (org);
63  checkComparisons (org);
64  checkComponentDiagnostics();
65  }
66 
67 
68  void
69  checkBasics (Time const& ref)
70  {
71  Time zero;
72  Time two (FSecs(2));
73  Time max (Time::MAX);
74  Time min (Time::MIN);
75 
76  TimeVar var (ref);
77 
78  var += two;
79  var *= 2;
80  CHECK (zero == (var - 2*(ref + two)) );
81 
82  var = ref;
83  CHECK (zero == (var - ref));
84  }
85 
86 
87  void
88  checkComparisons (Time const& ref)
89  {
90  Time zero;
91  Time max (Time::MAX);
92  Time min (Time::MIN);
93 
94  CHECK (zero == Time());
95  CHECK (min < zero);
96  CHECK (max > zero);
97 
98  TimeVar var (ref);
99  CHECK ( (var == ref) );
100  CHECK (!(var != ref) );
101  CHECK ( (var >= ref) );
102  CHECK ( (var <= ref) );
103  CHECK (!(var < ref) );
104  CHECK (!(var > ref) );
105 
106  var += Time(FSecs(2));
107  CHECK (!(var == ref) );
108  CHECK ( (var != ref) );
109  CHECK ( (var >= ref) );
110  CHECK (!(var <= ref) );
111  CHECK (!(var < ref) );
112  CHECK ( (var > ref) );
113 
114  gavl_time_t gat(var);
115  CHECK (!(gat == ref) );
116  CHECK ( (gat != ref) );
117  CHECK ( (gat >= ref) );
118  CHECK (!(gat <= ref) );
119  CHECK (!(gat < ref) );
120  CHECK ( (gat > ref) );
121 
122  CHECK ( (var == gat) );
123  CHECK (!(var != gat) );
124  CHECK ( (var >= gat) );
125  CHECK ( (var <= gat) );
126  CHECK (!(var < gat) );
127  CHECK (!(var > gat) );
128  }
129 
130 
131  void
132  checkComponentDiagnostics()
133  {
134  int millis = rand() % 1000;
135  int secs = rand() % 60;
136  int mins = rand() % 60;
137  int hours = rand() % 100;
138 
139  Time time(millis,secs,mins,hours);
140  CHECK (Time() < time);
141  CHECK (millis == getMillis(time));
142  CHECK (secs == getSecs (time));
143  CHECK (mins == getMins (time));
144  CHECK (hours == getHours (time));
145  cout << time << endl;
146 
147  Time t2(2008,0);
148  cout << t2 << endl;
149  CHECK ( 8 == getMillis(t2));
150  CHECK ( 2 == getSecs (t2));
151  CHECK ( 0 == getMins (t2));
152  CHECK ( 0 == getHours (t2));
153 
154  Time t3(2008,88);
155  cout << t3 << endl;
156  CHECK ( 8 == getMillis(t3));
157  CHECK (30 == getSecs (t3));
158  CHECK ( 1 == getMins (t3));
159  CHECK ( 0 == getHours (t3));
160 
161  Time t4(2008,118,58);
162  cout << t4 << endl;
163  CHECK ( 8 == getMillis(t4));
164  CHECK ( 0 == getSecs (t4));
165  CHECK ( 0 == getMins (t4));
166  CHECK ( 1 == getHours (t4));
167  }
168  };
169 
170 
172  LAUNCHER (TimeBasics_test, "unit common");
173 
174 
175 
176 }} // namespace lib::test
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
Definition: timevalue.hpp:241
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:49
Extension to the lib::time::Time wrapper, adding output and further diagnostic aids.
Implementation namespace for support and library code.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Definition: timevalue.hpp:229
ExampleStrategy::Qualifier two(string additionalArg)
definition of another qualifier two(arg), accepting an additional argument
a family of time value like entities and their relationships.
static const Time MAX
Definition: timevalue.hpp:318