Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
multifact-singleton-test.cpp
Go to the documentation of this file.
1/*
2 MultiFactSingleton(Test) - using MultiFact to manage a family of singletons
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
19#include "lib/test/run.hpp"
21#include "lib/multifact.hpp"
22#include "lib/format-cout.hpp"
23#include "lib/util.hpp"
24
25#include <boost/lexical_cast.hpp>
26#include <string>
27
28
29
30namespace lib {
31namespace test{
32
33 using boost::lexical_cast;
36 using util::isnil;
37 using std::ostream;
38 using std::string;
39
40 using LERR_(INVALID);
41
42
43 namespace { // hierarchy of test dummy objects
44
45 struct Interface
46 {
47 virtual ~Interface() {};
48 virtual operator string () const =0;
49 };
50
51
52 enum theID
53 { ONE = 1
54 , TWO
57 };
58
60
61
62 template<theID ii>
64 : public Interface
65 {
66 operator string() const override
67 {
68 return "Impl-"+lexical_cast<string> (ii);
69 }
70 };
71
74
75 // Configure the products to be fabricated....
80 }
81
82
83
84
85
86 /******************************************************************/
103 class MultiFactSingleton_test : public Test
104 {
105 void
106 run (Arg)
107 {
108 cout << theFact(ONE) << endl;
109 cout << theFact(TWO) << endl;
110 cout << theFact(THR) << endl;
111 cout << theFact(FOU) << endl;
112 cout << showSizeof (theFact) << endl;
113
114 Interface & o1 = theFact(ONE);
115 Interface & o2 = theFact(ONE);
116 CHECK (isSameObject(o1,o2));
117
118 TestFactory anotherFact;
119 CHECK (isnil (anotherFact));
120 VERIFY_ERROR (INVALID, anotherFact(ONE) );
121
122 TestFactory::Singleton<Implementation<ONE>> anotherSingletonHolder (anotherFact,ONE);
123 Interface & o3 = anotherFact(ONE);
124 CHECK (isSameObject(o2,o3));
125 }
126 };
127
128
131
132
133
134}} // namespace lib::test
Convenience shortcut for automatically setting up a production line, to fabricate a singleton instanc...
Factory for creating a family of objects by ID.
Target object to be instantiated as Singleton Allocates a variable amount of additional heap memory a...
#define LERR_(_NAME_)
Definition error.hpp:45
Automatically use custom string conversion in C++ stream output.
Framework for building a configurable factory, to generate families of related objects.
string showSizeof(size_t siz, string name)
for printing sizeof().
Implementation namespace for support and library code.
basic_ostream< char, char_traits< char > > ostream
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
A collection of frequently used helper functions to support unit testing.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...