SpiecsEngine
 
Loading...
Searching...
No Matches
RuntimeMemoryBlock_test.h
Go to the documentation of this file.
1/**
2* @file RuntimeMemoryBlock_test.h.
3* @brief The RuntimeMemoryBlock Definitions.
4* @author Spices.
5*/
6
7#pragma once
8#include <gmock/gmock.h>
9#include <Core/Container/RuntimeMemoryBlock.h>
10#include "Instrumentor.h"
11
12namespace SpicesTest {
13
14 /**
15 * @brief Unit Test for RuntimeMemoryBlock
16 */
18 {
19 protected:
20
21 /**
22 * @brief The interface is inherited from testing::Test.
23 * Registry on Initialize.
24 */
25 void SetUp() override {
26 m0.add_element("1", "float");
27 m0.add_element("2", "float2");
28 m0.add_element("3", "float3");
29 m0.add_element("4", "float4");
30 }
31
32 /**
33 * @brief Testing class TearDown function.
34 */
36
37 scl::runtime_memory_block m0; /* @brief Test Item. */
38 };
39
40 /**
41 * @brief Testing if initialize successfully.
42 */
44
46
47 /**
48 * @brief Testing initialized container's size.
49 */
50 EXPECT_EQ(m0.size(), 4);
51
52 /**
53 * @brief Testing initialized container's bytes.
54 */
55 EXPECT_EQ(m0.get_bytes(), 40);
56
57 /**
58 * @brief Testing initialized container's address.
59 */
60 EXPECT_EQ(m0.get_addr(), nullptr);
61
62 /**
63 * @brief Testing initialized container's item_location.
64 */
65 EXPECT_EQ(m0.item_location("1"), 0);
66 EXPECT_EQ(m0.item_location("2"), 4);
67 EXPECT_EQ(m0.item_location("3"), 12);
68 EXPECT_EQ(m0.item_location("4"), 24);
69 }
70
71 /**
72 * @brief Testing if Add element successfully.
73 */
75
77
78 /**
79 * @brief Testing initialized container's size.
80 */
81 m0.add_element("5", "float");
82 m0.add_element("6", "float2");
83
84 /**
85 * @brief Testing initialized container's size.
86 */
87 EXPECT_EQ(m0.size(), 6);
88
89 /**
90 * @brief Testing initialized container's bytes.
91 */
92 EXPECT_EQ(m0.get_bytes(), 52);
93
94 /**
95 * @brief Testing initialized container's address.
96 */
97 EXPECT_EQ(m0.get_addr(), nullptr);
98
99 /**
100 * @brief Testing initialized container's item_location.
101 */
102 EXPECT_EQ(m0.item_location("5"), 40);
103 EXPECT_EQ(m0.item_location("6"), 44);
104 }
105
106 /**
107 * @brief Testing if Build successfully.
108 */
110
112
113 /**
114 * @brief Testing Build container.
115 */
117
118 EXPECT_EQ(m0.get_addr(), nullptr);
119 EXPECT_EQ(m1.get_addr(), nullptr);
120
121 m1.add_element("1", "float3");
122
123 EXPECT_EQ(m1.get_addr(), nullptr);
124
125 m0.build();
126 m1.build();
127
128 EXPECT_NE(m0.get_addr(), nullptr);
129 EXPECT_NE(m1.get_addr(), nullptr);
130 }
131
132 /**
133 * @brief Testing if Explain element successfully.
134 */
136
138
139 /**
140 * @brief Build before explain.
141 */
142 m0.build();
143
144 /**
145 * @brief Testing if build succeed.
146 */
147 EXPECT_NE(m0.get_value<float>("1"), 1.0f);
148 EXPECT_NE(m0.get_value<glm::vec2>("2"), glm::vec2(2.0f));
149 EXPECT_NE(m0.get_value<glm::vec3>("3"), glm::vec3(3.0f));
150 EXPECT_NE(m0.get_value<glm::vec4>("4"), glm::vec4(4.0f));
151
152 /**
153 * @brief Testing if float value explained succees.
154 */
155 m0.explain_element<float>("1", 1.0f);
156 EXPECT_EQ(m0.get_value<float>("1"), 1.0f);
157
158 /**
159 * @brief Testing if float2 value explained succees.
160 */
161 m0.explain_element<glm::vec2>("2", glm::vec2(2.0f));
162 EXPECT_EQ(m0.get_value<glm::vec2>("2"), glm::vec2(2.0f));
163
164 /**
165 * @brief Testing if float3 value explained succees.
166 */
167 m0.explain_element<glm::vec3>("3", glm::vec3(3.0f));
168 EXPECT_EQ(m0.get_value<glm::vec3>("3"), glm::vec3(3.0f));
169
170 /**
171 * @brief Testing if float4 value explained succees.
172 */
173 m0.explain_element<glm::vec4>("4", glm::vec4(4.0f));
174 EXPECT_EQ(m0.get_value<glm::vec4>("4"), glm::vec4(4.0f));
175 }
176
177 /**
178 * @brief Testing if Destruct successfully.
179 */
181
183
184 /**
185 * @brief New a object.
186 */
187 auto m1 = new scl::runtime_memory_block();
188
189 /**
190 * @brief Testing if init succeed.
191 */
192 m1->add_element("1", "float3");
193 m1->build();
194 m1->explain_element<glm::vec3>("1", glm::vec3(3.0f));
195
196 EXPECT_EQ(m1->get_value<glm::vec3>("1"), glm::vec3(3.0f));
197
198 /**
199 * @brief Test failed.
200 * @todo More effective test.
201 */
202 void* addr = m1->get_addr();
203 EXPECT_NE(addr, nullptr);
204
205 delete m1;
206 EXPECT_NE(addr, nullptr);
207 }
208
209 /**
210 * @brief Testing if ItemLocation test successfully.
211 */
213
215
216 /**
217 * @brief item location in valid item.
218 */
219 EXPECT_EQ(m0.item_location("1"), 0 );
220 EXPECT_EQ(m0.item_location("2"), 4 );
221 EXPECT_EQ(m0.item_location("3"), 12);
222 EXPECT_EQ(m0.item_location("4"), 24);
223
224 /**
225 * @brief item location in unvalid item.
226 */
227 EXPECT_EQ(m0.item_location("5"), UINT32_MAX);
228 EXPECT_EQ(m0.item_location("6"), UINT32_MAX);
229 EXPECT_EQ(m0.item_location("7"), UINT32_MAX);
230 EXPECT_EQ(m0.item_location("8"), UINT32_MAX);
231 }
232
233 /**
234 * @brief Testing if has_value test successfully.
235 */
237
239
240 /**
241 * @brief item location in valid item.
242 */
243 EXPECT_EQ(m0.has_value("1"), true);
244 EXPECT_EQ(m0.has_value("2"), true);
245 EXPECT_EQ(m0.has_value("3"), true);
246 EXPECT_EQ(m0.has_value("4"), true);
247
248 /**
249 * @brief item location in unvalid item.
250 */
251 EXPECT_EQ(m0.has_value("5"), false);
252 EXPECT_EQ(m0.has_value("6"), false);
253 EXPECT_EQ(m0.has_value("7"), false);
254 EXPECT_EQ(m0.has_value("8"), false);
255 }
256}
#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()
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.
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.
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(),...
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(runtime_memory_block_test, Initialize)
Testing if initialize successfully.
TEST_F(directed_acyclic_graph_test, Addnode)
Testing if add node successfully.
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
std::thread::id ThreadID
std::chrono::microseconds ElapsedTime
FloatingPointMicroseconds Start