4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief singleton.test unit tests */
26 //#include "singleton.test.hh"
27 //#include "singleton.test.ih"
31 #include "singleton.hh"
33 #include "../Utils/auto_unit_test.hh"
34 #include <boost/test/test_tools.hpp>
37 ///////////////////////////////cc.p////////////////////////////////////////
41 class Test : public senf::singleton<Test>
43 friend class senf::singleton<Test>;
45 Test() : foo_(1234) {}
50 using senf::singleton<Test>::instance;
51 using senf::singleton<Test>::alive;
53 int foo() { return foo_; }
57 BOOST_AUTO_UNIT_TEST(sInGlEtOn)
59 BOOST_CHECK_EQUAL( Test::instance().foo(), 1234 );
60 BOOST_CHECK( Test::alive() );
65 bool test1Dead (false);
66 bool test2Dead (false);
68 bool test1Alive (false);
69 bool test2Alive (false);
71 struct AliveTest1 : public senf::singleton<AliveTest1>
73 friend class senf::singleton<AliveTest1>;
74 using senf::singleton<AliveTest1>::alive;
75 using senf::singleton<AliveTest1>::instance;
80 struct AliveTest2 : public senf::singleton<AliveTest2>
82 friend class senf::singleton<AliveTest2>;
83 using senf::singleton<AliveTest2>::alive;
84 using senf::singleton<AliveTest2>::instance;
89 AliveTest1::AliveTest1()
91 test2Alive = AliveTest2::alive();
94 AliveTest1::~AliveTest1()
97 assert( ! AliveTest2::alive() );
98 std::cerr << "singleton alive test ok\n";
103 AliveTest2::AliveTest2()
105 test1Alive = AliveTest1::alive();
108 AliveTest2::~AliveTest2()
111 assert( ! AliveTest1::alive() );
112 std::cerr << "singleton alive test ok\n";
119 BOOST_AUTO_UNIT_TEST(singletonAlive)
121 (void) AliveTest1::instance();
122 (void) AliveTest2::instance();
124 BOOST_CHECK( (test1Alive && !test2Alive) || (!test1Alive && test2Alive) );
125 BOOST_CHECK( AliveTest1::alive() );
126 BOOST_CHECK( AliveTest2::alive() );
129 ///////////////////////////////cc.e////////////////////////////////////////
136 // comment-column: 40
137 // c-file-style: "senf"
138 // indent-tabs-mode: nil
139 // ispell-local-dictionary: "american"
140 // compile-command: "scons -u test"