From edc2598f277da2f25305481038ca19e877e2a746 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 9 Jan 2011 05:51:26 +0100 Subject: [PATCH] cover additional time handling convenience shortcuts --- src/lib/time/timevalue.hpp | 9 +++++++++ tests/lib/time/time-value-test.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/lib/time/timevalue.hpp b/src/lib/time/timevalue.hpp index 65402882a..dfda0009a 100644 --- a/src/lib/time/timevalue.hpp +++ b/src/lib/time/timevalue.hpp @@ -337,6 +337,8 @@ namespace time { // standard copy acceptable; + double asDouble() const; + static const FrameRate PAL; static const FrameRate NTSC; @@ -394,6 +396,13 @@ namespace time { : IFrac (__ensure_nonzero(fractionalRate)) { } + inline double + FrameRate::asDouble() const + { + return boost::rational_cast (*this); + } + + }} // lib::time diff --git a/tests/lib/time/time-value-test.cpp b/tests/lib/time/time-value-test.cpp index 342697b8f..d504197d5 100644 --- a/tests/lib/time/time-value-test.cpp +++ b/tests/lib/time/time-value-test.cpp @@ -22,6 +22,7 @@ #include "lib/test/run.hpp" +#include "lib/test/test-helper.hpp" #include "lib/time/timevalue.hpp" #include "lib/time/display.hpp" #include "lib/util.hpp" @@ -38,6 +39,7 @@ using std::cout; using std::endl; using std::string; +using lumiera::error::LUMIERA_ERROR_BOTTOM_VALUE; namespace lib { namespace time{ @@ -70,6 +72,7 @@ namespace test{ checkBasicTimeValues (ref); checkMutableTime (ref); checkTimeConveniance (ref); + verify_invalidFramerateProtection(); createOffsets (ref); buildDuration (ref); buildTimeSpan (ref); @@ -194,6 +197,17 @@ namespace test{ } + void + verify_invalidFramerateProtection() + { + VERIFY_ERROR (BOTTOM_VALUE, FrameRate infinite(0) ); + VERIFY_ERROR (BOTTOM_VALUE, FrameRate infinite(0,123) ); + + CHECK (isnil (Duration (0, FrameRate::PAL))); + CHECK (isnil (Duration (0, FrameRate(123)))); + } + + void createOffsets (TimeValue org) { @@ -234,6 +248,16 @@ namespace test{ CHECK (distance > zero); CHECK (distance == backwards.abs()); + Duration unit(50, FrameRate::PAL); + CHECK (Time(2) == unit); // duration of 50 frames at 25fps is... (guess what) + + CHECK (FrameRate::PAL.duration() == Time(FSecs(1,25))); + CHECK (FrameRate::NTSC.duration() == Time(FSecs(1001,3000))); + cout << "NTSC-Framerate = " << FrameRate::NTSC.asDouble() << endl; + + CHECK (zero == Duration::NIL); + CHECK (isnil (Duration::NIL)); + // assign to variable for calculations point = backwards; point *= 2;