4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief singleton unit tests */
31 //#include "singleton.test.hh"
32 //#include "singleton.test.ih"
36 #include "singleton.hh"
37 #include "IgnoreValue.hh"
39 #include <senf/Utils/auto_unit_test.hh>
40 #include <boost/test/test_tools.hpp>
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
47 class Test : public senf::singleton<Test>
49 friend class senf::singleton<Test>;
51 Test() : foo_(1234) {}
56 using senf::singleton<Test>::instance;
57 using senf::singleton<Test>::alive;
59 int foo() { return foo_; }
63 SENF_AUTO_UNIT_TEST(sInGlEtOn)
65 BOOST_CHECK_EQUAL( Test::instance().foo(), 1234 );
66 BOOST_CHECK( Test::alive() );
71 bool test1Dead (false);
72 bool test2Dead (false);
74 bool test1Alive (false);
75 bool test2Alive (false);
77 struct AliveTest1 : public senf::singleton<AliveTest1>
79 friend class senf::singleton<AliveTest1>;
80 using senf::singleton<AliveTest1>::alive;
81 using senf::singleton<AliveTest1>::instance;
86 struct AliveTest2 : public senf::singleton<AliveTest2>
88 friend class senf::singleton<AliveTest2>;
89 using senf::singleton<AliveTest2>::alive;
90 using senf::singleton<AliveTest2>::instance;
95 AliveTest1::AliveTest1()
97 test2Alive = AliveTest2::alive();
100 AliveTest1::~AliveTest1()
103 if (! AliveTest2::alive() )
104 std::cerr << "singleton alive test ok\n";
106 std::cerr << "singleton alive test 2 NOT ok!\n";
113 AliveTest2::AliveTest2()
115 test1Alive = AliveTest1::alive();
118 AliveTest2::~AliveTest2()
121 if (! AliveTest1::alive() )
122 std::cerr << "singleton alive test ok\n";
124 std::cerr << "singleton alive test 1 NOT ok!\n";
133 SENF_AUTO_UNIT_TEST(singletonAlive)
135 senf::IGNORE( AliveTest1::instance() );
136 senf::IGNORE( AliveTest2::instance() );
138 BOOST_CHECK( (test1Alive && !test2Alive) || (!test1Alive && test2Alive) );
139 BOOST_CHECK( AliveTest1::alive() );
140 BOOST_CHECK( AliveTest2::alive() );
143 //-/////////////////////////////////////////////////////////////////////////////////////////////////
150 // comment-column: 40
151 // c-file-style: "senf"
152 // indent-tabs-mode: nil
153 // ispell-local-dictionary: "american"
154 // compile-command: "scons -u test"