From 940d63a9fa999eefc9a0814099504f9fc6228bd3 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 16 Oct 2008 22:02:13 +0200 Subject: [PATCH] time wrapper minimal test coverage --- src/lib/lumitime.cpp | 7 +- src/lib/lumitime.hpp | 24 ++++- src/proc/mobject/session/clip.cpp | 2 +- src/proc/mobject/session/locatingpin.hpp | 2 +- tests/40components.tests | 5 + tests/common/timewrappertest.cpp | 129 +++++++++++++++++++++++ 6 files changed, 160 insertions(+), 9 deletions(-) create mode 100644 tests/common/timewrappertest.cpp diff --git a/src/lib/lumitime.cpp b/src/lib/lumitime.cpp index d9e849a49..867477c5f 100644 --- a/src/lib/lumitime.cpp +++ b/src/lib/lumitime.cpp @@ -25,12 +25,11 @@ #include -namespace lumiera - { +namespace lumiera { - const Time Time::MAX = +std::numeric_limits::max(); - const Time Time::MIN = -std::numeric_limits::max(); + const Time Time::MAX ( +std::numeric_limits::max() ); + const Time Time::MIN ( -std::numeric_limits::max() ); } // namespace lumiera diff --git a/src/lib/lumitime.hpp b/src/lib/lumitime.hpp index 5bc60c044..da0d58ee7 100644 --- a/src/lib/lumitime.hpp +++ b/src/lib/lumitime.hpp @@ -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 > > + boost::totally_ordered > > { 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 ; } }; diff --git a/src/proc/mobject/session/clip.cpp b/src/proc/mobject/session/clip.cpp index ce0e87a9f..78655283f 100644 --- a/src/proc/mobject/session/clip.cpp +++ b/src/proc/mobject/session/clip.cpp @@ -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); } diff --git a/src/proc/mobject/session/locatingpin.hpp b/src/proc/mobject/session/locatingpin.hpp index 799255589..27074e0cd 100644 --- a/src/proc/mobject/session/locatingpin.hpp +++ b/src/proc/mobject/session/locatingpin.hpp @@ -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&); diff --git a/tests/40components.tests b/tests/40components.tests index 1ce98d957..221c5e3db 100644 --- a/tests/40components.tests +++ b/tests/40components.tests @@ -354,6 +354,11 @@ return: 0 END +TEST "Time Wrapper" TimeWrapper_test < Testgroup=ALL diff --git a/tests/common/timewrappertest.cpp b/tests/common/timewrappertest.cpp new file mode 100644 index 000000000..0a96ab7aa --- /dev/null +++ b/tests/common/timewrappertest.cpp @@ -0,0 +1,129 @@ +/* + TimeWrapper(Test) - working with gavl_time_t values in C++... + + Copyright (C) Lumiera.org + 2008, Hermann Vosseler + + 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 + +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 (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