Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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"
21
22#include "steam/asset/meta.hpp"
25#include "lib/format-cout.hpp"
26#include "lib/util.hpp"
27
28#include <boost/rational.hpp>
29
30using boost::rational_cast;
32
33
34
35namespace steam {
36namespace asset{
37namespace meta {
38namespace test {
39
40 using namespace lib::time;
41
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();
71 }
72
73
74 void
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
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
125
126
127}}}} // namespace steam::asset::meta::test
Internal and organisational metadata.
string const & getSym() const
Definition entry-id.hpp:169
Framerate specified as frames per second.
Duration duration() const
duration of one frame
Definition time.cpp:286
static const FrameRate PAL
predefined constant for PAL framerate
basic constant internal time value.
Lumiera's internal time value datatype.
static MetaFactory create
storage for the static MetaFactory instance
static PGrid build(FrameRate frames_per_second)
Automatically use custom string conversion in C++ stream output.
unsigned int uint
Definition integral.hpp:29
string randStr(size_t len)
create garbage string of given length
std::shared_ptr< const Grid > PGrid
Definition grid.hpp:70
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Building and configuring a meta asset.
The asset subsystem of the Steam-Layer.
Steam-Layer implementation namespace root.
Test runner and basic definitions for tests.
bool isnil(lib::time::Duration const &dur)
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
typed symbolic and hash ID for asset-like position accounting.
Definition entry-id.hpp:219
lib::P< TimeGrid > predecessor
when building a compound or variable grid, the predecessor is the grid active before the origin of th...
lib::P< TimeGrid > commit()
create a time grid based on settings within this builder
A collection of frequently used helper functions to support unit testing.
To establish a reference scale for quantised time values.
a family of time value like entities and their relationships.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...