Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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
29using boost::lexical_cast;
31using util::_Fmt;
32using util::isnil;
33using std::string;
34
35
36namespace lib {
37namespace 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:
52
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;
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
Access point to singletons and other kinds of dependencies designated by type.
Definition depend.hpp:281
Helper to abstract creation and lifecycle of a dependency.
Definition depend.hpp:127
virtual void run(Arg arg)
Target object to be instantiated as Singleton Allocates a variable amount of additional heap memory a...
static void setCountParam(uint c)
Target object to be created by Test-Factories or as Singleton.
A front-end for using printf-style formatting.
Singleton services and Dependency Injection.
Automatically use custom string conversion in C++ stream output.
Front-end for printf-style string template interpolation.
unsigned int uint
Definition integral.hpp:29
Implementation namespace for support and library code.
Test runner and basic definitions for tests.
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee's memory identities.
Definition util.hpp:421
bool isnil(lib::time::Duration const &dur)
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Dummy target object to be created by factory for unit tests Used to verify sane memory management and...
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...