2010-12-22 04:09:27 +01:00
|
|
|
/*
|
|
|
|
|
TimeValue(Test) - working with time values and time intervals in C++...
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
#include "lib/time/timevalue.hpp"
|
|
|
|
|
#include "lib/util.hpp"
|
|
|
|
|
|
2010-12-26 23:00:34 +01:00
|
|
|
#include <boost/lexical_cast.hpp>
|
2010-12-22 04:09:27 +01:00
|
|
|
//#include <iostream>
|
|
|
|
|
//#include <cstdlib>
|
|
|
|
|
|
2010-12-26 23:00:34 +01:00
|
|
|
using boost::lexical_cast;
|
|
|
|
|
using util::isnil;
|
2010-12-22 04:09:27 +01:00
|
|
|
//using std::rand;
|
|
|
|
|
//using std::cout;
|
|
|
|
|
//using std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace lib {
|
|
|
|
|
namespace time{
|
|
|
|
|
namespace test{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************
|
|
|
|
|
* @test verify handling of time values, time intervals.
|
|
|
|
|
* - creating times and time intervals
|
|
|
|
|
* - comparisons
|
|
|
|
|
* - time arithmetics
|
|
|
|
|
*/
|
|
|
|
|
class TimeValue_test : public Test
|
|
|
|
|
{
|
2010-12-27 05:55:15 +01:00
|
|
|
gavl_time_t
|
|
|
|
|
random_or_get (Arg arg)
|
|
|
|
|
{
|
|
|
|
|
if (isnil(arg))
|
|
|
|
|
return (rand() % 10000);
|
|
|
|
|
else
|
|
|
|
|
return lexical_cast<gavl_time_t> (arg[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-12-22 04:09:27 +01:00
|
|
|
virtual void
|
|
|
|
|
run (Arg arg)
|
|
|
|
|
{
|
2010-12-27 05:55:15 +01:00
|
|
|
TimeValue ref (random_or_get(arg));
|
2010-12-22 04:09:27 +01:00
|
|
|
|
2010-12-27 05:55:15 +01:00
|
|
|
checkBasicTimeValues (ref);
|
2010-12-22 04:09:27 +01:00
|
|
|
checkComparisons (ref);
|
|
|
|
|
checkComponentAccess();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-12-27 05:55:15 +01:00
|
|
|
/** @test creating some time values and performing trivial comparisons.
|
|
|
|
|
* @note you can't do much beyond that, because TimeValues as such
|
|
|
|
|
* are a "dead end": they are opaque and can't be altered.
|
|
|
|
|
*/
|
2010-12-22 04:09:27 +01:00
|
|
|
void
|
2010-12-27 05:55:15 +01:00
|
|
|
checkBasicTimeValues (TimeValue org)
|
2010-12-22 04:09:27 +01:00
|
|
|
{
|
2010-12-27 05:55:15 +01:00
|
|
|
TimeValue zero;
|
|
|
|
|
TimeValue one (1);
|
|
|
|
|
TimeValue max (Time::MAX);
|
|
|
|
|
TimeValue min (Time::MIN);
|
|
|
|
|
|
|
|
|
|
TimeValue val (org);
|
|
|
|
|
|
|
|
|
|
CHECK (zero == zero);
|
|
|
|
|
CHECK (zero <= zero);
|
|
|
|
|
CHECK (zero >= zero);
|
|
|
|
|
|
|
|
|
|
CHECK (zero < one);
|
|
|
|
|
CHECK (min < max);
|
|
|
|
|
CHECK (min < val);
|
|
|
|
|
CHECK (val < max);
|
|
|
|
|
|
|
|
|
|
// mixed comparisons with raw numeric time
|
|
|
|
|
gavl_time_t g2 (-2);
|
|
|
|
|
CHECK (zero > g2);
|
|
|
|
|
CHECK (one > g2);
|
|
|
|
|
CHECK (one >= g2);
|
|
|
|
|
CHECK (g2 < max);
|
|
|
|
|
|
|
|
|
|
CHECK (!(g2 > max));
|
|
|
|
|
CHECK (!(g2 < min));
|
2010-12-22 04:09:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-12-27 05:55:15 +01:00
|
|
|
checkComparisons (TimeValue org)
|
2010-12-22 04:09:27 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
checkComponentAccess()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
LAUNCHER (TimeValue_test, "unit common");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}}} // namespace lib::time::test
|