Lumiera  0.pre.03
»edit your freedom«
timings-test.cpp
1 /*
2  Timings(Test) - document and verify basic frame step timings
3 
4  Copyright (C) Lumiera.org
5  2012, 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 
30 #include "lib/test/run.hpp"
31 #include "lib/test/test-helper.hpp"
32 
33 #include "steam/play/timings.hpp"
34 #include "lib/time/timevalue.hpp"
35 //#include "lib/time/timequant.hpp"
36 //#include "lib/format-cout.hpp"
37 //#include "lib/util-coll.hpp"
38 #include "lib/util.hpp"
39 
40 //#include <functional>
41 //#include <vector>
42 
43 using test::Test;
44 using util::isnil;
45 //using std::vector;
46 //using std::function;
47 using std::rand;
48 
49 
50 namespace steam {
51 namespace engine{
52 namespace test {
53 
54  using lib::time::FSecs;
55  using lib::time::FrameCnt;
57  using lib::time::Duration;
58  using lib::time::Offset;
59  using lib::time::Time;
60  using play::Timings;
61 
62  namespace { // Test fixture...
63 
64  /* == test parameters == */
65 
66  const uint START_FRAME(10);
67 
68 
69 
70  FSecs
71  randTicks()
72  {
73  return FSecs{1 + rand() % 600, 1 + rand() % 600};
74  }
75 
76  } // (End) Test fixture
77 
78 
79 
80 
81  /***************************************************************/
87  class Timings_test : public Test
88  {
89 
90  virtual void
91  run (Arg)
92  {
95  }
96 
97 
101  void
103  {
104  Timings timings (FrameRate::PAL);
105  CHECK (timings.getOrigin() == Time::ZERO);
106 
107  ENSURE (START_FRAME == 10);
108  CHECK (timings.getFrameStartAt(START_FRAME) == Time::ZERO + Duration(10, FrameRate::PAL));
109  CHECK (timings.getFrameStartAt(START_FRAME+1) == Time::ZERO + Duration(11, FrameRate::PAL));
110  }
111 
112 
115  void
117  {
118  Timings timings (FrameRate::PAL);
119  Time refPoint{randTicks()};
120 
121  FrameCnt startFrame = timings.getBreakPointAfter (refPoint);
122  Time frameStart = timings.getFrameStartAt(startFrame);
123 
124  Duration frameDuration (1, FrameRate::PAL);
125 
126  CHECK (frameStart >= refPoint);
127  CHECK (frameStart < refPoint + frameDuration);
128  }
129  };
130 
131 
133  LAUNCHER (Timings_test, "unit engine");
134 
135 
136 
137 }}} // namespace steam::engine::test
FrameCnt getBreakPointAfter(TimeValue refPoint) const
the next grid point at or after the given reference time
Definition: timings.cpp:152
Definition: run.hpp:49
Framerate specified as frames per second.
Definition: timevalue.hpp:664
Generic frame timing specification.
Definition: timings.hpp:95
Steam-Layer implementation namespace root.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
Abstract Base Class for all testcases.
Definition: run.hpp:62
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
A collection of frequently used helper functions to support unit testing.
Offset measures a distance in time.
Definition: timevalue.hpp:367
How to define a timing specification or constraint.
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:477
int64_t FrameCnt
relative framecount or frame number.
Definition: digxel.hpp:321
a family of time value like entities and their relationships.
static const FrameRate PAL
predefined constant for PAL framerate
Definition: timevalue.hpp:680