SpiecsEngine
 
Loading...
Searching...
No Matches
Delegate_test.h
Go to the documentation of this file.
1/**
2* @file Delegate_test.h.
3* @brief The ClassLibrary_test Definitions.
4* @author Spices.
5*/
6
7#pragma once
8#include <gmock/gmock.h>
9#include <Core/Delegate/DelegateBasic.h>
10#include "Instrumentor.h"
11
12namespace SpicesTest {
13
14 /**
15 * @brief Test Function Class.
16 */
18 {
19 public:
20
21 /**
22 * @brief Basic Override Class Function.
23 */
24 void Test()
25 {
26 std::cout << "Hello DelegateFuncTest::Test" << std::endl;
27 }
28
29 /**
30 * @brief Basic Override Class Function.
31 * @param[in] f In float.
32 */
33 void Test(float f)
34 {
35 std::cout << "Hello DelegateFuncTest::Test(float)" << std::endl;
36 }
37
38 /**
39 * @brief Basic Class Function.
40 * @param[in] a In a.
41 * @param[in] b In b.
42 */
43 void Test0(int a, int b)
44 {
45 std::cout << "Hello DelegateFuncTest::Test0(int, int)" << " " << a << " " << b << std::endl;
46 }
47
48 /**
49 * @brief Static Class Function.
50 */
51 static void Test1()
52 {
53 std::cout << "Hello DelegateFuncTest::Test1" << std::endl;
54 }
55 };
56
57 /**
58 * @brief Template Function.
59 * @tparam Args any type.
60 */
61 template<typename ...Args>
62 void DelegateTestT(Args ...args)
63 {
64 std::cout << "Hello DelegateTestT(args...)" << std::endl;
65 }
66
67 /**
68 * @brief Instance Delegate Class.
69 */
71 DELEGATE_ONE_PARAM(Test1, float)
72 DELEGATE_TWO_PARAM(Test2, int, int)
73 DELEGATE_THREE_PARAM(Test3, glm::vec2, glm::vec2, glm::vec2)
74 DELEGATE_FOUR_PARAM(Test4, glm::vec3, glm::vec3, glm::vec3, glm::vec3)
75 DELEGATE_FIVE_PARAM(Test5, glm::vec4, glm::vec4, glm::vec4, glm::vec4, glm::vec4)
76 DELEGATE_SIX_PARAM(Test6, bool, bool, bool, bool, bool, bool)
77 DELEGATE_SEVEN_PARAM(Test7, bool, bool, bool, bool, bool, bool, bool)
78 DELEGATE_EIGHT_PARAM(Test8, bool, bool, bool, bool, bool, bool, bool, bool)
79 DELEGATE_NINE_PARAM(Test9, bool, bool, bool, bool, bool, bool, bool, bool, bool)
80
81 /**
82 * @brief Unit Test for Delegate
83 */
84 class Delegate_test : public testing::Test
85 {
86 protected:
87
88 /**
89 * @brief The interface is inherited from testing::Test.
90 * Registry on Initialize.
91 */
92 void SetUp() override {
94 }
95
96 /**
97 * @brief Testing class TearDown function.
98 */
101 }
102
103 DelegateTest0 test0;
104 DelegateTest1 test1;
105 DelegateTest2 test2;
106 DelegateTest3 test3;
107 DelegateTest4 test4;
108 DelegateTest5 test5;
109 DelegateTest6 test6;
110 DelegateTest7 test7;
111 DelegateTest8 test8;
112 DelegateTest9 test9;
113 };
114
115 /**
116 * @brief Testing if bind successfully.
117 */
119
121
122 DelegateFuncTest funcTestClass;
123
124 test0.Bind(std::bind((void(DelegateFuncTest::*)())&DelegateFuncTest::Test, &funcTestClass)); /* @brief Override Class Function. */
125 test1.Bind(std::bind((void(DelegateFuncTest::*)(float))&DelegateFuncTest::Test, &funcTestClass, std::placeholders::_1)); /* @brief Override Class Function. */
126 test2.Bind(std::bind(&DelegateFuncTest::Test0, &funcTestClass, std::placeholders::_1, std::placeholders::_2)); /* @brief Class Function. */
127 test0.Bind(std::bind(&DelegateFuncTest::Test1)); /* @brief Static Class Function. */
128
129 test0.Bind([&]() { return funcTestClass.Test(); }); /* @brief Lambda Override Class Function. */
130 test1.Bind([&](float f) { return funcTestClass.Test(f); }); /* @brief Lambda Override Class Function. */
131 test2.Bind([&](int a, int b) { return funcTestClass.Test0(a, b); }); /* @brief Lambda Class Function. */
132 test0.Bind([&]() { return DelegateFuncTest::Test1(); }); /* @brief Lambda Static Class Function. */
133 test0.Bind([&]() { return DelegateTestT(); }); /* @brief Lambda Template Function. */
134
135 test1.Bind([](bool val) { return val; }); /* @brief Lambda Function. */
136
137 /**
138 * @brief Test Size is correct.
139 */
140 EXPECT_EQ(test0.size(), 5);
141 EXPECT_EQ(test1.size(), 3);
142 EXPECT_EQ(test2.size(), 2);
143 EXPECT_EQ(test2.empty(), false);
144 }
145
146 /**
147 * @brief Testing if unbind successfully.
148 */
150
152
153 DelegateFuncTest funcTestClass;
154
155 test0.Bind(std::bind((void(DelegateFuncTest::*)())&DelegateFuncTest::Test, &funcTestClass));
156 test0.Bind(std::bind(&DelegateFuncTest::Test1));
157 test0.Bind([&]() { return funcTestClass.Test(); });
158 test0.Bind([&]() { return DelegateFuncTest::Test1(); });
159 test0.Bind([&]() { return DelegateTestT(); });
160
161 EXPECT_EQ(test0.size(), 5);
162 EXPECT_EQ(test2.empty(), true);
163
164 test0.UnBind(std::bind((void(DelegateFuncTest::*)()) & DelegateFuncTest::Test, &funcTestClass));
165 test0.UnBind(std::bind(&DelegateFuncTest::Test1));
166 test0.UnBind([&]() { return funcTestClass.Test(); });
167 test0.UnBind([&]() { return DelegateFuncTest::Test1(); });
168 test0.UnBind([&]() { return DelegateTestT(); });
169
170 EXPECT_EQ(test0.size(), 3);
171 EXPECT_EQ(test2.empty(), true);
172 }
173
174 /**
175 * @brief Testing if broadcast successfully.
176 */
178
180
181 DelegateFuncTest funcTestClass;
182
183 test2.Bind(std::bind(&DelegateFuncTest::Test0, &funcTestClass, std::placeholders::_1, std::placeholders::_2));
184 test2.Broadcast(1, 10);
185
186 EXPECT_EQ(test2.size(), 1);
187 EXPECT_EQ(test2.empty(), false);
188 }
189
190 /**
191 * @brief Testing if copy successfully.
192 */
194
196
197 DelegateFuncTest funcTestClass;
198
199 /**
200 * @brief Bind to test2.
201 */
202 {
203 test2.Bind(std::bind(&DelegateFuncTest::Test0, &funcTestClass, std::placeholders::_1, std::placeholders::_2));
204
205 EXPECT_EQ(test2.size(), 1);
206 EXPECT_EQ(test2.empty(), false);
207 }
208
209 /**
210 * @brief Copy from test2.
211 */
212 {
213 DelegateTest2 test2c = test2;
214
215 EXPECT_EQ(test2c.size(), 1);
216 EXPECT_EQ(test2c.empty(), false);
217
218 test2c.UnBind(std::bind(&DelegateFuncTest::Test0, &funcTestClass, std::placeholders::_1, std::placeholders::_2));
219
220 EXPECT_EQ(test2.size(), 0);
221 EXPECT_EQ(test2.empty(), true);
222 }
223 }
224}
#define DELEGATE_ONE_PARAM(name, p0)
Use this macro to instance a Delegate Class. One Parameter Specific.
#define DELEGATE_THREE_PARAM(name, p0, p1, p2)
Use this macro to instance a Delegate Class. Three Parameter Specific.
#define DELEGATE_SIX_PARAM(name, p0, p1, p2, p3, p4, p5)
Use this macro to instance a Delegate Class. Six Parameter Specific.
#define DELEGATE_FIVE_PARAM(name, p0, p1, p2, p3, p4)
Use this macro to instance a Delegate Class. Five Parameter Specific.
#define DELEGATE_NONE_PARAM(name)
Use this macro to instance a Delegate Class. None Parameter Specific.
#define DELEGATE_SEVEN_PARAM(name, p0, p1, p2, p3, p4, p5, p6)
Use this macro to instance a Delegate Class. Seven Parameter Specific.
#define DELEGATE_EIGHT_PARAM(name, p0, p1, p2, p3, p4, p5, p6, p7)
Use this macro to instance a Delegate Class. Eight Parameter Specific.
#define DELEGATE_TWO_PARAM(name, p0, p1)
Use this macro to instance a Delegate Class. Two Parameter Specific.
#define DELEGATE_FOUR_PARAM(name, p0, p1, p2, p3)
Use this macro to instance a Delegate Class. Four Parameter Specific.
#define DELEGATE_NINE_PARAM(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)
Use this macro to instance a Delegate Class. Nine Parameter Specific.
#define SPICES_FUNC_SIG
#define SPICESTEST_PROFILE_SCOPE_LINE2(name, line)
#define SPICESTEST_PROFILE_SCOPE(name)
#define SPICES_PROFILE
#define SPICESTEST_PROFILE_END_SESSION()
#define SPICESTEST_PROFILE_BEGIN_SESSION(name, filepath)
#define SPICESTEST_PROFILE_SCOPE_LINE(name, line)
#define SPICESTEST_PROFILE_FUNCTION()
void Test0(int a, int b)
Basic Class Function.
void Test(float f)
Basic Override Class Function.
void Test()
Basic Override Class Function.
static void Test1()
Static Class Function.
Test Function Class.
void SetUp() override
The interface is inherited from testing::Test. Registry on Initialize.
void TearDown() override
Testing class TearDown function.
Instance Delegate Class.
InstrumentationTimer(const char *name)
std::chrono::time_point< std::chrono::steady_clock > m_StartTimepoint
Instrumentor(Instrumentor &&)=delete
static Instrumentor & Get()
void BeginSession(const std::string &name, const std::string &filepath="results.json")
void WriteProfile(const ProfileResult &result)
InstrumentationSession * m_CurrentSession
std::ofstream m_OutputStream
Instrumentor(const Instrumentor &)=delete
void Test(float f)
Basic Override Class Function.
void Test()
Basic Override Class Function.
void TearDown() override
Testing class TearDown function.
std::vector< scl::directed_acyclic_node > m_Nodes
void SetUp() override
Testing class initialize function.
The interface is inherited from testing::Test. Registy on Initialize.
void SetUp() override
The interface is inherited from testing::Test. Registry on Initialize.
void TearDown() override
The interface is inherited from testing::Test. Call before Destructor.
The interface is inherited from testing::Test. Registry on Initialize.
scl::kd_tree< 2 > m_KDTree
Create a KDTree with 2 dimensions.
Definition KDTree_test.h:57
void TearDown() override
Testing class TearDown function.
Definition KDTree_test.h:52
void SetUp() override
Testing class initialize function.
Definition KDTree_test.h:27
The interface is inherited from testing::Test. Registry on Initialize.
Definition KDTree_test.h:21
scl::linked_unordered_map< int, std::string > c1
scl::linked_unordered_map< float, std::string > c2
scl::linked_unordered_map< std::string, std::string > c0
void SetUp() override
Testing class initialize function.
void TearDown() override
Testing class TearDown function.
The interface is inherited from testing::Test. Registry on Initialize.
void SetUp() override
The interface is inherited from testing::Test. Registry on Initialize.
void TearDown() override
Testing class TearDown function.
Unit Test for RuntimeMemoryBlock.
void TearDown() override
The interface is inherited from testing::Test. Call before Destructor.
void SetUp() override
The interface is inherited from testing::Test. Registry on Initialize.
The interface is inherited from testing::Test. Registry on Initialize.
static void Init()
Init Log.
Definition Log.cpp:24
static void ShutDown()
Shutdown Log.
Definition Log.cpp:82
behave_state_list. wrapper of combing all state behaves.
bool Empty() const
Determine if this list is empty.
Definition FreeList.h:50
void Push(void *obj)
Recycle a object memory to this free list.
Definition FreeList.cpp:13
void *& Begin()
Get current pointer (no const & reference version).
Definition FreeList.h:94
void *& End()
Get end pointer (no const & reference version).
Definition FreeList.h:100
Free list for memory pool.
Definition FreeList.h:16
The kd_tree with K dimensions container Class. K the number of dimensions. Every node in the tree is ...
Definition KDTree.h:27
The container combines hashmap and list together. Used in the case that we want iter a hashmap in ord...
void build()
Malloc a memory to begin_.
void add_element(const std::string &name, const std::string &type)
Add a element to object_, means a memory block will be occupied with given param type.
runtime_memory_block()=default
Constructor Function.
void * get_addr() const
Get the begin_.
The container is wrapper of a continue memory block. Used in Material::BuildMaterial(),...
Bidirectional cyclic linked list for span.
Definition SpanList.h:73
span * m_Next
next span.
Definition SpanList.h:41
span * m_Prev
previous span.
Definition SpanList.h:46
Used for manage multiple page memory.
Definition SpanList.h:15
simple tree.
Definition Tree.h:18
This Class is similar to std::vector, the difference between that is this one allocates memory by mal...
Definition Vector.h:18
int main(int argc, char **argv)
The Entry of SpicesTest.
Definition main.cpp:76
constexpr auto CleanupOutputString(const char(&expr)[N], const char(&remove)[K])
TEST_F(free_list_test, PushPop)
Testing scl::free_list::Push/Pop.
TEST_F(runtime_memory_block_test, Initialize)
Testing if initialize successfully.
TEST_F(directed_acyclic_graph_test, Addnode)
Testing if add node successfully.
TEST_F(span_list_test, Initialize)
Testing scl::span_list::Initialize.
TEST_F(linked_unordered_map_test, Initialize)
Testing if initialize successfully.
TEST_F(kd_tree_test, Insert)
Testing if Insert successfully.
Definition KDTree_test.h:63
void DelegateTestT(Args ...args)
Template Function.
TEST(tuple_test, IterTuple)
Testing std::tuple Helper Function.
Definition Tuple_test.h:17
TEST_F(Delegate_test, Bind)
Testing if bind successfully.
void IterTuple(Tuple &tuple, Function &&f)
Iter a tuple.
Definition Tuple.h:34
std::thread::id ThreadID
std::chrono::microseconds ElapsedTime
FloatingPointMicroseconds Start