diff --git a/src/lib/time/timecode.cpp b/src/lib/time/timecode.cpp index 3f0331e7e..4cce6fd66 100644 --- a/src/lib/time/timecode.cpp +++ b/src/lib/time/timecode.cpp @@ -67,7 +67,7 @@ namespace time { TimeValue Frames::parse (string const& frameNumber, QuantR frameGrid) { - static regex frameNr_parser ("(-?\\d+)#"); + static regex frameNr_parser ("(? (match[1])); @@ -115,7 +115,8 @@ namespace time { TimeValue Seconds::parse (string const& seconds, QuantR grid) { - static regex fracSecs_parser ("(-?\\d+)(?:([\\-\\+]\\d+)?/(\\d+))?sec"); + static regex fracSecs_parser ("(? (match[N]) smatch match; diff --git a/tests/40components.tests b/tests/40components.tests index c8cd30aad..320c283c3 100644 --- a/tests/40components.tests +++ b/tests/40components.tests @@ -704,7 +704,7 @@ return: 0 END -PLANNED "Parsing time values" TimeParsing_test < -//#include -//#include - -//using boost::lexical_cast; -//using util::isnil; using lib::Symbol; using util::cStr; -//using std::rand; -//using std::cout; -//using std::endl; namespace lib { @@ -51,6 +40,7 @@ namespace test{ using asset::meta::TimeGrid; using format::LUMIERA_ERROR_INVALID_TIMECODE; + namespace { // Helper for writing test cases Symbol DEFAULT_GRID = "pal0"; @@ -111,17 +101,25 @@ namespace test{ virtual void run (Arg) { - TimeGrid::build("pal0", FrameRate::PAL); - TimeGrid::build("pal10", FrameRate::PAL, Time(0,10)); + defineTestTimeGrids(); parseFrames(); parseFractionalSeconds(); +/////////////////////////////////////////////TODO // parseHms(); // parseSmpte(); // parseDropFrame(); } + void + defineTestTimeGrids() + { + TimeGrid::build(DEFAULT_GRID, FrameRate::PAL); + TimeGrid::build(OFFSET_GRID, FrameRate::PAL, Time(0,10)); + } + + void parseFrames () { @@ -141,16 +139,50 @@ namespace test{ Parsing ("xxx25#xxx") .should_yield (1); Parsing ("12 25#") .should_yield (1); - Parsing ("12 25# 33#") .should_yield (1); + Parsing ("12 25# 33#") .should_yield (1); // note pitfall: the first valid number is used Parsing ("12\n 25# \n 33#") .should_yield (1); - Parsing ("12.25#") .should_yield (1); + Parsing ("12.25#") .should_fail(); // rejected because of leading dot (ambiguity) } void parseFractionalSeconds () { - UNIMPLEMENTED ("verify reading fractional seconds as timecode format"); + Parsing ("0sec") .should_yield (0); + Parsing ("1sec") .should_yield (1); + Parsing ("10sec") .should_yield (10); + Parsing ("100sec") .should_yield (100); + Parsing ("-10sec") .should_yield (-10); + Parsing ("-0sec") .should_yield (0); + + Parsing ("1/2sec") .should_yield (Time(500,0) ); + Parsing ("1/25sec") .should_yield (Time( 40,0) ); + Parsing ("1/250sec") .should_yield (Time( 4,0) ); // no quantisation involved in parsing + Parsing ("1/250sec", OFFSET_GRID).should_yield (Time(4,10)); // ...but the origin of the grid is used + + Parsing ("10/2sec") .should_yield (5); + Parsing ("1000/200sec") .should_yield (5); + Parsing ("-10/2sec") .should_yield (-5); + Parsing ("10/-2sec") .should_fail(); // only leading sign allowed (ambiguity) + + Parsing ("1+1/2sec") .should_yield (Time(500,1) ); + Parsing ("1-1/2sec") .should_yield (Time(500,0) ); + Parsing ("-1-1/2sec") .should_yield (-Time(500,1) ); + Parsing ("-1+1/2sec") .should_yield (-Time(500,0) ); + Parsing ("-1+1/-2sec") .should_fail(); + + Parsing ("-12+24690/12345sec", OFFSET_GRID).should_yield(0); // origin=+10sec -12sec + 2/1sec == 0 + + Parsing ("1") .should_fail(); + Parsing ("1 sec") .should_fail(); + Parsing ("--1sec") .should_fail(); + Parsing ("/-1sec") .should_fail(); + Parsing ("1.2sec") .should_fail(); + Parsing ("1/.2sec") .should_fail(); + Parsing ("1 + 2 / 4 sec") .should_fail(); + Parsing ("1 + 2 / 4sec") .should_yield(4); // note pitfall: leading garbage not considered + Parsing ("xxx4secxxxx") .should_yield(4); + Parsing ("x1# 8/2sec 2sec").should_yield(4); // note pitfall: first valid number used }