Update usage of Dqn.h in Dqn_UnitTests.cpp
This commit is contained in:
parent
26ec804fd8
commit
3b38cca63e
@ -14,5 +14,5 @@ REM Tp Treat header file as CPP source file
|
|||||||
cl /MT /EHa /GR- /Od /Oi /Z7 /W4 /WX /wd4201 /D DQN_HEADER_IMPLEMENTATION /Tp ../Code/DqnHeader.h /link /nologo
|
cl /MT /EHa /GR- /Od /Oi /Z7 /W4 /WX /wd4201 /D DQN_HEADER_IMPLEMENTATION /Tp ../Code/DqnHeader.h /link /nologo
|
||||||
DqnHeader.exe ..\Code\Dqn.h > ..\Code\DqnHeader_Generated.h
|
DqnHeader.exe ..\Code\Dqn.h > ..\Code\DqnHeader_Generated.h
|
||||||
|
|
||||||
cl /MT /EHa /GR- /Od /Oi /Z7 /W4 /WX /P /wd4201 /D DQN_IMPLEMENTATION ../Code/Dqn_UnitTests.cpp /link /nologo
|
cl /MT /EHa /GR- /Od /Oi /Z7 /W4 /WX /wd4201 /D DQN_IMPLEMENTATION ../Code/Dqn_UnitTests.cpp /link /nologo
|
||||||
popd
|
popd
|
||||||
|
12
Code/Dqn.h
12
Code/Dqn.h
@ -989,10 +989,9 @@ DQN_HEADER_COPY_PROTOTYPE(void, Dqn_FixedArray_Clear(DQN_FIXED_ARRAY_TEMPLATE_DE
|
|||||||
DQN_FIXED_ARRAY_TEMPLATE
|
DQN_FIXED_ARRAY_TEMPLATE
|
||||||
DQN_HEADER_COPY_PROTOTYPE(void, Dqn_FixedArray_EraseStable(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize index))
|
DQN_HEADER_COPY_PROTOTYPE(void, Dqn_FixedArray_EraseStable(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize index))
|
||||||
{
|
{
|
||||||
Dqn_EraseStableFromCArray<T>(a->data, a->len--, a->Max(), index);
|
Dqn__EraseStableFromCArray<T>(a->data, a->len--, a->Max(), index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DQN_FIXED_ARRAY_TEMPLATE
|
DQN_FIXED_ARRAY_TEMPLATE
|
||||||
DQN_HEADER_COPY_PROTOTYPE(void, Dqn_FixedArray_EraseUnstable(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize index))
|
DQN_HEADER_COPY_PROTOTYPE(void, Dqn_FixedArray_EraseUnstable(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize index))
|
||||||
{
|
{
|
||||||
@ -1009,7 +1008,6 @@ DQN_HEADER_COPY_PROTOTYPE(void, Dqn_FixedArray_Pop(DQN_FIXED_ARRAY_TEMPLATE_DECL
|
|||||||
a->len -= num;
|
a->len -= num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DQN_FIXED_ARRAY_TEMPLATE
|
DQN_FIXED_ARRAY_TEMPLATE
|
||||||
DQN_HEADER_COPY_PROTOTYPE(T *, Dqn_FixedArray_Peek(DQN_FIXED_ARRAY_TEMPLATE_DECL *a))
|
DQN_HEADER_COPY_PROTOTYPE(T *, Dqn_FixedArray_Peek(DQN_FIXED_ARRAY_TEMPLATE_DECL *a))
|
||||||
{
|
{
|
||||||
@ -1083,13 +1081,13 @@ DQN_HEADER_COPY_END
|
|||||||
|
|
||||||
DQN_HEADER_COPY_PROTOTYPE(template <typename T> Dqn_StaticArray<T> , Dqn_StaticArray_InitMemory (T *memory, Dqn_isize max, Dqn_isize len = 0)) { Dqn_StaticArray<T> result = {}; result.data = memory; result.len = len; result.max = max; return result; }
|
DQN_HEADER_COPY_PROTOTYPE(template <typename T> Dqn_StaticArray<T> , Dqn_StaticArray_InitMemory (T *memory, Dqn_isize max, Dqn_isize len = 0)) { Dqn_StaticArray<T> result = {}; result.data = memory; result.len = len; result.max = max; return result; }
|
||||||
DQN_HEADER_COPY_PROTOTYPE(template <typename T> T *, Dqn_StaticArray_Add (Dqn_StaticArray<T> *a, T const *items, Dqn_isize num)) { DQN_ASSERT(a->len + num <= a->max); T *result = static_cast<T *>(Dqn_MemCopy(a->data + a->len, items, sizeof(T) * num)); a->len += num; return result; }
|
DQN_HEADER_COPY_PROTOTYPE(template <typename T> T *, Dqn_StaticArray_Add (Dqn_StaticArray<T> *a, T const *items, Dqn_isize num)) { DQN_ASSERT(a->len + num <= a->max); T *result = static_cast<T *>(Dqn_MemCopy(a->data + a->len, items, sizeof(T) * num)); a->len += num; return result; }
|
||||||
DQN_HEADER_COPY_PROTOTYPE(template <typename T> T *, Dqn_StaticArray_Add (Dqn_StaticArray<T> *a, T const item)) { DQN_ASSERT(a->len < a->max); a->data[a->len++] = item; return &a->data[a->len - 1]; }
|
DQN_HEADER_COPY_PROTOTYPE(template <typename T> T *, Dqn_StaticArray_Add (Dqn_StaticArray<T> *a, T const item)) { DQN_ASSERT(a->len < a->max); a->data[a->len++] = item; return &a->data[a->len - 1]; }
|
||||||
DQN_HEADER_COPY_PROTOTYPE(template <typename T> T *, Dqn_StaticArray_Make (Dqn_StaticArray<T> *a, Dqn_isize num)) { DQN_ASSERT(a->len + num <= a->max); T *result = a->data + a->len; a->len += num; return result;}
|
DQN_HEADER_COPY_PROTOTYPE(template <typename T> T *, Dqn_StaticArray_Make (Dqn_StaticArray<T> *a, Dqn_isize num)) { DQN_ASSERT(a->len + num <= a->max); T *result = a->data + a->len; a->len += num; return result;}
|
||||||
DQN_HEADER_COPY_PROTOTYPE(template <typename T> void , Dqn_StaticArray_Clear (Dqn_StaticArray<T> *a)) { a->len = 0; }
|
DQN_HEADER_COPY_PROTOTYPE(template <typename T> void , Dqn_StaticArray_Clear (Dqn_StaticArray<T> *a)) { a->len = 0; }
|
||||||
DQN_HEADER_COPY_PROTOTYPE(template <typename T> void , Dqn_StaticArray_EraseStable (Dqn_StaticArray<T> *a, Dqn_isize index)) { Dqn_EraseStableFromCArray<T>(a->data, a->len--, a->max, index); }
|
DQN_HEADER_COPY_PROTOTYPE(template <typename T> void , Dqn_StaticArray_EraseStable (Dqn_StaticArray<T> *a, Dqn_isize index)) { Dqn__EraseStableFromCArray<T>(a->data, a->len--, a->max, index); }
|
||||||
DQN_HEADER_COPY_PROTOTYPE(template <typename T> void , Dqn_StaticArray_EraseUnstable(Dqn_StaticArray<T> *a, Dqn_isize index)) { DQN_ASSERT(index >= 0 && index < a->len); if (--a->len == 0) return; a->data[index] = a->data[a->len]; }
|
DQN_HEADER_COPY_PROTOTYPE(template <typename T> void , Dqn_StaticArray_EraseUnstable(Dqn_StaticArray<T> *a, Dqn_isize index)) { DQN_ASSERT(index >= 0 && index < a->len); if (--a->len == 0) return; a->data[index] = a->data[a->len]; }
|
||||||
DQN_HEADER_COPY_PROTOTYPE(template <typename T> void , Dqn_StaticArray_Pop (Dqn_StaticArray<T> *a, Dqn_isize num)) { DQN_ASSERT(a->len - num >= 0); a->len -= num; }
|
DQN_HEADER_COPY_PROTOTYPE(template <typename T> void , Dqn_StaticArray_Pop (Dqn_StaticArray<T> *a, Dqn_isize num)) { DQN_ASSERT(a->len - num >= 0); a->len -= num; }
|
||||||
DQN_HEADER_COPY_PROTOTYPE(template <typename T> T *, Dqn_StaticArray_Peek (Dqn_StaticArray<T> *a)) { T *result = (a->len == 0) ? nullptr : a->data + (a->len - 1); return result; }
|
DQN_HEADER_COPY_PROTOTYPE(template <typename T> T *, Dqn_StaticArray_Peek (Dqn_StaticArray<T> *a)) { T *result = (a->len == 0) ? nullptr : a->data + (a->len - 1); return result; }
|
||||||
|
|
||||||
// @ -------------------------------------------------------------------------------------------------
|
// @ -------------------------------------------------------------------------------------------------
|
||||||
// @
|
// @
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
|
#define DQN_USE_PRIMITIVE_TYPEDEFS
|
||||||
#define _CRT_SECURE_NO_WARNINGS
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
#include "Dqn.h"
|
#include "Dqn.h"
|
||||||
|
|
||||||
struct TestState
|
struct TestState
|
||||||
{
|
{
|
||||||
Dqn_MemArena arena;
|
Dqn_MemArena arena;
|
||||||
int indent_level;
|
int indent_level;
|
||||||
Slice<char> name;
|
Dqn_Slice<char> name;
|
||||||
Slice<char> fail_expr;
|
Dqn_Slice<char> fail_expr;
|
||||||
Slice<char> fail_msg;
|
Dqn_Slice<char> fail_msg;
|
||||||
bool scope_started;
|
bool scope_started;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TestingState
|
struct TestingState
|
||||||
@ -33,7 +34,7 @@ struct TestingState
|
|||||||
TestState_PrintResult(&testing_state.test); \
|
TestState_PrintResult(&testing_state.test); \
|
||||||
testing_state.test = {}; \
|
testing_state.test = {}; \
|
||||||
}; \
|
}; \
|
||||||
testing_state.test.name = AsprintfSlice(&testing_state.test.arena, test_name); \
|
testing_state.test.name = Dqn_AsprintfSlice(&testing_state.test.arena, test_name); \
|
||||||
testing_state.test.scope_started = true; \
|
testing_state.test.scope_started = true; \
|
||||||
testing_state.num_tests_in_group++
|
testing_state.num_tests_in_group++
|
||||||
|
|
||||||
@ -49,8 +50,8 @@ struct TestingState
|
|||||||
DQN_ASSERT(testing_state.test.scope_started); \
|
DQN_ASSERT(testing_state.test.scope_started); \
|
||||||
if (!(expr)) \
|
if (!(expr)) \
|
||||||
{ \
|
{ \
|
||||||
testing_state.test.fail_expr = AsprintfSlice(&testing_state.test.arena, #expr); \
|
testing_state.test.fail_expr = Dqn_AsprintfSlice(&testing_state.test.arena, #expr); \
|
||||||
testing_state.test.fail_msg = AsprintfSlice(&testing_state.test.arena, msg, ##__VA_ARGS__); \
|
testing_state.test.fail_msg = Dqn_AsprintfSlice(&testing_state.test.arena, msg, ##__VA_ARGS__); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TEST_EXPECT(testing_state, expr) TEST_EXPECT_MSG(testing_state, expr, "")
|
#define TEST_EXPECT(testing_state, expr) TEST_EXPECT_MSG(testing_state, expr, "")
|
||||||
@ -185,7 +186,6 @@ FILE_SCOPE void UnitTests()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NOTE: Dqn_StringBuilder_AppendChar
|
// NOTE: Dqn_StringBuilder_AppendChar
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Append char and build using malloc");
|
TEST_START_SCOPE(testing_state, "Append char and build using malloc");
|
||||||
@ -295,124 +295,124 @@ FILE_SCOPE void UnitTests()
|
|||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// NOTE: Dqn_StrToI64
|
// NOTE: Dqn_Str_ToI64
|
||||||
//
|
//
|
||||||
// ---------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------
|
||||||
{
|
{
|
||||||
TEST_DECLARE_GROUP_SCOPED(testing_state, "Dqn_StrToI64");
|
TEST_DECLARE_GROUP_SCOPED(testing_state, "Dqn_Str_ToI64");
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert nullptr");
|
TEST_START_SCOPE(testing_state, "Convert nullptr");
|
||||||
i64 result = Dqn_StrToI64(nullptr);
|
i64 result = Dqn_Str_ToI64(nullptr);
|
||||||
TEST_EXPECT(testing_state, result == 0);
|
TEST_EXPECT(testing_state, result == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert empty string");
|
TEST_START_SCOPE(testing_state, "Convert empty string");
|
||||||
i64 result = Dqn_StrToI64("");
|
i64 result = Dqn_Str_ToI64("");
|
||||||
TEST_EXPECT(testing_state, result == 0);
|
TEST_EXPECT(testing_state, result == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert \"1\"");
|
TEST_START_SCOPE(testing_state, "Convert \"1\"");
|
||||||
i64 result = Dqn_StrToI64("1");
|
i64 result = Dqn_Str_ToI64("1");
|
||||||
TEST_EXPECT(testing_state, result == 1);
|
TEST_EXPECT(testing_state, result == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert \"-0\"");
|
TEST_START_SCOPE(testing_state, "Convert \"-0\"");
|
||||||
i64 result = Dqn_StrToI64("-0");
|
i64 result = Dqn_Str_ToI64("-0");
|
||||||
TEST_EXPECT(testing_state, result == 0);
|
TEST_EXPECT(testing_state, result == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert \"-1\"");
|
TEST_START_SCOPE(testing_state, "Convert \"-1\"");
|
||||||
i64 result = Dqn_StrToI64("-1");
|
i64 result = Dqn_Str_ToI64("-1");
|
||||||
TEST_EXPECT(testing_state, result == -1);
|
TEST_EXPECT(testing_state, result == -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert \"1.2\"");
|
TEST_START_SCOPE(testing_state, "Convert \"1.2\"");
|
||||||
i64 result = Dqn_StrToI64("1.2");
|
i64 result = Dqn_Str_ToI64("1.2");
|
||||||
TEST_EXPECT(testing_state, result == 1);
|
TEST_EXPECT(testing_state, result == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert \"1,234\"");
|
TEST_START_SCOPE(testing_state, "Convert \"1,234\"");
|
||||||
i64 result = Dqn_StrToI64("1,234");
|
i64 result = Dqn_Str_ToI64("1,234");
|
||||||
TEST_EXPECT(testing_state, result == 1234);
|
TEST_EXPECT(testing_state, result == 1234);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert \"1,2\"");
|
TEST_START_SCOPE(testing_state, "Convert \"1,2\"");
|
||||||
i64 result = Dqn_StrToI64("1,2");
|
i64 result = Dqn_Str_ToI64("1,2");
|
||||||
TEST_EXPECT(testing_state, result == 12);
|
TEST_EXPECT(testing_state, result == 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert \"12a3\"");
|
TEST_START_SCOPE(testing_state, "Convert \"12a3\"");
|
||||||
i64 result = Dqn_StrToI64("12a3");
|
i64 result = Dqn_Str_ToI64("12a3");
|
||||||
TEST_EXPECT(testing_state, result == 12);
|
TEST_EXPECT(testing_state, result == 12);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// NOTE: Dqn_StrToU64
|
// NOTE: Dqn_Str_ToU64
|
||||||
//
|
//
|
||||||
// ---------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------
|
||||||
{
|
{
|
||||||
TEST_DECLARE_GROUP_SCOPED(testing_state, "Dqn_StrToU64");
|
TEST_DECLARE_GROUP_SCOPED(testing_state, "Dqn_Str_ToU64");
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert nullptr");
|
TEST_START_SCOPE(testing_state, "Convert nullptr");
|
||||||
u64 result = Dqn_StrToU64(nullptr);
|
u64 result = Dqn_Str_ToU64(nullptr);
|
||||||
TEST_EXPECT(testing_state, result == 0);
|
TEST_EXPECT(testing_state, result == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert empty string");
|
TEST_START_SCOPE(testing_state, "Convert empty string");
|
||||||
u64 result = Dqn_StrToU64("");
|
u64 result = Dqn_Str_ToU64("");
|
||||||
TEST_EXPECT(testing_state, result == 0);
|
TEST_EXPECT(testing_state, result == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert \"1\"");
|
TEST_START_SCOPE(testing_state, "Convert \"1\"");
|
||||||
u64 result = Dqn_StrToU64("1");
|
u64 result = Dqn_Str_ToU64("1");
|
||||||
TEST_EXPECT(testing_state, result == 1);
|
TEST_EXPECT(testing_state, result == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert \"-0\"");
|
TEST_START_SCOPE(testing_state, "Convert \"-0\"");
|
||||||
u64 result = Dqn_StrToU64("-0");
|
u64 result = Dqn_Str_ToU64("-0");
|
||||||
TEST_EXPECT(testing_state, result == 0);
|
TEST_EXPECT(testing_state, result == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert \"-1\"");
|
TEST_START_SCOPE(testing_state, "Convert \"-1\"");
|
||||||
u64 result = Dqn_StrToU64("-1");
|
u64 result = Dqn_Str_ToU64("-1");
|
||||||
TEST_EXPECT(testing_state, result == 0);
|
TEST_EXPECT(testing_state, result == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert \"1.2\"");
|
TEST_START_SCOPE(testing_state, "Convert \"1.2\"");
|
||||||
u64 result = Dqn_StrToU64("1.2");
|
u64 result = Dqn_Str_ToU64("1.2");
|
||||||
TEST_EXPECT(testing_state, result == 1);
|
TEST_EXPECT(testing_state, result == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert \"1,234\"");
|
TEST_START_SCOPE(testing_state, "Convert \"1,234\"");
|
||||||
u64 result = Dqn_StrToU64("1,234");
|
u64 result = Dqn_Str_ToU64("1,234");
|
||||||
TEST_EXPECT(testing_state, result == 1234);
|
TEST_EXPECT(testing_state, result == 1234);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert \"1,2\"");
|
TEST_START_SCOPE(testing_state, "Convert \"1,2\"");
|
||||||
u64 result = Dqn_StrToU64("1,2");
|
u64 result = Dqn_Str_ToU64("1,2");
|
||||||
TEST_EXPECT(testing_state, result == 12);
|
TEST_EXPECT(testing_state, result == 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TEST_START_SCOPE(testing_state, "Convert \"12a3\"");
|
TEST_START_SCOPE(testing_state, "Convert \"12a3\"");
|
||||||
u64 result = Dqn_StrToU64("12a3");
|
u64 result = Dqn_Str_ToU64("12a3");
|
||||||
TEST_EXPECT(testing_state, result == 12);
|
TEST_EXPECT(testing_state, result == 12);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -422,7 +422,6 @@ int main(char *argv[], int argc)
|
|||||||
{
|
{
|
||||||
(void)argv; (void)argc;
|
(void)argv; (void)argc;
|
||||||
UnitTests();
|
UnitTests();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user