SpiecsEngine
 
Loading...
Searching...
No Matches
FileLibrary_test.h
Go to the documentation of this file.
1/**
2* @file FileLibrary_test.h.
3* @brief The FileLibrary_test Definitions.
4* @author Spices.
5*/
6
7#pragma once
8#include <gmock/gmock.h>
9#include <Core/Library/FileLibrary.h>
10#include "Instrumentor.h"
11
12namespace SpicesTest {
13
14 /**
15 * @brief Testing Spices::FileLibrary::Exists.
16 */
18
20
21 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Exists("premake5.lua"), true);
22 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Exists("vendor/googletest/premake5.lua"), true);
23 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Exists("src/main.cpp"), true);
24
25 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Exists("src/main1.cpp"), false);
26 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Exists("src/main2.cpp"), false);
27 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Exists("src/main3.cpp"), false);
28 }
29
30 /**
31 * @brief Testing Spices::FileLibrary::Open.
32 */
34
36
37 Spices::FileHandle handle{};
38 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Open("premake5.lua", Spices::FileModes::FILE_MODE_READ, false, &handle), true);
39
40 EXPECT_EQ(handle.is_valid, true);
41 EXPECT_NE(handle.handle, nullptr);
42 }
43
44 /**
45 * @brief Testing Spices::FileLibrary::Close.
46 */
48
50
51 Spices::FileHandle handle{};
52 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Open("premake5.lua", Spices::FileModes::FILE_MODE_READ, false, &handle), true);
53
54 EXPECT_EQ(handle.is_valid, true);
55 EXPECT_NE(handle.handle, nullptr);
56
58 }
59
60 /**
61 * @brief Testing Spices::FileLibrary::Size.
62 */
64
66
67 Spices::FileHandle handle{};
68 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Open("premake5.lua", Spices::FileModes::FILE_MODE_READ, false, &handle), true);
69
70 EXPECT_EQ(handle.is_valid, true);
71 EXPECT_NE(handle.handle, nullptr);
72
73 uint64_t size;
74 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Size(&handle, &size), true);
75 EXPECT_EQ(size, 5767);
76
78 }
79
80 /**
81 * @brief Testing Spices::FileLibrary::Read.
82 */
84
86
87 Spices::FileHandle handle{};
88 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Open("premake5.lua", Spices::FileModes::FILE_MODE_READ, false, &handle), true);
89
90 EXPECT_EQ(handle.is_valid, true);
91 EXPECT_NE(handle.handle, nullptr);
92
93 // First Line.
94 {
95 char data[29];
96 uint64_t bytes;
97 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Read(&handle, 29, data, &bytes), true);
98 EXPECT_EQ(bytes, 29);
99
100 std::string firstLineRead(data, bytes);
101 std::string firstLine = "-- @file SpicesTest Premake.\n";
102
103 EXPECT_STREQ(firstLineRead.c_str(), firstLine.c_str());
104 }
105
106 // Second Line.
107 {
108 char data[61];
109 uint64_t bytes;
110 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Read(&handle, 61, data, &bytes), true);
111 EXPECT_EQ(bytes, 61);
112
113 std::string firstLineRead(data, bytes);
114 std::string firstLine = "-- @brief Defines details of the UintTest Solution Building.\n";
115
116 EXPECT_STREQ(firstLineRead.c_str(), firstLine.c_str());
117 }
118
119 // Third Line.
120 {
121 char data[32];
122 uint64_t bytes;
123 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Read(&handle, 32, data, &bytes), true);
124 EXPECT_EQ(bytes, 32);
125
126 std::string firstLineRead(data, bytes);
127 std::string firstLine = "-- @author The Cherno & Spices.\n";
128
129 EXPECT_STREQ(firstLineRead.c_str(), firstLine.c_str());
130 }
131
133 }
134
135 /**
136 * @brief Testing Spices::FileLibrary::Read_Line.
137 */
139
141
142 Spices::FileHandle handle{};
143 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Open("premake5.lua", Spices::FileModes::FILE_MODE_READ, false, &handle), true);
144
145 EXPECT_EQ(handle.is_valid, true);
146 EXPECT_NE(handle.handle, nullptr);
147
148 // First Line.
149 {
150 char data[100];
151 uint64_t bytes;
152 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Read_Line(&handle, 1000, data, &bytes), true);
153 EXPECT_EQ(bytes, 29);
154
155 std::string firstLineRead(data, bytes);
156 std::string firstLine = "-- @file SpicesTest Premake.\n";
157
158 EXPECT_STREQ(firstLineRead.c_str(), firstLine.c_str());
159 }
160
161 // Second Line.
162 {
163 char data[100];
164 uint64_t bytes;
165 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Read_Line(&handle, 1000, data, &bytes), true);
166 EXPECT_EQ(bytes, 61);
167
168 std::string firstLineRead(data, bytes);
169 std::string firstLine = "-- @brief Defines details of the UintTest Solution Building.\n";
170
171 EXPECT_STREQ(firstLineRead.c_str(), firstLine.c_str());
172 }
173
174 // Third Line.
175 {
176 char data[100];
177 uint64_t bytes;
178 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Read_Line(&handle, 1000, data, &bytes), true);
179 EXPECT_EQ(bytes, 32);
180
181 std::string firstLineRead(data, bytes);
182 std::string firstLine = "-- @author The Cherno & Spices.\n";
183
184 EXPECT_STREQ(firstLineRead.c_str(), firstLine.c_str());
185 }
186
188 }
189
190 /**
191 * @brief Testing Spices::FileLibrary::Read_all_bytes.
192 */
194
196
197 Spices::FileHandle handle{};
198 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Open("premake5.lua", Spices::FileModes::FILE_MODE_READ, false, &handle), true);
199
200 EXPECT_EQ(handle.is_valid, true);
201 EXPECT_NE(handle.handle, nullptr);
202
203 {
204 char data[6000];
205 uint64_t bytes;
206
207 /**
208 * @todo Returns false here, but not known why?
209 */
211 }
212
214 }
215
216 /**
217 * @brief Testing Spices::FileLibrary::Write.
218 */
220
222
223 Spices::FileHandle handle{};
225
226 EXPECT_EQ(handle.is_valid, true);
227 EXPECT_NE(handle.handle, nullptr);
228
229 {
230 std::string data = "First Line.";
231 uint64_t bytes;
232 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Write(&handle, data.size(), data.c_str(), &bytes), true);
233
234 EXPECT_EQ(bytes, data.size());
235 }
236
238 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Delete("Write.txt"), true);
239 }
240
241 /**
242 * @brief Testing Spices::FileLibrary::Delete.
243 */
245
247
248 Spices::FileHandle handle{};
250
252 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Delete("Write.txt"), true);
253 }
254
255 /**
256 * @brief Testing Spices::FileLibrary::Write_Line.
257 */
259
261
262 Spices::FileHandle handle{};
264
265 EXPECT_EQ(handle.is_valid, true);
266 EXPECT_NE(handle.handle, nullptr);
267
268 {
269 const std::string data = "First Line.";
270 uint64_t bytes;
271 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Write_Line(&handle, data.c_str()), true);
272 }
273
275 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Delete("Write.txt"), true);
276 }
277
278 /**
279 * @brief Testing Spices::FileLibrary::CopyFile.
280 */
282
284
285 Spices::FileHandle handle{};
287 EXPECT_EQ(Spices::FileLibrary::FileLibrary_CopyFile("Write.txt", "Write1.txt"), true);
288
290 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Delete("Write.txt"), true);
291 EXPECT_EQ(Spices::FileLibrary::FileLibrary_Delete("Write1.txt"), true);
292 }
293}
#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
Declare Empty Class.
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 std::string GetClassString(ClassType t)
Get Class Name as string.
Class Static Function Library.
static bool FileLibrary_Size(const FileHandle *handle, uint64_t *out_size)
Calculate The file size.
static bool FileLibrary_Read(const FileHandle *handle, uint64_t data_size, void *out_data, uint64_t *out_bytes_read)
Read Specific size of data form the current file handle pointer, and move pointer the same size.
static bool FileLibrary_Write_Line(const FileHandle *handle, const char *text)
Write one line data to the file handle pointer.
static bool FileLibrary_Write(const FileHandle *handle, uint64_t data_size, const void *data, uint64_t *out_bytes_written)
Write given data to the file handle pointer.
static bool FileLibrary_Open(const char *path, FileModes mode, bool binary, FileHandle *out_handle)
Open the file using given string.
static void FileLibrary_Close(FileHandle *handle)
Close the file by the file handle.
static bool FileLibrary_Delete(const char *filePath)
Delete a file from disk.
static bool FileLibrary_CopyFile(std::string srcFilePath, std::string dstFilePath)
Copy a file to dst path.
static bool FileLibrary_Read_Line(const FileHandle *handle, uint64_t max_length, char *line_buf, uint64_t *out_line_length)
Read one line from the current file handle pointer, and move pointer the same size.
static bool FileLibrary_Exists(const char *path)
Determine whether the given string is existing a file.
static bool FileLibrary_Read_all_bytes(const FileHandle *handle, char *out_bytes, uint64_t *out_bytes_read)
Read all data form the current file handle pointer.
File Static Function Library.
Definition FileLibrary.h:49
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.
FileModes
file mode
Definition FileLibrary.h:32
@ FILE_MODE_READ
model : read
Definition FileLibrary.h:37
@ FILE_MODE_WRITE
model : write
Definition FileLibrary.h:42
void IterTuple(Tuple &tuple, Function &&f)
Iter a tuple.
Definition Tuple.h:34
std::thread::id ThreadID
std::chrono::microseconds ElapsedTime
FloatingPointMicroseconds Start
void * handle
FILE* handle. Need cast while use.
Definition FileLibrary.h:21
bool is_valid
Is this handle Valid.
Definition FileLibrary.h:26
This Struct is FILE* handle pointer Wrapper.
Definition FileLibrary.h:15