X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2Fsingleton.test.cc;h=781d4340ca2acfa633b8d40f32241e7dceace5f0;hb=412024ed31a4ab4eaea7a4165a434f8efebee325;hp=39272955cc6e1219f8dc00939876f3165e22dbfb;hpb=f73fa16ed5abdce272ac77f8b8b9ef2b9922c266;p=senf.git diff --git a/Utils/singleton.test.cc b/Utils/singleton.test.cc index 3927295..781d434 100644 --- a/Utils/singleton.test.cc +++ b/Utils/singleton.test.cc @@ -1,8 +1,8 @@ // $Id$ // -// Copyright (C) 2007 -// Fraunhofer Institute for Open Communication Systems (FOKUS) -// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Copyright (C) 2007 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify @@ -27,6 +27,7 @@ //#include "singleton.test.ih" // Custom includes +#include #include "singleton.hh" #include "../Utils/auto_unit_test.hh" @@ -36,17 +37,18 @@ ///////////////////////////////cc.p//////////////////////////////////////// namespace { - + class Test : public senf::singleton { friend class senf::singleton; - + Test() : foo_(1234) {} int foo_; public: using senf::singleton::instance; + using senf::singleton::alive; int foo() { return foo_; } }; @@ -55,6 +57,73 @@ namespace { BOOST_AUTO_UNIT_TEST(sInGlEtOn) { BOOST_CHECK_EQUAL( Test::instance().foo(), 1234 ); + BOOST_CHECK( Test::alive() ); +} + +namespace { + + bool test1Dead (false); + bool test2Dead (false); + + bool test1Alive (false); + bool test2Alive (false); + + struct AliveTest1 : public senf::singleton + { + friend class senf::singleton; + using senf::singleton::alive; + using senf::singleton::instance; + AliveTest1(); + ~AliveTest1(); + }; + + struct AliveTest2 : public senf::singleton + { + friend class senf::singleton; + using senf::singleton::alive; + using senf::singleton::instance; + AliveTest2(); + ~AliveTest2(); + }; + + AliveTest1::AliveTest1() + { + test2Alive = AliveTest2::alive(); + } + + AliveTest1::~AliveTest1() + { + if (test2Dead) { + assert( ! AliveTest2::alive() ); + std::cerr << "singleton alive test ok\n"; + } + test1Dead = true; + } + + AliveTest2::AliveTest2() + { + test1Alive = AliveTest1::alive(); + } + + AliveTest2::~AliveTest2() + { + if (test1Dead) { + assert( ! AliveTest1::alive() ); + std::cerr << "singleton alive test ok\n"; + } + test2Dead = true; + } + +} + +BOOST_AUTO_UNIT_TEST(singletonAlive) +{ + (void) AliveTest1::instance(); + (void) AliveTest2::instance(); + + BOOST_CHECK( (test1Alive && !test2Alive) || (!test1Alive && test2Alive) ); + BOOST_CHECK( AliveTest1::alive() ); + BOOST_CHECK( AliveTest2::alive() ); } ///////////////////////////////cc.e////////////////////////////////////////