Lumiera  0.pre.03
»edit your freedom«
time-quantisation-test.cpp
Go to the documentation of this file.
1 /*
2  TimeQuantisation(Test) - handling of virtually grid aligned time values
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 
20 #include "lib/test/run.hpp"
21 #include "lib/test/test-helper.hpp"
23 #include "lib/time/timequant.hpp"
24 #include "lib/format-cout.hpp"
25 #include "lib/util.hpp"
26 
27 #include <boost/lexical_cast.hpp>
28 
29 using boost::lexical_cast;
30 using util::isnil;
31 using util::contains;
32 
33 
34 namespace lib {
35 namespace time{
36 namespace test{
37 
39 
40 
41  /****************************************************/
50  class TimeQuantisation_test : public Test
51  {
52  int
53  random_or_get (Arg arg)
54  {
55  if (isnil(arg))
56  {// use random time value for all tests
57  seedRand();
58  return 1 + rani(100'000);
59  }
60  else // use argument as 1/10 seconds
61  return 10 * lexical_cast<int> (arg[1]);
62  }
63 
64 
65 
70  virtual void
71  run (Arg arg)
72  {
73  Time ref (random_or_get(arg),0,0,0);
74  CHECK (TimeValue(0) < ref);
75 
76  checkSimpleUsage (ref);
77  check_theFullStory (ref);
78  checkMultipleGrids (ref);
79  checkGridBinding (ref);
80  }
81 
82 
83  void
84  checkSimpleUsage (TimeValue org)
85  {
86  TimeGrid::build("my_simple_grid", 25); // "someone" has defined a time grid
87 
88  QuTime qVal (org, "my_simple_grid"); // create time quantised to this grid
89 
90  FrameNr count(qVal); // materialise this quantised time into..
91  int n = count; // frame count, accessible as plain number
92 
93  CHECK (Time(FSecs(n, 25)) <= org); // verify quantisation: the original time
94  CHECK (org < Time(FSecs(n+1, 25))); // is properly bracketed by [n, n+1[
95  }
96 
97 
98  void
99  check_theFullStory (TimeValue org)
100  {
101  cout << "TEST rawTime:"<<Time{org} << endl;
102  PQuant fixQ (new FixedFrameQuantiser(25));
103  QuTime qVal (org, fixQ);
104 
105  CHECK ( qVal == org); // Note: stores the raw value, but tagged with a grid
106  CHECK ( fixQ.get() == PQuant(qVal).get());
107  CHECK ( qVal.supports<format::Frames>());
108  CHECK ( qVal.supports<format::Smpte>());
109 
110  SmpteTC smpteTCode = qVal.formatAs<format::Smpte>();
111  showTimeCode (smpteTCode);
112 
113  HmsTC pureTimeCode = qVal.formatAs<format::Hms>();
114  showTimeCode (pureTimeCode); ////////////////////////////////////////////////////////////////TICKET #736 : HMS not implemented yet
115 
116  FrameNr frameTCode = qVal.formatAs<format::Frames>();
117  showTimeCode (frameTCode);
118 
119  Secs seconds = qVal.formatAs<format::Seconds>();
120  showTimeCode (seconds); ////////////////////////////////////////////////////////////////TICKET #736 : Seconds not implemented yet
121  }
122 
123  template<class TC>
124  void
125  showTimeCode (TC timecodeValue)
126  {
127  cout << timecodeValue.describe()
128  << " time = "<< timecodeValue.getTime()
129  << " code = "<< timecodeValue
130  << endl;
131  }
132 
133 
134  void
135  checkMultipleGrids (TimeValue org)
136  {
137  TimeGrid::build("my_alternate_grid", FrameRate::NTSC);
138 
139  QuTime palVal (org, "my_simple_grid");
140  QuTime ntscVal (org, "my_alternate_grid");
141 
142  CHECK (org == palVal);
143  CHECK (org == ntscVal);
144 
145  FrameNr palNr (palVal);
146  FrameNr ntscNr(ntscVal);
147  CHECK (palNr <= ntscNr);
148  }
149 
150 
151  void
152  checkGridBinding (TimeValue org)
153  {
154  // refer to a grid not yet defined
155  VERIFY_ERROR (UNKNOWN_GRID, QuTime weird(org, "special_funny_grid"));
156 
157  TimeGrid::build("special_funny_grid", 1); // provide the grid's definition (1 frame per second)
158 
159  QuTime funny (org, "special_funny_grid"); // now OK, grid is known
160  int cnt = funny.formatAs<format::Frames>();
161  // and now performing quantisation is OK
162  SmpteTC smpte (funny); // also converting into SMPTE (which implies frame quantisation)
163  CHECK (0 == smpte.frames); // we have 1fps, thus the frame part is always zero!
164  CHECK (cnt % 60 == smpte.secs); // and the seconds part will be in sync with the frame count
165  }
166  };
167 
168 
170  LAUNCHER (TimeQuantisation_test, "unit common");
171 
172 
173 
174 }}} // namespace lib::time::test
Interface: a grid and scale definition for time quantisation.
Definition: time-grid.hpp:77
Frame count as timecode format.
Definition: formats.hpp:75
Automatically use custom string conversion in C++ stream output.
Classical Timecode value reminiscent to SMPTE format.
Definition: timecode.hpp:141
Definition: run.hpp:40
int rani(uint bound=_iBOUND())
Definition: random.hpp:135
Implementation namespace for support and library code.
format::Traits< FMT >::TimeCode formatAs() const
create new time code instance, then castInto
Definition: timequant.hpp:138
Simplistic test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A collection of frequently used helper functions to support unit testing.
Support library to represent grid-aligned time specifications This is part of Lumiera&#39;s time and time...
To establish a reference scale for quantised time values.
bool contains(SEQ const &cont, typename SEQ::const_reference val)
shortcut for brute-force containment test in any sequential container
Definition: util.hpp:255
grid aligned time specification, referring to a specific scale.
Definition: timequant.hpp:90