/* TimeControl(Test) - mutating time entities with life connection and feedback Copyright (C) 2011, Hermann Vosseler   **Lumiera** 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. See the file COPYING for further details. * *****************************************************************/ /** @file time-control-test.cpp ** unit test \ref TimeControl_test */ #include "lib/test/run.hpp" #include "lib/test/test-helper.hpp" #include "lib/time/timevalue.hpp" #include "lib/time/timequant.hpp" #include "lib/time/control.hpp" #include "lib/meta/generator-combinations.hpp" #include "steam/asset/meta/time-grid.hpp" #include "lib/item-wrapper.hpp" #include "lib/format-cout.hpp" #include "lib/util.hpp" #include #include #include using boost::lexical_cast; using util::typeStr; using util::isnil; using std::string; namespace lib { namespace time{ namespace test{ namespace error = lumiera::error; using lib::wrapper::ItemWrapper; using steam::asset::meta::TimeGrid; using lib::meta::Types; using lib::meta::InstantiateChainedCombinations; using LERR_(UNCONNECTED); namespace { // Test setup and helpers.... inline string pop (Arg arg) { if (isnil (arg)) return ""; string entry = arg[0]; arg.erase (arg.begin()); return entry; } /** * Mock object to receive change notifications. * A copy of the most recently received value * is memorised within an embedded buffer, * to be verified by the actual tests. */ template class TestListener : util::NonCopyable { mutable ItemWrapper received_; public: TestListener() : received_{TI{Time::ZERO}} { } TestListener(TI const& initialValue) : received_{initialValue} { } void operator() (TI const& changeValue) const { received_ = changeValue; } TI const& receivedValue() const { return *received_; } }; }//(End)Test helpers /*******************************************************************//** * @test use the time::Control to push a sequence of modifications to * various time entities; in all cases, a suitable change should * be imposed to the target and then a notification signal * should be invoked. * * After covering a simple basic case, this test uses * template metaprogramming techniques to build a matrix of all * possible type combinations and then performs a standard test * sequence for each of these type combinations. Within this * test sequence, verification functions are invoked, which * are defined with specialisations to adapt for the various * types to be covered. */ class TimeControl_test : public Test { raw_time_64 random_or_get (string arg) { if (isnil(arg)) return raw_time_64(1 + rani (100000)) * TimeValue::SCALE; else return lexical_cast (arg); } virtual void run (Arg arg) { if (isnil(arg)) seedRand(); TimeValue o (random_or_get (pop(arg))); TimeValue c (random_or_get (pop(arg))); CHECK (c!=Time::ZERO && o != c, "unsuitable testdata"); // 25fps-grid, but with an time origin offset by 1/50sec TimeGrid::build("test_grid_PAL", FrameRate::PAL, Time(FSecs(1,50))); // disjoint NTSC-framerate grid for grid aligned changes TimeGrid::build("test_grid_NTSC", FrameRate::NTSC); verifyBasics(); verifyMatrix_of_MutationCases(o,c); } void verifyBasics() { TimeSpan target(Time(0,10), FSecs(5)); Control