2009-08-27 16:21:21 +02:00
|
|
|
|
/*
|
2017-02-22 03:17:18 +01:00
|
|
|
|
TimeBasics(Test) - working with Lumiera's internal Time values
|
2010-12-17 23:28:49 +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)
|
|
|
|
|
|
2008, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +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-17 23:28:49 +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
|
|
|
|
* *****************************************************************/
|
2009-08-27 16:21:21 +02:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file time-basics-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref TimeBasics_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2009-08-27 16:21:21 +02:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
2016-01-07 03:58:29 +01:00
|
|
|
|
#include "lib/time/timevalue.hpp"
|
2025-05-27 20:43:52 +02:00
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2024-11-13 02:23:23 +01:00
|
|
|
|
#include "lib/random.hpp"
|
2009-08-27 16:21:21 +02:00
|
|
|
|
#include "lib/util.hpp"
|
2016-01-07 03:58:29 +01:00
|
|
|
|
|
2009-08-27 16:21:21 +02:00
|
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
using boost::lexical_cast;
|
|
|
|
|
|
using util::isnil;
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-15 22:10:26 +02:00
|
|
|
|
namespace lib {
|
|
|
|
|
|
namespace test{
|
|
|
|
|
|
|
|
|
|
|
|
using time::Time;
|
|
|
|
|
|
using time::TimeVar;
|
|
|
|
|
|
using time::FSecs;
|
2025-05-27 20:43:52 +02:00
|
|
|
|
using time::raw_time_64;
|
2009-08-27 16:21:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/****************************************//**
|
2011-05-15 22:10:26 +02:00
|
|
|
|
* @test sanity check of basic Time handling.
|
2009-08-27 16:21:21 +02:00
|
|
|
|
*/
|
2013-01-07 05:43:01 +01:00
|
|
|
|
class TimeBasics_test : public Test
|
2009-08-27 16:21:21 +02:00
|
|
|
|
{
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
run (Arg arg)
|
|
|
|
|
|
{
|
2011-05-15 22:10:26 +02:00
|
|
|
|
FSecs refval = isnil(arg)? 1 : lexical_cast<long> (arg[1]);
|
2009-08-27 16:21:21 +02:00
|
|
|
|
|
2011-05-15 22:10:26 +02:00
|
|
|
|
Time org(refval);
|
2009-08-27 16:21:21 +02:00
|
|
|
|
|
2011-05-15 22:10:26 +02:00
|
|
|
|
checkBasics (org);
|
|
|
|
|
|
checkComparisons (org);
|
2025-05-27 20:43:52 +02:00
|
|
|
|
checkComponentBreakdown();
|
2009-08-27 16:21:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
checkBasics (Time const& ref)
|
|
|
|
|
|
{
|
|
|
|
|
|
Time zero;
|
2011-05-15 22:10:26 +02:00
|
|
|
|
Time two (FSecs(2));
|
2009-08-27 16:21:21 +02:00
|
|
|
|
Time max (Time::MAX);
|
|
|
|
|
|
Time min (Time::MIN);
|
|
|
|
|
|
|
2011-05-15 22:10:26 +02:00
|
|
|
|
TimeVar var (ref);
|
2009-08-27 16:21:21 +02:00
|
|
|
|
|
2011-05-15 22:10:26 +02:00
|
|
|
|
var += two;
|
|
|
|
|
|
var *= 2;
|
|
|
|
|
|
CHECK (zero == (var - 2*(ref + two)) );
|
2009-08-27 16:21:21 +02:00
|
|
|
|
|
2011-05-15 22:10:26 +02:00
|
|
|
|
var = ref;
|
|
|
|
|
|
CHECK (zero == (var - ref));
|
2009-08-27 16:21:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
checkComparisons (Time const& ref)
|
|
|
|
|
|
{
|
|
|
|
|
|
Time zero;
|
|
|
|
|
|
Time max (Time::MAX);
|
|
|
|
|
|
Time min (Time::MIN);
|
|
|
|
|
|
|
2011-05-15 22:10:26 +02:00
|
|
|
|
CHECK (zero == Time());
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (min < zero);
|
|
|
|
|
|
CHECK (max > zero);
|
2009-08-27 16:21:21 +02:00
|
|
|
|
|
2011-05-15 22:10:26 +02:00
|
|
|
|
TimeVar var (ref);
|
|
|
|
|
|
CHECK ( (var == ref) );
|
|
|
|
|
|
CHECK (!(var != ref) );
|
|
|
|
|
|
CHECK ( (var >= ref) );
|
|
|
|
|
|
CHECK ( (var <= ref) );
|
|
|
|
|
|
CHECK (!(var < ref) );
|
|
|
|
|
|
CHECK (!(var > ref) );
|
2009-08-27 16:21:21 +02:00
|
|
|
|
|
2011-05-15 22:10:26 +02:00
|
|
|
|
var += Time(FSecs(2));
|
|
|
|
|
|
CHECK (!(var == ref) );
|
|
|
|
|
|
CHECK ( (var != ref) );
|
|
|
|
|
|
CHECK ( (var >= ref) );
|
|
|
|
|
|
CHECK (!(var <= ref) );
|
|
|
|
|
|
CHECK (!(var < ref) );
|
|
|
|
|
|
CHECK ( (var > ref) );
|
2009-08-27 16:21:21 +02:00
|
|
|
|
|
2025-06-18 16:50:19 +02:00
|
|
|
|
raw_time_64 rat = _raw(var);
|
2025-05-27 20:43:52 +02:00
|
|
|
|
CHECK (!(rat == ref) );
|
|
|
|
|
|
CHECK ( (rat != ref) );
|
|
|
|
|
|
CHECK ( (rat >= ref) );
|
|
|
|
|
|
CHECK (!(rat <= ref) );
|
|
|
|
|
|
CHECK (!(rat < ref) );
|
|
|
|
|
|
CHECK ( (rat > ref) );
|
|
|
|
|
|
|
|
|
|
|
|
CHECK ( (var == rat) );
|
|
|
|
|
|
CHECK (!(var != rat) );
|
|
|
|
|
|
CHECK ( (var >= rat) );
|
|
|
|
|
|
CHECK ( (var <= rat) );
|
|
|
|
|
|
CHECK (!(var < rat) );
|
|
|
|
|
|
CHECK (!(var > rat) );
|
2009-08-27 16:21:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2025-05-27 20:43:52 +02:00
|
|
|
|
checkComponentBreakdown()
|
2009-08-27 16:21:21 +02:00
|
|
|
|
{
|
2025-05-27 20:43:52 +02:00
|
|
|
|
Time t1(2008,0);
|
|
|
|
|
|
CHECK (t1 == "0:00:02.008"_expect);
|
|
|
|
|
|
|
|
|
|
|
|
Time t2(2008,88);
|
|
|
|
|
|
CHECK (t2 == "0:01:30.008"_expect);
|
|
|
|
|
|
|
|
|
|
|
|
Time t3(2008,118,58);
|
|
|
|
|
|
CHECK (t3 == "1:00:00.008"_expect);
|
|
|
|
|
|
|
|
|
|
|
|
Time t4(t2 - t3);
|
|
|
|
|
|
CHECK (t4 == "-0:58:30.000"_expect);
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (Time::ZERO == "0:00:00.000"_expect);
|
|
|
|
|
|
CHECK (Time::MAX == "85401592:56:01.825"_expect);
|
|
|
|
|
|
CHECK (Time::MIN == "-85401592:56:01.825"_expect);
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-11-13 02:23:23 +01:00
|
|
|
|
seedRand();
|
2025-05-27 20:43:52 +02:00
|
|
|
|
int millis = 1 + rani (999);
|
|
|
|
|
|
int secs = rani (60);
|
|
|
|
|
|
int mins = rani (60);
|
|
|
|
|
|
int hours = rani (100);
|
|
|
|
|
|
|
|
|
|
|
|
Time randTime(millis,secs,mins,hours);
|
|
|
|
|
|
CHECK (Time() < randTime);
|
|
|
|
|
|
|
|
|
|
|
|
const auto TIME_SCALE_sec{lib::time::TimeValue::SCALE };
|
|
|
|
|
|
const auto TIME_SCALE_ms {lib::time::TimeValue::SCALE / 1000};
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (millis == (_raw(randTime) / TIME_SCALE_ms ) % 1000);
|
|
|
|
|
|
CHECK (secs == (_raw(randTime) / TIME_SCALE_sec) % 60);
|
|
|
|
|
|
CHECK (mins == (_raw(randTime) / TIME_SCALE_sec / 60) % 60);
|
|
|
|
|
|
CHECK (hours == _raw(randTime) / TIME_SCALE_sec / 60 / 60);
|
2009-08-27 16:21:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
2013-01-07 05:43:01 +01:00
|
|
|
|
LAUNCHER (TimeBasics_test, "unit common");
|
2009-08-27 16:21:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-15 22:10:26 +02:00
|
|
|
|
}} // namespace lib::test
|