Lumiera  0.pre.03
»edit your freedom«
placement-hierarchy-test.cpp
Go to the documentation of this file.
1 /*
2  PlacementHierarchy(Test) - cooperating hierarchical placement types
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"
20 #include "lib/test/test-helper.hpp"
21 #include "lib/depend-inject.hpp"
26 #include "steam/asset/media.hpp"
27 #include "lib/format-cout.hpp"
28 #include "lib/error.hpp"
29 #include "lib/util.hpp"
30 
31 
32 
33 namespace steam {
34 namespace mobject {
35 namespace session {
36 namespace test {
37 
38  using session::Clip;
39  using lib::test::showSizeof;
40  using namespace mobject::test;
41  using lumiera::error::LUMIERA_ERROR_ASSERTION;
42 
43  using MediaAccessMock = lib::DependInject<vault::MediaAccessFacade>
44  ::Local<vault::test::MediaAccessMock>;
45 
46 
47  /***********************************************************************************/
55  class PlacementHierarchy_test : public Test
56  {
57 
58  virtual void
59  run (Arg)
60  {
61  MediaAccessMock useMockMedia;
62 
63 
64  typedef Placement<MObject> PMObj;
65  typedef TestPlacement<> PDummy;
66  typedef TestPlacement<TestSubMO1> PSub1;
67  typedef TestPlacement<TestSubMO2> PSub2;
69 
70  PSub1 pSub1(*new TestSubMO1);
71  PSub2 pSub2(*new TestSubMO2);
72  PSub21 pSub3(*new TestSubMO21);
73 
74  PDummy pSubM (pSub3);
75 
76  PMObj pClip = asset::Media::create("test-1", asset::VIDEO)->createClip();
77 
78  CHECK (INSTANCEOF (Placement<MObject>, &pSub1));
79  CHECK (INSTANCEOF (Placement<MObject>, &pSub2));
80  CHECK (INSTANCEOF (Placement<MObject>, &pSub3));
81  CHECK (INSTANCEOF (Placement<MObject>, &pSubM));
82 
83  CHECK (INSTANCEOF (Placement<DummyMO>, &pSub1));
84  CHECK (INSTANCEOF (Placement<DummyMO>, &pSub2));
85  CHECK (INSTANCEOF (Placement<DummyMO>, &pSub3));
86 
87  CHECK (INSTANCEOF (TestPlacement<DummyMO>, &pSub1));
88  CHECK (INSTANCEOF (TestPlacement<DummyMO>, &pSub2));
89  CHECK (INSTANCEOF (TestPlacement<DummyMO>, &pSub3));
90 
91  CHECK ( INSTANCEOF (TestPlacement<TestSubMO2>, &pSub3));
92 
93  // the following won't succeed...
94 // CHECK (INSTANCEOF (TestPlacement<TestSubMO21>, &pSub2)); // parent not instance of subclass
95 // CHECK (INSTANCEOF (TestPlacement<TestSubMO2>, &pSub1)); // separate branch in the hierarchy
96 
97  cout << showSizeof(pSub1) << endl;
98  cout << showSizeof(pSub2) << endl;
99  cout << showSizeof(pSub3) << endl;
100  cout << showSizeof(pSubM) << endl;
101  cout << showSizeof(pClip) << endl;
102 
103  CHECK (sizeof(pSub1) == sizeof(pSub3));
104  CHECK (sizeof(pClip) == sizeof(pSub3));
105 
106  cout << pSub1 << endl;
107  cout << pSub2 << endl;
108  cout << pSub3 << endl;
109  cout << pSubM << endl;
110  cout << pClip << endl;
111 
112  pSub3->specialAPI();
113 
114  CHECK (2 == pSubM.use_count());
115  CHECK (2 == pSub3.use_count());
116  pClip = pSubM; // slicing and shared ownership
117  CHECK (3 == pSubM.use_count());
118  CHECK (3 == pSub3.use_count());
119  CHECK (3 == pClip.use_count());
120 
121 
122  // now do a brute-force re-interpretation
123  // note this is still protected by an ASSERT on the operator->()
124  PSub21& hijacked = reinterpret_cast<PSub21&> (pClip);
125 
126  hijacked->specialAPI();
127  CHECK (3 == hijacked.use_count());
128  CHECK (hijacked.getID() == pClip.getID());
129 
130  cout << format_PlacementID(pSub1) << endl;
131  cout << format_PlacementID(pSub2) << endl;
132  cout << format_PlacementID(pSub3) << endl;
133  cout << format_PlacementID(pSubM) << endl;
134  cout << format_PlacementID(pClip) << endl;
135 
136  pClip = pSub1;
137  CHECK (2 == pSubM.use_count());
138  CHECK (2 == pSub3.use_count());
139 
140  CHECK (2 == pClip.use_count());
141  CHECK (2 == pSub1.use_count());
142 
143 #if false
144  VERIFY_ERROR (ASSERTION, hijacked->specialAPI() );
147 #endif
148 
149  // runtime type diagnostics based on pointee RTTI
150  CHECK ( pSub2.isCompatible<MObject>());
151  CHECK ( pSub2.isCompatible<DummyMO>());
152  CHECK ( pSub2.isCompatible<TestSubMO2>());
153  CHECK (!pSub2.isCompatible<TestSubMO21>());
154  CHECK (!pSub2.isCompatible<TestSubMO1>());
155  CHECK (!pSub2.isCompatible<Clip>());
156  }
157  };
158 
159 
161  LAUNCHER (PlacementHierarchy_test, "unit session");
162 
163 
164 }}}} // namespace steam::mobject::session::test
Automatically use custom string conversion in C++ stream output.
Subclass-1 is not defined "processible", thus will always be handled as DummyMO...
Test MObject subclass, which, contrary to any real MObject, can be created directly without involving...
Media data represented a specific kind of Asset.
Definition: run.hpp:40
Core abstraction: placement of a media object into session context.
#define INSTANCEOF(CLASS, EXPR)
shortcut for subclass test, intended for assertions only.
Definition: util.hpp:514
Per type specific configuration of instances created as service dependencies.
MObject in the Session to represent a clip on the timeline.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Unit test helper to access an emulated media file.
A user visible/editable Clip is a reference to a contiguous sequence of media data loaded as Asset in...
static MediaFactory create
storage for the static MediaFactory instance
Definition: media.hpp:75
Steam-Layer implementation namespace root.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:65
MObject is the interface class for all "Media Objects".
Definition: mobject.hpp:70
This framework allows to (re)configure the lib::Depend front-end for dependency-injection.
Simplistic test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A collection of frequently used helper functions to support unit testing.
A hierarchy of simple dummy-Media-Objects for easy unit testing.
Lumiera error handling (C++ interface).
Subclass-2 is defined "processible", but we omit the necessary "applicable" definition in TestTool...