2010-12-31 23:04:13 +01:00
|
|
|
/*
|
|
|
|
|
TimeGridBasics(Test) - verify a simple reference scale for time quantisation
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2010, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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...
|
|
|
|
|
int randomFrame = (rand() % MAX_FRAMES);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
int fract = 2 + rand() % DIRT_GRAIN;
|
|
|
|
|
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
|