From 3cc3f6947129ecafcbf7344a1b25b8ce1cf5d947 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 11 Jan 2017 04:19:43 +0100 Subject: [PATCH] SessionCommand: draft the idea of a function(integration) test --- src/gui/ctrl/command-handler.hpp | 2 + tests/basics/time/time-formats-test.cpp | 6 +- .../control/session-command-function-test.cpp | 194 ++++++++++++++++++ tests/gui/abstract-tangible-test.cpp | 3 +- 4 files changed, 201 insertions(+), 4 deletions(-) create mode 100644 tests/core/proc/control/session-command-function-test.cpp diff --git a/src/gui/ctrl/command-handler.hpp b/src/gui/ctrl/command-handler.hpp index 082474974..1d9083a04 100644 --- a/src/gui/ctrl/command-handler.hpp +++ b/src/gui/ctrl/command-handler.hpp @@ -52,12 +52,14 @@ #include "include/session-command-facade.h" #include +#include namespace gui { namespace ctrl{ namespace error = lumiera::error; + using std::string; using lib::diff::Rec; using lib::diff::GenNode; using lib::diff::DataCap; diff --git a/tests/basics/time/time-formats-test.cpp b/tests/basics/time/time-formats-test.cpp index 040259a1a..c04dd22a6 100644 --- a/tests/basics/time/time-formats-test.cpp +++ b/tests/basics/time/time-formats-test.cpp @@ -30,7 +30,6 @@ #include "lib/format-cout.hpp" #include "lib/util.hpp" -#include #include #include @@ -45,6 +44,7 @@ namespace time{ namespace test{ using proc::asset::meta::TimeGrid; + using util::toString; using format::Frames; using format::Smpte; @@ -58,7 +58,7 @@ namespace test{ while (!frameNr) frameNr = rand() % (2*MAX_FRAME) - MAX_FRAME; - return lexical_cast(frameNr)+"#"; + return toString(frameNr)+"#"; } } @@ -128,7 +128,7 @@ namespace test{ CHECK (5 == frames2 - frames1); q2.accept (Mutation::changeTime(v1)); - CHECK (30 == q2.formatAs() - frames1); + CHECK (30 == q2.formatAs() - frames1); // q2 == v1 == t1 + (6*5)/(5*5)sec CHECK (quellCode == string(frames1)); CHECK (quellCode != string(frames2)); diff --git a/tests/core/proc/control/session-command-function-test.cpp b/tests/core/proc/control/session-command-function-test.cpp new file mode 100644 index 000000000..7664cf68a --- /dev/null +++ b/tests/core/proc/control/session-command-function-test.cpp @@ -0,0 +1,194 @@ +/* + SessionCommandFunction(Test) - function test of command dispatch via SessionCommand facade + + Copyright (C) Lumiera.org + 2017, 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 "lib/test/run.hpp" +#include "lib/test/test-helper.hpp" +#include "proc/control/proc-dispatcher.hpp" +#include "proc/control/command-def.hpp" +#include "gui/ctrl/command-handler.hpp" +#include "proc/asset/meta/time-grid.hpp" +#include "lib/time/timequant.hpp" +#include "lib/time/timecode.hpp" +#include "lib/format-obj.hpp" +#include "lib/symbol.hpp" +//#include "lib/util.hpp" + +//#include + + +namespace proc { +namespace control { +namespace test { + + +// using std::function; +// using std::rand; + using lib::test::randTime; + using gui::ctrl::CommandHandler; + using lib::time::Time; + using lib::time::TimeVar; + using lib::time::Duration; + using lib::time::Offset; + using lib::Symbol; +// using util::isnil; + using util::toString; + + + namespace { // test fixture... + + /* === mock operation to be dispatched as command === */ + + const Symbol COMMAND_ID{"test.dispatch.function.command"}; + + TimeVar dummyState = randTime(); + + void + operate (Duration dur, Offset offset, int factor) + { + dummyState += dur + offset*factor; + } + + string + capture (Duration, Offset, int) + { + return dummyState; + } + + void + undoIt (Duration, Offset, int, string oldState) + { +// dummyState = oldState; + } + + + }//(End) test fixture + +// typedef shared_ptr PCommandImpl; +// typedef HandlingPattern const& HaPatt; + + + + + + + /******************************************************************************************//** + * @test verify integrated functionality of command dispatch through the SessionCommand facade. + * - operate lifecycle of the supporting components, + * similar to activating the »session subsystem« + * - generate command messages similar to what is received from the UI-Bus + * - us the handler mechanism from gui::ctrl::CoreService to talk to the facade + * - have a specially rigged command function to observe invocation + * - wait for the session loop thread to dispatch this command + * - verify that commands are really executed single-threaded + * + * @see proc::SessionSubsystem + * @see ProcDispatcher + * @see CommandQueue_test + * @see AbstractTangible_test::invokeCommand() + */ + class SessionCommandFunction_test : public Test + { + + //------------------FIXTURE + public: + SessionCommandFunction_test() + { + CommandDef (COMMAND_ID) + .operation (operate) + .captureUndo (capture) + .undoOperation (undoIt) + ; + } + ~SessionCommandFunction_test() + { + Command::remove (COMMAND_ID); + } + //-------------(End)FIXTURE + + + virtual void + run (Arg) + { + startDispatcher(); + perform_simpleInvocation(); + perform_messageInvocation(); + perform_massivelyParallel(); + stopDispatcher(); + } + + + void + startDispatcher() + { + UNIMPLEMENTED ("start the session loop thread"); + } + + + void + stopDispatcher() + { + UNIMPLEMENTED ("stop the session loop thread"); + } + + + void + perform_simpleInvocation() + { + UNIMPLEMENTED ("invoke the facade directly"); + } + + + /** @test invoke a command in the same way as CoreService does + * when handling command messages from the UI-Bus + * - use the help of an InvocationTrail, similar to what the + * [generic UI element](\ref gui::model::Tangible) does + * - generate a argument binding message + * - generate a "bang!" message + */ + void + perform_messageInvocation() + { + UNIMPLEMENTED ("invoke via message"); + } + + + /** @test verify that commands are properly enqueued + * and executed one by one + * - create several threads to send random command messages + * - verify that, after executing all commands, the internal + * state variable reflects the result of a proper + * sequential calculation and summation + */ + void + perform_massivelyParallel() + { + UNIMPLEMENTED ("verify sequentialisation by queue"); + } + }; + + + /** Register this test class... */ + LAUNCHER (SessionCommandFunction_test, "function controller"); + + +}}} // namespace proc::control::test diff --git a/tests/gui/abstract-tangible-test.cpp b/tests/gui/abstract-tangible-test.cpp index 3cae68913..929ff9458 100644 --- a/tests/gui/abstract-tangible-test.cpp +++ b/tests/gui/abstract-tangible-test.cpp @@ -91,7 +91,8 @@ namespace test { namespace { // test fixture... - // dummy operation to be invoked through the command system + /* === dummy operation to be invoked through the command system === */ + int dummyState = 0; void