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
|
|
|
|
2009-08-27 16:21:21 +02:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-08-27 16:21:21 +02:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
2009-08-27 16:21:21 +02:00
|
|
|
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.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-08-27 16:21:21 +02:00
|
|
|
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.
|
2010-12-17 23:28:49 +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"
|
|
|
|
|
#include "lib/time/diagnostics.hpp"
|
|
|
|
|
#include "lib/format-cout.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>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
|
|
using boost::lexical_cast;
|
|
|
|
|
using util::isnil;
|
|
|
|
|
using std::rand;
|
|
|
|
|
|
|
|
|
|
|
2011-05-15 22:10:26 +02:00
|
|
|
namespace lib {
|
|
|
|
|
namespace test{
|
|
|
|
|
|
|
|
|
|
using time::Time;
|
|
|
|
|
using time::TimeVar;
|
|
|
|
|
using time::FSecs;
|
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);
|
|
|
|
|
checkComponentDiagnostics();
|
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
|
|
|
|
2011-05-15 22:10:26 +02:00
|
|
|
gavl_time_t gat(var);
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK (!(gat == ref) );
|
|
|
|
|
CHECK ( (gat != ref) );
|
|
|
|
|
CHECK ( (gat >= ref) );
|
|
|
|
|
CHECK (!(gat <= ref) );
|
|
|
|
|
CHECK (!(gat < ref) );
|
|
|
|
|
CHECK ( (gat > ref) );
|
2009-08-27 16:21:21 +02:00
|
|
|
|
2011-05-15 22:10:26 +02:00
|
|
|
CHECK ( (var == gat) );
|
|
|
|
|
CHECK (!(var != gat) );
|
|
|
|
|
CHECK ( (var >= gat) );
|
|
|
|
|
CHECK ( (var <= gat) );
|
|
|
|
|
CHECK (!(var < gat) );
|
|
|
|
|
CHECK (!(var > gat) );
|
2009-08-27 16:21:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-05-15 22:10:26 +02:00
|
|
|
checkComponentDiagnostics()
|
2009-08-27 16:21:21 +02:00
|
|
|
{
|
|
|
|
|
int millis = rand() % 1000;
|
|
|
|
|
int secs = rand() % 60;
|
|
|
|
|
int mins = rand() % 60;
|
|
|
|
|
int hours = rand() % 100;
|
|
|
|
|
|
|
|
|
|
Time time(millis,secs,mins,hours);
|
2011-05-15 22:10:26 +02:00
|
|
|
CHECK (Time() < time);
|
|
|
|
|
CHECK (millis == getMillis(time));
|
|
|
|
|
CHECK (secs == getSecs (time));
|
|
|
|
|
CHECK (mins == getMins (time));
|
|
|
|
|
CHECK (hours == getHours (time));
|
2009-08-27 16:21:21 +02:00
|
|
|
cout << time << endl;
|
|
|
|
|
|
|
|
|
|
Time t2(2008,0);
|
|
|
|
|
cout << t2 << endl;
|
2011-05-15 22:10:26 +02:00
|
|
|
CHECK ( 8 == getMillis(t2));
|
|
|
|
|
CHECK ( 2 == getSecs (t2));
|
|
|
|
|
CHECK ( 0 == getMins (t2));
|
|
|
|
|
CHECK ( 0 == getHours (t2));
|
2009-08-27 16:21:21 +02:00
|
|
|
|
|
|
|
|
Time t3(2008,88);
|
|
|
|
|
cout << t3 << endl;
|
2011-05-15 22:10:26 +02:00
|
|
|
CHECK ( 8 == getMillis(t3));
|
|
|
|
|
CHECK (30 == getSecs (t3));
|
|
|
|
|
CHECK ( 1 == getMins (t3));
|
|
|
|
|
CHECK ( 0 == getHours (t3));
|
2009-08-27 16:21:21 +02:00
|
|
|
|
|
|
|
|
Time t4(2008,118,58);
|
|
|
|
|
cout << t4 << endl;
|
2011-05-15 22:10:26 +02:00
|
|
|
CHECK ( 8 == getMillis(t4));
|
|
|
|
|
CHECK ( 0 == getSecs (t4));
|
|
|
|
|
CHECK ( 0 == getMins (t4));
|
|
|
|
|
CHECK ( 1 == getHours (t4));
|
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
|