Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
memento-tie-test.cpp
Go to the documentation of this file.
1/*
2 MementoTie(Test) - check the mechanism for capturing and providing undo-state
3
4 Copyright (C)
5 2009, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
19#include "lib/test/run.hpp"
22
23#include <functional>
24
25using std::function;
26using std::bind;
27
28
29namespace steam {
30namespace control {
31namespace test {
32
33 namespace {
34
35 int testVal=0;
36
37 void
38 undo (short param, int memento)
39 {
40 testVal += param-memento;
41 }
42
43 int
44 capture (short param)
45 {
46 return testVal+param;
47 }
48
49
53 const size_t ALIGNMENT = sizeof(size_t);
54 }
55
56 using LERR_(MISSING_MEMENTO);
57
58
59
60 /*************************************************************************************/
71 class MementoTie_test : public Test
72 {
73
74 virtual void
75 run (Arg)
76 {
77 seedRand();
79 }
80
81
83 typedef void OpSIG(short);
85
86
87 void
89 {
90 function<void(short,int)> undo_func = undo;
91 function< int(short)> cap_func = capture;
92
94
97
98 VERIFY_ERROR (MISSING_MEMENTO, bound_undo_func(123) );
99 VERIFY_ERROR (MISSING_MEMENTO, mementoHolder.getState() );
100
101 short rr (rani (100));
102 testVal = 0;
103 bound_cap_func(rr); // invoke state capturing
104
105 CHECK (rr == mementoHolder.getState());
106
107 testVal = 10; // meanwhile "somehow" mutate the state
108 bound_undo_func(0); // invoking the undo() feeds back the memento
109 CHECK (testVal == 10-rr);
110
111 // this cycle can be repeated with different state values
112 rr = rani (100);
113 testVal = rr;
114 bound_cap_func(5); // capture new state
115 CHECK (5+rr == mementoHolder.getState());
116
117 testVal = -20;
119 CHECK (testVal == -20 + 3*rr - (5+rr));
120 }
121 };
122
123
125 LAUNCHER (MementoTie_test, "unit controller");
126
127
128}}} // namespace steam::control::test
void OpSIG(short)
assumed signature of the Command "Operation"
#define LERR_(_NAME_)
Definition error.hpp:45
A special binding used by Steam-Layer commands for capturing UNDO state information.
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
const size_t ALIGNMENT
maximum additional storage maybe wasted due to alignment of the memento value within MementoTie
Steam-Layer implementation namespace root.
Test runner and basic definitions for tests.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
A collection of frequently used helper functions to support unit testing.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.