-
Notifications
You must be signed in to change notification settings - Fork 0
/
globals_test.cpp
83 lines (66 loc) · 1.52 KB
/
globals_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#define SPS_DEBUG 1
#include <gtest/gtest.h>
#include <sps/globals.hpp>
#include <array>
class Test : public sps::Singleton<Test> {
public:
private:
Test() {
m_float = 2.0f;
}
float m_float;
Test& operator=(const Test& rhs) = delete;
friend class sps::Singleton<Test>;
};
template int sps::Singleton<Test>::InstanceDestroy();
template <class T>
class TTest : public sps::Singleton<TTest<T> > {
public:
T m_value;
TTest() {
m_value = T(1.0);
}
private:
friend class sps::Singleton<TTest<T> >;
};
// Explicit instantiate destructor (otherwise not called)
template int sps::Singleton<TTest<float> >::InstanceDestroy();
class Defaulted : public sps::Default<Defaulted> {
public:
Defaulted() {
debug_print("\n");
}
~Defaulted() {
debug_print("\n");
}
private:
float m_data;
};
// Explicit instantiate destructor (otherwise not called)
template int sps::Default<Defaulted>::InstanceDestroy();
// My stuff
void fun() {
Test* test = Test::InstanceGet();
SPS_UNREFERENCED_PARAMETER(test);
}
TEST(globals_test, singleton_test) {
// We cannot instantiate templates here
fun();
}
void fun0() {
const TTest<float>* test = TTest<float>::InstanceGet();
// If you make ctor public
TTest<float> object;
SPS_UNREFERENCED_PARAMETER(test);
}
TEST(globals_test, singleton_ttest) {
// We cannot instantiate templates here
fun0();
}
TEST(globals_test, default_test) {
Defaulted d;
}
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}