Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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)
5 2016, 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#include "lib/idi/entry-id.hpp"
23#include "lib/diff/gen-node.hpp"
24#include "lib/util.hpp"
25
26#include <string>
27
28
29using std::string;
33using util::isnil;
34
35
36namespace stage {
37namespace ctrl {
38namespace test {
39
40 using lumiera::error::LUMIERA_ERROR_WRONG_TYPE;
41
42
43 /**************************************************************************/
49 class StateMapGroupingStorage_test : public Test
50 {
51
52 virtual void
53 run (Arg)
54 {
55 EntryID<char> woof ("wau");
56 EntryID<int> wooof ("wau"); // different (type) hash
57
58 EntryID<int> miaow ("miau");
59 EntryID<int> quack ("quack");
60
61 GenNode poodle{"poodle", "Pudel"};
62 GenNode toyPoodle{"poodle", "Zwergpudel"};
63 GenNode labradoodle {"poodle", false }; // different payload type
64 GenNode mastiff{"mastiff", "Dogge"};
65 GenNode duck{"duck", "Ente"};
66
67
69
70 CHECK (isnil (storage));
71 CHECK (0 == storage.size());
72
73 storage.record (woof, poodle);
74 CHECK (not isnil(storage));
75 CHECK (1 == storage.size());
76
77 CHECK (poodle == storage.retrieve(woof, "poodle"));
78 CHECK (not isSameObject (poodle, storage.retrieve(woof, "poodle")));
79
80 CHECK (Ref::NO == storage.retrieve(wooof, "poodle"));
81 CHECK (Ref::NO == storage.retrieve(woof, "pooodle"));
82
83 storage.record (woof, mastiff);
84 CHECK (2 == storage.size());
85 CHECK (poodle == storage.retrieve(woof, "poodle"));
86 CHECK (mastiff == storage.retrieve(woof, "mastiff"));
87
88 // upgrade the poodle
89 storage.record (woof, toyPoodle);
90 CHECK (2 == storage.size());
91 CHECK (poodle != storage.retrieve(woof, "poodle"));
92 CHECK (toyPoodle == storage.retrieve(woof, "poodle"));
93
94 // since properties are keyed just by ID-string,
95 // we might attempt sneak in a fake poodle
96 // fortunately GenNode disallows cross-type abominations
97 VERIFY_ERROR (WRONG_TYPE, storage.record (woof, labradoodle) );
98
99 CHECK (2 == storage.size());
100 CHECK (toyPoodle == storage.retrieve(woof, "poodle"));
101 CHECK (mastiff == storage.retrieve(woof, "mastiff"));
102
103
104 storage.record (quack, duck);
105 CHECK (3 == storage.size());
106 CHECK (toyPoodle == storage.retrieve(woof, "poodle"));
107 CHECK (mastiff == storage.retrieve(woof, "mastiff"));
108 CHECK (duck == storage.retrieve(quack, "duck"));
109
110 auto elm = storage.find(woof);
111 CHECK (elm != storage.end());
112 CHECK (woof == StateMapGroupingStorage::getID(*elm));
113 CHECK (2 == StateMapGroupingStorage::getState(*elm).size());
114 CHECK (Ref::NO == StateMapGroupingStorage::getState(*elm, "doodle"));
115 CHECK (toyPoodle == StateMapGroupingStorage::getState(*elm, "poodle"));
116 CHECK (mastiff == StateMapGroupingStorage::getState(*elm, "mastiff"));
117
118 elm = storage.find(miaow);
119 CHECK (elm == storage.end());
120
121 CHECK (Ref::NO == storage.retrieve(miaow, "meow"));
122 storage.record (miaow, labradoodle);
123 CHECK (labradoodle == storage.retrieve(miaow, "poodle"));
124 CHECK (4 == storage.size());
125
126 storage.clearProperty(miaow, "meow");
127 CHECK (4 == storage.size());
128 CHECK (labradoodle == storage.retrieve(miaow, "poodle"));
129 // clearing non existent property has no effect
130
131 storage.clearProperty(miaow, "poodle");
132 CHECK (3 == storage.size());
133 CHECK (Ref::NO == storage.retrieve(miaow, "poodle"));
134
135 // but note, an empty element record has been left back (this is harmless)
136 elm = storage.find(miaow);
137 CHECK (elm != storage.end());
138 CHECK (miaow == StateMapGroupingStorage::getID(*elm));
139 CHECK (0 == StateMapGroupingStorage::getState(*elm).size());
140
141
142 storage.clear();
143 CHECK (isnil (storage));
144 CHECK (0 == storage.size());
145 CHECK (Ref::NO == storage.retrieve(woof, "poodle"));
146 CHECK (Ref::NO == storage.retrieve(woof, "mastiff"));
147 CHECK (Ref::NO == storage.retrieve(quack, "duck"));
148 }
149 };
150
151
154
155
156}}} // namespace stage::ctrl::test
Map storage for captured presentation state information.
static StateData const & getState(Record const &entry)
void clearProperty(BareEntryID const &elementID, string propertyKey)
clear previously recorded state for a given element and specific property
static BareEntryID const & getID(Record const &entry)
void record(BareEntryID const &elementID, GenNode const &stateMark)
remember the state mark for the denoted element
GenNode const & retrieve(BareEntryID const &elementID, string propertyKey) const
retrieve captured state
iterator find(BareEntryID const &elementID) const
Bare symbolic and hash ID used for accounting of asset like entries.
Generic building block for tree shaped (meta)data structures.
Lumiera GTK UI implementation root.
Definition guifacade.cpp:37
Test runner and basic definitions for tests.
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee's memory identities.
Definition util.hpp:421
bool isnil(lib::time::Duration const &dur)
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Implementation of storage for captured presentation state.
generic data element node within a tree
Definition gen-node.hpp:224
static const Ref NO
symbolic ID ref "_NO_"
Definition gen-node.hpp:862
typed symbolic and hash ID for asset-like position accounting.
Definition entry-id.hpp:219
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.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...