Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
typed-id-test.cpp
Go to the documentation of this file.
1/*
2 TypedID(Test) - verifying registration service for ID to type association
3
4 Copyright (C)
5 2010, 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"
21
23#include "lib/idi/entry-id.hpp"
24#include "lib/p.hpp"
27//#include "steam/mobject/session/clip.hpp"
28//#include "steam/mobject/session/fork.hpp"
29//#include "lib/meta/trait-special.hpp"
30#include "lib/util-foreach.hpp"
31#include "lib/format-cout.hpp"
32#include "lib/symbol.hpp"
33
34//#include <unordered_map>
35//#include <string>
36
37//using lib::test::showSizeof;
38//using lib::test::randStr;
39//using util::isSameObject;
40//using util::and_all;
41using util::for_each;
42using util::isnil;
43//using lib::Literal;
44using lib::Symbol;
45using lib::P;
46//using std::string;
47
48
49
50namespace steam {
51namespace mobject {
52namespace session {
53namespace test {
54
55 struct DummyEntity { };
56
58
59}}}}
60
61namespace lumiera{
62namespace query {
63
69 template<>
70 struct TypeHandlerXX<steam::mobject::session::test::DummyEntity>
71 {
72 static Symbol getID() { return "typed-id-test-dummy"; }
73
74 };
75
76}}
77
78
79
80namespace lib {
81namespace idi {
82namespace test{
83
86
87 using DummyID = EntryID<DummyEntity>;
88
89 namespace { // Test definitions...
90
91 }
92
93
94
95 /***********************************************************************/
110 class TypedID_test : public Test
111 {
112
113 virtual void
121
122
123 void
125 {
126#if false
127 uint type_cnt = TypedID::type_count();
128 uint elm_cnt = TypedID::element_count();
129
130 PDum d1 = TypedID::get<DummyEntity> ("top");
131 CHECK (!d1); // doesn't exist
132
133 // the above request automatically opened a new category
134 CHECK (type_cnt+1 == TypedID::type_count());
135
136 PDum up (new DummyEntity ("up"));
137 PDum down (new DummyEntity ("down"));
138
139 CHECK (elm_cnt+2 == TypedID::element_count());
140
141 DummyID idu = TypedID::getID<DummyEntity> ("up");
142 CHECK (idu);
143 CHECK ("up" == idu.getSym());
144#endif
145 }
146
147
148 void
150 {
151#if false
152 PInv inventory = asset::Meta::create (Category (META,"typed-id-test-dummy"));
153 CHECK (inventory);
154 CHECK (0 == inventory->size());
155
156 // The Inventory is a first-class Asset
157 CHECK (AssetManager::instance().known (inventory->getID()));
158
159 PDum up (new DummyEntity ("up"));
160 PDum down (new DummyEntity ("down"));
161
162 // changes reflected immediately
163 CHECK (2 == inventory->size());
164
165 for_each (inventory->all(), show<BareEntryID> );
166#endif
167 }
168
169 template<typename X>
170 static void
171 show (X& o)
172 {
173 cout << "---" << o << endl;
174 }
175
176
177 void
179 {
180#if false
181 PDum top (new DummyEntity ("top"));
182 PDum bot (new DummyEntity ("bottom"));
183
184 CHECK (1 == top.use_count());
185 CHECK (1 == bot.use_count()); // we hold the only reference
186
187 VERIFY_ERROR (MISSING_INSTANCE, TypedID::get<DummyEntity> ("top"));
188
189 // to enable fetching instances, an instance link needs to be provided
190 top->registerInstance (top);
191 TypedID::registerInstance<DummyEntity> (bot);
192
193 PDum d1 = TypedID::get<DummyEntity> ("top");
194 CHECK (d1);
195 CHECK (d1 == top);
196 CHECK (d1 != bot);
197 CHECK (2 == top.use_count());
198 CHECK (1 == bot.use_count());
199
200 d1 = TypedID::get<DummyEntity> ("bottom");
201 CHECK (d1);
202 CHECK (d1 != top);
203 CHECK (d1 == bot);
204 CHECK (1 == top.use_count());
205 CHECK (2 == bot.use_count());
206
207 for_each (TypedID::allInstances<DummyEntity>(), show<DummyEntity> );
208#endif
209 }
210
211
212 void
214 {
215#if false
216
217 PDum cha (new DummyEntity ("charm"));
218 PDum bea (new DummyEntity ("beauty"));
219
220 CHECK (2 == TypedID::entry_count<DummyEntity>());
221
222 cha.reset();
223 CHECK (1 == TypedID::entry_count<DummyEntity>());
224 CHECK (bea == *(TypedID::allInstances<DummyEntity>()));
225
226 bea.reset();
227 CHECK (0 == TypedID::entry_count<DummyEntity>());
228 CHECK (! (TypedID::get<DummyEntity>("beauty")));
229 CHECK (isnil (TypedID::allInstances<DummyEntity>()));
230#endif
231 }
232 };
233
234
235
237 LAUNCHER (TypedID_test, "unit asset");
238
239
240}}} // namespace lib::idi::test
Steam-Layer Interface: Asset Lookup and Organisation.
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition p.hpp:77
Token or Atom with distinct identity.
Definition symbol.hpp:120
Bare symbolic and hash ID used for accounting of asset like entries.
Automatically use custom string conversion in C++ stream output.
unsigned int uint
Definition integral.hpp:29
Exposing an ID registration cluster as a Meta Asset.
EntryID< Dummy > DummyID
Implementation namespace for support and library code.
Adapter for using this type as a primary type within Lumiera's Steam-Layer.
Definition typed-id.hpp:64
Lumiera public interface.
Definition advice.hpp:102
Namespace of Session and user visible high-level objects.
Definition sequence.hpp:65
Steam-Layer implementation namespace root.
Test runner and basic definitions for tests.
disable_if< can_IterForEach< Container >, FUN > for_each(Container const &coll, FUN doIt)
operate on all elements of a STL container.
bool isnil(lib::time::Duration const &dur)
Customised refcounting smart pointer.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Marker types to indicate a literal string and a Symbol.
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.
Frontend for a registration service to associate object identities, symbolic identifiers and types.
Perform operations "for each element" of a collection.