parsing fractional seconds: unit test pass
This commit is contained in:
parent
c7bb7154a7
commit
f85c86d6c8
3 changed files with 52 additions and 19 deletions
|
|
@ -67,7 +67,7 @@ namespace time {
|
||||||
TimeValue
|
TimeValue
|
||||||
Frames::parse (string const& frameNumber, QuantR frameGrid)
|
Frames::parse (string const& frameNumber, QuantR frameGrid)
|
||||||
{
|
{
|
||||||
static regex frameNr_parser ("(-?\\d+)#");
|
static regex frameNr_parser ("(?<![\\.\\-\\d])(-?\\d+)#"); // no leading [.-\d], number+'#'
|
||||||
smatch match;
|
smatch match;
|
||||||
if (regex_search (frameNumber, match, frameNr_parser))
|
if (regex_search (frameNumber, match, frameNr_parser))
|
||||||
return frameGrid.timeOf (lexical_cast<int64_t> (match[1]));
|
return frameGrid.timeOf (lexical_cast<int64_t> (match[1]));
|
||||||
|
|
@ -115,7 +115,8 @@ namespace time {
|
||||||
TimeValue
|
TimeValue
|
||||||
Seconds::parse (string const& seconds, QuantR grid)
|
Seconds::parse (string const& seconds, QuantR grid)
|
||||||
{
|
{
|
||||||
static regex fracSecs_parser ("(-?\\d+)(?:([\\-\\+]\\d+)?/(\\d+))?sec");
|
static regex fracSecs_parser ("(?<![\\./\\-\\d])(-?\\d+)(?:([\\-\\+]\\d+)?/(\\d+))?sec");
|
||||||
|
//__no leading[./-\d] number [+-] number '/' number 'sec'
|
||||||
|
|
||||||
#define SUB_EXPR(N) lexical_cast<long> (match[N])
|
#define SUB_EXPR(N) lexical_cast<long> (match[N])
|
||||||
smatch match;
|
smatch match;
|
||||||
|
|
|
||||||
|
|
@ -704,7 +704,7 @@ return: 0
|
||||||
END
|
END
|
||||||
|
|
||||||
|
|
||||||
PLANNED "Parsing time values" TimeParsing_test <<END
|
TEST "Parsing time values" TimeParsing_test <<END
|
||||||
END
|
END
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,23 +25,12 @@
|
||||||
#include "lib/test/test-helper.hpp"
|
#include "lib/test/test-helper.hpp"
|
||||||
#include "proc/asset/meta/time-grid.hpp"
|
#include "proc/asset/meta/time-grid.hpp"
|
||||||
#include "lib/time/quantiser.hpp"
|
#include "lib/time/quantiser.hpp"
|
||||||
//#include "lib/time/timequant.hpp"
|
|
||||||
#include "lib/time/timecode.hpp"
|
#include "lib/time/timecode.hpp"
|
||||||
//#include "lib/time/display.hpp"
|
|
||||||
#include "lib/symbol.hpp"
|
#include "lib/symbol.hpp"
|
||||||
#include "lib/util.hpp"
|
#include "lib/util.hpp"
|
||||||
|
|
||||||
//#include <boost/lexical_cast.hpp>
|
|
||||||
//#include <iostream>
|
|
||||||
//#include <cstdlib>
|
|
||||||
|
|
||||||
//using boost::lexical_cast;
|
|
||||||
//using util::isnil;
|
|
||||||
using lib::Symbol;
|
using lib::Symbol;
|
||||||
using util::cStr;
|
using util::cStr;
|
||||||
//using std::rand;
|
|
||||||
//using std::cout;
|
|
||||||
//using std::endl;
|
|
||||||
|
|
||||||
|
|
||||||
namespace lib {
|
namespace lib {
|
||||||
|
|
@ -51,6 +40,7 @@ namespace test{
|
||||||
using asset::meta::TimeGrid;
|
using asset::meta::TimeGrid;
|
||||||
using format::LUMIERA_ERROR_INVALID_TIMECODE;
|
using format::LUMIERA_ERROR_INVALID_TIMECODE;
|
||||||
|
|
||||||
|
|
||||||
namespace { // Helper for writing test cases
|
namespace { // Helper for writing test cases
|
||||||
|
|
||||||
Symbol DEFAULT_GRID = "pal0";
|
Symbol DEFAULT_GRID = "pal0";
|
||||||
|
|
@ -111,17 +101,25 @@ namespace test{
|
||||||
virtual void
|
virtual void
|
||||||
run (Arg)
|
run (Arg)
|
||||||
{
|
{
|
||||||
TimeGrid::build("pal0", FrameRate::PAL);
|
defineTestTimeGrids();
|
||||||
TimeGrid::build("pal10", FrameRate::PAL, Time(0,10));
|
|
||||||
|
|
||||||
parseFrames();
|
parseFrames();
|
||||||
parseFractionalSeconds();
|
parseFractionalSeconds();
|
||||||
|
/////////////////////////////////////////////TODO
|
||||||
// parseHms();
|
// parseHms();
|
||||||
// parseSmpte();
|
// parseSmpte();
|
||||||
// parseDropFrame();
|
// parseDropFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
defineTestTimeGrids()
|
||||||
|
{
|
||||||
|
TimeGrid::build(DEFAULT_GRID, FrameRate::PAL);
|
||||||
|
TimeGrid::build(OFFSET_GRID, FrameRate::PAL, Time(0,10));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
parseFrames ()
|
parseFrames ()
|
||||||
{
|
{
|
||||||
|
|
@ -141,16 +139,50 @@ namespace test{
|
||||||
|
|
||||||
Parsing<format::Frames> ("xxx25#xxx") .should_yield (1);
|
Parsing<format::Frames> ("xxx25#xxx") .should_yield (1);
|
||||||
Parsing<format::Frames> ("12 25#") .should_yield (1);
|
Parsing<format::Frames> ("12 25#") .should_yield (1);
|
||||||
Parsing<format::Frames> ("12 25# 33#") .should_yield (1);
|
Parsing<format::Frames> ("12 25# 33#") .should_yield (1); // note pitfall: the first valid number is used
|
||||||
Parsing<format::Frames> ("12\n 25# \n 33#") .should_yield (1);
|
Parsing<format::Frames> ("12\n 25# \n 33#") .should_yield (1);
|
||||||
Parsing<format::Frames> ("12.25#") .should_yield (1);
|
Parsing<format::Frames> ("12.25#") .should_fail(); // rejected because of leading dot (ambiguity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
parseFractionalSeconds ()
|
parseFractionalSeconds ()
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED ("verify reading fractional seconds as timecode format");
|
Parsing<format::Seconds> ("0sec") .should_yield (0);
|
||||||
|
Parsing<format::Seconds> ("1sec") .should_yield (1);
|
||||||
|
Parsing<format::Seconds> ("10sec") .should_yield (10);
|
||||||
|
Parsing<format::Seconds> ("100sec") .should_yield (100);
|
||||||
|
Parsing<format::Seconds> ("-10sec") .should_yield (-10);
|
||||||
|
Parsing<format::Seconds> ("-0sec") .should_yield (0);
|
||||||
|
|
||||||
|
Parsing<format::Seconds> ("1/2sec") .should_yield (Time(500,0) );
|
||||||
|
Parsing<format::Seconds> ("1/25sec") .should_yield (Time( 40,0) );
|
||||||
|
Parsing<format::Seconds> ("1/250sec") .should_yield (Time( 4,0) ); // no quantisation involved in parsing
|
||||||
|
Parsing<format::Seconds> ("1/250sec", OFFSET_GRID).should_yield (Time(4,10)); // ...but the origin of the grid is used
|
||||||
|
|
||||||
|
Parsing<format::Seconds> ("10/2sec") .should_yield (5);
|
||||||
|
Parsing<format::Seconds> ("1000/200sec") .should_yield (5);
|
||||||
|
Parsing<format::Seconds> ("-10/2sec") .should_yield (-5);
|
||||||
|
Parsing<format::Seconds> ("10/-2sec") .should_fail(); // only leading sign allowed (ambiguity)
|
||||||
|
|
||||||
|
Parsing<format::Seconds> ("1+1/2sec") .should_yield (Time(500,1) );
|
||||||
|
Parsing<format::Seconds> ("1-1/2sec") .should_yield (Time(500,0) );
|
||||||
|
Parsing<format::Seconds> ("-1-1/2sec") .should_yield (-Time(500,1) );
|
||||||
|
Parsing<format::Seconds> ("-1+1/2sec") .should_yield (-Time(500,0) );
|
||||||
|
Parsing<format::Seconds> ("-1+1/-2sec") .should_fail();
|
||||||
|
|
||||||
|
Parsing<format::Seconds> ("-12+24690/12345sec", OFFSET_GRID).should_yield(0); // origin=+10sec -12sec + 2/1sec == 0
|
||||||
|
|
||||||
|
Parsing<format::Seconds> ("1") .should_fail();
|
||||||
|
Parsing<format::Seconds> ("1 sec") .should_fail();
|
||||||
|
Parsing<format::Seconds> ("--1sec") .should_fail();
|
||||||
|
Parsing<format::Seconds> ("/-1sec") .should_fail();
|
||||||
|
Parsing<format::Seconds> ("1.2sec") .should_fail();
|
||||||
|
Parsing<format::Seconds> ("1/.2sec") .should_fail();
|
||||||
|
Parsing<format::Seconds> ("1 + 2 / 4 sec") .should_fail();
|
||||||
|
Parsing<format::Seconds> ("1 + 2 / 4sec") .should_yield(4); // note pitfall: leading garbage not considered
|
||||||
|
Parsing<format::Seconds> ("xxx4secxxxx") .should_yield(4);
|
||||||
|
Parsing<format::Seconds> ("x1# 8/2sec 2sec").should_yield(4); // note pitfall: first valid number used
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue