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) Lumiera.org
5  2010, 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/test/test-helper.hpp"
30 
31 #include "steam/asset/meta.hpp"
33 #include "lib/time/timevalue.hpp"
34 #include "lib/format-cout.hpp"
35 #include "lib/util.hpp"
36 
37 #include <boost/rational.hpp>
38 
39 using boost::rational_cast;
40 using lib::test::randStr;
41 
42 
43 
44 namespace steam {
45 namespace asset{
46 namespace meta {
47 namespace test {
48 
49  using namespace lib::time;
50 
51  typedef Builder<TimeGrid> GridBuilder;
52 
53  namespace { // Test definitions...
54 
55  const Time TEST_ORIGIN (12,34);
56  const FrameRate TEST_FPS (5,6);
57 
58  const uint MAX_FRAMES = 1000;
59  const uint DIRT_GRAIN = 50;
60  }
61 
62 
63 
64  /***********************************************************************/
71  class TimeGridBasics_test : public Test
72  {
73 
74  virtual void
75  run (Arg)
76  {
77  createGrid_fullProcedure();
78  createGrid_simplified();
79  }
80 
81 
82  void
83  createGrid_fullProcedure()
84  {
85  GridID myGrID (randStr(8));
86  GridBuilder spec = asset::Meta::create (myGrID);
87 
88  CHECK ( spec.fps == 1);
89  CHECK ( spec.origin == TimeValue(0));
90  CHECK (!spec.predecessor);
91 
92  spec.fps = TEST_FPS;
93  spec.origin = TEST_ORIGIN;
94 
95  PGrid myGrid = spec.commit();
96  CHECK (myGrid);
97  CHECK (myGrid->ident.name == myGrID.getSym());
98 
99  // now verify the grid
100  // by performing some conversions...
101  int randomFrame = (rand() % MAX_FRAMES);
102 
103  Time point (myGrid->timeOf (randomFrame));
104  CHECK (point == TEST_ORIGIN + randomFrame * TEST_FPS.duration());
105 
106  int fract = 2 + rand() % DIRT_GRAIN;
107  FSecs dirt = (1/TEST_FPS) / fract;
108  ASSERT (Time(dirt) < TEST_FPS.duration());
109  ASSERT (0 < dirt);
110 
111  Time dirty(point + Time(dirt));
112  CHECK (point == TEST_ORIGIN + myGrid->gridLocal(dirty));
113  }
114 
115 
116  void
117  createGrid_simplified()
118  {
119  PGrid simplePALGrid = TimeGrid::build (FrameRate::PAL);
120  CHECK (simplePALGrid);
121  CHECK (!util::isnil (simplePALGrid->ident.name)); // note: name-ID filled in automatically
122  cout << "simple PAL Grid: " << simplePALGrid->ident << endl;
123 
124  CHECK (Time(0,2) == simplePALGrid->timeOf(50));
125  CHECK (Time(0,2) == simplePALGrid->timeOf(FSecs(2)));
126  }
127  };
128 
129 
130 
132  LAUNCHER (TimeGridBasics_test, "unit asset");
133 
134 
135 }}}} // namespace steam::asset::meta::test
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:49
Framerate specified as frames per second.
Definition: timevalue.hpp:664
typed symbolic and hash ID for asset-like position accounting.
Definition: entry-id.hpp:135
static PGrid build(FrameRate frames_per_second)
Definition: time-grid.cpp:167
Steam-Layer implementation namespace root.
string randStr(size_t len)
create garbage string of given length
Definition: test-helper.cpp:69
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
static MetaFactory create
storage for the static MetaFactory instance
Definition: asset/meta.hpp:123
lib::P< TimeGrid > commit()
create a time grid based on settings within this builder
Definition: time-grid.cpp:145
Internal and organisational metadata.
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.
Duration duration() const
duration of one frame
Definition: time.cpp:263
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:44
basic constant internal time value.
Definition: timevalue.hpp:142
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:118
static const FrameRate PAL
predefined constant for PAL framerate
Definition: timevalue.hpp:680