From 832bafccff577246dde2d11c23582f6a644c6c94 Mon Sep 17 00:00:00 2001 From: talha Date: Wed, 13 Mar 2024 23:18:29 +0500 Subject: Refactored Memory, Removed Strings --- strings/test.cpp | 65 -------------------------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 strings/test.cpp (limited to 'strings/test.cpp') diff --git a/strings/test.cpp b/strings/test.cpp deleted file mode 100644 index 49f81c9..0000000 --- a/strings/test.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include "strings.h" -#include "strings.cpp" - -void TestCstrSize() -{ - u64 size = CstrSize("hello sailor\n"); - assert(size == 13 && "test_cstr_size() failed" - "the cstr size was wrong\n"); -} - -void TestEmptyCstrSize() -{ - u64 size = CstrSize(""); - assert(size == 0 && "test_empty_cstr_size() failed" - "the cstr size was wrong\n"); -} - -void TestStr8InitCstr(u8* buffer, u64 buffer_size) -{ - struct arena a = {}; - arena_init(&a, buffer, buffer_size); - struct res_str8 qres = Str8InitCstr(&a, "hello sailor"); - assert((qres.bytes_count == 12) && "Error TestStr8InitCstr:\n" - "Reason: Invalid size of allocated string\n" - "Hint: check what is happening to the bytes_count and how it is set first\n"); -} - -void TestStr8InitCstrEmpty(u8* buffer, u64 buffer_size) -{ - struct arena a = {}; - arena_init(&a, buffer, buffer_size); - struct res_str8 qres = Str8InitCstr(&a, ""); - assert((qres.string.size == 0) && "Error TestStr8InitCstrEmpty:\n" - "Reason: Invalid size of allocated string\n" - "Hint: check what is happening to the bytes_count and how it is set first\n"); -} - -void TestStr8InitCstrNoSpace(u8* buffer, u8 buffer_size) -{ - struct arena a = {}; - arena_init(&a, buffer, buffer_size); - struct res_str8 qres = Str8InitCstr(&a, "hello sailor, looks like you've got no space here on this boat!"); - assert(qres.string.size == 0 && "Error TestStr8InitStrNoSpace:\n" - "Reason: the bytes count is not 0, even though the string is larger than the supposedly available\n" - "arena space. This is an error and should not occur.\n" - "Hint: Look at what is going on in the allocation since that arena helpers handle allocations\n."); -} - -void test_strings() -{ - printf("\n======= Testing Strings Library =======\n"); - printf("===== Testing Cstring Functions =====\n"); - TestCstrSize(); - TestEmptyCstrSize(); - - u64 buffer_size = KB(64); - u8* buffer = (u8*)malloc(sizeof(u8)*buffer_size); - - TestStr8InitCstr(buffer, buffer_size); - TestStr8InitCstrEmpty(buffer, buffer_size); - TestStr8InitCstrNoSpace(buffer, 8); - printf("Cstring tests passed successfully\n"); - free(buffer); -} -- cgit v1.2.3