Lumiera  0.pre.03
»edit your freedom«
state-map-grouping-storage-test.cpp
Go to the documentation of this file.
1 /*
2  StateMapGroupingStorage(Test) - verify storage table for capturing UI state
3 
4  Copyright (C) Lumiera.org
5  2016, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
29 #include "lib/test/test-helper.hpp"
31 #include "lib/idi/entry-id.hpp"
32 #include "lib/diff/gen-node.hpp"
33 #include "lib/util.hpp"
34 
35 #include <string>
36 
37 
38 using std::string;
39 using lib::idi::EntryID;
40 using lib::diff::GenNode;
41 using util::isSameObject;
42 using util::isnil;
43 
44 
45 namespace stage {
46 namespace ctrl {
47 namespace test {
48 
49  using lumiera::error::LUMIERA_ERROR_WRONG_TYPE;
50 
51 
52  /**************************************************************************/
58  class StateMapGroupingStorage_test : public Test
59  {
60 
61  virtual void
62  run (Arg)
63  {
64  EntryID<char> woof ("wau");
65  EntryID<int> wooof ("wau"); // different (type) hash
66 
67  EntryID<int> miaow ("miau");
68  EntryID<int> quack ("quack");
69 
70  GenNode poodle{"poodle", "Pudel"};
71  GenNode toyPoodle{"poodle", "Zwergpudel"};
72  GenNode labradoodle {"poodle", false }; // different payload type
73  GenNode mastiff{"mastiff", "Dogge"};
74  GenNode duck{"duck", "Ente"};
75 
76 
78 
79  CHECK (isnil (storage));
80  CHECK (0 == storage.size());
81 
82  storage.record (woof, poodle);
83  CHECK (not isnil(storage));
84  CHECK (1 == storage.size());
85 
86  CHECK (poodle == storage.retrieve(woof, "poodle"));
87  CHECK (not isSameObject (poodle, storage.retrieve(woof, "poodle")));
88 
89  CHECK (Ref::NO == storage.retrieve(wooof, "poodle"));
90  CHECK (Ref::NO == storage.retrieve(woof, "pooodle"));
91 
92  storage.record (woof, mastiff);
93  CHECK (2 == storage.size());
94  CHECK (poodle == storage.retrieve(woof, "poodle"));
95  CHECK (mastiff == storage.retrieve(woof, "mastiff"));
96 
97  // upgrade the poodle
98  storage.record (woof, toyPoodle);
99  CHECK (2 == storage.size());
100  CHECK (poodle != storage.retrieve(woof, "poodle"));
101  CHECK (toyPoodle == storage.retrieve(woof, "poodle"));
102 
103  // since properties are keyed just by ID-string,
104  // we might attempt sneak in a fake poodle
105  // fortunately GenNode disallows cross-type abominations
106  VERIFY_ERROR (WRONG_TYPE, storage.record (woof, labradoodle) );
107 
108  CHECK (2 == storage.size());
109  CHECK (toyPoodle == storage.retrieve(woof, "poodle"));
110  CHECK (mastiff == storage.retrieve(woof, "mastiff"));
111 
112 
113  storage.record (quack, duck);
114  CHECK (3 == storage.size());
115  CHECK (toyPoodle == storage.retrieve(woof, "poodle"));
116  CHECK (mastiff == storage.retrieve(woof, "mastiff"));
117  CHECK (duck == storage.retrieve(quack, "duck"));
118 
119  auto elm = storage.find(woof);
120  CHECK (elm != storage.end());
121  CHECK (woof == StateMapGroupingStorage::getID(*elm));
122  CHECK (2 == StateMapGroupingStorage::getState(*elm).size());
123  CHECK (Ref::NO == StateMapGroupingStorage::getState(*elm, "doodle"));
124  CHECK (toyPoodle == StateMapGroupingStorage::getState(*elm, "poodle"));
125  CHECK (mastiff == StateMapGroupingStorage::getState(*elm, "mastiff"));
126 
127  elm = storage.find(miaow);
128  CHECK (elm == storage.end());
129 
130  CHECK (Ref::NO == storage.retrieve(miaow, "meow"));
131  storage.record (miaow, labradoodle);
132  CHECK (labradoodle == storage.retrieve(miaow, "poodle"));
133  CHECK (4 == storage.size());
134 
135  storage.clearProperty(miaow, "meow");
136  CHECK (4 == storage.size());
137  CHECK (labradoodle == storage.retrieve(miaow, "poodle"));
138  // clearing non existent property has no effect
139 
140  storage.clearProperty(miaow, "poodle");
141  CHECK (3 == storage.size());
142  CHECK (Ref::NO == storage.retrieve(miaow, "poodle"));
143 
144  // but note, an empty element record has been left back (this is harmless)
145  elm = storage.find(miaow);
146  CHECK (elm != storage.end());
147  CHECK (miaow == StateMapGroupingStorage::getID(*elm));
148  CHECK (0 == StateMapGroupingStorage::getState(*elm).size());
149 
150 
151  storage.clear();
152  CHECK (isnil (storage));
153  CHECK (0 == storage.size());
154  CHECK (Ref::NO == storage.retrieve(woof, "poodle"));
155  CHECK (Ref::NO == storage.retrieve(woof, "mastiff"));
156  CHECK (Ref::NO == storage.retrieve(quack, "duck"));
157  }
158  };
159 
160 
162  LAUNCHER (StateMapGroupingStorage_test, "unit stage");
163 
164 
165 }}} // namespace stage::ctrl::test
void record(BareEntryID const &elementID, GenNode const &stateMark)
remember the state mark for the denoted element
Definition: run.hpp:49
Implementation of storage for captured presentation state.
void clearProperty(BareEntryID const &elementID, string propertyKey)
clear previously recorded state for a given element and specific property
typed symbolic and hash ID for asset-like position accounting.
Definition: entry-id.hpp:135
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Map storage for captured presentation state information.
Simple test class runner.
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Generic building block for tree shaped (meta)data structures.
A collection of frequently used helper functions to support unit testing.
static const Ref NO
symbolic ID ref "_NO_"
Definition: gen-node.hpp:870
GenNode const & retrieve(BareEntryID const &elementID, string propertyKey) const
retrieve captured state
Bare symbolic and hash ID used for accounting of asset like entries.
generic data element node within a tree
Definition: gen-node.hpp:231
bool isSameObject(A const &a, B const &b)
compare plain object identity, bypassing any custom comparison operators.
Definition: util.hpp:372