From c7bb7154a720071916737f5b4e2c4016d1a88cdc Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 13 May 2011 07:46:21 +0200 Subject: [PATCH] draft a test to cover parsing of timecode values --- src/lib/time/lumitime.cpp | 2 +- tests/40components.tests | 4 + tests/lib/time/time-parsing-test.cpp | 183 +++++++++++++++++++++++++++ 3 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 tests/lib/time/time-parsing-test.cpp diff --git a/src/lib/time/lumitime.cpp b/src/lib/time/lumitime.cpp index af3313772..bb1c0e1a0 100644 --- a/src/lib/time/lumitime.cpp +++ b/src/lib/time/lumitime.cpp @@ -58,7 +58,7 @@ namespace time { , uint hours ) : TimeValue(lumiera_build_time (millis,secs,mins,hours)) - { } + { } /** convenience constructor to build an Time value diff --git a/tests/40components.tests b/tests/40components.tests index 51b9c54bc..c8cd30aad 100644 --- a/tests/40components.tests +++ b/tests/40components.tests @@ -704,6 +704,10 @@ return: 0 END +PLANNED "Parsing time values" TimeParsing_test < + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +* *****************************************************/ + + +#include "lib/test/run.hpp" +#include "lib/test/test-helper.hpp" +#include "proc/asset/meta/time-grid.hpp" +#include "lib/time/quantiser.hpp" +//#include "lib/time/timequant.hpp" +#include "lib/time/timecode.hpp" +//#include "lib/time/display.hpp" +#include "lib/symbol.hpp" +#include "lib/util.hpp" + +//#include +//#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 { +namespace time{ +namespace test{ + + using asset::meta::TimeGrid; + using format::LUMIERA_ERROR_INVALID_TIMECODE; + + namespace { // Helper for writing test cases + + Symbol DEFAULT_GRID = "pal0"; + Symbol OFFSET_GRID = "pal10"; + + /** + * Expression builder + * for writing time value parsing tests + */ + template + class Parsing + { + string const& timeSpec_; + PQuant grid_; + + public: + Parsing (string const& toParse, Symbol gridID =DEFAULT_GRID) + : timeSpec_(toParse) + , grid_(Quantiser::retrieve(gridID)) + { } + + + void + should_yield (TimeValue const& expected) + { + TimeValue parsed = FMT::parse (timeSpec_, *grid_); + CHECK (parsed == expected, "parsing '%s' resulted in %s instead of %s" + , cStr(timeSpec_) + , cStr(Time(parsed)) + , cStr(Time(expected))); + } + + void + should_yield (FSecs const& expectedSecs) + { + should_yield (Time (expectedSecs)); + } + + void + should_fail () + { + VERIFY_ERROR (INVALID_TIMECODE, FMT::parse (timeSpec_, *grid_)); + } + + }; + + }//(End)Test case helper + + + + + /******************************************************** + * @test parse textual time specifications given + * in the supported timecode formats + */ + class TimeParsing_test : public Test + { + virtual void + run (Arg) + { + TimeGrid::build("pal0", FrameRate::PAL); + TimeGrid::build("pal10", FrameRate::PAL, Time(0,10)); + + parseFrames(); + parseFractionalSeconds(); +// parseHms(); +// parseSmpte(); +// parseDropFrame(); + } + + + void + parseFrames () + { + Parsing ("0#") .should_yield (0); + Parsing ("1#") .should_yield (FSecs(1,25) ); + Parsing ("-1#") .should_yield (FSecs(-1,25) ); + Parsing ("-0#") .should_yield (0); + Parsing ("25#") .should_yield (1 ); + Parsing ("26#") .should_yield (Time(40,1) ); + Parsing ("25#", OFFSET_GRID).should_yield (1+10 ); + Parsing ("-1#", OFFSET_GRID).should_yield (10 - FSecs(1,25)); + + Parsing ("23") .should_fail(); + Parsing ("23 #") .should_fail(); + Parsing ("23.#") .should_fail(); + Parsing ("23x#") .should_fail(); + + Parsing ("xxx25#xxx") .should_yield (1); + Parsing ("12 25#") .should_yield (1); + Parsing ("12 25# 33#") .should_yield (1); + Parsing ("12\n 25# \n 33#") .should_yield (1); + Parsing ("12.25#") .should_yield (1); + } + + + void + parseFractionalSeconds () + { + UNIMPLEMENTED ("verify reading fractional seconds as timecode format"); + } + + + void + parseHms () + { + UNIMPLEMENTED ("verify reading hour-minutes-seconds-millis time specs"); + } + + + void + parseSmpte () + { + } + + + void + parseDropFrame () + { + UNIMPLEMENTED ("verify especially SMPTE-drop-frame timecode"); + } + }; + + + /** Register this test class... */ + LAUNCHER (TimeParsing_test, "unit common"); + + + +}}} // namespace lib::time::test