LUMIERA.clone/tests/basics/time/time-parsing-test.cpp
Ichthyostega afa7ca2e4d Upgrade: switch to C++23 (see #1245)
The Lumiera »Reference Platform« is now upgraded to Debian/Buster, which provides GCC-14 and Clang-20.
Thus the compiler support for C++20 language features seems solid enough, and C++23,
while still in ''experimental stage'' can be seen as a complement and addendum.

This changeset
 * upgrades the compile switches for the build system
 * provides all the necessary adjustments to keep the code base compilable

Notable changes:
 * λ-capture by value now requires explicit qualification how to handle `this`
 * comparison operators are now handled transparently by the core language,
   largely obsoleting boost::operators. This change incurs several changes
   to implicit handling rules and causes lots of ambiguities — which typically
   pinpoint some long standing design issues, especially related to MObjects
   and the ''time entities''. Most tweaks done here can be ''considered preliminary''
 * unfortunately the upgraded standard ''fails'' to handle **tuple-like** entities
   in a satisfactory way — rather an ''exposition-only'' concept is introduced,
   which applies solely to some containers from the STL, thereby breaking some
   very crucial code in the render entities, which was built upon the notion of
   ''tuple-like'' entities and the ''tuple protocol''. The solution is to
   abandon the STL in this respect and **provide an alternative implementation**
   of the `apply` function and related elements.
2025-06-19 01:52:55 +02:00

210 lines
7.6 KiB
C++
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
TimeParsing(Test) - handling textual time(code) specifications
Copyright (C)
2011, Hermann Vosseler <Ichthyostega@web.de>
  **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.
* *****************************************************************/
/** @file time-parsing-test.cpp
** unit test \ref TimeParsing_test
*/
#include "lib/test/run.hpp"
#include "lib/test/test-helper.hpp"
#include "steam/asset/meta/time-grid.hpp"
#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{
using steam::asset::meta::TimeGrid;
using LERR_(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 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"
, timeSpec_.c_str()
, string{Time(parsed)}.c_str()
, string{Time(expected)}.c_str());
}
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)
{
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 ()
{
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);
Parsing<format::Frames> ("12 25# 33#") .should_yield (1); // note pitfall: the first valid number is used
Parsing<format::Frames> ("12 25# \n 33#") .should_yield (1);
Parsing<format::Frames> ("12\n 25# \n 33#") .should_yield (1);
Parsing<format::Frames> ("12.25#") .should_fail(); // rejected because of leading dot (ambiguity)
}
void
parseFractionalSeconds ()
{
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
}
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