time wrapper minimal test coverage

This commit is contained in:
Fischlurch 2008-10-16 22:02:13 +02:00
parent dedb70aac9
commit 940d63a9fa
6 changed files with 160 additions and 9 deletions

View file

@ -25,12 +25,11 @@
#include <limits>
namespace lumiera
{
namespace lumiera {
const Time Time::MAX = +std::numeric_limits<int64_t>::max();
const Time Time::MIN = -std::numeric_limits<int64_t>::max();
const Time Time::MAX ( +std::numeric_limits<int64_t>::max() );
const Time Time::MIN ( -std::numeric_limits<int64_t>::max() );
} // namespace lumiera

View file

@ -38,14 +38,28 @@ namespace lumiera {
* a temporal position (time point) relative to an (implicit) timeline zero
* point, or it could represent a time interval.
*
* This wrapper is deliberately kept rather limited as not to be completely
* interchangeable with and integral type. The rationale is that time values
* should be kept separate and tagged as time values. The following is supported:
* - conversions from / to gavl_time_t (which is effectively a int64_t)
* - additions and subtractions of time values
* - multiplication with an integral factor
* - comparisons between time values and gavl_time_t values
*
* @todo consider the possible extensions
* - parsing and pretty printing
* - quantising of floating point values
* - conversion to boost::rational
* - define a Framerate type
*
* @note this is currently (10/08) an experimental implementation to ease
* the time handling within C++ code. It is advisable not to use it
* on external interfaces (use gavl_time_t there please).
*/
class Time
: boost::additive<Time,
boost::multipliable<Time, int64_t,
boost::totally_ordered<Time> > >
boost::totally_ordered<Time,
boost::totally_ordered<Time, gavl_time_t> > >
{
gavl_time_t t_;
@ -53,7 +67,8 @@ namespace lumiera {
static const Time MAX ;
static const Time MIN ;
Time(gavl_time_t val=0) : t_(val) {}
explicit Time (gavl_time_t val=0) : t_(val) {}
operator gavl_time_t () { return t_; }
@ -66,7 +81,10 @@ namespace lumiera {
// Supporting totally_ordered
friend bool operator< (Time const& t1, Time const& t2) { return t1.t_ < t2.t_; }
friend bool operator< (Time const& t1, gavl_time_t t2) { return t1.t_ < t2 ; }
friend bool operator> (Time const& t1, gavl_time_t t2) { return t1.t_ > t2 ; }
friend bool operator== (Time const& t1, Time const& t2) { return t1.t_ == t2.t_; }
friend bool operator== (Time const& t1, gavl_time_t t2) { return t1.t_ == t2 ; }
};

View file

@ -51,7 +51,7 @@ namespace mobject
Clip::isValid () const
{
TODO ("check consistency of clip length def, implies accessing the underlying media def");
return length > 0;
return length > Time(0);
}

View file

@ -104,7 +104,7 @@ namespace mobject
/* Factory functions for adding LocatingPins */
FixedLocation& operator() (Time start, Track track=0);
RelativeLocation& operator() (PMO refObj, Time offset=0);
RelativeLocation& operator() (PMO refObj, Time offset=Time(0)); //////////TODO: warning, just a dummy placeholder for now!!
LocatingPin (const LocatingPin&);
LocatingPin& operator= (const LocatingPin&);

View file

@ -354,6 +354,11 @@ return: 0
END
TEST "Time Wrapper" TimeWrapper_test <<END
return: 0
END
TEST "TestOption_test" TestOption_test <<END
out: Testing invocation with cmdline: ...
out: --> Testgroup=ALL

View file

@ -0,0 +1,129 @@
/*
TimeWrapper(Test) - working with gavl_time_t values in C++...
Copyright (C) Lumiera.org
2008, 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 "common/test/run.hpp"
#include "common/util.hpp"
#include <boost/lexical_cast.hpp>
using boost::lexical_cast;
using util::isnil;
#include "common/lumitime.hpp"
namespace lumiera {
namespace test {
/********************************************
* @test sanity of the C++ time wrapper.
*/
class TimeWrapper_test : public Test
{
virtual void
run (Arg arg)
{
int64_t refval= isnil(arg)? 1 : lexical_cast<int64_t> (arg[1]);
Time ref (refval);
checkBasics (ref);
checkComparisons (ref);
}
void
checkBasics (Time const& ref)
{
Time zero;
Time one (1);
Time max (Time::MAX);
Time min (Time::MIN);
Time val (ref);
val += Time(2);
val *= 2;
ASSERT (zero == (val - 2*(ref + Time(2))) );
val = ref;
ASSERT (zero == (val - ref));
}
void
checkComparisons (Time const& ref)
{
Time zero;
Time max (Time::MAX);
Time min (Time::MIN);
ASSERT (zero == Time(0));
ASSERT (min < zero);
ASSERT (max > zero);
Time val (ref);
ASSERT ( (val == ref) );
ASSERT (!(val != ref) );
ASSERT ( (val >= ref) );
ASSERT ( (val <= ref) );
ASSERT (!(val < ref) );
ASSERT (!(val > ref) );
val += Time(2);
ASSERT (!(val == ref) );
ASSERT ( (val != ref) );
ASSERT ( (val >= ref) );
ASSERT (!(val <= ref) );
ASSERT (!(val < ref) );
ASSERT ( (val > ref) );
gavl_time_t gat(val);
ASSERT (!(gat == ref) );
ASSERT ( (gat != ref) );
ASSERT ( (gat >= ref) );
ASSERT (!(gat <= ref) );
ASSERT (!(gat < ref) );
ASSERT ( (gat > ref) );
ASSERT ( (val == gat) );
ASSERT (!(val != gat) );
ASSERT ( (val >= gat) );
ASSERT ( (val <= gat) );
ASSERT (!(val < gat) );
ASSERT (!(val > gat) );
}
};
/** Register this test class... */
LAUNCHER (TimeWrapper_test, "unit common");
} // namespace test
} // namespace lumiera