From 3b38cca63e70b7d1e003375be151b87e3ad07587 Mon Sep 17 00:00:00 2001 From: doyle Date: Tue, 3 Sep 2019 23:19:03 +1000 Subject: [PATCH] Update usage of Dqn.h in Dqn_UnitTests.cpp --- Code/Build.bat | 2 +- Code/Dqn.h | 12 ++++---- Code/Dqn_UnitTests.cpp | 65 +++++++++++++++++++++--------------------- 3 files changed, 38 insertions(+), 41 deletions(-) diff --git a/Code/Build.bat b/Code/Build.bat index 0d8fa4b..ecfe9f8 100644 --- a/Code/Build.bat +++ b/Code/Build.bat @@ -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 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 diff --git a/Code/Dqn.h b/Code/Dqn.h index 19990e6..09bff58 100644 --- a/Code/Dqn.h +++ b/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_HEADER_COPY_PROTOTYPE(void, Dqn_FixedArray_EraseStable(DQN_FIXED_ARRAY_TEMPLATE_DECL *a, Dqn_isize index)) { - Dqn_EraseStableFromCArray(a->data, a->len--, a->Max(), index); + Dqn__EraseStableFromCArray(a->data, a->len--, a->Max(), index); } - DQN_FIXED_ARRAY_TEMPLATE 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; } - DQN_FIXED_ARRAY_TEMPLATE 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 Dqn_StaticArray , Dqn_StaticArray_InitMemory (T *memory, Dqn_isize max, Dqn_isize len = 0)) { Dqn_StaticArray result = {}; result.data = memory; result.len = len; result.max = max; return result; } DQN_HEADER_COPY_PROTOTYPE(template T *, Dqn_StaticArray_Add (Dqn_StaticArray *a, T const *items, Dqn_isize num)) { DQN_ASSERT(a->len + num <= a->max); T *result = static_cast(Dqn_MemCopy(a->data + a->len, items, sizeof(T) * num)); a->len += num; return result; } -DQN_HEADER_COPY_PROTOTYPE(template T *, Dqn_StaticArray_Add (Dqn_StaticArray *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 T *, Dqn_StaticArray_Add (Dqn_StaticArray *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 T *, Dqn_StaticArray_Make (Dqn_StaticArray *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 void , Dqn_StaticArray_Clear (Dqn_StaticArray *a)) { a->len = 0; } -DQN_HEADER_COPY_PROTOTYPE(template void , Dqn_StaticArray_EraseStable (Dqn_StaticArray *a, Dqn_isize index)) { Dqn_EraseStableFromCArray(a->data, a->len--, a->max, index); } +DQN_HEADER_COPY_PROTOTYPE(template void , Dqn_StaticArray_Clear (Dqn_StaticArray *a)) { a->len = 0; } +DQN_HEADER_COPY_PROTOTYPE(template void , Dqn_StaticArray_EraseStable (Dqn_StaticArray *a, Dqn_isize index)) { Dqn__EraseStableFromCArray(a->data, a->len--, a->max, index); } DQN_HEADER_COPY_PROTOTYPE(template void , Dqn_StaticArray_EraseUnstable(Dqn_StaticArray *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 void , Dqn_StaticArray_Pop (Dqn_StaticArray *a, Dqn_isize num)) { DQN_ASSERT(a->len - num >= 0); a->len -= num; } -DQN_HEADER_COPY_PROTOTYPE(template T *, Dqn_StaticArray_Peek (Dqn_StaticArray *a)) { T *result = (a->len == 0) ? nullptr : a->data + (a->len - 1); return result; } +DQN_HEADER_COPY_PROTOTYPE(template T *, Dqn_StaticArray_Peek (Dqn_StaticArray *a)) { T *result = (a->len == 0) ? nullptr : a->data + (a->len - 1); return result; } // @ ------------------------------------------------------------------------------------------------- // @ diff --git a/Code/Dqn_UnitTests.cpp b/Code/Dqn_UnitTests.cpp index fd60961..2c77118 100644 --- a/Code/Dqn_UnitTests.cpp +++ b/Code/Dqn_UnitTests.cpp @@ -1,14 +1,15 @@ +#define DQN_USE_PRIMITIVE_TYPEDEFS #define _CRT_SECURE_NO_WARNINGS #include "Dqn.h" struct TestState { - Dqn_MemArena arena; - int indent_level; - Slice name; - Slice fail_expr; - Slice fail_msg; - bool scope_started; + Dqn_MemArena arena; + int indent_level; + Dqn_Slice name; + Dqn_Slice fail_expr; + Dqn_Slice fail_msg; + bool scope_started; }; struct TestingState @@ -33,7 +34,7 @@ struct TestingState TestState_PrintResult(&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.num_tests_in_group++ @@ -49,8 +50,8 @@ struct TestingState DQN_ASSERT(testing_state.test.scope_started); \ if (!(expr)) \ { \ - testing_state.test.fail_expr = AsprintfSlice(&testing_state.test.arena, #expr); \ - testing_state.test.fail_msg = AsprintfSlice(&testing_state.test.arena, msg, ##__VA_ARGS__); \ + testing_state.test.fail_expr = Dqn_AsprintfSlice(&testing_state.test.arena, #expr); \ + 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, "") @@ -185,7 +186,6 @@ FILE_SCOPE void UnitTests() } } - // NOTE: Dqn_StringBuilder_AppendChar { 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"); - i64 result = Dqn_StrToI64(nullptr); + i64 result = Dqn_Str_ToI64(nullptr); TEST_EXPECT(testing_state, result == 0); } { TEST_START_SCOPE(testing_state, "Convert empty string"); - i64 result = Dqn_StrToI64(""); + i64 result = Dqn_Str_ToI64(""); TEST_EXPECT(testing_state, result == 0); } { 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_START_SCOPE(testing_state, "Convert \"-0\""); - i64 result = Dqn_StrToI64("-0"); + i64 result = Dqn_Str_ToI64("-0"); TEST_EXPECT(testing_state, result == 0); } { 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_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_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_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_START_SCOPE(testing_state, "Convert \"12a3\""); - i64 result = Dqn_StrToI64("12a3"); + i64 result = Dqn_Str_ToI64("12a3"); 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"); - u64 result = Dqn_StrToU64(nullptr); + u64 result = Dqn_Str_ToU64(nullptr); TEST_EXPECT(testing_state, result == 0); } { TEST_START_SCOPE(testing_state, "Convert empty string"); - u64 result = Dqn_StrToU64(""); + u64 result = Dqn_Str_ToU64(""); TEST_EXPECT(testing_state, result == 0); } { 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_START_SCOPE(testing_state, "Convert \"-0\""); - u64 result = Dqn_StrToU64("-0"); + u64 result = Dqn_Str_ToU64("-0"); TEST_EXPECT(testing_state, result == 0); } { 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_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_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_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_START_SCOPE(testing_state, "Convert \"12a3\""); - u64 result = Dqn_StrToU64("12a3"); + u64 result = Dqn_Str_ToU64("12a3"); TEST_EXPECT(testing_state, result == 12); } } @@ -422,7 +422,6 @@ int main(char *argv[], int argc) { (void)argv; (void)argc; UnitTests(); - return 0; }