Lumiera  0.pre.03
»edit your freedom«
singleton-test.cpp
Go to the documentation of this file.
1 /*
2  Singleton(Test) - unittest for our Singleton template
3 
4  Copyright (C)
5  2008, 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/format-string.hpp"
21 #include "lib/format-cout.hpp"
22 #include "lib/util.hpp"
23 
24 #include "test-target-obj.hpp"
25 #include "lib/depend.hpp"
26 
27 #include <boost/lexical_cast.hpp>
28 
29 using boost::lexical_cast;
30 using util::isSameObject;
31 using util::_Fmt;
32 using util::isnil;
33 using std::string;
34 
35 
36 namespace lib {
37 namespace test{
38 
39 
45  class TargetObj : public TestTargetObj
46  {
47  public:
48  static int cnt;
49  static void setCountParam (uint c) { TargetObj::cnt = c; }
50  protected:
51  TargetObj () : TestTargetObj(cnt) {}
52 
53  friend class lib::DependencyFactory<TargetObj>;
54  };
55 
56  int TargetObj::cnt = 0;
57 
58 
59 
60 
61 
62 
63 
64  /***************************************************************/
71  class Singleton_test : public Test
72  {
73 
74  virtual void
75  run (Arg arg)
76  {
77  uint num{firstVal (arg)};
78 
79  Depend<TargetObj> singleton;
80 
81  cout << _Fmt("testing TargetObj(%d) as Singleton\n") % num;
82  TargetObj::setCountParam(num);
83  TargetObj& t1 = singleton();
84  TargetObj& t2 = singleton();
85 
86  CHECK (isSameObject(t1, t2), "not a Singleton, got two different instances." );
87 
88  cout << "calling a non-static method on the Singleton instance" <<endl
89  << t1 << endl;
90  }
91  };
92 
93 
94 
96  LAUNCHER (Singleton_test, "unit common");
97 
98 
99 
100 }} // namespace lib::test
Automatically use custom string conversion in C++ stream output.
Dummy target object to be created by factory for unit tests Used to verify sane memory management and...
Definition: run.hpp:40
Front-end for printf-style string template interpolation.
A front-end for using printf-style formatting.
Access point to singletons and other kinds of dependencies designated by type.
Definition: depend.hpp:280
Implementation namespace for support and library code.
Target object to be created by Test-Factories or as Singleton.
Target object to be instantiated as Singleton Allocates a variable amount of additional heap memory a...
Simplistic test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Singleton services and Dependency Injection.
Helper to abstract creation and lifecycle of a dependency.
Definition: depend.hpp:125
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee&#39;s memory identities. ...
Definition: util.hpp:421