From a8a0e07726297f56855ac13f1e3bea4392072bae Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 23 Jul 2009 03:47:57 +0200 Subject: [PATCH] test driven brainstorming --- .../proc/control/command-use1-test.cpp | 190 ++++++++++++++++++ .../proc/control/test-dummy-commands.hpp | 105 ++++++++++ wiki/renderengine.html | 4 +- 3 files changed, 297 insertions(+), 2 deletions(-) create mode 100644 tests/components/proc/control/command-use1-test.cpp create mode 100644 tests/components/proc/control/test-dummy-commands.hpp diff --git a/tests/components/proc/control/command-use1-test.cpp b/tests/components/proc/control/command-use1-test.cpp new file mode 100644 index 000000000..a8b6f94a4 --- /dev/null +++ b/tests/components/proc/control/command-use1-test.cpp @@ -0,0 +1,190 @@ +/* + CommandUse1(Test) - usage scenario 1 + + Copyright (C) Lumiera.org + 2009, 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/asset/media.hpp" +//#include "proc/mobject/session.hpp" +//#include "proc/mobject/session/edl.hpp" +//#include "proc/mobject/session/testclip.hpp" +//#include "proc/mobject/test-dummy-mobject.hpp" +//#include "lib/p.hpp" +//#include "proc/mobject/placement.hpp" +//#include "proc/mobject/placement-index.hpp" +//#include "proc/mobject/explicitplacement.hpp" +#include "proc/control/command-def.hpp" +//#include "lib/lumitime.hpp" +#include "lib/util.hpp" + +#include "proc/control/test-dummy-commands.hpp" + +//#include +//#include +//#include +//#include + +//using boost::format; +//using lumiera::Time; +//using util::contains; +//using std::string; +//using std::rand; +//using std::cout; +//using std::endl; + + +namespace control { +namespace test { + +// using lib::test::showSizeof; + using util::isSameObject; + +// using session::test::TestClip; +// using lumiera::P; + + + //using lumiera::typelist::BuildTupleAccessor; + + + + + + + /*************************************************************************** + * @test command usage scenario 1: defining commands in various ways. + * + * @todo WIP + */ + class CommandUse1_test : public Test + { + + int randVal; + int shuffle() { return randVal = 10 + (rand() % 40); } + + + + virtual void + run (Arg) + { + command1::checksum_ = 0; + allInOneStep(); + definePrototype(); + usePrototype(); + + ASSERT (0 == command1::checksum_); + } + + + void + allInOneStep() + { + + CommandDef ("test.command1.1") + .operation (command1::operate) + .captureUndo (command1::capture) + .undoOperation (command1::undoIt) + .bind (shuffle()) + .exec() + ; + + ASSERT (randVal == checksum_); + + Command::get("test.command1.1").undo(); + ASSERT ( 0 == command1::checksum_); + } + + + void + definePrototype() + { + CommandDef ("test.command1.2") + .operation (command1::operate) + .captureUndo (command1::capture) + .undoOperation (command1::undoIt) + .bind (shuffle()) + ; + + + ASSERT (Command::get("test.command1.2").canExec()); + } + + + void + usePrototype() + { + Command c1 = Command::get("test.command1.2"); + ASSERT (c1); + ASSERT (c1.canExec()); + ASSERT (!c1.canUndo()); + + Command c2 = Command::get("test.command1.2"); + ASSERT (c1); + ASSERT (c1.canExec()); + ASSERT (!c1.canUndo()); + + ASSERT (c1 == c2); + ASSERT (!isSameObject(c1, c2)); + + ASSERT (0 == command1::checksum_); + + c1(); + + ASSERT (randVal == command1::checksum_); + ASSERT (c1.canUndo()); + ASSERT (c1 != c2); + ASSERT (!c2.canUndo()); + + c2(); + ASSERT (randVal + randVal == command1::checksum_); + ASSERT (c2.canUndo()); + ASSERT (c1 != c2); + + c1.undo(); + ASSERT (0 == command1::checksum_); + c2.undo(); + ASSERT (randVal == command1::checksum_); + + c2.bind(23); + c2(); + ASSERT (randVal + 23 == command1::checksum_); + + // you should not use a command more than once (but it works...) + c1(); + ASSERT (randVal + 23 + randVal == command1::checksum_); + c1.undo(); + ASSERT (randVal + 23 == command1::checksum_); + // note we've overwritten the previous undo state + // and get the sate captured on the second invocation + + c2.undo() + ASSERT (randVal == command1::checksum_); + c1.undo(); + ASSERT (randVal + 23 == command1::checksum_); + } + }; + + + /** Register this test class... */ + LAUNCHER (CommandUse1_test, "function controller"); + + +}} // namespace control::test diff --git a/tests/components/proc/control/test-dummy-commands.hpp b/tests/components/proc/control/test-dummy-commands.hpp new file mode 100644 index 000000000..9f94cc725 --- /dev/null +++ b/tests/components/proc/control/test-dummy-commands.hpp @@ -0,0 +1,105 @@ +/* + TEST-DUMMY-COMMANDS.hpp - dummy function used to build test commands + + Copyright (C) Lumiera.org + 2009, 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. + +*/ + + +/** @file test-dummy-commands.hpp + ** Some dummy command functions used for building unit test cases. + ** Any of these functions comes in triples of operation function, undo state + ** capturing function and und function. They are placed into a nested test + ** namespace, together with some global variables used as a backdoor to + ** verify the effect of calling these functions. + ** + ** @see command-use1-test.cpp + ** @see CommandBasic_test simple complete command definition example + ** + */ + + + +#ifndef COMMAND_TEST_DUMMY_COMMANDS_H +#define COMMAND_TEST_DUMMY_COMMANDS_H + +//#include "pre.hpp" +//#include "lib/test/run.hpp" +#include "lib/test/test-helper.hpp" +//#include "proc/asset/media.hpp" +//#include "proc/mobject/session.hpp" +//#include "proc/mobject/session/edl.hpp" +//#include "proc/mobject/session/testclip.hpp" +//#include "proc/mobject/test-dummy-mobject.hpp" +//#include "lib/p.hpp" +//#include "proc/mobject/placement.hpp" +//#include "proc/mobject/placement-index.hpp" +//#include "proc/mobject/explicitplacement.hpp" +//#include "proc/control/command-def.hpp" +//#include "lib/lumitime.hpp" +//#include "lib/util.hpp" + + +//#include +//#include +//#include +//#include + +//using boost::format; +//using lumiera::Time; +//using util::contains; +//using std::string; +//using std::rand; +//using std::cout; +//using std::endl; + + +namespace control { +namespace test { + +// using lib::test::showSizeof; + + + + + namespace command1 { ///< test command just adding a given value + + long checksum_ = 0; + + void + operate (int someVal) + { + checksum_ += someVal; + } + + long + capture (int) + { + return checksum_; + } + + void + undoIt (int, long oldVal) + { + checksum_ = oldVal; + } + + } + + +}} // namespace control::test diff --git a/wiki/renderengine.html b/wiki/renderengine.html index d0df4536a..2e9bd3a53 100644 --- a/wiki/renderengine.html +++ b/wiki/renderengine.html @@ -1025,10 +1025,10 @@ A command is operated or executed by passing it to an ''execution pattern'' & When a command has been executed (and maybe undone), it's best to leave it alone, because the UndoManager might hold a reference. At any time, c ''clone of the command'' could be created, maybe bound with different arguments and treated separately from the original command. -
+
//for now (7/09) I'll use this page to collect ideas how commands might be used...//
 
-* use a command for getting a log entry and an unto possibility automatically
+* use a command for getting a log entry and an undo possibility automatically
 * might define, bind and then execute a command at once
 * might define it and bind it to a standard set of parameters, to be used as a prototype later.
 * might just create the definition, leaving the argument binding to the actual call site