dry-run: switch the lumitime-test.cpp to use the new Time framework

This commit is contained in:
Fischlurch 2011-05-15 22:10:26 +02:00
parent 99bf3c6d81
commit ee5c9910e1
2 changed files with 158 additions and 58 deletions

View file

@ -0,0 +1,96 @@
/*
DIAGNOSTICS.hpp - diagnostics and output helpers for time(code) values
Copyright (C) Lumiera.org
2011, 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.
*/
/** @file diagnostics.hpp
** Extension to the lib::time::Time wrapper, adding output and further
** diagnostic aids. This shouldn't be confused with formatting into
** distinctive \em Timecode formats. There is an elaborate framework
** for the latter: basically you'd need first to create a frame quantised
** time value (QuTime) -- from there you can build various timecode
** representations.
**
** To the contrary, the purpose of this header is to help with debugging,
** writing unit tests and similar diagnostic activities.
**
** @see timevalue.hpp
** @see lumitime-test.cpp
**
*/
#ifndef LIB_TIME_DIAGNOSTICS_H
#define LIB_TIME_DIAGNOSTICS_H
#include "lib/time/timevalue.hpp"
#include "lib/time.h"
#include <iostream>
#include <string>
namespace lib {
namespace time {
/** writes time value, formatted as HH:MM:SS:mmm
* @see lumiera_tmpbuf_print_time */
inline std::ostream&
operator<< (std::ostream& os, TimeValue const& t)
{
return os << std::string(Time(t));
}
/* === H:M:S:mm component diagnostics === */
inline int
getHours (TimeValue const& t)
{
return lumiera_time_hours (_raw(t));
}
inline int
getMins (TimeValue const& t)
{
return lumiera_time_minutes (_raw(t));
}
inline int
getSecs (TimeValue const& t)
{
return lumiera_time_seconds (_raw(t));
}
inline int
getMillis (TimeValue t)
{
return lumiera_time_millis (_raw(t));
}
}} // lib::time
#endif

View file

@ -35,30 +35,34 @@ using std::cout;
using std::endl; using std::endl;
#include "lib/lumitime.hpp" #include "lib/time/timevalue.hpp"
#include "lib/lumitime-fmt.hpp" #include "lib/time/diagnostics.hpp"
namespace lumiera{ namespace lib {
namespace test { namespace test{
using time::Time;
using time::TimeVar;
using time::FSecs;
/******************************************** /********************************************
* @test sanity of the C++ time wrapper. * @test sanity check of basic Time handling.
*/ */
class LumiTime_test : public Test class LumiTime_test : public Test
{ {
virtual void virtual void
run (Arg arg) run (Arg arg)
{ {
long refval= isnil(arg)? 1 : lexical_cast<long> (arg[1]); FSecs refval = isnil(arg)? 1 : lexical_cast<long> (arg[1]);
Time ref (refval); Time org(refval);
checkBasics (ref); checkBasics (org);
checkComparisons (ref); checkComparisons (org);
checkComponentAccess(); checkComponentDiagnostics();
} }
@ -66,18 +70,18 @@ namespace test {
checkBasics (Time const& ref) checkBasics (Time const& ref)
{ {
Time zero; Time zero;
Time one (1); Time two (FSecs(2));
Time max (Time::MAX); Time max (Time::MAX);
Time min (Time::MIN); Time min (Time::MIN);
Time val (ref); TimeVar var (ref);
val += Time(2); var += two;
val *= 2; var *= 2;
CHECK (zero == (val - 2*(ref + Time(2))) ); CHECK (zero == (var - 2*(ref + two)) );
val = ref; var = ref;
CHECK (zero == (val - ref)); CHECK (zero == (var - ref));
} }
@ -88,27 +92,27 @@ namespace test {
Time max (Time::MAX); Time max (Time::MAX);
Time min (Time::MIN); Time min (Time::MIN);
CHECK (zero == Time(0)); CHECK (zero == Time());
CHECK (min < zero); CHECK (min < zero);
CHECK (max > zero); CHECK (max > zero);
Time val (ref); TimeVar var (ref);
CHECK ( (val == ref) ); CHECK ( (var == ref) );
CHECK (!(val != ref) ); CHECK (!(var != ref) );
CHECK ( (val >= ref) ); CHECK ( (var >= ref) );
CHECK ( (val <= ref) ); CHECK ( (var <= ref) );
CHECK (!(val < ref) ); CHECK (!(var < ref) );
CHECK (!(val > ref) ); CHECK (!(var > ref) );
val += Time(2); var += Time(FSecs(2));
CHECK (!(val == ref) ); CHECK (!(var == ref) );
CHECK ( (val != ref) ); CHECK ( (var != ref) );
CHECK ( (val >= ref) ); CHECK ( (var >= ref) );
CHECK (!(val <= ref) ); CHECK (!(var <= ref) );
CHECK (!(val < ref) ); CHECK (!(var < ref) );
CHECK ( (val > ref) ); CHECK ( (var > ref) );
gavl_time_t gat(val); gavl_time_t gat(var);
CHECK (!(gat == ref) ); CHECK (!(gat == ref) );
CHECK ( (gat != ref) ); CHECK ( (gat != ref) );
CHECK ( (gat >= ref) ); CHECK ( (gat >= ref) );
@ -116,17 +120,17 @@ namespace test {
CHECK (!(gat < ref) ); CHECK (!(gat < ref) );
CHECK ( (gat > ref) ); CHECK ( (gat > ref) );
CHECK ( (val == gat) ); CHECK ( (var == gat) );
CHECK (!(val != gat) ); CHECK (!(var != gat) );
CHECK ( (val >= gat) ); CHECK ( (var >= gat) );
CHECK ( (val <= gat) ); CHECK ( (var <= gat) );
CHECK (!(val < gat) ); CHECK (!(var < gat) );
CHECK (!(val > gat) ); CHECK (!(var > gat) );
} }
void void
checkComponentAccess() checkComponentDiagnostics()
{ {
int millis = rand() % 1000; int millis = rand() % 1000;
int secs = rand() % 60; int secs = rand() % 60;
@ -134,34 +138,34 @@ namespace test {
int hours = rand() % 100; int hours = rand() % 100;
Time time(millis,secs,mins,hours); Time time(millis,secs,mins,hours);
CHECK (millis == time.getMillis()); CHECK (Time() < time);
CHECK (secs == time.getSecs()); CHECK (millis == getMillis(time));
CHECK (mins == time.getMins()); CHECK (secs == getSecs (time));
CHECK (hours == time.getHours()); CHECK (mins == getMins (time));
CHECK (hours == getHours (time));
cout << time << endl; cout << time << endl;
Time t2(2008,0); Time t2(2008,0);
cout << t2 << endl; cout << t2 << endl;
CHECK ( 8 == t2.getMillis()); CHECK ( 8 == getMillis(t2));
CHECK ( 2 == t2.getSecs()); CHECK ( 2 == getSecs (t2));
CHECK ( 0 == t2.getMins()); CHECK ( 0 == getMins (t2));
CHECK ( 0 == t2.getHours()); CHECK ( 0 == getHours (t2));
Time t3(2008,88); Time t3(2008,88);
cout << t3 << endl; cout << t3 << endl;
CHECK ( 8 == t3.getMillis()); CHECK ( 8 == getMillis(t3));
CHECK (30 == t3.getSecs()); CHECK (30 == getSecs (t3));
CHECK ( 1 == t3.getMins()); CHECK ( 1 == getMins (t3));
CHECK ( 0 == t3.getHours()); CHECK ( 0 == getHours (t3));
Time t4(2008,118,58); Time t4(2008,118,58);
cout << t4 << endl; cout << t4 << endl;
CHECK ( 8 == t4.getMillis()); CHECK ( 8 == getMillis(t4));
CHECK ( 0 == t4.getSecs()); CHECK ( 0 == getSecs (t4));
CHECK ( 0 == t4.getMins()); CHECK ( 0 == getMins (t4));
CHECK ( 1 == t4.getHours()); CHECK ( 1 == getHours (t4));
} }
}; };
@ -170,4 +174,4 @@ namespace test {
}} // namespace lumiera::test }} // namespace lib::test