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 unit tests */
26 //#include "singleton.test.hh"
27 //#include "singleton.test.ih"
31 #include "singleton.hh"
32 #include "IgnoreValue.hh"
34 #include <senf/Utils/auto_unit_test.hh>
35 #include <boost/test/test_tools.hpp>
38 ///////////////////////////////cc.p////////////////////////////////////////
42 class Test : public senf::singleton<Test>
44 friend class senf::singleton<Test>;
46 Test() : foo_(1234) {}
51 using senf::singleton<Test>::instance;
52 using senf::singleton<Test>::alive;
54 int foo() { return foo_; }
58 SENF_AUTO_UNIT_TEST(sInGlEtOn)
60 BOOST_CHECK_EQUAL( Test::instance().foo(), 1234 );
61 BOOST_CHECK( Test::alive() );
66 bool test1Dead (false);
67 bool test2Dead (false);
69 bool test1Alive (false);
70 bool test2Alive (false);
72 struct AliveTest1 : public senf::singleton<AliveTest1>
74 friend class senf::singleton<AliveTest1>;
75 using senf::singleton<AliveTest1>::alive;
76 using senf::singleton<AliveTest1>::instance;
81 struct AliveTest2 : public senf::singleton<AliveTest2>
83 friend class senf::singleton<AliveTest2>;
84 using senf::singleton<AliveTest2>::alive;
85 using senf::singleton<AliveTest2>::instance;
90 AliveTest1::AliveTest1()
92 test2Alive = AliveTest2::alive();
95 AliveTest1::~AliveTest1()
98 if (! AliveTest2::alive() )
99 std::cerr << "singleton alive test ok\n";
101 std::cerr << "singleton alive test 2 NOT ok!\n";
108 AliveTest2::AliveTest2()
110 test1Alive = AliveTest1::alive();
113 AliveTest2::~AliveTest2()
116 if (! AliveTest1::alive() )
117 std::cerr << "singleton alive test ok\n";
119 std::cerr << "singleton alive test 1 NOT ok!\n";
128 SENF_AUTO_UNIT_TEST(singletonAlive)
130 senf::IGNORE( AliveTest1::instance() );
131 senf::IGNORE( AliveTest2::instance() );
133 BOOST_CHECK( (test1Alive && !test2Alive) || (!test1Alive && test2Alive) );
134 BOOST_CHECK( AliveTest1::alive() );
135 BOOST_CHECK( AliveTest2::alive() );
138 ///////////////////////////////cc.e////////////////////////////////////////
145 // comment-column: 40
146 // c-file-style: "senf"
147 // indent-tabs-mode: nil
148 // ispell-local-dictionary: "american"
149 // compile-command: "scons -u test"