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 00011 static int g_count = 0; 00012 00013 class Instance 00014 { 00015 public: 00016 Instance() { 00017 ++g_count; 00018 } 00019 ~Instance() {} 00020 }; 00021 00022 } // namespace 00023 00024 BOOST_AUTO_TEST_CASE(singleton_basic) 00025 { 00026 Instance* instance1 = Singleton<Instance>::GetInstance(); 00027 Instance* instance2 = Singleton<Instance>::GetInstance(); 00028 Instance* instance3 = Singleton<Instance>::GetInstance(); 00029 BOOST_REQUIRE(instance1 == instance2); 00030 BOOST_REQUIRE(instance2 == instance3); 00031 BOOST_CHECK_EQUAL(1, g_count); 00032 00033 Singleton<Instance>::Delete(); 00034 }