Loading [MathJax]/extensions/TeX/AMSmath.js
Radium Engine  1.5.29
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
singleton.cpp
1#include <Core/Utils/Singleton.hpp>
2
3#include <catch2/catch_test_macros.hpp>
4
5class TestSingleton
6{
7 RA_SINGLETON_INTERFACE( TestSingleton );
8
9 public:
10 static int cpt;
11
12 private:
13 TestSingleton() { cpt++; }
14};
15
16int TestSingleton::cpt = 0;
17
18RA_SINGLETON_IMPLEMENTATION( TestSingleton );
19
20TEST_CASE( "Core/Utils/Singleton", "[unittests][Core][Core/Utils][Singleton]" ) {
21
22 REQUIRE( TestSingleton::getInstance() == nullptr );
23 auto p1 = TestSingleton::createInstance();
24 REQUIRE( TestSingleton::getInstance() != nullptr );
25 REQUIRE( p1 == TestSingleton::getInstance() );
26 REQUIRE( TestSingleton::cpt == 1 );
27
28 TestSingleton::destroyInstance();
29 REQUIRE( TestSingleton::getInstance() == nullptr );
30 auto p2 = TestSingleton::createInstance();
31 REQUIRE( TestSingleton::getInstance() != nullptr );
32 REQUIRE( p2 == TestSingleton::getInstance() );
33 REQUIRE( TestSingleton::cpt == 2 );
34}