00001 #include "Singleton.h" 00002 00003 #define BOOST_TEST_MODULE MertSingleton 00004 #include <boost/test/unit_test.hpp> 00005 00006 using namespace MosesTuning; 00007 00008 namespace { 00009 00010 static int g_count = 0; 00011 00012 class Instance { 00013 public: 00014 Instance() { ++g_count; } 00015 ~Instance() {} 00016 }; 00017 00018 } // namespace 00019 00020 BOOST_AUTO_TEST_CASE(singleton_basic) { 00021 Instance* instance1 = Singleton<Instance>::GetInstance(); 00022 Instance* instance2 = Singleton<Instance>::GetInstance(); 00023 Instance* instance3 = Singleton<Instance>::GetInstance(); 00024 BOOST_REQUIRE(instance1 == instance2); 00025 BOOST_REQUIRE(instance2 == instance3); 00026 BOOST_CHECK_EQUAL(1, g_count); 00027 00028 Singleton<Instance>::Delete(); 00029 }
1.5.9