code unit test to demonstrate full time/timecode usage cycle

This commit is contained in:
Fischlurch 2011-05-14 21:18:13 +02:00
parent f85c86d6c8
commit 4bf53bba0f
3 changed files with 74 additions and 7 deletions

View file

@ -102,7 +102,8 @@ namespace time {
FrameNr (QuTime const& quantisedTime);
// CountVal implicitly convertible to long
using TCode::operator string;
// CountVal implicitly convertible to long
};

View file

@ -699,6 +699,9 @@ END
TEST "Time formats and timecodes" TimeFormats_test <<END
out: Framecount=".+#" time = .+:..:..
out: SMPTE=".+:..:..:.." time = .+:..:..
out-lit: ----SMPTE-----
out-lit: SMPTE=" 5:42:23:13" time = 5:42:23.520
return: 0
END

View file

@ -26,16 +26,19 @@
#include "proc/asset/meta/time-grid.hpp"
#include "lib/time/timequant.hpp"
#include "lib/time/timecode.hpp"
#include "lib/time/mutation.hpp"
#include "lib/time/display.hpp"
#include "lib/util.hpp"
#include <boost/lexical_cast.hpp>
#include <iostream>
//#include <cstdlib>
#include <string>
#include <cstdlib>
using boost::lexical_cast;
using util::isnil;
//using std::rand;
using std::rand;
using std::string;
using std::cout;
using std::endl;
@ -45,6 +48,24 @@ namespace time{
namespace test{
using asset::meta::TimeGrid;
using format::Frames;
using format::Smpte;
namespace{
const int MAX_FRAME = 265*24*60*60*25;
string
generateRandomFrameNr()
{
uint frameNr(0);
while (!frameNr)
frameNr = rand() % (2*MAX_FRAME) - MAX_FRAME;
return lexical_cast<string>(frameNr)+"#";
}
}
/********************************************************
* @test verify handling of grid aligned timecode values.
@ -60,7 +81,7 @@ namespace test{
{
TimeGrid::build("pal0", FrameRate::PAL);
// checkTimecodeUsageCycle ();
checkTimecodeUsageCycle ();
// checkFrames ();
// checkSeconds ();
// checkHms ();
@ -70,13 +91,54 @@ namespace test{
}
/** @test demonstrate a full usage cycle of timecode and time values.
* Starting with a textual representation according to a specific timecode format,
* and based on the knowledge of the implicit underlying time grid (coordinate system,
* here with origin=0 and framerate=25fps), this timecode string may be parsed.
* This brings us (back) to the very origin, which is a raw TimeValue (internal time).
* Now, this time value might be manipulated, compared to other values etc.
* Anyway, at some point these time values need to be related to some time scale again,
* leading to quantised time values, which finally can be cast into a timecode format
* for external representation again, thus closing the circle.
*/
void
checkTimecodeUsageCycle ()
{
UNIMPLEMENTED ("full usage cycle for a timecode value");
string quellCode = generateRandomFrameNr();
PQuant refScale = Quantiser::retrieve("pal0");
/////////TODO: parse-funktion, wie?
/////////TODO: vieleicht doch irgendwo eine Funktion zum Materialisieren?
// get internal (raw) time value
TimeValue t1 = format::Frames::parse(quellCode, *refScale);
ENSURE (0 != t1);
// manipulating
TimeVar v1(t1);
v1 += Time(FSecs(6,5));
CHECK (t1 < v1);
// quantising into an external grid
QuTime q1 (t1, "pal0");
CHECK (q1 == t1);
// further mutations (here nudge by +5 grid steps)
QuTime q2 = q1;
q2.accept (Mutation::nudge(+5));
CHECK (q1 < q2);
// converting (back) into a timecode format
FrameNr frames1(q1);
FrameNr frames2(q2);
CHECK (5 == frames2 - frames1);
q2.accept (Mutation::changeTime(v1));
CHECK (30 == q2.formatAs<Frames>() - frames1);
CHECK (quellCode == string(frames1));
CHECK (quellCode != string(frames2));
showTimeCode (frames1);
showTimeCode (frames2);
showTimeCode (q2.formatAs<Smpte>());
}
@ -125,6 +187,7 @@ namespace test{
QuTime t1 (raw, "pal0");
SmpteTC smpte(t1);
cout << "----SMPTE-----" << endl;
showTimeCode(smpte);
CHECK (" 5:42:23:13" == string(smpte));
CHECK (raw - Time(35,0) == smpte.getTime()); // timecode value got quantised towards next lower frame