Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
test-dummy-mobject.hpp
Go to the documentation of this file.
1/*
2 TEST-DUMMY-MOBJECT.hpp - dummy MObject hierarchy for unit tests
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
31#ifndef MOBJECT_TEST_DUMMY_MOBJECT_H
32#define MOBJECT_TEST_DUMMY_MOBJECT_H
33
34#include "lib/test/run.hpp"
35
39#include "lib/format-string.hpp"
40#include "lib/format-cout.hpp"
41#include "lib/symbol.hpp"
42#include "lib/util.hpp"
43
44#include <cstdlib>
45
46using util::_Fmt;
47using std::string;
48using std::rand;
49
50
51
52namespace steam {
53namespace mobject {
54namespace test {
55
56 using lib::rani;
57 using lib::Symbol;
59
60
66 {
67 int id_;
68
69 public:
70 DummyMO() : id_{rani(1000)} {}
71 DummyMO(int i) : id_(i) {}
72
74
75 virtual bool isValid() const { return true;}
76 virtual string initShortID() const { return buildShortID("DummyMO"); }
77 virtual operator string() const { return display("DummyMO"); }
78 static void killDummy (MObject* dum) { delete (DummyMO*)dum; }
79
80 protected:
81 string
82 display(Symbol name) const
83 {
84 static _Fmt fmt{"%s(ID=%03d)"};
85 return fmt % name % this->id_;
86 }
87 };
88
94 {
95 virtual operator string() const { return display("TestSubMO1"); }
96 };
97
104 {
106
107 virtual operator string() const { return display("TestSubMO2"); }
108 };
109
111 {
112 virtual operator string() const { return display("TestSubMO21"); }
113 virtual void specialAPI() const { cout << "specialAPI()\n";}
114 };
115
116
117
118 template<class DMO=DummyMO, class B=DummyMO>
119 class TestPlacement ;
120
121 template<>
122 class TestPlacement<> : public Placement<DummyMO>
123 {
124 public:
126 : Placement<DummyMO>::Placement(dummyObj, &DummyMO::killDummy)
127 { }
128
129 // allowing all kinds of copy
131 : Placement<DummyMO>::Placement(refP)
132 { }
133 };
134
135 template<class DMO, class B>
136 class TestPlacement : public TestPlacement<B>
137 {
138 public:
139 TestPlacement(DMO& dummyObj)
140 : TestPlacement<B>(dummyObj)
141 { }
142
143 DMO *
145 {
146 ENSURE (INSTANCEOF (DMO, this->get()));
147 return static_cast<DMO*>
149 }
150 };
151
152 template class TestPlacement<TestSubMO21,TestSubMO2>;
153
154
155
156}}} // namespace steam::mobject::test
157#endif
Visiting-tool mechanism configured specifically for the Builder.
Token or Atom with distinct identity.
Definition symbol.hpp:120
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...
Base class of all BuilderTools, used according to the visitor pattern: each Tool contains the concret...
abstract base class of all MObjects for providing common services.
string buildShortID(lib::Literal typeID, string suffix="") const
Test MObject subclass, which, contrary to any real MObject, can be created directly without involving...
virtual string initShortID() const
static void killDummy(MObject *dum)
virtual bool isValid() const
MObject self-test (usable for asserting)
string display(Symbol name) const
TestPlacement(Placement< DummyMO > const &refP)
A front-end for using printf-style formatting.
Automatically use custom string conversion in C++ stream output.
Front-end for printf-style string template interpolation.
int rani(uint bound=_iBOUND())
Definition random.hpp:135
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.
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,...
Marker types to indicate a literal string and a Symbol.
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