Lumiera  0.pre.03
»edit your freedom«
time-grid-basics-test.cpp
Go to the documentation of this file.
1 /*
2  TimeGridBasics(Test) - verify a simple reference scale for time quantisation
3 
4  Copyright (C)
5  2010, 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"
20 #include "lib/test/test-helper.hpp"
21 
22 #include "steam/asset/meta.hpp"
24 #include "lib/time/timevalue.hpp"
25 #include "lib/format-cout.hpp"
26 #include "lib/util.hpp"
27 
28 #include <boost/rational.hpp>
29 
30 using boost::rational_cast;
31 using lib::test::randStr;
32 
33 
34 
35 namespace steam {
36 namespace asset{
37 namespace meta {
38 namespace test {
39 
40  using namespace lib::time;
41 
42  typedef Builder<TimeGrid> GridBuilder;
43 
44  namespace { // Test definitions...
45 
46  const Time TEST_ORIGIN (12,34);
47  const FrameRate TEST_FPS (5,6);
48 
49  const uint MAX_FRAMES = 1000;
50  const uint DIRT_GRAIN = 50;
51  }
52 
53 
54 
55  /***********************************************************************/
62  class TimeGridBasics_test : public Test
63  {
64 
65  virtual void
66  run (Arg)
67  {
68  seedRand();
69  createGrid_fullProcedure();
70  createGrid_simplified();
71  }
72 
73 
74  void
75  createGrid_fullProcedure()
76  {
77  GridID myGrID (randStr(8));
78  GridBuilder spec = asset::Meta::create (myGrID);
79 
80  CHECK ( spec.fps == 1);
81  CHECK ( spec.origin == TimeValue(0));
82  CHECK (!spec.predecessor);
83 
84  spec.fps = TEST_FPS;
85  spec.origin = TEST_ORIGIN;
86 
87  PGrid myGrid = spec.commit();
88  CHECK (myGrid);
89  CHECK (myGrid->ident.name == myGrID.getSym());
90 
91  // now verify the grid
92  // by performing some conversions...
93  int randomFrame = rani(MAX_FRAMES);
94 
95  Time point (myGrid->timeOf (randomFrame));
96  CHECK (point == TEST_ORIGIN + randomFrame * TEST_FPS.duration());
97 
98  int fract = 2 + rani(DIRT_GRAIN);
99  FSecs dirt = (1/TEST_FPS) / fract;
100  ASSERT (Time(dirt) < TEST_FPS.duration());
101  ASSERT (0 < dirt);
102 
103  Time dirty(point + Time(dirt));
104  CHECK (point == TEST_ORIGIN + myGrid->gridLocal(dirty));
105  }
106 
107 
108  void
109  createGrid_simplified()
110  {
111  PGrid simplePALGrid = TimeGrid::build (FrameRate::PAL);
112  CHECK (simplePALGrid);
113  CHECK (!util::isnil (simplePALGrid->ident.name)); // note: name-ID filled in automatically
114  cout << "simple PAL Grid: " << simplePALGrid->ident << endl;
115 
116  CHECK (Time(0,2) == simplePALGrid->timeOf(50));
117  CHECK (Time(0,2) == simplePALGrid->timeOf(FSecs(2)));
118  }
119  };
120 
121 
122 
124  LAUNCHER (TimeGridBasics_test, "unit asset");
125 
126 
127 }}}} // namespace steam::asset::meta::test
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:40
Framerate specified as frames per second.
Definition: timevalue.hpp:655
typed symbolic and hash ID for asset-like position accounting.
Definition: entry-id.hpp:126
int rani(uint bound=_iBOUND())
Definition: random.hpp:135
static PGrid build(FrameRate frames_per_second)
Definition: time-grid.cpp:158
Steam-Layer implementation namespace root.
string randStr(size_t len)
create garbage string of given length
Definition: test-helper.cpp:61
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
static MetaFactory create
storage for the static MetaFactory instance
Definition: asset/meta.hpp:114
lib::P< TimeGrid > commit()
create a time grid based on settings within this builder
Definition: time-grid.cpp:136
Internal and organisational metadata.
Simplistic 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:220
A collection of frequently used helper functions to support unit testing.
Duration duration() const
duration of one frame
Definition: time.cpp:254
To establish a reference scale for quantised time values.
a family of time value like entities and their relationships.
The asset subsystem of the Steam-Layer.
Definition: wrapperptr.hpp:35
basic constant internal time value.
Definition: timevalue.hpp:133
lib::P< TimeGrid > predecessor
when building a compound or variable grid, the predecessor is the grid active before the origin of th...
Definition: time-grid.hpp:109
static const FrameRate PAL
predefined constant for PAL framerate
Definition: timevalue.hpp:671