2011-05-13 07:46:21 +02:00
|
|
|
|
/*
|
|
|
|
|
|
TimeParsing(Test) - handling textual time(code) specifications
|
|
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2011, Hermann Vosseler <Ichthyostega@web.de>
|
2011-05-13 07:46:21 +02:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
**Lumiera** 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. See the file COPYING for further details.
|
2011-05-13 07:46:21 +02:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
* *****************************************************************/
|
2011-05-13 07:46:21 +02:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file time-parsing-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref TimeParsing_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2011-05-13 07:46:21 +02:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/asset/meta/time-grid.hpp"
|
2011-05-13 07:46:21 +02:00
|
|
|
|
#include "lib/time/quantiser.hpp"
|
|
|
|
|
|
#include "lib/time/timecode.hpp"
|
|
|
|
|
|
#include "lib/symbol.hpp"
|
|
|
|
|
|
#include "lib/util.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
using lib::Symbol;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace lib {
|
|
|
|
|
|
namespace time{
|
|
|
|
|
|
namespace test{
|
|
|
|
|
|
|
2018-11-15 23:59:23 +01:00
|
|
|
|
using steam::asset::meta::TimeGrid;
|
2024-03-16 02:04:47 +01:00
|
|
|
|
using LERR_(INVALID_TIMECODE);
|
2011-05-13 07:46:21 +02:00
|
|
|
|
|
2011-05-14 04:17:22 +02:00
|
|
|
|
|
2011-05-13 07:46:21 +02:00
|
|
|
|
namespace { // Helper for writing test cases
|
|
|
|
|
|
|
|
|
|
|
|
Symbol DEFAULT_GRID = "pal0";
|
|
|
|
|
|
Symbol OFFSET_GRID = "pal10";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Expression builder
|
|
|
|
|
|
* for writing time value parsing tests
|
|
|
|
|
|
*/
|
|
|
|
|
|
template<class FMT>
|
|
|
|
|
|
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"
|
2025-06-18 16:50:19 +02:00
|
|
|
|
, timeSpec_.c_str()
|
|
|
|
|
|
, string{Time(parsed)}.c_str()
|
|
|
|
|
|
, string{Time(expected)}.c_str());
|
2011-05-13 07:46:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/****************************************************//**
|
2011-05-13 07:46:21 +02:00
|
|
|
|
* @test parse textual time specifications given
|
|
|
|
|
|
* in the supported timecode formats
|
|
|
|
|
|
*/
|
|
|
|
|
|
class TimeParsing_test : public Test
|
|
|
|
|
|
{
|
|
|
|
|
|
virtual void
|
2025-06-07 23:59:57 +02:00
|
|
|
|
run (Arg)
|
2011-05-13 07:46:21 +02:00
|
|
|
|
{
|
2011-05-14 04:17:22 +02:00
|
|
|
|
defineTestTimeGrids();
|
2011-05-13 07:46:21 +02:00
|
|
|
|
|
|
|
|
|
|
parseFrames();
|
|
|
|
|
|
parseFractionalSeconds();
|
2011-05-14 04:17:22 +02:00
|
|
|
|
/////////////////////////////////////////////TODO
|
2011-05-13 07:46:21 +02:00
|
|
|
|
// parseHms();
|
|
|
|
|
|
// parseSmpte();
|
|
|
|
|
|
// parseDropFrame();
|
2025-06-07 23:59:57 +02:00
|
|
|
|
}
|
2011-05-13 07:46:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
2011-05-14 04:17:22 +02:00
|
|
|
|
void
|
|
|
|
|
|
defineTestTimeGrids()
|
|
|
|
|
|
{
|
|
|
|
|
|
TimeGrid::build(DEFAULT_GRID, FrameRate::PAL);
|
|
|
|
|
|
TimeGrid::build(OFFSET_GRID, FrameRate::PAL, Time(0,10));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-13 07:46:21 +02:00
|
|
|
|
void
|
|
|
|
|
|
parseFrames ()
|
|
|
|
|
|
{
|
|
|
|
|
|
Parsing<format::Frames> ("0#") .should_yield (0);
|
|
|
|
|
|
Parsing<format::Frames> ("1#") .should_yield (FSecs(1,25) );
|
|
|
|
|
|
Parsing<format::Frames> ("-1#") .should_yield (FSecs(-1,25) );
|
|
|
|
|
|
Parsing<format::Frames> ("-0#") .should_yield (0);
|
|
|
|
|
|
Parsing<format::Frames> ("25#") .should_yield (1 );
|
|
|
|
|
|
Parsing<format::Frames> ("26#") .should_yield (Time(40,1) );
|
|
|
|
|
|
Parsing<format::Frames> ("25#", OFFSET_GRID).should_yield (1+10 );
|
|
|
|
|
|
Parsing<format::Frames> ("-1#", OFFSET_GRID).should_yield (10 - FSecs(1,25));
|
|
|
|
|
|
|
|
|
|
|
|
Parsing<format::Frames> ("23") .should_fail();
|
|
|
|
|
|
Parsing<format::Frames> ("23 #") .should_fail();
|
|
|
|
|
|
Parsing<format::Frames> ("23.#") .should_fail();
|
|
|
|
|
|
Parsing<format::Frames> ("23x#") .should_fail();
|
|
|
|
|
|
|
|
|
|
|
|
Parsing<format::Frames> ("xxx25#xxx") .should_yield (1);
|
|
|
|
|
|
Parsing<format::Frames> ("12 25#") .should_yield (1);
|
2011-05-14 04:17:22 +02:00
|
|
|
|
Parsing<format::Frames> ("12 25# 33#") .should_yield (1); // note pitfall: the first valid number is used
|
2019-06-24 02:41:02 +02:00
|
|
|
|
Parsing<format::Frames> ("12 25# \n 33#") .should_yield (1);
|
2011-05-13 07:46:21 +02:00
|
|
|
|
Parsing<format::Frames> ("12\n 25# \n 33#") .should_yield (1);
|
2011-05-14 04:17:22 +02:00
|
|
|
|
Parsing<format::Frames> ("12.25#") .should_fail(); // rejected because of leading dot (ambiguity)
|
2011-05-13 07:46:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
parseFractionalSeconds ()
|
|
|
|
|
|
{
|
2011-05-14 04:17:22 +02:00
|
|
|
|
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) );
|
2025-06-07 23:59:57 +02:00
|
|
|
|
Parsing<format::Seconds> ("1/250sec") .should_yield (Time( 4,0) ); // no quantisation involved in parsing
|
2011-05-14 04:17:22 +02:00
|
|
|
|
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
|
2011-05-13 07:46:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|