Lumiera  0.pre.03
»edit your freedom«
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) Lumiera.org
5  2009, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
40 #ifndef MOBJECT_TEST_DUMMY_MOBJECT_H
41 #define MOBJECT_TEST_DUMMY_MOBJECT_H
42 
43 #include "lib/test/run.hpp"
44 
48 #include "lib/format-string.hpp"
49 #include "lib/format-cout.hpp"
50 #include "lib/symbol.hpp"
51 #include "lib/util.hpp"
52 
53 #include <cstdlib>
54 
55 using util::_Fmt;
56 using std::string;
57 using std::rand;
58 
59 
60 
61 namespace steam {
62 namespace mobject {
63 namespace test {
64 
65  using lib::Symbol;
66  using builder::BuilderTool;
67 
68 
74  {
75  int id_;
76 
77  public:
78  DummyMO() : id_(rand() % 1000) {}
79  DummyMO(int i) : id_(i) {}
80 
81  DEFINE_PROCESSABLE_BY (BuilderTool);
82 
83  virtual bool isValid() const { return true;}
84  virtual string initShortID() const { return buildShortID("DummyMO"); }
85  virtual operator string() const { return display("DummyMO"); }
86  static void killDummy (MObject* dum) { delete (DummyMO*)dum; }
87 
88  protected:
89  string
90  display(Symbol name) const
91  {
92  static _Fmt fmt{"%s(ID=%03d)"};
93  return fmt % name % this->id_;
94  }
95  };
96 
101  struct TestSubMO1 : DummyMO
102  {
103  virtual operator string() const { return display("TestSubMO1"); }
104  };
105 
111  struct TestSubMO2 : DummyMO
112  {
114 
115  virtual operator string() const { return display("TestSubMO2"); }
116  };
117 
119  {
120  virtual operator string() const { return display("TestSubMO21"); }
121  virtual void specialAPI() const { cout << "specialAPI()\n";}
122  };
123 
124 
125 
126  template<class DMO=DummyMO, class B=DummyMO>
128 
129  template<>
130  class TestPlacement<> : public Placement<DummyMO>
131  {
132  public:
133  TestPlacement(DummyMO& dummyObj)
134  : Placement<DummyMO>::Placement(dummyObj, &DummyMO::killDummy)
135  { }
136 
137  // allowing all kinds of copy
138  TestPlacement(Placement<DummyMO> const& refP)
140  { }
141  };
142 
143  template<class DMO, class B>
144  class TestPlacement : public TestPlacement<B>
145  {
146  public:
147  TestPlacement(DMO& dummyObj)
148  : TestPlacement<B>(dummyObj)
149  { }
150 
151  DMO *
152  operator-> () const
153  {
154  ENSURE (INSTANCEOF (DMO, this->get()));
155  return static_cast<DMO*>
157  }
158  };
159 
161 
162 
163 
164 }}} // namespace steam::mobject::test
165 #endif
A refcounting Handle to an MObject of type MO, used to constrain or explicitly specify the location w...
Definition: trait.hpp:91
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...
Definition: run.hpp:49
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:492
Front-end for printf-style string template interpolation.
Base class of all BuilderTools, used according to the visitor pattern: each Tool contains the concret...
Steam-Layer implementation namespace root.
A front-end for using printf-style formatting.
MObject is the interface class for all "Media Objects".
Definition: mobject.hpp:79
Token or Atom with distinct identity.
Definition: symbol.hpp:126
Visiting-tool mechanism configured specifically for the Builder.
Marker types to indicate a literal string and a Symbol.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
virtual bool isValid() const
MObject self-test (usable for asserting)
abstract base class of all MObjects for providing common services.
Definition: abstractmo.hpp:48
#define DEFINE_PROCESSABLE_BY(TOOL)
mark a Visitable subclass as actually treat-able by some "visiting tool" base interface.
Definition: visitor.hpp:231
Subclass-2 is defined "processible", but we omit the necessary "applicable" definition in TestTool...
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption