SpiecsEngine
 
Loading...
Searching...
No Matches
FreeList_test.h
Go to the documentation of this file.
1/**
2* @file FreeList_test.h.
3* @brief The FreeList_test Definitions.
4* @author Spices.
5*/
6
7#pragma once
8#include <gmock/gmock.h>
9#include <Core/Container/FreeList.h>
10#include "Instrumentor.h"
11
12namespace SpicesTest {
13
14 /**
15 * @brief The interface is inherited from testing::Test.
16 * Registry on Initialize.
17 */
18 class free_list_test : public testing::Test
19 {
20 protected:
21
22 /**
23 * @brief The interface is inherited from testing::Test.
24 * Registry on Initialize.
25 */
26 void SetUp() override {}
27
28 /**
29 * @brief The interface is inherited from testing::Test.
30 * Call before Destructor.
31 */
33
35 };
36
37 /**
38 * @brief Testing scl::free_list::Push/Pop.
39 */
41
43
44 std::array<int, 2> a;
45 uint64_t b = 0;
46 char* c = nullptr;
47 std::tuple<int, void* (*)(int)> d { 1, nullptr };
48
49 EXPECT_EQ(m_FreeList.Empty(), true);
50 EXPECT_EQ(m_FreeList.ApplyforNBlocks(), 1);
51 EXPECT_EQ(m_FreeList.Size(), 0);
52 EXPECT_EQ(m_FreeList.Begin(), nullptr);
53 EXPECT_EQ(m_FreeList.End(), nullptr);
54
55 {
56 m_FreeList.Push(&a);
57 m_FreeList.Push(&b);
58 m_FreeList.Push(&c);
59 m_FreeList.Push(&d);
60
61 EXPECT_EQ(m_FreeList.Empty(), false);
62 EXPECT_EQ(m_FreeList.ApplyforNBlocks(), 1);
63 EXPECT_EQ(m_FreeList.Size(), 4);
64 EXPECT_EQ(m_FreeList.End(), &a);
65
66 const void* p = m_FreeList.Begin();
67 EXPECT_EQ(p, &d);
68
69 const void* p1 = *(void**)p;
70 EXPECT_EQ(p1, &c);
71
72 const void* p2 = *(void**)p1;
73 EXPECT_EQ(p2, &b);
74
75 const void* p3 = *(void**)p2;
76 EXPECT_EQ(p3, &a);
77
78 const void* p4 = *(void**)p3;
79 EXPECT_EQ(p4, nullptr);
80 }
81
82 {
83 EXPECT_EQ(m_FreeList.Pop(), &d);
84 EXPECT_EQ(m_FreeList.Pop(), &c);
85 EXPECT_EQ(m_FreeList.Pop(), &b);
86 EXPECT_EQ(m_FreeList.Pop(), &a);
87
88 EXPECT_EQ(m_FreeList.Empty(), true);
89 EXPECT_EQ(m_FreeList.ApplyforNBlocks(), 1);
90 EXPECT_EQ(m_FreeList.Size(), 0);
91 EXPECT_EQ(m_FreeList.Begin(), nullptr);
92 EXPECT_EQ(m_FreeList.End(), nullptr);
93 }
94 }
95
96 /**
97 * @brief Testing scl::free_list::PushRange/PopRange.
98 */
100
102
103 scl::free_list list;
104
105 std::array<int, 2> a;
106 uint64_t b = 0;
107 char* c = nullptr;
108 std::tuple<int, void* (*)(int)> d { 1, nullptr };
109
110 m_FreeList.Push(&a);
111 m_FreeList.Push(&b);
112
113 list.Push(&c);
114 list.Push(&d);
115
116 {
117 m_FreeList.PushRange(list.Begin(), list.End(), list.Size());
118
119 EXPECT_EQ(m_FreeList.Empty(), false);
120 EXPECT_EQ(m_FreeList.ApplyforNBlocks(), 1);
121 EXPECT_EQ(m_FreeList.Size(), 4);
122 EXPECT_EQ(m_FreeList.End(), &a);
123
124 const void* p = m_FreeList.Begin();
125 EXPECT_EQ(p, &d);
126
127 const void* p1 = *(void**)p;
128 EXPECT_EQ(p1, &c);
129
130 const void* p2 = *(void**)p1;
131 EXPECT_EQ(p2, &b);
132
133 const void* p3 = *(void**)p2;
134 EXPECT_EQ(p3, &a);
135
136 const void* p4 = *(void**)p3;
137 EXPECT_EQ(p4, nullptr);
138 }
139
140 {
141 scl::free_list list2;
142 m_FreeList.PopRange(list2.Begin(), list2.End(), list.Size());
143
144 {
145 EXPECT_EQ(m_FreeList.Empty(), false);
146 EXPECT_EQ(m_FreeList.ApplyforNBlocks(), 1);
147 EXPECT_EQ(m_FreeList.Size(), 2);
148 EXPECT_EQ(m_FreeList.End(), &a);
149
150 const void* p = m_FreeList.Begin();
151 EXPECT_EQ(p, &b);
152
153 const void* p1 = *(void**)p;
154 EXPECT_EQ(p1, &a);
155
156 const void* p2 = *(void**)p1;
157 EXPECT_EQ(p2, nullptr);
158 }
159
160 {
161 EXPECT_EQ(list2.Empty(), false);
162 EXPECT_EQ(list2.ApplyforNBlocks(), 1);
163 EXPECT_EQ(list2.Size(), 0);
164 EXPECT_EQ(list2.End(), &c);
165
166 const void* p = list2.Begin();
167 EXPECT_EQ(p, &d);
168
169 const void* p1 = *(void**)p;
170 EXPECT_EQ(p1, &c);
171
172 const void* p2 = *(void**)p1;
173 EXPECT_EQ(p2, nullptr);
174 }
175 }
176 }
177}
#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.
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.
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(),...
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(linked_unordered_map_test, Initialize)
Testing if initialize successfully.
TEST_F(kd_tree_test, Insert)
Testing if Insert successfully.
Definition KDTree_test.h:63
TEST(tuple_test, IterTuple)
Testing std::tuple Helper Function.
Definition Tuple_test.h:17
void IterTuple(Tuple &tuple, Function &&f)
Iter a tuple.
Definition Tuple.h:34
std::thread::id ThreadID
std::chrono::microseconds ElapsedTime
FloatingPointMicroseconds Start