Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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"
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
33namespace steam {
34namespace mobject {
35namespace session {
36namespace test {
37
38 using session::Clip;
40 using namespace mobject::test;
41 using lumiera::error::LUMIERA_ERROR_ASSERTION;
42
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
146 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
162
163
164}}}} // namespace steam::mobject::session::test
This framework allows to (re)configure the lib::Depend front-end for dependency-injection.
static MediaFactory create
storage for the static MediaFactory instance
Definition media.hpp:75
MObject is the interface class for all "Media Objects".
Definition mobject.hpp:72
A refcounting Handle to an MObject of type MO, used to constrain or explicitly specify the location w...
A user visible/editable Clip is a reference to a contiguous sequence of media data loaded as Asset in...
Test MObject subclass, which, contrary to any real MObject, can be created directly without involving...
Per type specific configuration of instances created as service dependencies.
Lumiera error handling (C++ interface).
Automatically use custom string conversion in C++ stream output.
Unit test helper to access an emulated media file.
Media data represented a specific kind of Asset.
MObject in the Session to represent a clip on the timeline.
string showSizeof(size_t siz, string name)
for printing sizeof().
Namespace of Session and user visible high-level objects.
Definition sequence.hpp:65
TestPlacement< DummyMO > PDummy
lib::DependInject< vault::MediaAccessFacade > ::Local< vault::test::MediaAccessMock > MediaAccessMock
string format_PlacementID(Placement< MObject > const &pla)
Definition placement.cpp:60
Steam-Layer implementation namespace root.
Test runner and basic definitions for tests.
Core abstraction: placement of a media object into session context.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Subclass-1 is not defined "processible", thus will always be handled as DummyMO...
Subclass-2 is defined "processible", but we omit the necessary "applicable" definition in TestTool,...
A hierarchy of simple dummy-Media-Objects for easy unit testing.
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...
#define INSTANCEOF(CLASS, EXPR)
shortcut for subclass test, intended for assertions only.
Definition util.hpp:514