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)
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 
46 using util::_Fmt;
47 using std::string;
48 using std::rand;
49 
50 
51 
52 namespace steam {
53 namespace mobject {
54 namespace test {
55 
56  using lib::rani;
57  using lib::Symbol;
58  using builder::BuilderTool;
59 
60 
66  {
67  int id_;
68 
69  public:
70  DummyMO() : id_{rani(1000)} {}
71  DummyMO(int i) : id_(i) {}
72 
73  DEFINE_PROCESSABLE_BY (BuilderTool);
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 
93  struct TestSubMO1 : DummyMO
94  {
95  virtual operator string() const { return display("TestSubMO1"); }
96  };
97 
103  struct TestSubMO2 : DummyMO
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>
120 
121  template<>
122  class TestPlacement<> : public Placement<DummyMO>
123  {
124  public:
125  TestPlacement(DummyMO& dummyObj)
126  : Placement<DummyMO>::Placement(dummyObj, &DummyMO::killDummy)
127  { }
128 
129  // allowing all kinds of copy
130  TestPlacement(Placement<DummyMO> const& 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 *
144  operator-> () const
145  {
146  ENSURE (INSTANCEOF (DMO, this->get()));
147  return static_cast<DMO*>
149  }
150  };
151 
153 
154 
155 
156 }}} // namespace steam::mobject::test
157 #endif
A refcounting Handle to an MObject of type MO, used to constrain or explicitly specify the location w...
Definition: trait.hpp:82
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: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
Front-end for printf-style string template interpolation.
int rani(uint bound=_iBOUND())
Definition: random.hpp:135
Base class of all BuilderTools, used according to the visitor pattern: each Tool contains the concret...
Definition: buildertool.hpp:97
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:70
Token or Atom with distinct identity.
Definition: symbol.hpp:117
Visiting-tool mechanism configured specifically for the Builder.
Marker types to indicate a literal string and a Symbol.
Simplistic 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:39
#define DEFINE_PROCESSABLE_BY(TOOL)
mark a Visitable subclass as actually treat-able by some "visiting tool" base interface.
Definition: visitor.hpp:222
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