2010-12-31 23:04:13 +01:00
|
|
|
|
/*
|
|
|
|
|
|
TimeGridBasics(Test) - verify a simple reference scale for time quantisation
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2010, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-31 23:04:13 +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.
|
2010-12-31 23:04:13 +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
|
|
|
|
* *****************************************************************/
|
2010-12-31 23:04:13 +01:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file time-grid-basics-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref TimeGridBasics_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2010-12-31 23:04:13 +01:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
|
#include "lib/test/test-helper.hpp"
|
|
|
|
|
|
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/asset/meta.hpp"
|
|
|
|
|
|
#include "steam/asset/meta/time-grid.hpp"
|
2011-01-15 14:07:25 +01:00
|
|
|
|
#include "lib/time/timevalue.hpp"
|
2016-01-07 03:58:29 +01:00
|
|
|
|
#include "lib/format-cout.hpp"
|
2011-01-15 15:04:23 +01:00
|
|
|
|
#include "lib/util.hpp"
|
2010-12-31 23:04:13 +01:00
|
|
|
|
|
2011-01-15 14:07:25 +01:00
|
|
|
|
#include <boost/rational.hpp>
|
2010-12-31 23:04:13 +01:00
|
|
|
|
|
2011-01-15 14:07:25 +01:00
|
|
|
|
using boost::rational_cast;
|
2010-12-31 23:04:13 +01:00
|
|
|
|
using lib::test::randStr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
namespace steam {
|
2011-01-15 15:04:23 +01:00
|
|
|
|
namespace asset{
|
2010-12-31 23:04:13 +01:00
|
|
|
|
namespace meta {
|
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
2011-01-15 14:07:25 +01:00
|
|
|
|
using namespace lib::time;
|
|
|
|
|
|
|
2010-12-31 23:04:13 +01:00
|
|
|
|
typedef Builder<TimeGrid> GridBuilder;
|
|
|
|
|
|
|
|
|
|
|
|
namespace { // Test definitions...
|
|
|
|
|
|
|
Timehandling: choose safer representation for fractional seconds (closes #939)
When drafting the time handling framework some years ago,
I foresaw the possible danger of mixing up numbers relating
to fractional seconds, with other plain numbers intended as
frame counts or as micro ticks. Thus I deliberately picked
an incompatible integer type for FSecs = boost::rational<long>
However, using long is problematic in itself, since its actual
bit length is not fixed, and especially on 32bit platforms long
is quite surprisingly defined to be the same as int.
However, meanwhile, using the new C++ features, I have blocked
pretty much any possible implicit conversion path, requiring
explicit conversions in the relevant ctor invocations. So,
after weighting in the alternatives, FSecs is now defined
as boost::rational<int64_t>.
2020-02-17 02:36:54 +01:00
|
|
|
|
const Time TEST_ORIGIN (12,34);
|
|
|
|
|
|
const FrameRate TEST_FPS (5,6);
|
2010-12-31 23:04:13 +01:00
|
|
|
|
|
2011-01-15 14:07:25 +01:00
|
|
|
|
const uint MAX_FRAMES = 1000;
|
|
|
|
|
|
const uint DIRT_GRAIN = 50;
|
2010-12-31 23:04:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/***********************************************************************//**
|
2010-12-31 23:04:13 +01:00
|
|
|
|
* @test build some simple time grids and verify their behaviour
|
|
|
|
|
|
* for quantising (grid aligning) time values.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @see asset::meta::TimeGrid
|
|
|
|
|
|
* @see time-quantisation-test.cpp usage context
|
|
|
|
|
|
*/
|
|
|
|
|
|
class TimeGridBasics_test : public Test
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
run (Arg)
|
|
|
|
|
|
{
|
2024-11-13 02:23:23 +01:00
|
|
|
|
seedRand();
|
2010-12-31 23:04:13 +01:00
|
|
|
|
createGrid_fullProcedure();
|
|
|
|
|
|
createGrid_simplified();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
createGrid_fullProcedure()
|
|
|
|
|
|
{
|
|
|
|
|
|
GridID myGrID (randStr(8));
|
|
|
|
|
|
GridBuilder spec = asset::Meta::create (myGrID);
|
|
|
|
|
|
|
2018-08-11 19:43:57 +02:00
|
|
|
|
CHECK ( spec.fps == 1);
|
|
|
|
|
|
CHECK ( spec.origin == TimeValue(0));
|
|
|
|
|
|
CHECK (!spec.predecessor);
|
2010-12-31 23:04:13 +01:00
|
|
|
|
|
Timehandling: choose safer representation for fractional seconds (closes #939)
When drafting the time handling framework some years ago,
I foresaw the possible danger of mixing up numbers relating
to fractional seconds, with other plain numbers intended as
frame counts or as micro ticks. Thus I deliberately picked
an incompatible integer type for FSecs = boost::rational<long>
However, using long is problematic in itself, since its actual
bit length is not fixed, and especially on 32bit platforms long
is quite surprisingly defined to be the same as int.
However, meanwhile, using the new C++ features, I have blocked
pretty much any possible implicit conversion path, requiring
explicit conversions in the relevant ctor invocations. So,
after weighting in the alternatives, FSecs is now defined
as boost::rational<int64_t>.
2020-02-17 02:36:54 +01:00
|
|
|
|
spec.fps = TEST_FPS;
|
|
|
|
|
|
spec.origin = TEST_ORIGIN;
|
2010-12-31 23:04:13 +01:00
|
|
|
|
|
|
|
|
|
|
PGrid myGrid = spec.commit();
|
|
|
|
|
|
CHECK (myGrid);
|
2011-01-15 15:04:23 +01:00
|
|
|
|
CHECK (myGrid->ident.name == myGrID.getSym());
|
2010-12-31 23:04:13 +01:00
|
|
|
|
|
2011-01-15 14:07:25 +01:00
|
|
|
|
// now verify the grid
|
|
|
|
|
|
// by performing some conversions...
|
2024-11-13 02:23:23 +01:00
|
|
|
|
int randomFrame = rani(MAX_FRAMES);
|
2011-01-15 14:07:25 +01:00
|
|
|
|
|
|
|
|
|
|
Time point (myGrid->timeOf (randomFrame));
|
Timehandling: choose safer representation for fractional seconds (closes #939)
When drafting the time handling framework some years ago,
I foresaw the possible danger of mixing up numbers relating
to fractional seconds, with other plain numbers intended as
frame counts or as micro ticks. Thus I deliberately picked
an incompatible integer type for FSecs = boost::rational<long>
However, using long is problematic in itself, since its actual
bit length is not fixed, and especially on 32bit platforms long
is quite surprisingly defined to be the same as int.
However, meanwhile, using the new C++ features, I have blocked
pretty much any possible implicit conversion path, requiring
explicit conversions in the relevant ctor invocations. So,
after weighting in the alternatives, FSecs is now defined
as boost::rational<int64_t>.
2020-02-17 02:36:54 +01:00
|
|
|
|
CHECK (point == TEST_ORIGIN + randomFrame * TEST_FPS.duration());
|
2011-01-15 14:07:25 +01:00
|
|
|
|
|
2024-11-13 02:23:23 +01:00
|
|
|
|
int fract = 2 + rani(DIRT_GRAIN);
|
Timehandling: choose safer representation for fractional seconds (closes #939)
When drafting the time handling framework some years ago,
I foresaw the possible danger of mixing up numbers relating
to fractional seconds, with other plain numbers intended as
frame counts or as micro ticks. Thus I deliberately picked
an incompatible integer type for FSecs = boost::rational<long>
However, using long is problematic in itself, since its actual
bit length is not fixed, and especially on 32bit platforms long
is quite surprisingly defined to be the same as int.
However, meanwhile, using the new C++ features, I have blocked
pretty much any possible implicit conversion path, requiring
explicit conversions in the relevant ctor invocations. So,
after weighting in the alternatives, FSecs is now defined
as boost::rational<int64_t>.
2020-02-17 02:36:54 +01:00
|
|
|
|
FSecs dirt = (1/TEST_FPS) / fract;
|
|
|
|
|
|
ASSERT (Time(dirt) < TEST_FPS.duration());
|
2013-02-13 04:53:15 +01:00
|
|
|
|
ASSERT (0 < dirt);
|
2011-01-15 14:07:25 +01:00
|
|
|
|
|
|
|
|
|
|
Time dirty(point + Time(dirt));
|
2022-12-05 01:05:23 +01:00
|
|
|
|
CHECK (point == TEST_ORIGIN + myGrid->gridLocal(dirty));
|
2010-12-31 23:04:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
createGrid_simplified()
|
|
|
|
|
|
{
|
2023-12-03 23:33:06 +01:00
|
|
|
|
PGrid simplePALGrid = TimeGrid::build (FrameRate::PAL);
|
2011-01-15 15:04:23 +01:00
|
|
|
|
CHECK (simplePALGrid);
|
|
|
|
|
|
CHECK (!util::isnil (simplePALGrid->ident.name)); // note: name-ID filled in automatically
|
|
|
|
|
|
cout << "simple PAL Grid: " << simplePALGrid->ident << endl;
|
|
|
|
|
|
|
2011-03-31 18:43:50 +02:00
|
|
|
|
CHECK (Time(0,2) == simplePALGrid->timeOf(50));
|
|
|
|
|
|
CHECK (Time(0,2) == simplePALGrid->timeOf(FSecs(2)));
|
2010-12-31 23:04:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
|
LAUNCHER (TimeGridBasics_test, "unit asset");
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
}}}} // namespace steam::asset::meta::test
|