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)
5  2012, 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 
21 #include "lib/test/run.hpp"
22 #include "lib/test/test-helper.hpp"
23 
24 #include "steam/play/timings.hpp"
25 #include "lib/time/timevalue.hpp"
26 //#include "lib/time/timequant.hpp"
27 //#include "lib/format-cout.hpp"
28 //#include "lib/util-coll.hpp"
29 #include "lib/util.hpp"
30 
31 //#include <functional>
32 //#include <vector>
33 
34 using test::Test;
35 using util::isnil;
36 //using std::vector;
37 //using std::function;
38 
39 
40 namespace steam {
41 namespace engine{
42 namespace test {
43 
44  using lib::time::FSecs;
45  using lib::time::FrameCnt;
47  using lib::time::Duration;
48  using lib::time::Offset;
49  using lib::time::Time;
50  using play::Timings;
51 
52  namespace { // Test fixture...
53 
54  /* == test parameters == */
55 
56  const uint START_FRAME(10);
57 
58 
59 
60  FSecs
61  randTicks()
62  {
63  return FSecs{1 + rani(600), 1 + rani(600)};
64  }
65 
66  } // (End) Test fixture
67 
68 
69 
70 
71  /***************************************************************/
77  class Timings_test : public Test
78  {
79 
80  virtual void
81  run (Arg)
82  {
83  seedRand();
86  }
87 
88 
92  void
94  {
95  Timings timings (FrameRate::PAL);
96  CHECK (timings.getOrigin() == Time::ZERO);
97 
98  ENSURE (START_FRAME == 10);
99  CHECK (timings.getFrameStartAt(START_FRAME) == Time::ZERO + Duration(10, FrameRate::PAL));
100  CHECK (timings.getFrameStartAt(START_FRAME+1) == Time::ZERO + Duration(11, FrameRate::PAL));
101  }
102 
103 
106  void
108  {
109  Timings timings (FrameRate::PAL);
110  Time refPoint{randTicks()};
111 
112  FrameCnt startFrame = timings.getBreakPointAfter (refPoint);
113  Time frameStart = timings.getFrameStartAt(startFrame);
114 
115  Duration frameDuration (1, FrameRate::PAL);
116 
117  CHECK (frameStart >= refPoint);
118  CHECK (frameStart < refPoint + frameDuration);
119  }
120  };
121 
122 
124  LAUNCHER (Timings_test, "unit engine");
125 
126 
127 
128 }}} // namespace steam::engine::test
FrameCnt getBreakPointAfter(TimeValue refPoint) const
the next grid point at or after the given reference time
Definition: timings.cpp:143
Definition: run.hpp:40
Framerate specified as frames per second.
Definition: timevalue.hpp:655
Generic frame timing specification.
Definition: timings.hpp:86
int rani(uint bound=_iBOUND())
Definition: random.hpp:135
Steam-Layer implementation namespace root.
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
Abstract Base Class for all testcases.
Definition: run.hpp:53
Simplistic test class runner.
void seedRand()
draw a new random seed from a common nucleus, and re-seed the default-Gen.
Definition: suite.cpp:211
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:220
A collection of frequently used helper functions to support unit testing.
Offset measures a distance in time.
Definition: timevalue.hpp:358
How to define a timing specification or constraint.
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:468
int64_t FrameCnt
relative framecount or frame number.
Definition: digxel.hpp:312
a family of time value like entities and their relationships.
static const FrameRate PAL
predefined constant for PAL framerate
Definition: timevalue.hpp:671