Lumiera  0.pre.03
»edit your freedom«
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"
20 #include "lib/test/test-helper.hpp"
21 
22 #include "steam/asset/typed-id.hpp"
23 #include "lib/idi/entry-id.hpp"
24 #include "lib/p.hpp"
25 #include "steam/assetmanager.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;
41 using util::for_each;
42 using util::isnil;
43 //using lib::Literal;
44 using lib::Symbol;
45 using lib::P;
46 //using std::string;
47 
48 
49 
50 namespace steam {
51 namespace mobject {
52 namespace session {
53 namespace test {
54 
55  struct DummyEntity { };
56 
57  typedef P<DummyEntity> PDum;
58 
59 }}}}
60 
61 namespace lumiera{
62 namespace 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 
80 namespace lib {
81 namespace idi {
82 namespace 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
114  run (Arg)
115  {
116  verifyRegistration();
117  verifyAssetFrontend();
118  verifyInstanceAccess();
119  verifyAutomaticCleanup();
120  }
121 
122 
123  void
124  verifyRegistration()
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
149  verifyAssetFrontend()
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
178  verifyInstanceAccess()
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
213  verifyAutomaticCleanup()
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
Adapter for using this type as a primary type within Lumiera&#39;s Steam-Layer.
Definition: typed-id.hpp:65
Steam-Layer Interface: Asset Lookup and Organisation.
Automatically use custom string conversion in C++ stream output.
Exposing an ID registration cluster as a Meta Asset.
Definition: run.hpp:40
typed symbolic and hash ID for asset-like position accounting.
Definition: entry-id.hpp:126
#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...
Customised refcounting smart pointer.
Steam-Layer implementation namespace root.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:65
static lib::Depend< AssetManager > instance
get at the system-wide asset manager instance.
Implementation namespace for support and library code.
Token or Atom with distinct identity.
Definition: symbol.hpp:117
Marker types to indicate a literal string and a Symbol.
Simplistic test class runner.
void for_each(CON const &elements, FUN function, P1 &&bind1, ARGS &&...args)
Accept binding for arbitrary function arguments.
A collection of frequently used helper functions to support unit testing.
Lumiera public interface.
Definition: advice.cpp:104
Bare symbolic and hash ID used for accounting of asset like entries.
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:71
Perform operations "for each element" of a collection.