2012-03-20 00:49:10 +04:00
|
|
|
#include "Singleton.h"
|
|
|
|
|
|
|
|
#define BOOST_TEST_MODULE MertSingleton
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
2012-07-01 00:39:10 +04:00
|
|
|
using namespace MosesTuning;
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
namespace
|
|
|
|
{
|
2012-03-20 00:49:10 +04:00
|
|
|
|
|
|
|
static int g_count = 0;
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
class Instance
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Instance() {
|
|
|
|
++g_count;
|
|
|
|
}
|
2012-03-20 00:49:10 +04:00
|
|
|
~Instance() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
BOOST_AUTO_TEST_CASE(singleton_basic)
|
|
|
|
{
|
2012-03-20 00:49:10 +04:00
|
|
|
Instance* instance1 = Singleton<Instance>::GetInstance();
|
|
|
|
Instance* instance2 = Singleton<Instance>::GetInstance();
|
|
|
|
Instance* instance3 = Singleton<Instance>::GetInstance();
|
|
|
|
BOOST_REQUIRE(instance1 == instance2);
|
|
|
|
BOOST_REQUIRE(instance2 == instance3);
|
|
|
|
BOOST_CHECK_EQUAL(1, g_count);
|
|
|
|
|
|
|
|
Singleton<Instance>::Delete();
|
|
|
|
}
|