2011-03-07 02:52:47 +01:00
|
|
|
|
/*
|
2012-12-02 01:54:02 +01:00
|
|
|
|
TimeMutation(Test) - explicitly changing time specifications
|
2011-03-07 02:52:47 +01: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
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2011, Hermann Vosseler <Ichthyostega@web.de>
|
2011-03-07 02:52:47 +01: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-03-07 02:52:47 +01: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-03-07 02:52:47 +01:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file time-mutation-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref TimeMutation_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2011-03-07 02:52:47 +01:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
|
#include "lib/test/test-helper.hpp"
|
|
|
|
|
|
#include "lib/time/timevalue.hpp"
|
|
|
|
|
|
#include "lib/time/timequant.hpp"
|
2011-04-25 06:46:36 +02:00
|
|
|
|
#include "lib/time/mutation.hpp"
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/asset/meta/time-grid.hpp"
|
2011-03-07 02:52:47 +01:00
|
|
|
|
#include "lib/util.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
|
|
using boost::lexical_cast;
|
|
|
|
|
|
using util::isnil;
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace lib {
|
|
|
|
|
|
namespace time{
|
|
|
|
|
|
namespace test{
|
|
|
|
|
|
|
2018-11-15 23:59:23 +01:00
|
|
|
|
using steam::asset::meta::TimeGrid;
|
2011-04-02 04:02:05 +02:00
|
|
|
|
|
2011-03-07 02:52:47 +01:00
|
|
|
|
namespace {
|
|
|
|
|
|
inline string
|
|
|
|
|
|
pop (Arg arg)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isnil (arg)) return "";
|
|
|
|
|
|
string entry = arg[0];
|
|
|
|
|
|
arg.erase (arg.begin());
|
|
|
|
|
|
return entry;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-14 22:52:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/************************************************************//**
|
2011-03-07 02:52:47 +01:00
|
|
|
|
* @test cover all basic cases for mutating a time specification.
|
|
|
|
|
|
* - change to a given value
|
|
|
|
|
|
* - change by an offset
|
|
|
|
|
|
* - change using a grid value
|
|
|
|
|
|
* - apply an (grid) increment
|
|
|
|
|
|
*/
|
|
|
|
|
|
class TimeMutation_test : public Test
|
|
|
|
|
|
{
|
2025-05-17 23:12:47 +02:00
|
|
|
|
raw_time_64
|
2011-03-07 02:52:47 +01:00
|
|
|
|
random_or_get (string arg)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isnil(arg))
|
2025-05-17 23:12:47 +02:00
|
|
|
|
return raw_time_64(1 + rani (100000)) * TimeValue::SCALE;
|
2011-03-07 02:52:47 +01:00
|
|
|
|
else
|
2025-05-17 23:12:47 +02:00
|
|
|
|
return lexical_cast<raw_time_64> (arg);
|
2011-03-07 02:52:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-04-02 04:02:05 +02:00
|
|
|
|
struct TestValues
|
|
|
|
|
|
{
|
|
|
|
|
|
TimeVar var;
|
2011-04-04 02:07:09 +02:00
|
|
|
|
Duration dur;
|
2011-04-02 04:02:05 +02:00
|
|
|
|
TimeSpan span;
|
|
|
|
|
|
QuTime quant;
|
|
|
|
|
|
|
|
|
|
|
|
TestValues (TimeValue o)
|
|
|
|
|
|
: var(o)
|
2011-04-04 02:07:09 +02:00
|
|
|
|
, dur(o)
|
2011-04-02 04:02:05 +02:00
|
|
|
|
, span(o, Offset(o))
|
|
|
|
|
|
, quant(o, "test_grid")
|
|
|
|
|
|
{ }
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2011-03-07 02:52:47 +01:00
|
|
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
run (Arg arg)
|
|
|
|
|
|
{
|
2024-11-13 02:23:23 +01:00
|
|
|
|
if (isnil(arg))
|
|
|
|
|
|
seedRand();
|
2011-03-07 02:52:47 +01:00
|
|
|
|
TimeValue o (random_or_get (pop(arg)));
|
|
|
|
|
|
TimeValue c (random_or_get (pop(arg)));
|
2011-04-26 06:11:31 +02:00
|
|
|
|
CHECK (o != c, "unsuitable testdata");
|
2011-03-07 02:52:47 +01:00
|
|
|
|
|
2011-04-02 04:02:05 +02:00
|
|
|
|
// using a 25fps-grid, but with an time origin offset by 1/50sec
|
|
|
|
|
|
TimeGrid::build("test_grid", FrameRate::PAL, Time(FSecs(1,50)));
|
|
|
|
|
|
|
2011-05-14 22:52:08 +02:00
|
|
|
|
QuTime qChange (c, "test_grid");
|
|
|
|
|
|
FrameNr count(qChange);
|
2011-03-07 02:52:47 +01:00
|
|
|
|
|
2011-04-25 06:46:36 +02:00
|
|
|
|
mutate_by_Value (o, Time(c));
|
2011-03-07 02:52:47 +01:00
|
|
|
|
mutate_by_Offset (o, Offset(c));
|
2011-05-14 22:52:08 +02:00
|
|
|
|
mutate_quantised (o, qChange);
|
2011-03-07 02:52:47 +01:00
|
|
|
|
mutate_by_Increment(o, count);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-04-25 06:46:36 +02:00
|
|
|
|
mutate_by_Value(TimeValue original, Time newStart)
|
2011-03-07 02:52:47 +01:00
|
|
|
|
{
|
2011-04-25 06:46:36 +02:00
|
|
|
|
TestValues t(original);
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (t.span.start() == original);
|
|
|
|
|
|
t.span.accept (Mutation::changeTime (newStart));
|
|
|
|
|
|
CHECK (t.span.start() != original);
|
|
|
|
|
|
CHECK (t.span.start() == newStart);
|
|
|
|
|
|
|
2011-05-14 22:52:08 +02:00
|
|
|
|
// instead of invoking directly, we can store and copy mutation messages
|
2011-04-25 06:46:36 +02:00
|
|
|
|
EncapsulatedMutation change_back(Mutation::changeTime (Time(original)));
|
|
|
|
|
|
t.span.accept (change_back);
|
|
|
|
|
|
CHECK (t.span.start() == original);
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (t.quant == original);
|
|
|
|
|
|
t.quant.accept (Mutation::changeTime (newStart));
|
|
|
|
|
|
CHECK (t.quant != original);
|
|
|
|
|
|
CHECK (t.quant == newStart);
|
|
|
|
|
|
|
|
|
|
|
|
// Durations have no start time...
|
|
|
|
|
|
VERIFY_ERROR (INVALID_MUTATION, t.dur.accept(change_back));
|
|
|
|
|
|
VERIFY_ERROR (INVALID_MUTATION, t.span.duration().accept(change_back));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (t.dur == original);
|
|
|
|
|
|
t.dur.accept (Mutation::changeDuration (Duration(2*t.var)));
|
|
|
|
|
|
CHECK (t.dur != original);
|
|
|
|
|
|
CHECK (t.dur == t.var*2);
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (t.span.start() == original);
|
|
|
|
|
|
CHECK (t.span.duration() == original);
|
|
|
|
|
|
t.span.accept (Mutation::changeDuration(Duration(3*t.var)));
|
|
|
|
|
|
CHECK (t.span.duration() != original);
|
|
|
|
|
|
CHECK (t.span.duration() == t.var*3); // affects the duration,
|
|
|
|
|
|
CHECK (t.span.start() == original); // while the start time remains unaltered
|
|
|
|
|
|
|
|
|
|
|
|
// can't change the 'duration' of a quantised time point...
|
|
|
|
|
|
VERIFY_ERROR (INVALID_MUTATION, t.quant.accept(Mutation::changeDuration (Duration(t.var))));
|
2011-03-07 02:52:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-04-25 18:51:50 +02:00
|
|
|
|
mutate_by_Offset (TimeValue original, Offset change)
|
2011-03-07 02:52:47 +01:00
|
|
|
|
{
|
2011-04-25 18:51:50 +02:00
|
|
|
|
TestValues t(original);
|
|
|
|
|
|
TimeValue& should_be(t.var+=change); // use as ref for verification
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (t.span == original);
|
|
|
|
|
|
CHECK (t.span != should_be);
|
|
|
|
|
|
t.span.accept (Mutation::adjust (change));
|
|
|
|
|
|
CHECK (t.span == should_be);
|
|
|
|
|
|
|
|
|
|
|
|
t.dur.accept (Mutation::adjust (change));
|
|
|
|
|
|
CHECK (t.dur == should_be);
|
|
|
|
|
|
|
|
|
|
|
|
t.quant.accept (Mutation::adjust (change));
|
|
|
|
|
|
CHECK (t.quant == should_be);
|
|
|
|
|
|
|
|
|
|
|
|
// adjustment is cumulative
|
|
|
|
|
|
EncapsulatedMutation back_off = Mutation::adjust (-change);
|
|
|
|
|
|
t.span.accept (back_off);
|
|
|
|
|
|
CHECK (t.span == original);
|
|
|
|
|
|
t.span.accept (back_off);
|
|
|
|
|
|
t.span.accept (back_off);
|
|
|
|
|
|
t.span.accept (back_off);
|
|
|
|
|
|
CHECK (t.span == Time(original) - 3*change);
|
2011-03-07 02:52:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-04-26 06:11:31 +02:00
|
|
|
|
mutate_quantised (TimeValue original, QuTime change)
|
2011-03-07 02:52:47 +01:00
|
|
|
|
{
|
2011-04-26 06:11:31 +02:00
|
|
|
|
TestValues t(original);
|
|
|
|
|
|
t.var = change;
|
|
|
|
|
|
CHECK (Time(change) == t.var); // the underlying raw time value
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (t.span == original);
|
|
|
|
|
|
t.span.accept (Mutation::materialise (change));
|
|
|
|
|
|
CHECK (t.span != original);
|
|
|
|
|
|
CHECK (t.span != t.var); // really materialised (grid-aligned)
|
|
|
|
|
|
|
|
|
|
|
|
// simulate what happened by explicit operations...
|
|
|
|
|
|
Secs seconds = change.formatAs<format::Seconds>();
|
2011-05-14 22:52:08 +02:00
|
|
|
|
PQuant quantiser(change);
|
|
|
|
|
|
Time materialised (quantiser->materialise(change));
|
2011-04-26 06:11:31 +02:00
|
|
|
|
CHECK (t.span == materialised);
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (t.span.duration() == original); // not affected by mutation as usual
|
|
|
|
|
|
VERIFY_ERROR (INVALID_MUTATION, t.dur.accept (Mutation::materialise (change)));
|
|
|
|
|
|
// not surprising, a time point has no duration!!
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (t.quant == original);
|
|
|
|
|
|
t.quant.accept (Mutation::materialise (change));
|
|
|
|
|
|
CHECK (t.quant != original);
|
|
|
|
|
|
CHECK (t.quant == materialised);
|
|
|
|
|
|
// but note, here we checked the underlying raw value.
|
|
|
|
|
|
// because t.quant is itself quantised, this might
|
|
|
|
|
|
// result in a second, chained quantisation finally
|
|
|
|
|
|
|
|
|
|
|
|
// Here accidentally both the change and t.quant use the same grid.
|
|
|
|
|
|
// For a more contrived example, we try to use a different grid...
|
2011-04-29 04:04:48 +02:00
|
|
|
|
TimeGrid::build("special_funny_grid", 1, Time(0,-10)); // (1 frame per second, zero point at -10s)
|
2011-04-26 06:11:31 +02:00
|
|
|
|
QuTime funny (original, "special_funny_grid");
|
|
|
|
|
|
funny.accept (Mutation::materialise (change));
|
|
|
|
|
|
CHECK (funny == t.quant); // leading to the same raw value this far
|
|
|
|
|
|
|
2011-05-14 22:52:08 +02:00
|
|
|
|
Time doublyQuantised (PQuant(funny)->materialise(funny));
|
2011-04-26 06:11:31 +02:00
|
|
|
|
CHECK (doublyQuantised != materialised);
|
2011-03-07 02:52:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-04-26 06:11:31 +02:00
|
|
|
|
mutate_by_Increment (TimeValue original, int change)
|
2011-03-07 02:52:47 +01:00
|
|
|
|
{
|
2011-04-26 06:11:31 +02:00
|
|
|
|
TestValues t(original);
|
|
|
|
|
|
|
|
|
|
|
|
// without any additional specification,
|
|
|
|
|
|
// the nudge-Mutation uses a 'natural grid'
|
|
|
|
|
|
t.span.accept (Mutation::nudge (change));
|
|
|
|
|
|
t.dur.accept (Mutation::nudge (change));
|
|
|
|
|
|
|
|
|
|
|
|
t.var += Time(FSecs(change)); // natural grid is in seconds
|
|
|
|
|
|
CHECK (t.span.start() == t.var);
|
|
|
|
|
|
CHECK (t.dur == t.var);
|
|
|
|
|
|
|
|
|
|
|
|
// any other grid can be specified explicitly
|
|
|
|
|
|
t.dur.accept (Mutation::nudge (change, "test_grid"));
|
|
|
|
|
|
CHECK (t.dur != t.var);
|
|
|
|
|
|
CHECK (t.dur == t.var + change * FrameRate::PAL.duration());
|
|
|
|
|
|
// ....this time the change was measured in grid units,
|
|
|
|
|
|
// taken relative to the origin of the specified grid
|
2011-04-27 02:25:36 +02:00
|
|
|
|
PQuant testGrid = Quantiser::retrieve("test_grid");
|
2011-04-26 06:11:31 +02:00
|
|
|
|
Offset distance (testGrid->timeOf(0), testGrid->timeOf(change));
|
|
|
|
|
|
CHECK (distance == change * FrameRate::PAL.duration());
|
2011-04-27 02:25:36 +02:00
|
|
|
|
CHECK (t.dur - t.var == distance);
|
2011-04-26 06:11:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// To the contrary, *quantised* values behave quite differently...
|
|
|
|
|
|
long frameNr = t.quant.formatAs<format::Frames>();
|
|
|
|
|
|
|
|
|
|
|
|
t.quant.accept (Mutation::nudge (change));
|
|
|
|
|
|
CHECK (t.quant != original);
|
|
|
|
|
|
long frameNr_after = t.quant.formatAs<format::Frames>();
|
2011-05-14 22:52:08 +02:00
|
|
|
|
CHECK (frameNr_after == frameNr + change);
|
|
|
|
|
|
//i.e. the quantised time's own grid is used
|
2011-03-07 02:52:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
|
LAUNCHER (TimeMutation_test, "unit common");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}}} // namespace lib::time::test
|