## Summary Standardize naming conventions across the entire wizapp-stdlib codebase by replacing inconsistent prefixes and snake_case with a unified `wp` prefix + CamelCase scheme. ## Changes ### Naming convention applied | Pattern | Before | After | |---|---|---| | Public functions | `wapp_module_function` | `wpModuleFunction` | | Public types | `GenericXxx`, bare `Xxx` | `WpXxx` | | Constants / enum values | `WAPP_XXX`, `SHELL_XXX` | `WP_XXX`, `WP_SHELL_XXX` | | Internal functions | `_module_function` | `_moduleFunction` | | Storage-class macros | `wapp_extern`, `wapp_intern` | `wp_extern`, `wp_intern` | ### Modules affected All 20 modules were renamed: `arena`, `array`, `dbl_list`, `queue`, `str8`, `mem_allocator`, `mem_utils`, `mem_os`, `file`, `cpath`, `log`, `shell_commander`, `shell_termcolour`, `shell_utils`, `prng/xorshift`, `uuid`, `tester`, `aliases`, `assert`, `misc_utils`, `platform` — plus their test files. ### Backward compatibility Added `src/oldnames.h` with `#define OLD_NAME NEW_NAME` for every renamed symbol, organized by module under Constants → Types → Functions sections. Existing code that includes this file will compile without changes. Reviewed-on: #12 Co-authored-by: Abdelrahman <said.abdelrahman89@gmail.com> Co-committed-by: Abdelrahman <said.abdelrahman89@gmail.com>
This commit was merged in pull request #12.
This commit is contained in:
@@ -6,62 +6,62 @@
|
||||
// allocation are aligned to power of 2 boundaries, the number of i32 values needed is hardcoded.
|
||||
#define TEMP_BUF_SIZE (40 + sizeof(i32) * 8)
|
||||
|
||||
wapp_intern u8 temp_buf[TEMP_BUF_SIZE] = {0};
|
||||
wapp_intern Allocator temp_allocator = {0};
|
||||
wp_intern u8 temp_buf[TEMP_BUF_SIZE] = {0};
|
||||
wp_intern WpAllocator temp_allocator = {0};
|
||||
|
||||
TestFuncResult test_arena_allocator(void) {
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(4096);
|
||||
WpTestFuncResult test_arena_allocator(void) {
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(4096);
|
||||
b8 result = allocator.obj != NULL && allocator.alloc != NULL &&
|
||||
allocator.alloc_aligned != NULL &&
|
||||
allocator.realloc != NULL && allocator.realloc_aligned != NULL &&
|
||||
allocator.free == NULL;
|
||||
void *ptr = wapp_mem_allocator_alloc(&allocator, 20);
|
||||
void *ptr = wpMemAllocatorAlloc(&allocator, 20);
|
||||
result = result && (ptr != NULL);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_allocator_with_buffer(void) {
|
||||
WpTestFuncResult test_arena_allocator_with_buffer(void) {
|
||||
u8 buffer[KiB(4)] = {0};
|
||||
|
||||
Allocator allocator = wapp_mem_arena_allocator_init_with_buffer(buffer, KiB(4));
|
||||
WpAllocator allocator = wpMemArenaAllocatorInitWithBuffer(buffer, KiB(4));
|
||||
b8 result = allocator.obj != NULL && allocator.alloc != NULL &&
|
||||
allocator.alloc_aligned != NULL &&
|
||||
allocator.realloc != NULL && allocator.realloc_aligned != NULL &&
|
||||
allocator.free == NULL;
|
||||
void *ptr = wapp_mem_allocator_alloc(&allocator, 20);
|
||||
void *ptr = wpMemAllocatorAlloc(&allocator, 20);
|
||||
result = result && (ptr != NULL);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_allocator_temp_begin(void) {
|
||||
temp_allocator = wapp_mem_arena_allocator_init_with_buffer(temp_buf, TEMP_BUF_SIZE);
|
||||
WpTestFuncResult test_arena_allocator_temp_begin(void) {
|
||||
temp_allocator = wpMemArenaAllocatorInitWithBuffer(temp_buf, TEMP_BUF_SIZE);
|
||||
|
||||
i32 *num1 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32));
|
||||
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
b8 result = num1 != NULL;
|
||||
|
||||
wapp_mem_arena_allocator_temp_begin(&temp_allocator);
|
||||
i32 *num2 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32));
|
||||
wpMemArenaAllocatorTempBegin(&temp_allocator);
|
||||
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
result = result && num2 != NULL;
|
||||
i32 *num3 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32));
|
||||
i32 *num3 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
result = result && num3 == NULL;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_allocator_temp_end(void) {
|
||||
wapp_mem_arena_allocator_temp_end(&temp_allocator);
|
||||
i32 *num1 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32));
|
||||
WpTestFuncResult test_arena_allocator_temp_end(void) {
|
||||
wpMemArenaAllocatorTempEnd(&temp_allocator);
|
||||
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
b8 result = num1 != NULL;
|
||||
i32 *num2 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32));
|
||||
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
result = result && num2 == NULL;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&temp_allocator);
|
||||
wpMemArenaAllocatorDestroy(&temp_allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
@@ -6,62 +6,62 @@
|
||||
// allocation are aligned to power of 2 boundaries, the number of i32 values needed is hardcoded.
|
||||
#define TEMP_BUF_SIZE (40 + sizeof(i32) * 8)
|
||||
|
||||
wapp_intern u8 temp_buf[TEMP_BUF_SIZE] = {};
|
||||
wapp_intern Allocator temp_allocator = {};
|
||||
wp_intern u8 temp_buf[TEMP_BUF_SIZE] = {};
|
||||
wp_intern WpAllocator temp_allocator = {};
|
||||
|
||||
TestFuncResult test_arena_allocator(void) {
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(4096);
|
||||
WpTestFuncResult test_arena_allocator(void) {
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(4096);
|
||||
b8 result = allocator.obj != nullptr && allocator.alloc != nullptr &&
|
||||
allocator.alloc_aligned != nullptr &&
|
||||
allocator.realloc != nullptr && allocator.realloc_aligned != nullptr &&
|
||||
allocator.free == nullptr;
|
||||
void *ptr = wapp_mem_allocator_alloc(&allocator, 20);
|
||||
void *ptr = wpMemAllocatorAlloc(&allocator, 20);
|
||||
result = result && (ptr != nullptr);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_allocator_with_buffer(void) {
|
||||
WpTestFuncResult test_arena_allocator_with_buffer(void) {
|
||||
u8 buffer[KiB(4)] = {0};
|
||||
|
||||
Allocator allocator = wapp_mem_arena_allocator_init_with_buffer(buffer, KiB(4));
|
||||
WpAllocator allocator = wpMemArenaAllocatorInitWithBuffer(buffer, KiB(4));
|
||||
b8 result = allocator.obj != NULL && allocator.alloc != NULL &&
|
||||
allocator.alloc_aligned != NULL &&
|
||||
allocator.realloc != NULL && allocator.realloc_aligned != NULL &&
|
||||
allocator.free == NULL;
|
||||
void *ptr = wapp_mem_allocator_alloc(&allocator, 20);
|
||||
void *ptr = wpMemAllocatorAlloc(&allocator, 20);
|
||||
result = result && (ptr != NULL);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_allocator_temp_begin(void) {
|
||||
temp_allocator = wapp_mem_arena_allocator_init_with_buffer(temp_buf, TEMP_BUF_SIZE);
|
||||
WpTestFuncResult test_arena_allocator_temp_begin(void) {
|
||||
temp_allocator = wpMemArenaAllocatorInitWithBuffer(temp_buf, TEMP_BUF_SIZE);
|
||||
|
||||
i32 *num1 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32));
|
||||
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
b8 result = num1 != NULL;
|
||||
|
||||
wapp_mem_arena_allocator_temp_begin(&temp_allocator);
|
||||
i32 *num2 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32));
|
||||
wpMemArenaAllocatorTempBegin(&temp_allocator);
|
||||
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
result = result && num2 != NULL;
|
||||
i32 *num3 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32));
|
||||
i32 *num3 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
result = result && num3 == NULL;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_allocator_temp_end(void) {
|
||||
wapp_mem_arena_allocator_temp_end(&temp_allocator);
|
||||
i32 *num1 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32));
|
||||
WpTestFuncResult test_arena_allocator_temp_end(void) {
|
||||
wpMemArenaAllocatorTempEnd(&temp_allocator);
|
||||
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
b8 result = num1 != NULL;
|
||||
i32 *num2 = (i32 *)wapp_mem_allocator_alloc(&temp_allocator, sizeof(i32));
|
||||
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
|
||||
result = result && num2 == NULL;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&temp_allocator);
|
||||
wpMemArenaAllocatorDestroy(&temp_allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
#include "wapp.h"
|
||||
|
||||
TestFuncResult test_arena_allocator(void);
|
||||
TestFuncResult test_arena_allocator_with_buffer(void);
|
||||
TestFuncResult test_arena_allocator_temp_begin(void);
|
||||
TestFuncResult test_arena_allocator_temp_end(void);
|
||||
WpTestFuncResult test_arena_allocator(void);
|
||||
WpTestFuncResult test_arena_allocator_with_buffer(void);
|
||||
WpTestFuncResult test_arena_allocator_temp_begin(void);
|
||||
WpTestFuncResult test_arena_allocator_temp_end(void);
|
||||
|
||||
#endif // !TEST_ALLOCATOR_H
|
||||
|
||||
+62
-62
@@ -4,143 +4,143 @@
|
||||
|
||||
#define ARENA_CAPACITY KiB(16)
|
||||
#define ARENA_BUF_SIZE KiB(4)
|
||||
// NOTE (Abdelrahman): Cannot query size of Arena here so it's hardcoded. Similarly, since arena
|
||||
// NOTE (Abdelrahman): Cannot query size of WpArena here so it's hardcoded. Similarly, since arena
|
||||
// allocation are aligned to power of 2 boundaries, the number of i32 values needed is hardcoded.
|
||||
#define TEMP_BUF_SIZE (40 + sizeof(i32) * 8)
|
||||
|
||||
wapp_intern Arena *arena = NULL;
|
||||
wapp_intern i32 count = 20;
|
||||
wapp_intern i32 *array = NULL;
|
||||
wapp_intern Arena *buf_arena = NULL;
|
||||
wapp_intern u8 buf[ARENA_BUF_SIZE] = {0};
|
||||
wapp_intern Arena *temp_arena = NULL;
|
||||
wapp_intern u8 temp_buf[TEMP_BUF_SIZE] = {0};
|
||||
wp_intern WpArena *arena = NULL;
|
||||
wp_intern i32 count = 20;
|
||||
wp_intern i32 *array = NULL;
|
||||
wp_intern WpArena *buf_arena = NULL;
|
||||
wp_intern u8 buf[ARENA_BUF_SIZE] = {0};
|
||||
wp_intern WpArena *temp_arena = NULL;
|
||||
wp_intern u8 temp_buf[TEMP_BUF_SIZE] = {0};
|
||||
|
||||
TestFuncResult test_arena_init_buffer(void) {
|
||||
b8 result = wapp_mem_arena_init_buffer(&buf_arena, buf, ARENA_BUF_SIZE);
|
||||
return wapp_tester_result(result);
|
||||
WpTestFuncResult test_arena_init_buffer(void) {
|
||||
b8 result = wpMemArenaInitBuffer(&buf_arena, buf, ARENA_BUF_SIZE);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_init_allocated(void) {
|
||||
b8 result = wapp_mem_arena_init_allocated(&arena, ARENA_CAPACITY);
|
||||
WpTestFuncResult test_arena_init_allocated(void) {
|
||||
b8 result = wpMemArenaInitAllocated(&arena, ARENA_CAPACITY);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_init_succeeds_when_reserving_very_large_size(void) {
|
||||
Arena *large_arena = NULL;
|
||||
WpTestFuncResult test_arena_init_succeeds_when_reserving_very_large_size(void) {
|
||||
WpArena *large_arena = NULL;
|
||||
u64 capacity = GiB(512);
|
||||
b8 result = wapp_mem_arena_init_allocated(&large_arena, capacity);
|
||||
b8 result = wpMemArenaInitAllocated(&large_arena, capacity);
|
||||
if (result) {
|
||||
wapp_mem_arena_destroy(&large_arena);
|
||||
wpMemArenaDestroy(&large_arena);
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_alloc_with_buffer(void) {
|
||||
i32 *arr = (i32 *)wapp_mem_arena_alloc(arena, count * sizeof(i32));
|
||||
WpTestFuncResult test_arena_alloc_with_buffer(void) {
|
||||
i32 *arr = (i32 *)wpMemArenaAlloc(arena, count * sizeof(i32));
|
||||
b8 result = arr != NULL;
|
||||
|
||||
for (i32 i = 0; i < count; ++i) {
|
||||
arr[i] = i * 10;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_alloc_succeeds_when_within_capacity(void) {
|
||||
array = wapp_mem_arena_alloc(arena, count * sizeof(i32));
|
||||
WpTestFuncResult test_arena_alloc_succeeds_when_within_capacity(void) {
|
||||
array = wpMemArenaAlloc(arena, count * sizeof(i32));
|
||||
b8 result = array != NULL;
|
||||
|
||||
for (i32 i = 0; i < count; ++i) {
|
||||
array[i] = i * 10;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_alloc_fails_when_over_capacity(void) {
|
||||
u8 *bytes = wapp_mem_arena_alloc(arena, ARENA_CAPACITY * 2);
|
||||
WpTestFuncResult test_arena_alloc_fails_when_over_capacity(void) {
|
||||
u8 *bytes = wpMemArenaAlloc(arena, ARENA_CAPACITY * 2);
|
||||
b8 result = bytes == NULL;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_realloc_bigger_size(void) {
|
||||
WpTestFuncResult test_arena_realloc_bigger_size(void) {
|
||||
u64 old_count = 10;
|
||||
u64 new_count = 20;
|
||||
i32 *bytes = wapp_mem_arena_alloc(arena, old_count * sizeof(i32));
|
||||
i32 *bytes = wpMemArenaAlloc(arena, old_count * sizeof(i32));
|
||||
|
||||
for (u64 i = 0; i < old_count; ++i) {
|
||||
bytes[i] = (i32)i;
|
||||
}
|
||||
|
||||
i32 *new_bytes = wapp_mem_arena_realloc(arena, bytes, old_count * sizeof(i32), new_count * sizeof(i32));
|
||||
i32 *new_bytes = wpMemArenaRealloc(arena, bytes, old_count * sizeof(i32), new_count * sizeof(i32));
|
||||
if (!new_bytes) {
|
||||
return wapp_tester_result(false);
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
for (u64 i = 0; i < new_count; ++i) {
|
||||
if (i < old_count && new_bytes[i] != bytes[i]) {
|
||||
return wapp_tester_result(false);
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
}
|
||||
|
||||
return wapp_tester_result(true);
|
||||
return wpTesterResult(true);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_realloc_smaller_size(void) {
|
||||
WpTestFuncResult test_arena_realloc_smaller_size(void) {
|
||||
u64 old_count = 10;
|
||||
u64 new_count = 5;
|
||||
i32 *bytes = wapp_mem_arena_alloc(arena, old_count * sizeof(i32));
|
||||
i32 *bytes = wpMemArenaAlloc(arena, old_count * sizeof(i32));
|
||||
|
||||
for (u64 i = 0; i < old_count; ++i) {
|
||||
bytes[i] = (i32)i;
|
||||
}
|
||||
|
||||
i32 *new_bytes = wapp_mem_arena_realloc(arena, bytes, old_count * sizeof(i32), new_count * sizeof(i32));
|
||||
i32 *new_bytes = wpMemArenaRealloc(arena, bytes, old_count * sizeof(i32), new_count * sizeof(i32));
|
||||
if (!new_bytes) {
|
||||
return wapp_tester_result(false);
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
for (u64 i = 0; i < new_count; ++i) {
|
||||
if (i < new_count && new_bytes[i] != bytes[i]) {
|
||||
return wapp_tester_result(false);
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
}
|
||||
|
||||
return wapp_tester_result(true);
|
||||
return wpTesterResult(true);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_temp_begin(void) {
|
||||
b8 result = wapp_mem_arena_init_buffer(&temp_arena, temp_buf, TEMP_BUF_SIZE);
|
||||
i32 *num1 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
WpTestFuncResult test_arena_temp_begin(void) {
|
||||
b8 result = wpMemArenaInitBuffer(&temp_arena, temp_buf, TEMP_BUF_SIZE);
|
||||
i32 *num1 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
result = result && num1 != NULL;
|
||||
|
||||
wapp_mem_arena_temp_begin(temp_arena);
|
||||
i32 *num2 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
wpMemArenaTempBegin(temp_arena);
|
||||
i32 *num2 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
result = result && num2 != NULL;
|
||||
i32 *num3 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
i32 *num3 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
result = result && num3 == NULL;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_temp_end(void) {
|
||||
wapp_mem_arena_temp_end(temp_arena);
|
||||
i32 *num1 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
WpTestFuncResult test_arena_temp_end(void) {
|
||||
wpMemArenaTempEnd(temp_arena);
|
||||
i32 *num1 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
b8 result = num1 != NULL;
|
||||
i32 *num2 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
i32 *num2 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
result = result && num2 == NULL;
|
||||
|
||||
wapp_mem_arena_destroy(&temp_arena);
|
||||
wpMemArenaDestroy(&temp_arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_clear(void) {
|
||||
wapp_mem_arena_clear(arena);
|
||||
WpTestFuncResult test_arena_clear(void) {
|
||||
wpMemArenaClear(arena);
|
||||
b8 result = true;
|
||||
|
||||
for (i32 i = 0; i < count; ++i) {
|
||||
@@ -150,19 +150,19 @@ TestFuncResult test_arena_clear(void) {
|
||||
}
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_destroy_buffer(void) {
|
||||
wapp_mem_arena_destroy(&buf_arena);
|
||||
WpTestFuncResult test_arena_destroy_buffer(void) {
|
||||
wpMemArenaDestroy(&buf_arena);
|
||||
b8 result = buf_arena == NULL;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_destroy_allocated(void) {
|
||||
wapp_mem_arena_destroy(&arena);
|
||||
WpTestFuncResult test_arena_destroy_allocated(void) {
|
||||
wpMemArenaDestroy(&arena);
|
||||
b8 result = arena == NULL;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
+62
-62
@@ -4,143 +4,143 @@
|
||||
|
||||
#define ARENA_CAPACITY KiB(16)
|
||||
#define ARENA_BUF_SIZE KiB(4)
|
||||
// NOTE (Abdelrahman): Cannot query size of Arena here so it's hardcoded. Similarly, since arena
|
||||
// NOTE (Abdelrahman): Cannot query size of WpArena here so it's hardcoded. Similarly, since arena
|
||||
// allocation are aligned to power of 2 boundaries, the number of i32 values needed is hardcoded.
|
||||
#define TEMP_BUF_SIZE (40 + sizeof(i32) * 8)
|
||||
|
||||
wapp_intern Arena *arena = NULL;
|
||||
wapp_intern i32 count = 20;
|
||||
wapp_intern i32 *array = NULL;
|
||||
wapp_intern Arena *buf_arena = NULL;
|
||||
wapp_intern u8 buf[ARENA_BUF_SIZE] = {};
|
||||
wapp_intern Arena *temp_arena = NULL;
|
||||
wapp_intern u8 temp_buf[TEMP_BUF_SIZE] = {};
|
||||
wp_intern WpArena *arena = NULL;
|
||||
wp_intern i32 count = 20;
|
||||
wp_intern i32 *array = NULL;
|
||||
wp_intern WpArena *buf_arena = NULL;
|
||||
wp_intern u8 buf[ARENA_BUF_SIZE] = {};
|
||||
wp_intern WpArena *temp_arena = NULL;
|
||||
wp_intern u8 temp_buf[TEMP_BUF_SIZE] = {};
|
||||
|
||||
TestFuncResult test_arena_init_buffer(void) {
|
||||
b8 result = wapp_mem_arena_init_buffer(&buf_arena, buf, ARENA_BUF_SIZE);
|
||||
return wapp_tester_result(result);
|
||||
WpTestFuncResult test_arena_init_buffer(void) {
|
||||
b8 result = wpMemArenaInitBuffer(&buf_arena, buf, ARENA_BUF_SIZE);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_init_allocated(void) {
|
||||
b8 result = wapp_mem_arena_init_allocated(&arena, ARENA_CAPACITY);
|
||||
WpTestFuncResult test_arena_init_allocated(void) {
|
||||
b8 result = wpMemArenaInitAllocated(&arena, ARENA_CAPACITY);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_init_succeeds_when_reserving_very_large_size(void) {
|
||||
Arena *large_arena = nullptr;
|
||||
WpTestFuncResult test_arena_init_succeeds_when_reserving_very_large_size(void) {
|
||||
WpArena *large_arena = nullptr;
|
||||
u64 capacity = GiB(512);
|
||||
b8 result = wapp_mem_arena_init_allocated(&large_arena, capacity);
|
||||
b8 result = wpMemArenaInitAllocated(&large_arena, capacity);
|
||||
if (result) {
|
||||
wapp_mem_arena_destroy(&large_arena);
|
||||
wpMemArenaDestroy(&large_arena);
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_alloc_with_buffer(void) {
|
||||
i32 *arr = (i32 *)wapp_mem_arena_alloc(arena, count * sizeof(i32));
|
||||
WpTestFuncResult test_arena_alloc_with_buffer(void) {
|
||||
i32 *arr = (i32 *)wpMemArenaAlloc(arena, count * sizeof(i32));
|
||||
b8 result = arr != NULL;
|
||||
|
||||
for (i32 i = 0; i < count; ++i) {
|
||||
arr[i] = i * 10;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_alloc_succeeds_when_within_capacity(void) {
|
||||
array = (i32 *)wapp_mem_arena_alloc(arena, count * sizeof(i32));
|
||||
WpTestFuncResult test_arena_alloc_succeeds_when_within_capacity(void) {
|
||||
array = (i32 *)wpMemArenaAlloc(arena, count * sizeof(i32));
|
||||
b8 result = array != nullptr;
|
||||
|
||||
for (i32 i = 0; i < count; ++i) {
|
||||
array[i] = i * 10;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_alloc_fails_when_over_capacity(void) {
|
||||
u8 *bytes = (u8 *)wapp_mem_arena_alloc(arena, ARENA_CAPACITY * 2);
|
||||
WpTestFuncResult test_arena_alloc_fails_when_over_capacity(void) {
|
||||
u8 *bytes = (u8 *)wpMemArenaAlloc(arena, ARENA_CAPACITY * 2);
|
||||
b8 result = bytes == nullptr;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_realloc_bigger_size(void) {
|
||||
WpTestFuncResult test_arena_realloc_bigger_size(void) {
|
||||
u64 old_count = 10;
|
||||
u64 new_count = 20;
|
||||
i32 *bytes = (i32 *)wapp_mem_arena_alloc(arena, old_count * sizeof(i32));
|
||||
i32 *bytes = (i32 *)wpMemArenaAlloc(arena, old_count * sizeof(i32));
|
||||
|
||||
for (u64 i = 0; i < old_count; ++i) {
|
||||
bytes[i] = (i32)i;
|
||||
}
|
||||
|
||||
i32 *new_bytes = (i32 *)wapp_mem_arena_realloc(arena, bytes, old_count * sizeof(i32), new_count * sizeof(i32));
|
||||
i32 *new_bytes = (i32 *)wpMemArenaRealloc(arena, bytes, old_count * sizeof(i32), new_count * sizeof(i32));
|
||||
if (!new_bytes) {
|
||||
return wapp_tester_result(false);
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
for (u64 i = 0; i < new_count; ++i) {
|
||||
if (i < old_count && new_bytes[i] != bytes[i]) {
|
||||
return wapp_tester_result(false);
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
}
|
||||
|
||||
return wapp_tester_result(true);
|
||||
return wpTesterResult(true);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_realloc_smaller_size(void) {
|
||||
WpTestFuncResult test_arena_realloc_smaller_size(void) {
|
||||
u64 old_count = 10;
|
||||
u64 new_count = 5;
|
||||
i32 *bytes = (i32 *)wapp_mem_arena_alloc(arena, old_count * sizeof(i32));
|
||||
i32 *bytes = (i32 *)wpMemArenaAlloc(arena, old_count * sizeof(i32));
|
||||
|
||||
for (u64 i = 0; i < old_count; ++i) {
|
||||
bytes[i] = (i32)i;
|
||||
}
|
||||
|
||||
i32 *new_bytes = (i32 *)wapp_mem_arena_realloc(arena, bytes, old_count * sizeof(i32), new_count * sizeof(i32));
|
||||
i32 *new_bytes = (i32 *)wpMemArenaRealloc(arena, bytes, old_count * sizeof(i32), new_count * sizeof(i32));
|
||||
if (!new_bytes) {
|
||||
return wapp_tester_result(false);
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
for (u64 i = 0; i < new_count; ++i) {
|
||||
if (i < new_count && new_bytes[i] != bytes[i]) {
|
||||
return wapp_tester_result(false);
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
}
|
||||
|
||||
return wapp_tester_result(true);
|
||||
return wpTesterResult(true);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_temp_begin(void) {
|
||||
b8 result = wapp_mem_arena_init_buffer(&temp_arena, temp_buf, TEMP_BUF_SIZE);
|
||||
i32 *num1 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
WpTestFuncResult test_arena_temp_begin(void) {
|
||||
b8 result = wpMemArenaInitBuffer(&temp_arena, temp_buf, TEMP_BUF_SIZE);
|
||||
i32 *num1 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
result = result && num1 != NULL;
|
||||
|
||||
wapp_mem_arena_temp_begin(temp_arena);
|
||||
i32 *num2 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
wpMemArenaTempBegin(temp_arena);
|
||||
i32 *num2 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
result = result && num2 != NULL;
|
||||
i32 *num3 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
i32 *num3 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
result = result && num3 == NULL;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_temp_end(void) {
|
||||
wapp_mem_arena_temp_end(temp_arena);
|
||||
i32 *num1 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
WpTestFuncResult test_arena_temp_end(void) {
|
||||
wpMemArenaTempEnd(temp_arena);
|
||||
i32 *num1 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
b8 result = num1 != NULL;
|
||||
i32 *num2 = (i32 *)wapp_mem_arena_alloc(temp_arena, sizeof(i32));
|
||||
i32 *num2 = (i32 *)wpMemArenaAlloc(temp_arena, sizeof(i32));
|
||||
result = result && num2 == NULL;
|
||||
|
||||
wapp_mem_arena_destroy(&temp_arena);
|
||||
wpMemArenaDestroy(&temp_arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_clear(void) {
|
||||
wapp_mem_arena_clear(arena);
|
||||
WpTestFuncResult test_arena_clear(void) {
|
||||
wpMemArenaClear(arena);
|
||||
b8 result = true;
|
||||
|
||||
for (i32 i = 0; i < count; ++i) {
|
||||
@@ -150,19 +150,19 @@ TestFuncResult test_arena_clear(void) {
|
||||
}
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_destroy_buffer(void) {
|
||||
wapp_mem_arena_destroy(&buf_arena);
|
||||
WpTestFuncResult test_arena_destroy_buffer(void) {
|
||||
wpMemArenaDestroy(&buf_arena);
|
||||
b8 result = buf_arena == NULL;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_destroy_allocated(void) {
|
||||
wapp_mem_arena_destroy(&arena);
|
||||
WpTestFuncResult test_arena_destroy_allocated(void) {
|
||||
wpMemArenaDestroy(&arena);
|
||||
b8 result = arena == nullptr;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
+13
-13
@@ -3,18 +3,18 @@
|
||||
|
||||
#include "wapp.h"
|
||||
|
||||
TestFuncResult test_arena_init_buffer(void);
|
||||
TestFuncResult test_arena_init_allocated(void);
|
||||
TestFuncResult test_arena_init_succeeds_when_reserving_very_large_size(void);
|
||||
TestFuncResult test_arena_alloc_with_buffer(void);
|
||||
TestFuncResult test_arena_alloc_succeeds_when_within_capacity(void);
|
||||
TestFuncResult test_arena_alloc_fails_when_over_capacity(void);
|
||||
TestFuncResult test_arena_realloc_bigger_size(void);
|
||||
TestFuncResult test_arena_realloc_smaller_size(void);
|
||||
TestFuncResult test_arena_clear(void);
|
||||
TestFuncResult test_arena_temp_begin(void);
|
||||
TestFuncResult test_arena_temp_end(void);
|
||||
TestFuncResult test_arena_destroy_buffer(void);
|
||||
TestFuncResult test_arena_destroy_allocated(void);
|
||||
WpTestFuncResult test_arena_init_buffer(void);
|
||||
WpTestFuncResult test_arena_init_allocated(void);
|
||||
WpTestFuncResult test_arena_init_succeeds_when_reserving_very_large_size(void);
|
||||
WpTestFuncResult test_arena_alloc_with_buffer(void);
|
||||
WpTestFuncResult test_arena_alloc_succeeds_when_within_capacity(void);
|
||||
WpTestFuncResult test_arena_alloc_fails_when_over_capacity(void);
|
||||
WpTestFuncResult test_arena_realloc_bigger_size(void);
|
||||
WpTestFuncResult test_arena_realloc_smaller_size(void);
|
||||
WpTestFuncResult test_arena_clear(void);
|
||||
WpTestFuncResult test_arena_temp_begin(void);
|
||||
WpTestFuncResult test_arena_temp_end(void);
|
||||
WpTestFuncResult test_arena_destroy_buffer(void);
|
||||
WpTestFuncResult test_arena_destroy_allocated(void);
|
||||
|
||||
#endif // !TEST_ARENA_H
|
||||
|
||||
@@ -1,172 +1,172 @@
|
||||
#include "test_i32_array.h"
|
||||
#include "wapp.h"
|
||||
|
||||
TestFuncResult test_i32_array(void) {
|
||||
WpTestFuncResult test_i32_array(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array = wapp_array(i32, 1, 2, 3, 4, 5, 6, 7);
|
||||
result = wapp_array_count(array) == 7 && wapp_array_capacity(array) == 16;
|
||||
WpI32Array array = wpArray(i32, 1, 2, 3, 4, 5, 6, 7);
|
||||
result = wpArrayCount(array) == 7 && wpArrayCapacity(array) == 16;
|
||||
|
||||
i32 *item;
|
||||
u64 count = wapp_array_count(array);
|
||||
u64 count = wpArrayCount(array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
item = wapp_array_get(i32, array, index);
|
||||
item = wpArrayGet(i32, array, index);
|
||||
result = result && item && *item == (i32)(index + 1);
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_with_capacity(void) {
|
||||
WpTestFuncResult test_i32_array_with_capacity(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array1 = wapp_array_with_capacity(i32, 64, ARRAY_INIT_NONE);
|
||||
result = wapp_array_count(array1) == 0 && wapp_array_capacity(array1) == 64;
|
||||
WpI32Array array1 = wpArrayWithCapacity(i32, 64, WP_ARRAY_INIT_NONE);
|
||||
result = wpArrayCount(array1) == 0 && wpArrayCapacity(array1) == 64;
|
||||
|
||||
I32Array array2 = wapp_array_with_capacity(i32, 64, ARRAY_INIT_FILLED);
|
||||
result = wapp_array_count(array2) == 64 && wapp_array_capacity(array2) == 64;
|
||||
WpI32Array array2 = wpArrayWithCapacity(i32, 64, WP_ARRAY_INIT_FILLED);
|
||||
result = wpArrayCount(array2) == 64 && wpArrayCapacity(array2) == 64;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_get(void) {
|
||||
WpTestFuncResult test_i32_array_get(void) {
|
||||
b8 result = true;
|
||||
|
||||
I32Array array = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
|
||||
i32 *item;
|
||||
u64 count = wapp_array_count(array);
|
||||
u64 count = wpArrayCount(array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
item = wapp_array_get(i32, array, index);
|
||||
item = wpArrayGet(i32, array, index);
|
||||
result = result && item && *item == (i32)index;
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_set(void) {
|
||||
WpTestFuncResult test_i32_array_set(void) {
|
||||
b8 result = true;
|
||||
|
||||
I32Array array = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
|
||||
i32 *item;
|
||||
u64 count = wapp_array_count(array);
|
||||
u64 count = wpArrayCount(array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
i32 num = (i32)(index * 2);
|
||||
wapp_array_set(i32, array, index, &num);
|
||||
item = wapp_array_get(i32, array, index);
|
||||
wpArraySet(i32, array, index, &num);
|
||||
item = wpArrayGet(i32, array, index);
|
||||
result = result && item && *item == (i32)(index * 2);
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_append_capped(void) {
|
||||
WpTestFuncResult test_i32_array_append_capped(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array = wapp_array_with_capacity(i32, 64, ARRAY_INIT_NONE);
|
||||
wapp_array_append_capped(i32, array, &((i32){10}));
|
||||
WpI32Array array = wpArrayWithCapacity(i32, 64, WP_ARRAY_INIT_NONE);
|
||||
wpArrayAppendCapped(i32, array, &((i32){10}));
|
||||
|
||||
result = wapp_array_count(array) == 1;
|
||||
i32 *item = wapp_array_get(i32, array, 0);
|
||||
result = wpArrayCount(array) == 1;
|
||||
i32 *item = wpArrayGet(i32, array, 0);
|
||||
result = result && item && *item == 10;
|
||||
|
||||
array = wapp_array(i32, 1);
|
||||
wapp_array_append_capped(i32, array, &((i32){10}));
|
||||
array = wpArray(i32, 1);
|
||||
wpArrayAppendCapped(i32, array, &((i32){10}));
|
||||
|
||||
result = result && wapp_array_count(array) == 2;
|
||||
result = result && wpArrayCount(array) == 2;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_extend_capped(void) {
|
||||
WpTestFuncResult test_i32_array_extend_capped(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array1 = wapp_array(i32, 1, 2, 3, 4);
|
||||
I32Array array2 = wapp_array(i32, 10, 20);
|
||||
WpI32Array array1 = wpArray(i32, 1, 2, 3, 4);
|
||||
WpI32Array array2 = wpArray(i32, 10, 20);
|
||||
|
||||
result = wapp_array_count(array1) == 4 && wapp_array_count(array2) == 2;
|
||||
result = wpArrayCount(array1) == 4 && wpArrayCount(array2) == 2;
|
||||
|
||||
wapp_array_extend_capped(i32, array1, array2);
|
||||
wpArrayExtendCapped(i32, array1, array2);
|
||||
|
||||
result = result && wapp_array_count(array1) == 6;
|
||||
result = result && wpArrayCount(array1) == 6;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_copy_capped(void) {
|
||||
WpTestFuncResult test_i32_array_copy_capped(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array src = wapp_array(i32, 1, 2, 3, 4, 5);
|
||||
I32Array dst1 = wapp_array(i32, 1, 2, 3, 4, 5, 6);
|
||||
I32Array dst2 = wapp_array(i32, 1, 2);
|
||||
WpI32Array src = wpArray(i32, 1, 2, 3, 4, 5);
|
||||
WpI32Array dst1 = wpArray(i32, 1, 2, 3, 4, 5, 6);
|
||||
WpI32Array dst2 = wpArray(i32, 1, 2);
|
||||
|
||||
u64 expected_count = 5;
|
||||
wapp_array_copy_capped(i32, dst1, src);
|
||||
result = wapp_array_count(dst1) == expected_count;
|
||||
wpArrayCopyCapped(i32, dst1, src);
|
||||
result = wpArrayCount(dst1) == expected_count;
|
||||
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
result = result && *wapp_array_get(i32, src, index) == *wapp_array_get(i32, dst1, index);
|
||||
result = result && *wpArrayGet(i32, src, index) == *wpArrayGet(i32, dst1, index);
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
}
|
||||
|
||||
expected_count = 4;
|
||||
wapp_array_copy_capped(i32, dst2, src);
|
||||
result = result && wapp_array_count(dst2) == expected_count;
|
||||
wpArrayCopyCapped(i32, dst2, src);
|
||||
result = result && wpArrayCount(dst2) == expected_count;
|
||||
|
||||
index = 0;
|
||||
running = true;
|
||||
while (running) {
|
||||
result = result && *wapp_array_get(i32, src, index) == *wapp_array_get(i32, dst2, index);
|
||||
result = result && *wpArrayGet(i32, src, index) == *wpArrayGet(i32, dst2, index);
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_alloc_capacity(void) {
|
||||
WpTestFuncResult test_i32_array_alloc_capacity(void) {
|
||||
b8 result;
|
||||
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(MiB(4));
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
|
||||
u64 capacity = 32;
|
||||
I32Array array = wapp_array_alloc_capacity(i32, &allocator, capacity, ARRAY_INIT_NONE);
|
||||
WpI32Array array = wpArrayAllocCapacity(i32, &allocator, capacity, WP_ARRAY_INIT_NONE);
|
||||
|
||||
result = array && wapp_array_capacity(array) == capacity;
|
||||
result = array && wpArrayCapacity(array) == capacity;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_append_alloc(void) {
|
||||
WpTestFuncResult test_i32_array_append_alloc(void) {
|
||||
b8 result;
|
||||
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(MiB(4));
|
||||
I32Array array1 = wapp_array(i32, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
I32Array array2 = wapp_array(i32, 1, 2);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
|
||||
WpI32Array array1 = wpArray(i32, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array2 = wpArray(i32, 1, 2);
|
||||
|
||||
I32Array arr_ptr = wapp_array_append_alloc(i32, &allocator, array1, &((i32){10}), ARRAY_INIT_NONE);
|
||||
WpI32Array arr_ptr = wpArrayAppendAlloc(i32, &allocator, array1, &((i32){10}), WP_ARRAY_INIT_NONE);
|
||||
result = arr_ptr == array1;
|
||||
|
||||
u64 count = 4;
|
||||
@@ -174,100 +174,100 @@ TestFuncResult test_i32_array_append_alloc(void) {
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
i32 num = (i32)index;
|
||||
arr_ptr = wapp_array_append_alloc(i32, &allocator, array2, &num, ARRAY_INIT_NONE);
|
||||
arr_ptr = wpArrayAppendAlloc(i32, &allocator, array2, &num, WP_ARRAY_INIT_NONE);
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
result = result && arr_ptr != array2;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_extend_alloc(void) {
|
||||
WpTestFuncResult test_i32_array_extend_alloc(void) {
|
||||
b8 result;
|
||||
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(MiB(4));
|
||||
I32Array array1 = wapp_array(i32, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
I32Array array2 = wapp_array(i32, 1, 2);
|
||||
I32Array array3 = wapp_array(i32, 1, 2, 3, 4);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
|
||||
WpI32Array array1 = wpArray(i32, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array2 = wpArray(i32, 1, 2);
|
||||
WpI32Array array3 = wpArray(i32, 1, 2, 3, 4);
|
||||
|
||||
I32Array arr_ptr = wapp_array_extend_alloc(i32, &allocator, array1, array3, ARRAY_INIT_NONE);
|
||||
WpI32Array arr_ptr = wpArrayExtendAlloc(i32, &allocator, array1, array3, WP_ARRAY_INIT_NONE);
|
||||
result = arr_ptr == array1;
|
||||
|
||||
arr_ptr = wapp_array_extend_alloc(i32, &allocator, array2, array3, ARRAY_INIT_NONE);
|
||||
arr_ptr = wpArrayExtendAlloc(i32, &allocator, array2, array3, WP_ARRAY_INIT_NONE);
|
||||
result = result && arr_ptr != array2;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_copy_alloc(void) {
|
||||
WpTestFuncResult test_i32_array_copy_alloc(void) {
|
||||
b8 result;
|
||||
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(MiB(4));
|
||||
I32Array src = wapp_array(i32, 1, 2, 3, 4, 5);
|
||||
I32Array dst1 = wapp_array(i32, 1, 2, 3, 4, 5, 6);
|
||||
I32Array dst2 = wapp_array(i32, 1, 2);
|
||||
I32Array array = NULL;
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
|
||||
WpI32Array src = wpArray(i32, 1, 2, 3, 4, 5);
|
||||
WpI32Array dst1 = wpArray(i32, 1, 2, 3, 4, 5, 6);
|
||||
WpI32Array dst2 = wpArray(i32, 1, 2);
|
||||
WpI32Array array = NULL;
|
||||
|
||||
u64 expected_count = 5;
|
||||
array = wapp_array_copy_alloc(i32, &allocator, dst1, src, ARRAY_INIT_NONE);
|
||||
result = wapp_array_count(array) == expected_count && array == dst1;
|
||||
array = wpArrayCopyAlloc(i32, &allocator, dst1, src, WP_ARRAY_INIT_NONE);
|
||||
result = wpArrayCount(array) == expected_count && array == dst1;
|
||||
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
result = result && *wapp_array_get(i32, src, index) == *wapp_array_get(i32, array, index);
|
||||
result = result && *wpArrayGet(i32, src, index) == *wpArrayGet(i32, array, index);
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
}
|
||||
|
||||
expected_count = 5;
|
||||
array = wapp_array_copy_alloc(i32, &allocator, dst2, src, ARRAY_INIT_NONE);
|
||||
result = result && wapp_array_count(array) == expected_count && array != dst2;
|
||||
array = wpArrayCopyAlloc(i32, &allocator, dst2, src, WP_ARRAY_INIT_NONE);
|
||||
result = result && wpArrayCount(array) == expected_count && array != dst2;
|
||||
|
||||
index = 0;
|
||||
running = true;
|
||||
while (running) {
|
||||
result = result && *wapp_array_get(i32, src, index) == *wapp_array_get(i32, array, index);
|
||||
result = result && *wpArrayGet(i32, src, index) == *wpArrayGet(i32, array, index);
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_pop(void) {
|
||||
WpTestFuncResult test_i32_array_pop(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array1 = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
I32Array array2 = wapp_array_with_capacity(i32, 32, ARRAY_INIT_NONE);
|
||||
WpI32Array array1 = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array2 = wpArrayWithCapacity(i32, 32, WP_ARRAY_INIT_NONE);
|
||||
|
||||
i32 item1 = wapp_array_pop(i32, array1);
|
||||
i32 item2 = wapp_array_pop(i32, array2);
|
||||
i32 item1 = wpArrayPop(i32, array1);
|
||||
i32 item2 = wpArrayPop(i32, array2);
|
||||
|
||||
result = item1 == 8 && item2 == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_clear(void) {
|
||||
WpTestFuncResult test_i32_array_clear(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
result = wapp_array_count(array) == 9;
|
||||
WpI32Array array = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
result = wpArrayCount(array) == 9;
|
||||
|
||||
wapp_array_clear(i32, array);
|
||||
wpArrayClear(i32, array);
|
||||
|
||||
result = result && wapp_array_count(array) == 0;
|
||||
result = result && wpArrayCount(array) == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
@@ -1,175 +1,175 @@
|
||||
#include "test_i32_array.h"
|
||||
#include "wapp.h"
|
||||
|
||||
TestFuncResult test_i32_array(void) {
|
||||
WpTestFuncResult test_i32_array(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array = wapp_array(i32, 1, 2, 3, 4, 5, 6, 7);
|
||||
result = wapp_array_count(array) == 7 && wapp_array_capacity(array) == 16;
|
||||
WpI32Array array = wpArray(i32, 1, 2, 3, 4, 5, 6, 7);
|
||||
result = wpArrayCount(array) == 7 && wpArrayCapacity(array) == 16;
|
||||
|
||||
i32 *item;
|
||||
u64 count = wapp_array_count(array);
|
||||
u64 count = wpArrayCount(array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
item = wapp_array_get(i32, array, index);
|
||||
item = wpArrayGet(i32, array, index);
|
||||
result = result && item && (*item == (i32)(index + 1));
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_with_capacity(void) {
|
||||
WpTestFuncResult test_i32_array_with_capacity(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array1 = wapp_array_with_capacity(i32, 64, ARRAY_INIT_NONE);
|
||||
result = wapp_array_count(array1) == 0 && wapp_array_capacity(array1) == 64;
|
||||
WpI32Array array1 = wpArrayWithCapacity(i32, 64, WP_ARRAY_INIT_NONE);
|
||||
result = wpArrayCount(array1) == 0 && wpArrayCapacity(array1) == 64;
|
||||
|
||||
I32Array array2 = wapp_array_with_capacity(i32, 64, ARRAY_INIT_FILLED);
|
||||
result = wapp_array_count(array2) == 64 && wapp_array_capacity(array2) == 64;
|
||||
WpI32Array array2 = wpArrayWithCapacity(i32, 64, WP_ARRAY_INIT_FILLED);
|
||||
result = wpArrayCount(array2) == 64 && wpArrayCapacity(array2) == 64;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_get(void) {
|
||||
WpTestFuncResult test_i32_array_get(void) {
|
||||
b8 result = true;
|
||||
|
||||
I32Array array = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
|
||||
i32 *item;
|
||||
u64 count = wapp_array_count(array);
|
||||
u64 count = wpArrayCount(array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
item = wapp_array_get(i32, array, index);
|
||||
item = wpArrayGet(i32, array, index);
|
||||
result = result && item && (*item == (i32)index);
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_set(void) {
|
||||
WpTestFuncResult test_i32_array_set(void) {
|
||||
b8 result = true;
|
||||
|
||||
I32Array array = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
|
||||
i32 *item;
|
||||
u64 count = wapp_array_count(array);
|
||||
u64 count = wpArrayCount(array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
i32 num = (i32)(index * 2);
|
||||
wapp_array_set(i32, array, index, &num);
|
||||
item = wapp_array_get(i32, array, index);
|
||||
wpArraySet(i32, array, index, &num);
|
||||
item = wpArrayGet(i32, array, index);
|
||||
result = result && item && (*item == (i32)(index * 2));
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_append_capped(void) {
|
||||
WpTestFuncResult test_i32_array_append_capped(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array = wapp_array_with_capacity(i32, 64, ARRAY_INIT_NONE);
|
||||
WpI32Array array = wpArrayWithCapacity(i32, 64, WP_ARRAY_INIT_NONE);
|
||||
i32 item1 = 10;
|
||||
wapp_array_append_capped(i32, array, &item1);
|
||||
wpArrayAppendCapped(i32, array, &item1);
|
||||
|
||||
result = wapp_array_count(array) == 1;
|
||||
i32 *item = wapp_array_get(i32, array, 0);
|
||||
result = wpArrayCount(array) == 1;
|
||||
i32 *item = wpArrayGet(i32, array, 0);
|
||||
result = result && item && *item == 10;
|
||||
|
||||
array = wapp_array(i32, 1);
|
||||
array = wpArray(i32, 1);
|
||||
i32 item2 = 10;
|
||||
wapp_array_append_capped(i32, array, &item2);
|
||||
wpArrayAppendCapped(i32, array, &item2);
|
||||
|
||||
result = result && wapp_array_count(array) == 2;
|
||||
result = result && wpArrayCount(array) == 2;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_extend_capped(void) {
|
||||
WpTestFuncResult test_i32_array_extend_capped(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array1 = wapp_array(i32, 1, 2, 3, 4);
|
||||
I32Array array2 = wapp_array(i32, 10, 20);
|
||||
WpI32Array array1 = wpArray(i32, 1, 2, 3, 4);
|
||||
WpI32Array array2 = wpArray(i32, 10, 20);
|
||||
|
||||
result = wapp_array_count(array1) == 4 && wapp_array_count(array2) == 2;
|
||||
result = wpArrayCount(array1) == 4 && wpArrayCount(array2) == 2;
|
||||
|
||||
wapp_array_extend_capped(i32, array1, array2);
|
||||
wpArrayExtendCapped(i32, array1, array2);
|
||||
|
||||
result = result && wapp_array_count(array1) == 6;
|
||||
result = result && wpArrayCount(array1) == 6;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_copy_capped(void) {
|
||||
WpTestFuncResult test_i32_array_copy_capped(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array src = wapp_array(i32, 1, 2, 3, 4, 5);
|
||||
I32Array dst1 = wapp_array(i32, 1, 2, 3, 4, 5, 6);
|
||||
I32Array dst2 = wapp_array(i32, 1, 2);
|
||||
WpI32Array src = wpArray(i32, 1, 2, 3, 4, 5);
|
||||
WpI32Array dst1 = wpArray(i32, 1, 2, 3, 4, 5, 6);
|
||||
WpI32Array dst2 = wpArray(i32, 1, 2);
|
||||
|
||||
u64 expected_count = 5;
|
||||
wapp_array_copy_capped(i32, dst1, src);
|
||||
result = wapp_array_count(dst1) == expected_count;
|
||||
wpArrayCopyCapped(i32, dst1, src);
|
||||
result = wpArrayCount(dst1) == expected_count;
|
||||
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
result = result && (*wapp_array_get(i32, src, index) == *wapp_array_get(i32, dst1, index));
|
||||
result = result && (*wpArrayGet(i32, src, index) == *wpArrayGet(i32, dst1, index));
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
}
|
||||
|
||||
expected_count = 4;
|
||||
wapp_array_copy_capped(i32, dst2, src);
|
||||
result = result && wapp_array_count(dst2) == expected_count;
|
||||
wpArrayCopyCapped(i32, dst2, src);
|
||||
result = result && wpArrayCount(dst2) == expected_count;
|
||||
|
||||
index = 0;
|
||||
running = true;
|
||||
while (running) {
|
||||
result = result && (*wapp_array_get(i32, src, index) == *wapp_array_get(i32, dst2, index));
|
||||
result = result && (*wpArrayGet(i32, src, index) == *wpArrayGet(i32, dst2, index));
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_alloc_capacity(void) {
|
||||
WpTestFuncResult test_i32_array_alloc_capacity(void) {
|
||||
b8 result;
|
||||
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(MiB(4));
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
|
||||
u64 capacity = 32;
|
||||
I32Array array = wapp_array_alloc_capacity(i32, &allocator, capacity, ARRAY_INIT_NONE);
|
||||
WpI32Array array = wpArrayAllocCapacity(i32, &allocator, capacity, WP_ARRAY_INIT_NONE);
|
||||
|
||||
result = array && wapp_array_capacity(array) == capacity;
|
||||
result = array && wpArrayCapacity(array) == capacity;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_append_alloc(void) {
|
||||
WpTestFuncResult test_i32_array_append_alloc(void) {
|
||||
b8 result;
|
||||
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(MiB(4));
|
||||
I32Array array1 = wapp_array(i32, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
I32Array array2 = wapp_array(i32, 1, 2);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
|
||||
WpI32Array array1 = wpArray(i32, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array2 = wpArray(i32, 1, 2);
|
||||
|
||||
i32 num = 10;
|
||||
I32Array arr_ptr = wapp_array_append_alloc(i32, &allocator, array1, &num, ARRAY_INIT_NONE);
|
||||
WpI32Array arr_ptr = wpArrayAppendAlloc(i32, &allocator, array1, &num, WP_ARRAY_INIT_NONE);
|
||||
result = arr_ptr == array1;
|
||||
|
||||
u64 count = 4;
|
||||
@@ -177,100 +177,100 @@ TestFuncResult test_i32_array_append_alloc(void) {
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
num = (i32)index;
|
||||
arr_ptr = wapp_array_append_alloc(i32, &allocator, array2, &num, ARRAY_INIT_NONE);
|
||||
arr_ptr = wpArrayAppendAlloc(i32, &allocator, array2, &num, WP_ARRAY_INIT_NONE);
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
result = result && arr_ptr != array2;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_extend_alloc(void) {
|
||||
WpTestFuncResult test_i32_array_extend_alloc(void) {
|
||||
b8 result;
|
||||
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(MiB(4));
|
||||
I32Array array1 = wapp_array(i32, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
I32Array array2 = wapp_array(i32, 1, 2);
|
||||
I32Array array3 = wapp_array(i32, 1, 2, 3, 4);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
|
||||
WpI32Array array1 = wpArray(i32, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array2 = wpArray(i32, 1, 2);
|
||||
WpI32Array array3 = wpArray(i32, 1, 2, 3, 4);
|
||||
|
||||
I32Array array = wapp_array_extend_alloc(i32, &allocator, array1, array3, ARRAY_INIT_NONE);
|
||||
WpI32Array array = wpArrayExtendAlloc(i32, &allocator, array1, array3, WP_ARRAY_INIT_NONE);
|
||||
result = array == array1;
|
||||
|
||||
array = wapp_array_extend_alloc(i32, &allocator, array2, array3, ARRAY_INIT_NONE);
|
||||
array = wpArrayExtendAlloc(i32, &allocator, array2, array3, WP_ARRAY_INIT_NONE);
|
||||
result = result && array != array2;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_copy_alloc(void) {
|
||||
WpTestFuncResult test_i32_array_copy_alloc(void) {
|
||||
b8 result;
|
||||
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(MiB(4));
|
||||
I32Array src = wapp_array(i32, 1, 2, 3, 4, 5);
|
||||
I32Array dst1 = wapp_array(i32, 1, 2, 3, 4, 5, 6);
|
||||
I32Array dst2 = wapp_array(i32, 1, 2);
|
||||
I32Array array = nullptr;
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
|
||||
WpI32Array src = wpArray(i32, 1, 2, 3, 4, 5);
|
||||
WpI32Array dst1 = wpArray(i32, 1, 2, 3, 4, 5, 6);
|
||||
WpI32Array dst2 = wpArray(i32, 1, 2);
|
||||
WpI32Array array = nullptr;
|
||||
|
||||
u64 expected_count = 5;
|
||||
array = wapp_array_copy_alloc(i32, &allocator, dst1, src, ARRAY_INIT_NONE);
|
||||
result = wapp_array_count(array) == expected_count && array == dst1;
|
||||
array = wpArrayCopyAlloc(i32, &allocator, dst1, src, WP_ARRAY_INIT_NONE);
|
||||
result = wpArrayCount(array) == expected_count && array == dst1;
|
||||
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
result = result && (*wapp_array_get(i32, src, index) == *wapp_array_get(i32, array, index));
|
||||
result = result && (*wpArrayGet(i32, src, index) == *wpArrayGet(i32, array, index));
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
}
|
||||
|
||||
expected_count = 5;
|
||||
array = wapp_array_copy_alloc(i32, &allocator, dst2, src, ARRAY_INIT_NONE);
|
||||
result = result && wapp_array_count(array) == expected_count && array != dst2;
|
||||
array = wpArrayCopyAlloc(i32, &allocator, dst2, src, WP_ARRAY_INIT_NONE);
|
||||
result = result && wpArrayCount(array) == expected_count && array != dst2;
|
||||
|
||||
index = 0;
|
||||
running = true;
|
||||
while (running) {
|
||||
result = result && (*wapp_array_get(i32, src, index) == *wapp_array_get(i32, array, index));
|
||||
result = result && (*wpArrayGet(i32, src, index) == *wpArrayGet(i32, array, index));
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_clear(void) {
|
||||
WpTestFuncResult test_i32_array_clear(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
result = wapp_array_count(array) == 9;
|
||||
WpI32Array array = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
result = wpArrayCount(array) == 9;
|
||||
|
||||
wapp_array_clear(i32, array);
|
||||
wpArrayClear(i32, array);
|
||||
|
||||
result = result && wapp_array_count(array) == 0;
|
||||
result = result && wpArrayCount(array) == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_i32_array_pop(void) {
|
||||
WpTestFuncResult test_i32_array_pop(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array1 = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
I32Array array2 = wapp_array_with_capacity(i32, 32, ARRAY_INIT_NONE);
|
||||
WpI32Array array1 = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array2 = wpArrayWithCapacity(i32, 32, WP_ARRAY_INIT_NONE);
|
||||
|
||||
i32 item1 = wapp_array_pop(i32, array1);
|
||||
i32 item2 = wapp_array_pop(i32, array2);
|
||||
i32 item1 = wpArrayPop(i32, array1);
|
||||
i32 item2 = wpArrayPop(i32, array2);
|
||||
|
||||
result = item1 == 8 && item2 == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
@@ -3,18 +3,18 @@
|
||||
|
||||
#include "wapp.h"
|
||||
|
||||
TestFuncResult test_i32_array(void);
|
||||
TestFuncResult test_i32_array_with_capacity(void);
|
||||
TestFuncResult test_i32_array_get(void);
|
||||
TestFuncResult test_i32_array_set(void);
|
||||
TestFuncResult test_i32_array_append_capped(void);
|
||||
TestFuncResult test_i32_array_extend_capped(void);
|
||||
TestFuncResult test_i32_array_copy_capped(void);
|
||||
TestFuncResult test_i32_array_alloc_capacity(void);
|
||||
TestFuncResult test_i32_array_append_alloc(void);
|
||||
TestFuncResult test_i32_array_extend_alloc(void);
|
||||
TestFuncResult test_i32_array_copy_alloc(void);
|
||||
TestFuncResult test_i32_array_pop(void);
|
||||
TestFuncResult test_i32_array_clear(void);
|
||||
WpTestFuncResult test_i32_array(void);
|
||||
WpTestFuncResult test_i32_array_with_capacity(void);
|
||||
WpTestFuncResult test_i32_array_get(void);
|
||||
WpTestFuncResult test_i32_array_set(void);
|
||||
WpTestFuncResult test_i32_array_append_capped(void);
|
||||
WpTestFuncResult test_i32_array_extend_capped(void);
|
||||
WpTestFuncResult test_i32_array_copy_capped(void);
|
||||
WpTestFuncResult test_i32_array_alloc_capacity(void);
|
||||
WpTestFuncResult test_i32_array_append_alloc(void);
|
||||
WpTestFuncResult test_i32_array_extend_alloc(void);
|
||||
WpTestFuncResult test_i32_array_copy_alloc(void);
|
||||
WpTestFuncResult test_i32_array_pop(void);
|
||||
WpTestFuncResult test_i32_array_clear(void);
|
||||
|
||||
#endif // !TEST_INT_ARRAY_H
|
||||
|
||||
@@ -2,24 +2,24 @@
|
||||
|
||||
#include "test_str8_array.h"
|
||||
|
||||
TestFuncResult test_str8_array(void) {
|
||||
WpTestFuncResult test_str8_array(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 expected[] = {wapp_str8_lit("Hello"), wapp_str8_lit("Hi"), wapp_str8_lit("Bye")};
|
||||
Str8Array array = wapp_array(Str8, wapp_str8_lit("Hello"), wapp_str8_lit("Hi"), wapp_str8_lit("Bye"));
|
||||
result = wapp_array_count(array) == 3 && wapp_array_capacity(array) == 8;
|
||||
WpStr8 expected[] = {wpStr8Lit("Hello"), wpStr8Lit("Hi"), wpStr8Lit("Bye")};
|
||||
WpStr8Array array = wpArray(WpStr8, wpStr8Lit("Hello"), wpStr8Lit("Hi"), wpStr8Lit("Bye"));
|
||||
result = wpArrayCount(array) == 3 && wpArrayCapacity(array) == 8;
|
||||
|
||||
Str8 *item;
|
||||
u64 count = wapp_array_count(array);
|
||||
WpStr8 *item;
|
||||
u64 count = wpArrayCount(array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
item = wapp_array_get(Str8, array, index);
|
||||
result = result && item && (wapp_str8_equal(item, &expected[index]));
|
||||
item = wpArrayGet(WpStr8, array, index);
|
||||
result = result && item && (wpStr8Equal(item, &expected[index]));
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
@@ -2,29 +2,29 @@
|
||||
|
||||
#include "test_str8_array.h"
|
||||
|
||||
TestFuncResult test_str8_array(void) {
|
||||
WpTestFuncResult test_str8_array(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 expected[] = {wapp_str8_lit("Hello"), wapp_str8_lit("Hi"), wapp_str8_lit("Bye")};
|
||||
WpStr8 expected[] = {wpStr8Lit("Hello"), wpStr8Lit("Hi"), wpStr8Lit("Bye")};
|
||||
|
||||
Str8 str1 = wapp_str8_lit("Hello");
|
||||
Str8 str2 = wapp_str8_lit("Hi");
|
||||
Str8 str3 = wapp_str8_lit("Bye");
|
||||
Str8Array array = wapp_array(Str8, str1, str2, str3);
|
||||
WpStr8 str1 = wpStr8Lit("Hello");
|
||||
WpStr8 str2 = wpStr8Lit("Hi");
|
||||
WpStr8 str3 = wpStr8Lit("Bye");
|
||||
WpStr8Array array = wpArray(WpStr8, str1, str2, str3);
|
||||
|
||||
result = wapp_array_count(array) == 3 && wapp_array_capacity(array) == 8;
|
||||
result = wpArrayCount(array) == 3 && wpArrayCapacity(array) == 8;
|
||||
|
||||
Str8 *item;
|
||||
u64 count = wapp_array_count(array);
|
||||
WpStr8 *item;
|
||||
u64 count = wpArrayCount(array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
item = wapp_array_get(Str8, array, index);
|
||||
result = result && item && (wapp_str8_equal(item, &expected[index]));
|
||||
item = wpArrayGet(WpStr8, array, index);
|
||||
result = result && item && (wpStr8Equal(item, &expected[index]));
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
|
||||
#include "wapp.h"
|
||||
|
||||
TestFuncResult test_str8_array(void);
|
||||
WpTestFuncResult test_str8_array(void);
|
||||
|
||||
#endif // !TEST_STR8_ARRAY_H
|
||||
|
||||
+102
-102
@@ -6,176 +6,176 @@
|
||||
#define MAIN_BUF_SIZE 4096
|
||||
#define TMP_BUF_SIZE 1024
|
||||
|
||||
TestFuncResult test_cpath_join_path(void) {
|
||||
WpTestFuncResult test_cpath_join_path(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 expected = wapp_str8_buf(MAIN_BUF_SIZE);
|
||||
Str8 out = wapp_str8_buf(MAIN_BUF_SIZE);
|
||||
Str8 tmp = wapp_str8_buf(TMP_BUF_SIZE);
|
||||
WpStr8 expected = wpStr8Buf(MAIN_BUF_SIZE);
|
||||
WpStr8 out = wpStr8Buf(MAIN_BUF_SIZE);
|
||||
WpStr8 tmp = wpStr8Buf(TMP_BUF_SIZE);
|
||||
|
||||
wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wapp_str8_format(&tmp, "%c", WAPP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%chome%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8Format(&tmp, "%c", WP_PATH_SEP);
|
||||
|
||||
Str8List parts = wapp_dbl_list(Str8);
|
||||
wapp_dbl_list_push_back(Str8, &parts, &tmp);
|
||||
wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_lit("home"));
|
||||
wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_lit("abdelrahman"));
|
||||
wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_lit("Documents"));
|
||||
WpStr8List parts = wpDblList(WpStr8);
|
||||
wpDblListPushBack(WpStr8, &parts, &tmp);
|
||||
wpDblListPushBack(WpStr8, &parts, &wpStr8Lit("home"));
|
||||
wpDblListPushBack(WpStr8, &parts, &wpStr8Lit("abdelrahman"));
|
||||
wpDblListPushBack(WpStr8, &parts, &wpStr8Lit("Documents"));
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = wapp_str8_equal(&out, &expected);
|
||||
wpCpathJoinPath(&out, &parts);
|
||||
result = wpStr8Equal(&out, &expected);
|
||||
|
||||
wapp_dbl_list_pop_front(Str8, &parts);
|
||||
wpDblListPopFront(WpStr8, &parts);
|
||||
|
||||
wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wpStr8Format(&expected, "home%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP);
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = result && wapp_str8_equal(&out, &expected);
|
||||
wpCpathJoinPath(&out, &parts);
|
||||
result = result && wpStr8Equal(&out, &expected);
|
||||
|
||||
wapp_str8_concat_capped(&tmp, &wapp_str8_lit_ro("home"));
|
||||
wapp_dbl_list_pop_front(Str8, &parts);
|
||||
wapp_dbl_list_push_front(Str8, &parts, &tmp);
|
||||
wpStr8ConcatCapped(&tmp, &wpStr8LitRo("home"));
|
||||
wpDblListPopFront(WpStr8, &parts);
|
||||
wpDblListPushFront(WpStr8, &parts, &tmp);
|
||||
|
||||
wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%chome%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = result && wapp_str8_equal(&out, &expected);
|
||||
wpCpathJoinPath(&out, &parts);
|
||||
result = result && wpStr8Equal(&out, &expected);
|
||||
|
||||
wapp_str8_format(&tmp, "home%c", WAPP_PATH_SEP);
|
||||
wapp_dbl_list_pop_front(Str8, &parts);
|
||||
wapp_dbl_list_push_front(Str8, &parts, &wapp_str8_lit("home"));
|
||||
wpStr8Format(&tmp, "home%c", WP_PATH_SEP);
|
||||
wpDblListPopFront(WpStr8, &parts);
|
||||
wpDblListPushFront(WpStr8, &parts, &wpStr8Lit("home"));
|
||||
|
||||
wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wpStr8Format(&expected, "home%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP);
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = result && wapp_str8_equal(&out, &expected);
|
||||
wpCpathJoinPath(&out, &parts);
|
||||
result = result && wpStr8Equal(&out, &expected);
|
||||
|
||||
wapp_dbl_list_empty(Str8, &parts);
|
||||
wpDblListEmpty(WpStr8, &parts);
|
||||
|
||||
wapp_str8_format(&tmp, "%chome", WAPP_PATH_SEP);
|
||||
wapp_dbl_list_push_back(Str8, &parts, &tmp);
|
||||
wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_lit(""));
|
||||
wpStr8Format(&tmp, "%chome", WP_PATH_SEP);
|
||||
wpDblListPushBack(WpStr8, &parts, &tmp);
|
||||
wpDblListPushBack(WpStr8, &parts, &wpStr8Lit(""));
|
||||
|
||||
wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%chome", WP_PATH_SEP);
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = result && wapp_str8_equal(&out, &expected);
|
||||
wpCpathJoinPath(&out, &parts);
|
||||
result = result && wpStr8Equal(&out, &expected);
|
||||
|
||||
wapp_dbl_list_pop_front(Str8, &parts);
|
||||
wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_lit(""));
|
||||
wpDblListPopFront(WpStr8, &parts);
|
||||
wpDblListPushBack(WpStr8, &parts, &wpStr8Lit(""));
|
||||
|
||||
wapp_str8_format(&expected, "%s", "");
|
||||
wpStr8Format(&expected, "%s", "");
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = result && wapp_str8_equal(&out, &expected);
|
||||
wpCpathJoinPath(&out, &parts);
|
||||
result = result && wpStr8Equal(&out, &expected);
|
||||
|
||||
wapp_dbl_list_pop_back(Str8, &parts);
|
||||
wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_lit("home"));
|
||||
wpDblListPopBack(WpStr8, &parts);
|
||||
wpDblListPushBack(WpStr8, &parts, &wpStr8Lit("home"));
|
||||
|
||||
wapp_str8_copy_cstr_capped(&expected, "home");
|
||||
wpStr8CopyCstrCapped(&expected, "home");
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = result && wapp_str8_equal(&out, &expected);
|
||||
wpCpathJoinPath(&out, &parts);
|
||||
result = result && wpStr8Equal(&out, &expected);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_cpath_dirname(void) {
|
||||
Allocator arena = wapp_mem_arena_allocator_init(MiB(8));
|
||||
if (wapp_mem_allocator_invalid(&arena)) {
|
||||
return wapp_tester_result(false);
|
||||
WpTestFuncResult test_cpath_dirname(void) {
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(MiB(8));
|
||||
if (wpMemAllocatorInvalid(&arena)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
b8 result;
|
||||
Str8 *output = NULL;
|
||||
WpStr8 *output = NULL;
|
||||
|
||||
Str8 expected = wapp_str8_buf(MAIN_BUF_SIZE);
|
||||
Str8 tmp = wapp_str8_buf(TMP_BUF_SIZE);
|
||||
WpStr8 expected = wpStr8Buf(MAIN_BUF_SIZE);
|
||||
WpStr8 tmp = wpStr8Buf(TMP_BUF_SIZE);
|
||||
|
||||
// CASE 1
|
||||
wapp_str8_format(&tmp, "%c", WAPP_PATH_SEP);
|
||||
wapp_str8_format(&expected, "%c", WAPP_PATH_SEP);
|
||||
wpStr8Format(&tmp, "%c", WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%c", WP_PATH_SEP);
|
||||
|
||||
output = wapp_cpath_dirname(&arena, &tmp);
|
||||
result = output != NULL && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirname(&arena, &tmp);
|
||||
result = output != NULL && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 2
|
||||
wapp_str8_format(&expected, "%s", ".");
|
||||
wpStr8Format(&expected, "%s", ".");
|
||||
|
||||
output = wapp_cpath_dirname(&arena, &wapp_str8_lit("home"));
|
||||
result = result && output != NULL && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirname(&arena, &wpStr8Lit("home"));
|
||||
result = result && output != NULL && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 3
|
||||
output = wapp_cpath_dirname(&arena, &wapp_str8_lit(""));
|
||||
result = result && output != NULL && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirname(&arena, &wpStr8Lit(""));
|
||||
result = result && output != NULL && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 4
|
||||
wapp_str8_format(&tmp, "%chome%ctest", WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP);
|
||||
wpStr8Format(&tmp, "%chome%ctest", WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%chome", WP_PATH_SEP);
|
||||
|
||||
output = wapp_cpath_dirname(&arena, &tmp);
|
||||
result = result && output != NULL && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirname(&arena, &tmp);
|
||||
result = result && output != NULL && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 5
|
||||
wapp_str8_format(&tmp, "%chome%ctest%c", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP);
|
||||
wpStr8Format(&tmp, "%chome%ctest%c", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%chome", WP_PATH_SEP);
|
||||
|
||||
output = wapp_cpath_dirname(&arena, &tmp);
|
||||
result = result && output != NULL && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirname(&arena, &tmp);
|
||||
result = result && output != NULL && wpStr8Equal(output, &expected);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_cpath_dirup(void) {
|
||||
Allocator arena = wapp_mem_arena_allocator_init(MiB(8));
|
||||
if (wapp_mem_allocator_invalid(&arena)) {
|
||||
return wapp_tester_result(false);
|
||||
WpTestFuncResult test_cpath_dirup(void) {
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(MiB(8));
|
||||
if (wpMemAllocatorInvalid(&arena)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
b8 result;
|
||||
Str8 *output = NULL;
|
||||
WpStr8 *output = NULL;
|
||||
|
||||
Str8 expected = wapp_str8_buf(MAIN_BUF_SIZE);
|
||||
Str8 tmp = wapp_str8_buf(TMP_BUF_SIZE);
|
||||
WpStr8 expected = wpStr8Buf(MAIN_BUF_SIZE);
|
||||
WpStr8 tmp = wpStr8Buf(TMP_BUF_SIZE);
|
||||
|
||||
// CASE 1
|
||||
wapp_str8_format(&tmp, "%c", WAPP_PATH_SEP);
|
||||
wapp_str8_format(&expected, "%c", WAPP_PATH_SEP);
|
||||
wpStr8Format(&tmp, "%c", WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%c", WP_PATH_SEP);
|
||||
|
||||
output = wapp_cpath_dirup(&arena, &tmp, 3);
|
||||
result = output != NULL && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirup(&arena, &tmp, 3);
|
||||
result = output != NULL && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 2
|
||||
wapp_str8_format(&tmp, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wapp_str8_format(&expected, "%c", WAPP_PATH_SEP);
|
||||
wpStr8Format(&tmp, "%chome%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%c", WP_PATH_SEP);
|
||||
|
||||
output = wapp_cpath_dirup(&arena, &tmp, 3);
|
||||
result = result && output != NULL && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirup(&arena, &tmp, 3);
|
||||
result = result && output != NULL && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 3
|
||||
wapp_str8_format(&tmp, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wapp_str8_copy_cstr_capped(&expected, ".");
|
||||
wpStr8Format(&tmp, "home%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8CopyCstrCapped(&expected, ".");
|
||||
|
||||
output = wapp_cpath_dirup(&arena, &tmp, 3);
|
||||
result = result && output != NULL && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirup(&arena, &tmp, 3);
|
||||
result = result && output != NULL && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 4
|
||||
wapp_str8_format(&tmp, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP);
|
||||
wpStr8Format(&tmp, "%chome%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%chome", WP_PATH_SEP);
|
||||
|
||||
output = wapp_cpath_dirup(&arena, &tmp, 2);
|
||||
result = result && output != NULL && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirup(&arena, &tmp, 2);
|
||||
result = result && output != NULL && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 5
|
||||
wapp_str8_format(&tmp, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wapp_str8_copy_cstr_capped(&expected, "home");
|
||||
wpStr8Format(&tmp, "home%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8CopyCstrCapped(&expected, "home");
|
||||
|
||||
output = wapp_cpath_dirup(&arena, &tmp, 2);
|
||||
result = result && output != NULL && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirup(&arena, &tmp, 2);
|
||||
result = result && output != NULL && wpStr8Equal(output, &expected);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
+112
-112
@@ -6,196 +6,196 @@
|
||||
#define MAIN_BUF_SIZE 4096
|
||||
#define TMP_BUF_SIZE 1024
|
||||
|
||||
TestFuncResult test_cpath_join_path(void) {
|
||||
WpTestFuncResult test_cpath_join_path(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 expected = wapp_str8_buf(MAIN_BUF_SIZE);
|
||||
Str8 out = wapp_str8_buf(MAIN_BUF_SIZE);
|
||||
Str8 tmp = wapp_str8_buf(TMP_BUF_SIZE);
|
||||
WpStr8 expected = wpStr8Buf(MAIN_BUF_SIZE);
|
||||
WpStr8 out = wpStr8Buf(MAIN_BUF_SIZE);
|
||||
WpStr8 tmp = wpStr8Buf(TMP_BUF_SIZE);
|
||||
|
||||
wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wapp_str8_format(&tmp, "%c", WAPP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%chome%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8Format(&tmp, "%c", WP_PATH_SEP);
|
||||
|
||||
Str8List parts = wapp_dbl_list(Str8);
|
||||
WpStr8List parts = wpDblList(WpStr8);
|
||||
|
||||
wapp_dbl_list_push_back(Str8, &parts, &tmp);
|
||||
wpDblListPushBack(WpStr8, &parts, &tmp);
|
||||
|
||||
Str8 home = wapp_str8_lit("home");
|
||||
wapp_dbl_list_push_back(Str8, &parts, &home);
|
||||
WpStr8 home = wpStr8Lit("home");
|
||||
wpDblListPushBack(WpStr8, &parts, &home);
|
||||
|
||||
Str8 user = wapp_str8_lit("abdelrahman");
|
||||
wapp_dbl_list_push_back(Str8, &parts, &user);
|
||||
WpStr8 user = wpStr8Lit("abdelrahman");
|
||||
wpDblListPushBack(WpStr8, &parts, &user);
|
||||
|
||||
Str8 docs = wapp_str8_lit("Documents");
|
||||
wapp_dbl_list_push_back(Str8, &parts, &docs);
|
||||
WpStr8 docs = wpStr8Lit("Documents");
|
||||
wpDblListPushBack(WpStr8, &parts, &docs);
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = wapp_str8_equal(&out, &expected);
|
||||
wpCpathJoinPath(&out, &parts);
|
||||
result = wpStr8Equal(&out, &expected);
|
||||
|
||||
wapp_dbl_list_pop_front(Str8, &parts);
|
||||
wpDblListPopFront(WpStr8, &parts);
|
||||
|
||||
wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wpStr8Format(&expected, "home%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP);
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = result && wapp_str8_equal(&out, &expected);
|
||||
wpCpathJoinPath(&out, &parts);
|
||||
result = result && wpStr8Equal(&out, &expected);
|
||||
|
||||
Str8RO str = wapp_str8_lit_ro("home");
|
||||
wapp_str8_concat_capped(&tmp, &str);
|
||||
wapp_dbl_list_pop_front(Str8, &parts);
|
||||
WpStr8RO str = wpStr8LitRo("home");
|
||||
wpStr8ConcatCapped(&tmp, &str);
|
||||
wpDblListPopFront(WpStr8, &parts);
|
||||
|
||||
wapp_dbl_list_push_front(Str8, &parts, &tmp);
|
||||
wpDblListPushFront(WpStr8, &parts, &tmp);
|
||||
|
||||
wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%chome%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = result && wapp_str8_equal(&out, &expected);
|
||||
wpCpathJoinPath(&out, &parts);
|
||||
result = result && wpStr8Equal(&out, &expected);
|
||||
|
||||
wapp_str8_format(&tmp, "home%c", WAPP_PATH_SEP);
|
||||
wapp_dbl_list_pop_front(Str8, &parts);
|
||||
wpStr8Format(&tmp, "home%c", WP_PATH_SEP);
|
||||
wpDblListPopFront(WpStr8, &parts);
|
||||
|
||||
Str8 home_2 = wapp_str8_lit("home");
|
||||
wapp_dbl_list_push_front(Str8, &parts, &home_2);
|
||||
WpStr8 home_2 = wpStr8Lit("home");
|
||||
wpDblListPushFront(WpStr8, &parts, &home_2);
|
||||
|
||||
wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wpStr8Format(&expected, "home%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP);
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = result && wapp_str8_equal(&out, &expected);
|
||||
wpCpathJoinPath(&out, &parts);
|
||||
result = result && wpStr8Equal(&out, &expected);
|
||||
|
||||
wapp_dbl_list_empty(Str8, &parts);
|
||||
wpDblListEmpty(WpStr8, &parts);
|
||||
|
||||
wapp_str8_format(&tmp, "%chome", WAPP_PATH_SEP);
|
||||
wpStr8Format(&tmp, "%chome", WP_PATH_SEP);
|
||||
|
||||
wapp_dbl_list_push_back(Str8, &parts, &tmp);
|
||||
wpDblListPushBack(WpStr8, &parts, &tmp);
|
||||
|
||||
Str8 empty = wapp_str8_lit("");
|
||||
wapp_dbl_list_push_back(Str8, &parts, &empty);
|
||||
WpStr8 empty = wpStr8Lit("");
|
||||
wpDblListPushBack(WpStr8, &parts, &empty);
|
||||
|
||||
wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%chome", WP_PATH_SEP);
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = result && wapp_str8_equal(&out, &expected);
|
||||
wpCpathJoinPath(&out, &parts);
|
||||
result = result && wpStr8Equal(&out, &expected);
|
||||
|
||||
wapp_dbl_list_pop_front(Str8, &parts);
|
||||
wpDblListPopFront(WpStr8, &parts);
|
||||
|
||||
Str8 empty_2 = wapp_str8_lit("");
|
||||
wapp_dbl_list_push_back(Str8, &parts, &empty_2);
|
||||
WpStr8 empty_2 = wpStr8Lit("");
|
||||
wpDblListPushBack(WpStr8, &parts, &empty_2);
|
||||
|
||||
wapp_str8_format(&expected, "%s", "");
|
||||
wpStr8Format(&expected, "%s", "");
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = result && wapp_str8_equal(&out, &expected);
|
||||
wpCpathJoinPath(&out, &parts);
|
||||
result = result && wpStr8Equal(&out, &expected);
|
||||
|
||||
wapp_dbl_list_pop_back(Str8, &parts);
|
||||
wpDblListPopBack(WpStr8, &parts);
|
||||
|
||||
Str8 home_3 = wapp_str8_lit("home");
|
||||
wapp_dbl_list_push_back(Str8, &parts, &home_3);
|
||||
WpStr8 home_3 = wpStr8Lit("home");
|
||||
wpDblListPushBack(WpStr8, &parts, &home_3);
|
||||
|
||||
wapp_str8_copy_cstr_capped(&expected, "home");
|
||||
wpStr8CopyCstrCapped(&expected, "home");
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = result && wapp_str8_equal(&out, &expected);
|
||||
wpCpathJoinPath(&out, &parts);
|
||||
result = result && wpStr8Equal(&out, &expected);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_cpath_dirname(void) {
|
||||
Allocator arena = wapp_mem_arena_allocator_init(MiB(8));
|
||||
if (wapp_mem_allocator_invalid(&arena)) {
|
||||
return wapp_tester_result(false);
|
||||
WpTestFuncResult test_cpath_dirname(void) {
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(MiB(8));
|
||||
if (wpMemAllocatorInvalid(&arena)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
b8 result;
|
||||
Str8 *output = nullptr;
|
||||
WpStr8 *output = nullptr;
|
||||
|
||||
Str8 expected = wapp_str8_buf(MAIN_BUF_SIZE);
|
||||
Str8 tmp = wapp_str8_buf(TMP_BUF_SIZE);
|
||||
WpStr8 expected = wpStr8Buf(MAIN_BUF_SIZE);
|
||||
WpStr8 tmp = wpStr8Buf(TMP_BUF_SIZE);
|
||||
|
||||
// CASE 1
|
||||
wapp_str8_format(&tmp, "%c", WAPP_PATH_SEP);
|
||||
wapp_str8_format(&expected, "%c", WAPP_PATH_SEP);
|
||||
wpStr8Format(&tmp, "%c", WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%c", WP_PATH_SEP);
|
||||
|
||||
output = wapp_cpath_dirname(&arena, &tmp);
|
||||
result = output != nullptr && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirname(&arena, &tmp);
|
||||
result = output != nullptr && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 2
|
||||
wapp_str8_format(&expected, "%s", ".");
|
||||
wpStr8Format(&expected, "%s", ".");
|
||||
|
||||
Str8 path = wapp_str8_lit("home");
|
||||
output = wapp_cpath_dirname(&arena, &path);
|
||||
result = result && output != nullptr && wapp_str8_equal(output, &expected);
|
||||
WpStr8 path = wpStr8Lit("home");
|
||||
output = wpCpathDirname(&arena, &path);
|
||||
result = result && output != nullptr && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 3
|
||||
path = wapp_str8_lit("");
|
||||
output = wapp_cpath_dirname(&arena, &path);
|
||||
result = result && output != nullptr && wapp_str8_equal(output, &expected);
|
||||
path = wpStr8Lit("");
|
||||
output = wpCpathDirname(&arena, &path);
|
||||
result = result && output != nullptr && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 4
|
||||
wapp_str8_format(&tmp, "%chome%ctest", WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP);
|
||||
wpStr8Format(&tmp, "%chome%ctest", WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%chome", WP_PATH_SEP);
|
||||
|
||||
output = wapp_cpath_dirname(&arena, &tmp);
|
||||
result = result && output != nullptr && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirname(&arena, &tmp);
|
||||
result = result && output != nullptr && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 5
|
||||
wapp_str8_format(&tmp, "%chome%ctest%c", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP);
|
||||
wpStr8Format(&tmp, "%chome%ctest%c", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%chome", WP_PATH_SEP);
|
||||
|
||||
output = wapp_cpath_dirname(&arena, &tmp);
|
||||
result = result && output != nullptr && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirname(&arena, &tmp);
|
||||
result = result && output != nullptr && wpStr8Equal(output, &expected);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_cpath_dirup(void) {
|
||||
Allocator arena = wapp_mem_arena_allocator_init(MiB(8));
|
||||
if (wapp_mem_allocator_invalid(&arena)) {
|
||||
return wapp_tester_result(false);
|
||||
WpTestFuncResult test_cpath_dirup(void) {
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(MiB(8));
|
||||
if (wpMemAllocatorInvalid(&arena)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
b8 result;
|
||||
Str8 *output = nullptr;
|
||||
WpStr8 *output = nullptr;
|
||||
|
||||
Str8 expected = wapp_str8_buf(MAIN_BUF_SIZE);
|
||||
Str8 tmp = wapp_str8_buf(TMP_BUF_SIZE);
|
||||
WpStr8 expected = wpStr8Buf(MAIN_BUF_SIZE);
|
||||
WpStr8 tmp = wpStr8Buf(TMP_BUF_SIZE);
|
||||
|
||||
// CASE 1
|
||||
wapp_str8_format(&tmp, "%c", WAPP_PATH_SEP);
|
||||
wapp_str8_format(&expected, "%c", WAPP_PATH_SEP);
|
||||
wpStr8Format(&tmp, "%c", WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%c", WP_PATH_SEP);
|
||||
|
||||
output = wapp_cpath_dirup(&arena, &tmp, 3);
|
||||
result = output != nullptr && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirup(&arena, &tmp, 3);
|
||||
result = output != nullptr && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 2
|
||||
wapp_str8_format(&tmp, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wapp_str8_format(&expected, "%c", WAPP_PATH_SEP);
|
||||
wpStr8Format(&tmp, "%chome%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%c", WP_PATH_SEP);
|
||||
|
||||
output = wapp_cpath_dirup(&arena, &tmp, 3);
|
||||
result = result && output != nullptr && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirup(&arena, &tmp, 3);
|
||||
result = result && output != nullptr && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 3
|
||||
wapp_str8_format(&tmp, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wapp_str8_copy_cstr_capped(&expected, ".");
|
||||
wpStr8Format(&tmp, "home%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8CopyCstrCapped(&expected, ".");
|
||||
|
||||
output = wapp_cpath_dirup(&arena, &tmp, 3);
|
||||
result = result && output != nullptr && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirup(&arena, &tmp, 3);
|
||||
result = result && output != nullptr && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 4
|
||||
wapp_str8_format(&tmp, "%chome%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wapp_str8_format(&expected, "%chome", WAPP_PATH_SEP);
|
||||
wpStr8Format(&tmp, "%chome%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8Format(&expected, "%chome", WP_PATH_SEP);
|
||||
|
||||
output = wapp_cpath_dirup(&arena, &tmp, 2);
|
||||
result = result && output != nullptr && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirup(&arena, &tmp, 2);
|
||||
result = result && output != nullptr && wpStr8Equal(output, &expected);
|
||||
|
||||
// CASE 5
|
||||
wapp_str8_format(&tmp, "home%cabdelrahman%cDocuments", WAPP_PATH_SEP, WAPP_PATH_SEP);
|
||||
wapp_str8_copy_cstr_capped(&expected, "home");
|
||||
wpStr8Format(&tmp, "home%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP);
|
||||
wpStr8CopyCstrCapped(&expected, "home");
|
||||
|
||||
output = wapp_cpath_dirup(&arena, &tmp, 2);
|
||||
result = result && output != nullptr && wapp_str8_equal(output, &expected);
|
||||
output = wpCpathDirup(&arena, &tmp, 2);
|
||||
result = result && output != nullptr && wpStr8Equal(output, &expected);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#include "wapp.h"
|
||||
|
||||
TestFuncResult test_cpath_join_path(void);
|
||||
TestFuncResult test_cpath_dirname(void);
|
||||
TestFuncResult test_cpath_dirup(void);
|
||||
WpTestFuncResult test_cpath_join_path(void);
|
||||
WpTestFuncResult test_cpath_dirname(void);
|
||||
WpTestFuncResult test_cpath_dirup(void);
|
||||
|
||||
#endif // !TEST_CPATH_H
|
||||
|
||||
+59
-59
@@ -3,48 +3,48 @@
|
||||
#include "test_file.h"
|
||||
|
||||
#define DST_CAPACITY 5
|
||||
wapp_intern Allocator arena = {0};
|
||||
wapp_intern Str8RO test_filename = wapp_str8_lit_ro_initialiser_list("wapptest.bin");
|
||||
wapp_intern Str8RO new_filename = wapp_str8_lit_ro_initialiser_list("wapptest2.bin");
|
||||
wapp_intern WFile *test_fp = NULL;
|
||||
wapp_intern I32Array src_array1 = wapp_array(i32, 0, 1, 2, 3, 4);
|
||||
wapp_intern I32Array src_array2 = wapp_array(i32, 5, 6, 7, 8, 9);
|
||||
wapp_intern I32Array src_array3 = wapp_array(i32, 10, 11, 12, 13, 14);
|
||||
wapp_intern I32Array dst_array = wapp_array_with_capacity(i32, DST_CAPACITY, false);
|
||||
wapp_intern i32 dst_buf[DST_CAPACITY] = {0};
|
||||
wp_intern WpAllocator arena = {0};
|
||||
wp_intern WpStr8RO test_filename = wpStr8LitRoInitialiserList("wapptest.bin");
|
||||
wp_intern WpStr8RO new_filename = wpStr8LitRoInitialiserList("wapptest2.bin");
|
||||
wp_intern WpFile *test_fp = NULL;
|
||||
wp_intern WpI32Array src_array1 = wpArray(i32, 0, 1, 2, 3, 4);
|
||||
wp_intern WpI32Array src_array2 = wpArray(i32, 5, 6, 7, 8, 9);
|
||||
wp_intern WpI32Array src_array3 = wpArray(i32, 10, 11, 12, 13, 14);
|
||||
wp_intern WpI32Array dst_array = wpArrayWithCapacity(i32, DST_CAPACITY, false);
|
||||
wp_intern i32 dst_buf[DST_CAPACITY] = {0};
|
||||
|
||||
TestFuncResult test_wapp_file_open(void) {
|
||||
arena = wapp_mem_arena_allocator_init(KiB(16));
|
||||
test_fp = wapp_file_open(&arena, &test_filename, WAPP_ACCESS_WRITE_EX);
|
||||
return wapp_tester_result(test_fp != NULL);
|
||||
WpTestFuncResult test_wapp_file_open(void) {
|
||||
arena = wpMemArenaAllocatorInit(KiB(16));
|
||||
test_fp = wpFileOpen(&arena, &test_filename, WP_ACCESS_WRITE_EX);
|
||||
return wpTesterResult(test_fp != NULL);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_get_current_position(void) {
|
||||
i64 pos = wapp_file_get_current_position(test_fp);
|
||||
return wapp_tester_result(pos == 0);
|
||||
WpTestFuncResult test_wapp_file_get_current_position(void) {
|
||||
i64 pos = wpFileGetCurrentPosition(test_fp);
|
||||
return wpTesterResult(pos == 0);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_seek(void) {
|
||||
wapp_file_write_array((GenericArray)src_array1, test_fp, wapp_array_count(src_array1));
|
||||
WpTestFuncResult test_wapp_file_seek(void) {
|
||||
wpFileWriteArray((WpArray)src_array1, test_fp, wpArrayCount(src_array1));
|
||||
|
||||
i64 seek_result = wapp_file_seek(test_fp, 0, WAPP_SEEK_END);
|
||||
b8 result = seek_result == (i64)(wapp_array_count(src_array1) * wapp_array_item_size(src_array1));
|
||||
i64 seek_result = wpFileSeek(test_fp, 0, WP_SEEK_END);
|
||||
b8 result = seek_result == (i64)(wpArrayCount(src_array1) * wpArrayItemSize(src_array1));
|
||||
|
||||
wapp_file_seek(test_fp, 0, WAPP_SEEK_START);
|
||||
wpFileSeek(test_fp, 0, WP_SEEK_START);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_get_length(void) {
|
||||
i64 length = wapp_file_get_length(test_fp);
|
||||
return wapp_tester_result(length == (i64)(wapp_array_count(src_array1) * wapp_array_item_size(src_array1)));
|
||||
WpTestFuncResult test_wapp_file_get_length(void) {
|
||||
i64 length = wpFileGetLength(test_fp);
|
||||
return wpTesterResult(length == (i64)(wpArrayCount(src_array1) * wpArrayItemSize(src_array1)));
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_read(void) {
|
||||
wapp_file_seek(test_fp, 0, WAPP_SEEK_START);
|
||||
WpTestFuncResult test_wapp_file_read(void) {
|
||||
wpFileSeek(test_fp, 0, WP_SEEK_START);
|
||||
|
||||
u64 byte_count = DST_CAPACITY * sizeof(i32);
|
||||
u64 count = wapp_file_read((void *)dst_buf, test_fp, byte_count);
|
||||
u64 count = wpFileRead((void *)dst_buf, test_fp, byte_count);
|
||||
b8 result = count == byte_count;
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
@@ -52,67 +52,67 @@ TestFuncResult test_wapp_file_read(void) {
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
result = result && (dst_buf[index] == *wapp_array_get(i32, src_array1, index));
|
||||
result = result && (dst_buf[index] == *wpArrayGet(i32, src_array1, index));
|
||||
++index;
|
||||
running = index < DST_CAPACITY;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_write(void) {
|
||||
wapp_file_seek(test_fp, 0, WAPP_SEEK_END);
|
||||
WpTestFuncResult test_wapp_file_write(void) {
|
||||
wpFileSeek(test_fp, 0, WP_SEEK_END);
|
||||
|
||||
u64 expected_count = wapp_array_count(src_array2) * wapp_array_item_size(src_array2);
|
||||
i64 count = wapp_file_write((void *)src_array2, test_fp, expected_count);
|
||||
u64 expected_count = wpArrayCount(src_array2) * wpArrayItemSize(src_array2);
|
||||
i64 count = wpFileWrite((void *)src_array2, test_fp, expected_count);
|
||||
|
||||
return wapp_tester_result(count >= 0 && (u64)count == expected_count);
|
||||
return wpTesterResult(count >= 0 && (u64)count == expected_count);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_read_array(void) {
|
||||
wapp_file_seek(test_fp, 0, WAPP_SEEK_START);
|
||||
WpTestFuncResult test_wapp_file_read_array(void) {
|
||||
wpFileSeek(test_fp, 0, WP_SEEK_START);
|
||||
|
||||
u64 count = wapp_file_read_array((GenericArray)dst_array, test_fp, wapp_array_count(src_array1));
|
||||
b8 result = count == wapp_array_count(src_array1) &&
|
||||
wapp_array_count(dst_array) == wapp_array_count(src_array1);
|
||||
u64 count = wpFileReadArray((WpArray)dst_array, test_fp, wpArrayCount(src_array1));
|
||||
b8 result = count == wpArrayCount(src_array1) &&
|
||||
wpArrayCount(dst_array) == wpArrayCount(src_array1);
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
result = result && (*wapp_array_get(i32, dst_array, index) == *wapp_array_get(i32, src_array1, index));
|
||||
result = result && (*wpArrayGet(i32, dst_array, index) == *wpArrayGet(i32, src_array1, index));
|
||||
++index;
|
||||
running = index < wapp_array_count(dst_array);
|
||||
running = index < wpArrayCount(dst_array);
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_write_array(void) {
|
||||
wapp_file_seek(test_fp, 0, WAPP_SEEK_END);
|
||||
WpTestFuncResult test_wapp_file_write_array(void) {
|
||||
wpFileSeek(test_fp, 0, WP_SEEK_END);
|
||||
|
||||
i64 count = wapp_file_write_array((GenericArray)src_array3, test_fp, wapp_array_count(src_array3));
|
||||
i64 count = wpFileWriteArray((WpArray)src_array3, test_fp, wpArrayCount(src_array3));
|
||||
|
||||
return wapp_tester_result(count >= 0 && (u64)count == wapp_array_count(src_array3));
|
||||
return wpTesterResult(count >= 0 && (u64)count == wpArrayCount(src_array3));
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_flush(void) {
|
||||
i32 flush_result = wapp_file_flush(test_fp);
|
||||
return wapp_tester_result(flush_result == 0);
|
||||
WpTestFuncResult test_wapp_file_flush(void) {
|
||||
i32 flush_result = wpFileFlush(test_fp);
|
||||
return wpTesterResult(flush_result == 0);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_close(void) {
|
||||
i32 close_result = wapp_file_close(test_fp);
|
||||
return wapp_tester_result(close_result == 0);
|
||||
WpTestFuncResult test_wapp_file_close(void) {
|
||||
i32 close_result = wpFileClose(test_fp);
|
||||
return wpTesterResult(close_result == 0);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_rename(void) {
|
||||
i32 rename_result = wapp_file_rename(&test_filename, &new_filename);
|
||||
return wapp_tester_result(rename_result == 0);
|
||||
WpTestFuncResult test_wapp_file_rename(void) {
|
||||
i32 rename_result = wpFileRename(&test_filename, &new_filename);
|
||||
return wpTesterResult(rename_result == 0);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_remove(void) {
|
||||
i32 remove_result = wapp_file_remove(&new_filename);
|
||||
return wapp_tester_result(remove_result == 0);
|
||||
WpTestFuncResult test_wapp_file_remove(void) {
|
||||
i32 remove_result = wpFileRemove(&new_filename);
|
||||
return wpTesterResult(remove_result == 0);
|
||||
}
|
||||
|
||||
+63
-63
@@ -3,52 +3,52 @@
|
||||
#include "test_file.h"
|
||||
|
||||
#define DST_CAPACITY 5
|
||||
wapp_intern Allocator arena = {};
|
||||
wapp_intern Str8RO test_filename = wapp_str8_lit_ro_initialiser_list("wapptest.bin");
|
||||
wapp_intern Str8RO new_filename = wapp_str8_lit_ro_initialiser_list("wapptest2.bin");
|
||||
wapp_intern WFile *test_fp = NULL;
|
||||
wapp_intern i32 dst_buf[DST_CAPACITY] = {0};
|
||||
wapp_intern I32Array src_array1;
|
||||
wapp_intern I32Array src_array2;
|
||||
wapp_intern I32Array src_array3;
|
||||
wapp_intern I32Array dst_array ;
|
||||
wp_intern WpAllocator arena = {};
|
||||
wp_intern WpStr8RO test_filename = wpStr8LitRoInitialiserList("wapptest.bin");
|
||||
wp_intern WpStr8RO new_filename = wpStr8LitRoInitialiserList("wapptest2.bin");
|
||||
wp_intern WpFile *test_fp = NULL;
|
||||
wp_intern i32 dst_buf[DST_CAPACITY] = {0};
|
||||
wp_intern WpI32Array src_array1;
|
||||
wp_intern WpI32Array src_array2;
|
||||
wp_intern WpI32Array src_array3;
|
||||
wp_intern WpI32Array dst_array ;
|
||||
|
||||
TestFuncResult test_wapp_file_open(void) {
|
||||
arena = wapp_mem_arena_allocator_init(KiB(16));
|
||||
src_array1 = wapp_array(i32, 0, 1, 2, 3, 4);
|
||||
src_array2 = wapp_array(i32, 5, 6, 7, 8, 9);
|
||||
src_array3 = wapp_array(i32, 10, 11, 12, 13, 14);
|
||||
dst_array = wapp_array_with_capacity(i32, DST_CAPACITY, false);
|
||||
test_fp = wapp_file_open(&arena, &test_filename, WAPP_ACCESS_WRITE_EX);
|
||||
return wapp_tester_result(test_fp != NULL);
|
||||
WpTestFuncResult test_wapp_file_open(void) {
|
||||
arena = wpMemArenaAllocatorInit(KiB(16));
|
||||
src_array1 = wpArray(i32, 0, 1, 2, 3, 4);
|
||||
src_array2 = wpArray(i32, 5, 6, 7, 8, 9);
|
||||
src_array3 = wpArray(i32, 10, 11, 12, 13, 14);
|
||||
dst_array = wpArrayWithCapacity(i32, DST_CAPACITY, false);
|
||||
test_fp = wpFileOpen(&arena, &test_filename, WP_ACCESS_WRITE_EX);
|
||||
return wpTesterResult(test_fp != NULL);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_get_current_position(void) {
|
||||
i64 pos = wapp_file_get_current_position(test_fp);
|
||||
return wapp_tester_result(pos == 0);
|
||||
WpTestFuncResult test_wapp_file_get_current_position(void) {
|
||||
i64 pos = wpFileGetCurrentPosition(test_fp);
|
||||
return wpTesterResult(pos == 0);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_seek(void) {
|
||||
wapp_file_write_array((GenericArray)src_array1, test_fp, wapp_array_count(src_array1));
|
||||
WpTestFuncResult test_wapp_file_seek(void) {
|
||||
wpFileWriteArray((WpArray)src_array1, test_fp, wpArrayCount(src_array1));
|
||||
|
||||
i64 seek_result = wapp_file_seek(test_fp, 0, WAPP_SEEK_END);
|
||||
b8 result = seek_result == (i64)(wapp_array_count(src_array1) * wapp_array_item_size(src_array1));
|
||||
i64 seek_result = wpFileSeek(test_fp, 0, WP_SEEK_END);
|
||||
b8 result = seek_result == (i64)(wpArrayCount(src_array1) * wpArrayItemSize(src_array1));
|
||||
|
||||
wapp_file_seek(test_fp, 0, WAPP_SEEK_START);
|
||||
wpFileSeek(test_fp, 0, WP_SEEK_START);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_get_length(void) {
|
||||
i64 length = wapp_file_get_length(test_fp);
|
||||
return wapp_tester_result(length == (i64)(wapp_array_count(src_array1) * wapp_array_item_size(src_array1)));
|
||||
WpTestFuncResult test_wapp_file_get_length(void) {
|
||||
i64 length = wpFileGetLength(test_fp);
|
||||
return wpTesterResult(length == (i64)(wpArrayCount(src_array1) * wpArrayItemSize(src_array1)));
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_read(void) {
|
||||
wapp_file_seek(test_fp, 0, WAPP_SEEK_START);
|
||||
WpTestFuncResult test_wapp_file_read(void) {
|
||||
wpFileSeek(test_fp, 0, WP_SEEK_START);
|
||||
|
||||
u64 byte_count = DST_CAPACITY * sizeof(i32);
|
||||
u64 count = wapp_file_read((void *)dst_buf, test_fp, byte_count);
|
||||
u64 count = wpFileRead((void *)dst_buf, test_fp, byte_count);
|
||||
b8 result = count == byte_count;
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
@@ -56,67 +56,67 @@ TestFuncResult test_wapp_file_read(void) {
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
result = result && (dst_buf[index] == *wapp_array_get(i32, src_array1, index));
|
||||
result = result && (dst_buf[index] == *wpArrayGet(i32, src_array1, index));
|
||||
++index;
|
||||
running = index < DST_CAPACITY;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_write(void) {
|
||||
wapp_file_seek(test_fp, 0, WAPP_SEEK_END);
|
||||
WpTestFuncResult test_wapp_file_write(void) {
|
||||
wpFileSeek(test_fp, 0, WP_SEEK_END);
|
||||
|
||||
u64 expected_count = wapp_array_count(src_array2) * wapp_array_item_size(src_array2);
|
||||
i64 count = wapp_file_write((void *)src_array2, test_fp, expected_count);
|
||||
u64 expected_count = wpArrayCount(src_array2) * wpArrayItemSize(src_array2);
|
||||
i64 count = wpFileWrite((void *)src_array2, test_fp, expected_count);
|
||||
|
||||
return wapp_tester_result(count >= 0 && (u64)count == expected_count);
|
||||
return wpTesterResult(count >= 0 && (u64)count == expected_count);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_read_array(void) {
|
||||
wapp_file_seek(test_fp, 0, WAPP_SEEK_START);
|
||||
WpTestFuncResult test_wapp_file_read_array(void) {
|
||||
wpFileSeek(test_fp, 0, WP_SEEK_START);
|
||||
|
||||
u64 count = wapp_file_read_array((GenericArray)dst_array, test_fp, wapp_array_count(src_array1));
|
||||
b8 result = count == wapp_array_count(src_array1) &&
|
||||
wapp_array_count(dst_array) == wapp_array_count(src_array1);
|
||||
u64 count = wpFileReadArray((WpArray)dst_array, test_fp, wpArrayCount(src_array1));
|
||||
b8 result = count == wpArrayCount(src_array1) &&
|
||||
wpArrayCount(dst_array) == wpArrayCount(src_array1);
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
result = result && (*wapp_array_get(i32, dst_array, index) == *wapp_array_get(i32, src_array1, index));
|
||||
result = result && (*wpArrayGet(i32, dst_array, index) == *wpArrayGet(i32, src_array1, index));
|
||||
++index;
|
||||
running = index < wapp_array_count(dst_array);
|
||||
running = index < wpArrayCount(dst_array);
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_write_array(void) {
|
||||
wapp_file_seek(test_fp, 0, WAPP_SEEK_END);
|
||||
WpTestFuncResult test_wapp_file_write_array(void) {
|
||||
wpFileSeek(test_fp, 0, WP_SEEK_END);
|
||||
|
||||
i64 count = wapp_file_write_array((GenericArray)src_array3, test_fp, wapp_array_count(src_array3));
|
||||
i64 count = wpFileWriteArray((WpArray)src_array3, test_fp, wpArrayCount(src_array3));
|
||||
|
||||
return wapp_tester_result(count >= 0 && (u64)count == wapp_array_count(src_array3));
|
||||
return wpTesterResult(count >= 0 && (u64)count == wpArrayCount(src_array3));
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_flush(void) {
|
||||
i32 flush_result = wapp_file_flush(test_fp);
|
||||
return wapp_tester_result(flush_result == 0);
|
||||
WpTestFuncResult test_wapp_file_flush(void) {
|
||||
i32 flush_result = wpFileFlush(test_fp);
|
||||
return wpTesterResult(flush_result == 0);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_close(void) {
|
||||
i32 close_result = wapp_file_close(test_fp);
|
||||
return wapp_tester_result(close_result == 0);
|
||||
WpTestFuncResult test_wapp_file_close(void) {
|
||||
i32 close_result = wpFileClose(test_fp);
|
||||
return wpTesterResult(close_result == 0);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_rename(void) {
|
||||
i32 rename_result = wapp_file_rename(&test_filename, &new_filename);
|
||||
return wapp_tester_result(rename_result == 0);
|
||||
WpTestFuncResult test_wapp_file_rename(void) {
|
||||
i32 rename_result = wpFileRename(&test_filename, &new_filename);
|
||||
return wpTesterResult(rename_result == 0);
|
||||
}
|
||||
|
||||
TestFuncResult test_wapp_file_remove(void) {
|
||||
i32 remove_result = wapp_file_remove(&new_filename);
|
||||
return wapp_tester_result(remove_result == 0);
|
||||
WpTestFuncResult test_wapp_file_remove(void) {
|
||||
i32 remove_result = wpFileRemove(&new_filename);
|
||||
return wpTesterResult(remove_result == 0);
|
||||
}
|
||||
|
||||
+12
-12
@@ -5,17 +5,17 @@
|
||||
|
||||
#include "wapp.h"
|
||||
|
||||
TestFuncResult test_wapp_file_open(void);
|
||||
TestFuncResult test_wapp_file_get_current_position(void);
|
||||
TestFuncResult test_wapp_file_seek(void);
|
||||
TestFuncResult test_wapp_file_get_length(void);
|
||||
TestFuncResult test_wapp_file_read(void);
|
||||
TestFuncResult test_wapp_file_write(void);
|
||||
TestFuncResult test_wapp_file_read_array(void);
|
||||
TestFuncResult test_wapp_file_write_array(void);
|
||||
TestFuncResult test_wapp_file_flush(void);
|
||||
TestFuncResult test_wapp_file_close(void);
|
||||
TestFuncResult test_wapp_file_rename(void);
|
||||
TestFuncResult test_wapp_file_remove(void);
|
||||
WpTestFuncResult test_wapp_file_open(void);
|
||||
WpTestFuncResult test_wapp_file_get_current_position(void);
|
||||
WpTestFuncResult test_wapp_file_seek(void);
|
||||
WpTestFuncResult test_wapp_file_get_length(void);
|
||||
WpTestFuncResult test_wapp_file_read(void);
|
||||
WpTestFuncResult test_wapp_file_write(void);
|
||||
WpTestFuncResult test_wapp_file_read_array(void);
|
||||
WpTestFuncResult test_wapp_file_write_array(void);
|
||||
WpTestFuncResult test_wapp_file_flush(void);
|
||||
WpTestFuncResult test_wapp_file_close(void);
|
||||
WpTestFuncResult test_wapp_file_rename(void);
|
||||
WpTestFuncResult test_wapp_file_remove(void);
|
||||
|
||||
#endif // !TEST_FILE_H
|
||||
|
||||
+24
-24
@@ -5,12 +5,12 @@
|
||||
|
||||
#define CAPACITY 8
|
||||
|
||||
TestFuncResult test_queue_push(void) {
|
||||
I32Queue queue = wapp_queue(i32, CAPACITY);
|
||||
WpTestFuncResult test_queue_push(void) {
|
||||
WpI32Queue queue = wpQueue(i32, CAPACITY);
|
||||
|
||||
for (u64 i = 0; i < CAPACITY; ++i) {
|
||||
i32 item = (i32)i;
|
||||
wapp_queue_push(i32, &queue, &item);
|
||||
wpQueuePush(i32, &queue, &item);
|
||||
}
|
||||
|
||||
b8 result = true;
|
||||
@@ -19,45 +19,45 @@ TestFuncResult test_queue_push(void) {
|
||||
result = result && value != NULL && *value == (i32)i;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_queue_push_alloc(void) {
|
||||
Allocator arena = wapp_mem_arena_allocator_init(MiB(64));
|
||||
I32Queue queue = wapp_queue(i32, CAPACITY);
|
||||
WpTestFuncResult test_queue_push_alloc(void) {
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(MiB(64));
|
||||
WpI32Queue queue = wpQueue(i32, CAPACITY);
|
||||
|
||||
for (u64 i = 0; i < CAPACITY; ++i) {
|
||||
i32 item = (i32)i;
|
||||
wapp_queue_push(i32, &queue, &item);
|
||||
wpQueuePush(i32, &queue, &item);
|
||||
}
|
||||
|
||||
b8 result = true;
|
||||
i32 item = 8;
|
||||
u64 new_capacity = CAPACITY * 2;
|
||||
I32Queue *new_queue = wapp_queue_push_alloc(i32, &arena, &queue, &item);
|
||||
WpI32Queue *new_queue = wpQueuePushAlloc(i32, &arena, &queue, &item);
|
||||
if (new_queue && new_queue != &queue) {
|
||||
queue = *new_queue;
|
||||
}
|
||||
u64 capacity = wapp_queue_capacity(&queue);
|
||||
u64 capacity = wpQueueCapacity(&queue);
|
||||
result = result && capacity == new_capacity;
|
||||
|
||||
for (u64 i = 0; i < 2; ++i) {
|
||||
wapp_queue_pop(i32, &queue);
|
||||
wpQueuePop(i32, &queue);
|
||||
}
|
||||
|
||||
u64 remaining = wapp_queue_capacity(&queue) - queue.count;
|
||||
u64 remaining = wpQueueCapacity(&queue) - queue.count;
|
||||
for (u64 i = 0; i < remaining; ++i) {
|
||||
item = (i32)(remaining + i);
|
||||
wapp_queue_push(i32, &queue, &item);
|
||||
wpQueuePush(i32, &queue, &item);
|
||||
}
|
||||
|
||||
++item;
|
||||
new_queue = wapp_queue_push_alloc(i32, &arena, &queue, &item);
|
||||
new_queue = wpQueuePushAlloc(i32, &arena, &queue, &item);
|
||||
if (new_queue && new_queue != &queue) {
|
||||
queue = *new_queue;
|
||||
}
|
||||
|
||||
result = result && wapp_queue_capacity(&queue) == new_capacity * 2;
|
||||
result = result && wpQueueCapacity(&queue) == new_capacity * 2;
|
||||
|
||||
i32 *arr = (i32 *)queue.items;
|
||||
for (u64 i = 0; i < queue.count; ++i) {
|
||||
@@ -65,34 +65,34 @@ TestFuncResult test_queue_push_alloc(void) {
|
||||
result = result && arr[i] == (i32)(2 + i);
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_queue_pop(void) {
|
||||
I32Queue queue = wapp_queue(i32, CAPACITY);
|
||||
WpTestFuncResult test_queue_pop(void) {
|
||||
WpI32Queue queue = wpQueue(i32, CAPACITY);
|
||||
for (u64 i = 0; i < CAPACITY; ++i) {
|
||||
i32 item = (i32)i;
|
||||
wapp_queue_push(i32, &queue, &item);
|
||||
wpQueuePush(i32, &queue, &item);
|
||||
}
|
||||
|
||||
b8 result = true;
|
||||
u64 half_count = queue.count / 2;
|
||||
for (u64 i = 0; i < half_count; ++i) {
|
||||
i32 *value = wapp_queue_pop(i32, &queue);
|
||||
i32 *value = wpQueuePop(i32, &queue);
|
||||
result = result && value != NULL && *value == (i32)i;
|
||||
}
|
||||
|
||||
for (u64 i = 0; i < half_count; ++i) {
|
||||
i32 item = (i32)i + CAPACITY;
|
||||
wapp_queue_push(i32, &queue, &item);
|
||||
wpQueuePush(i32, &queue, &item);
|
||||
}
|
||||
|
||||
for (u64 i = 0; i < CAPACITY; ++i) {
|
||||
i32 *value = wapp_queue_pop(i32, &queue);
|
||||
i32 *value = wpQueuePop(i32, &queue);
|
||||
result = result && value != NULL && *value == (i32)half_count + (i32)i;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
+24
-24
@@ -3,12 +3,12 @@
|
||||
|
||||
#define CAPACITY 8
|
||||
|
||||
TestFuncResult test_queue_push(void) {
|
||||
I32Queue queue = wapp_queue(i32, CAPACITY);
|
||||
WpTestFuncResult test_queue_push(void) {
|
||||
WpI32Queue queue = wpQueue(i32, CAPACITY);
|
||||
|
||||
for (u64 i = 0; i < CAPACITY; ++i) {
|
||||
i32 item = (i32)i;
|
||||
wapp_queue_push(i32, &queue, &item);
|
||||
wpQueuePush(i32, &queue, &item);
|
||||
}
|
||||
|
||||
b8 result = true;
|
||||
@@ -17,45 +17,45 @@ TestFuncResult test_queue_push(void) {
|
||||
result = result && value != NULL && *value == (i32)i;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_queue_push_alloc(void) {
|
||||
Allocator arena = wapp_mem_arena_allocator_init(MiB(64));
|
||||
I32Queue queue = wapp_queue(i32, CAPACITY);
|
||||
WpTestFuncResult test_queue_push_alloc(void) {
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(MiB(64));
|
||||
WpI32Queue queue = wpQueue(i32, CAPACITY);
|
||||
|
||||
for (u64 i = 0; i < CAPACITY; ++i) {
|
||||
i32 item = (i32)i;
|
||||
wapp_queue_push(i32, &queue, &item);
|
||||
wpQueuePush(i32, &queue, &item);
|
||||
}
|
||||
|
||||
b8 result = true;
|
||||
i32 item = 8;
|
||||
u64 new_capacity = CAPACITY * 2;
|
||||
I32Queue *new_queue = wapp_queue_push_alloc(i32, &arena, &queue, &item);
|
||||
WpI32Queue *new_queue = wpQueuePushAlloc(i32, &arena, &queue, &item);
|
||||
if (new_queue && new_queue != &queue) {
|
||||
queue = *new_queue;
|
||||
}
|
||||
u64 capacity = wapp_queue_capacity(&queue);
|
||||
u64 capacity = wpQueueCapacity(&queue);
|
||||
result = result && capacity == new_capacity;
|
||||
|
||||
for (u64 i = 0; i < 2; ++i) {
|
||||
wapp_queue_pop(i32, &queue);
|
||||
wpQueuePop(i32, &queue);
|
||||
}
|
||||
|
||||
u64 remaining = wapp_queue_capacity(&queue) - queue.count;
|
||||
u64 remaining = wpQueueCapacity(&queue) - queue.count;
|
||||
for (u64 i = 0; i < remaining; ++i) {
|
||||
item = (i32)(remaining + i);
|
||||
wapp_queue_push(i32, &queue, &item);
|
||||
wpQueuePush(i32, &queue, &item);
|
||||
}
|
||||
|
||||
++item;
|
||||
new_queue = wapp_queue_push_alloc(i32, &arena, &queue, &item);
|
||||
new_queue = wpQueuePushAlloc(i32, &arena, &queue, &item);
|
||||
if (new_queue && new_queue != &queue) {
|
||||
queue = *new_queue;
|
||||
}
|
||||
|
||||
result = result && wapp_queue_capacity(&queue) == new_capacity * 2;
|
||||
result = result && wpQueueCapacity(&queue) == new_capacity * 2;
|
||||
|
||||
i32 *arr = (i32 *)queue.items;
|
||||
for (u64 i = 0; i < queue.count; ++i) {
|
||||
@@ -63,34 +63,34 @@ TestFuncResult test_queue_push_alloc(void) {
|
||||
result = result && arr[i] == (i32)(2 + i);
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_queue_pop(void) {
|
||||
I32Queue queue = wapp_queue(i32, CAPACITY);
|
||||
WpTestFuncResult test_queue_pop(void) {
|
||||
WpI32Queue queue = wpQueue(i32, CAPACITY);
|
||||
for (u64 i = 0; i < CAPACITY; ++i) {
|
||||
i32 item = (i32)i;
|
||||
wapp_queue_push(i32, &queue, &item);
|
||||
wpQueuePush(i32, &queue, &item);
|
||||
}
|
||||
|
||||
b8 result = true;
|
||||
u64 half_count = queue.count / 2;
|
||||
for (u64 i = 0; i < half_count; ++i) {
|
||||
i32 *value = wapp_queue_pop(i32, &queue);
|
||||
i32 *value = wpQueuePop(i32, &queue);
|
||||
result = result && value != NULL && *value == (i32)i;
|
||||
}
|
||||
|
||||
for (u64 i = 0; i < half_count; ++i) {
|
||||
i32 item = (i32)i + CAPACITY;
|
||||
wapp_queue_push(i32, &queue, &item);
|
||||
wpQueuePush(i32, &queue, &item);
|
||||
}
|
||||
|
||||
for (u64 i = 0; i < CAPACITY; ++i) {
|
||||
i32 *value = wapp_queue_pop(i32, &queue);
|
||||
i32 *value = wpQueuePop(i32, &queue);
|
||||
result = result && value != NULL && *value == (i32)half_count + (i32)i;
|
||||
}
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
#include "wapp.h"
|
||||
|
||||
TestFuncResult test_queue_push(void);
|
||||
TestFuncResult test_queue_push_alloc(void);
|
||||
TestFuncResult test_queue_pop(void);
|
||||
WpTestFuncResult test_queue_push(void);
|
||||
WpTestFuncResult test_queue_push_alloc(void);
|
||||
WpTestFuncResult test_queue_pop(void);
|
||||
|
||||
#endif // !TEST_QUEUE_H
|
||||
|
||||
@@ -4,59 +4,59 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
TestFuncResult test_commander_cmd_success(void) {
|
||||
Str8List cmd = wapp_dbl_list(Str8);
|
||||
wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_lit("echo"));
|
||||
wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_lit("hello world"));
|
||||
WpTestFuncResult test_commander_cmd_success(void) {
|
||||
WpStr8List cmd = wpDblList(WpStr8);
|
||||
wpDblListPushBack(WpStr8, &cmd, &wpStr8Lit("echo"));
|
||||
wpDblListPushBack(WpStr8, &cmd, &wpStr8Lit("hello world"));
|
||||
|
||||
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, &cmd);
|
||||
WpCmdResult result = wpShellCommanderExecute(WP_SHELL_OUTPUT_DISCARD, NULL, &cmd);
|
||||
b8 succeeded = result.exited && result.exit_code == EXIT_SUCCESS &&
|
||||
result.error == SHELL_ERR_NO_ERROR;
|
||||
result.error == WP_SHELL_ERR_NO_ERROR;
|
||||
|
||||
return wapp_tester_result(succeeded);
|
||||
return wpTesterResult(succeeded);
|
||||
}
|
||||
|
||||
TestFuncResult test_commander_cmd_failure(void) {
|
||||
Str8List cmd = wapp_dbl_list(Str8);
|
||||
wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_lit("grep"));
|
||||
WpTestFuncResult test_commander_cmd_failure(void) {
|
||||
WpStr8List cmd = wpDblList(WpStr8);
|
||||
wpDblListPushBack(WpStr8, &cmd, &wpStr8Lit("grep"));
|
||||
|
||||
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, &cmd);
|
||||
WpCmdResult result = wpShellCommanderExecute(WP_SHELL_OUTPUT_DISCARD, NULL, &cmd);
|
||||
b8 failed = result.exited && result.exit_code != EXIT_SUCCESS &&
|
||||
result.error == SHELL_ERR_NO_ERROR;
|
||||
result.error == WP_SHELL_ERR_NO_ERROR;
|
||||
|
||||
return wapp_tester_result(failed);
|
||||
return wpTesterResult(failed);
|
||||
}
|
||||
|
||||
TestFuncResult test_commander_cmd_out_buf_success(void) {
|
||||
Str8 buf = wapp_str8_buf(64);
|
||||
Str8 expected = wapp_str8_buf(64);
|
||||
WpTestFuncResult test_commander_cmd_out_buf_success(void) {
|
||||
WpStr8 buf = wpStr8Buf(64);
|
||||
WpStr8 expected = wpStr8Buf(64);
|
||||
char msg[] = "hello world";
|
||||
wapp_str8_copy_cstr_capped(&expected, msg);
|
||||
wpStr8CopyCstrCapped(&expected, msg);
|
||||
|
||||
Str8List cmd = wapp_dbl_list(Str8);
|
||||
wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_lit("echo"));
|
||||
wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_lit(msg));
|
||||
WpStr8List cmd = wpDblList(WpStr8);
|
||||
wpDblListPushBack(WpStr8, &cmd, &wpStr8Lit("echo"));
|
||||
wpDblListPushBack(WpStr8, &cmd, &wpStr8Lit(msg));
|
||||
|
||||
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd);
|
||||
WpCmdResult result = wpShellCommanderExecute(WP_SHELL_OUTPUT_CAPTURE, &buf, &cmd);
|
||||
b8 succeeded = result.exited && result.exit_code == EXIT_SUCCESS &&
|
||||
result.error == SHELL_ERR_NO_ERROR && wapp_str8_equal_to_count(&buf, &expected, strlen(msg));
|
||||
result.error == WP_SHELL_ERR_NO_ERROR && wpStr8EqualToCount(&buf, &expected, strlen(msg));
|
||||
|
||||
return wapp_tester_result(succeeded);
|
||||
return wpTesterResult(succeeded);
|
||||
}
|
||||
|
||||
TestFuncResult test_commander_cmd_out_buf_failure(void) {
|
||||
Str8 buf = wapp_str8_buf(4);
|
||||
Str8 expected = wapp_str8_buf(64);
|
||||
WpTestFuncResult test_commander_cmd_out_buf_failure(void) {
|
||||
WpStr8 buf = wpStr8Buf(4);
|
||||
WpStr8 expected = wpStr8Buf(64);
|
||||
char msg[] = "hello world";
|
||||
wapp_str8_copy_cstr_capped(&expected, msg);
|
||||
wpStr8CopyCstrCapped(&expected, msg);
|
||||
|
||||
Str8List cmd = wapp_dbl_list(Str8);
|
||||
wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_lit("echo"));
|
||||
wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_lit(msg));
|
||||
WpStr8List cmd = wpDblList(WpStr8);
|
||||
wpDblListPushBack(WpStr8, &cmd, &wpStr8Lit("echo"));
|
||||
wpDblListPushBack(WpStr8, &cmd, &wpStr8Lit(msg));
|
||||
|
||||
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd);
|
||||
WpCmdResult result = wpShellCommanderExecute(WP_SHELL_OUTPUT_CAPTURE, &buf, &cmd);
|
||||
b8 failed = !result.exited && result.exit_code != EXIT_SUCCESS &&
|
||||
result.error == SHELL_ERR_OUT_BUF_FULL && !wapp_str8_equal(&buf, &expected);
|
||||
result.error == WP_SHELL_ERR_OUT_BUF_FULL && !wpStr8Equal(&buf, &expected);
|
||||
|
||||
return wapp_tester_result(failed);
|
||||
return wpTesterResult(failed);
|
||||
}
|
||||
|
||||
@@ -4,66 +4,66 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
TestFuncResult test_commander_cmd_success(void) {
|
||||
Str8List cmd = wapp_dbl_list(Str8);
|
||||
Str8 echo = wapp_str8_lit("echo");
|
||||
Str8 msg = wapp_str8_lit("hello world");
|
||||
wapp_dbl_list_push_back(Str8, &cmd, &echo);
|
||||
wapp_dbl_list_push_back(Str8, &cmd, &msg);
|
||||
WpTestFuncResult test_commander_cmd_success(void) {
|
||||
WpStr8List cmd = wpDblList(WpStr8);
|
||||
WpStr8 echo = wpStr8Lit("echo");
|
||||
WpStr8 msg = wpStr8Lit("hello world");
|
||||
wpDblListPushBack(WpStr8, &cmd, &echo);
|
||||
wpDblListPushBack(WpStr8, &cmd, &msg);
|
||||
|
||||
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, nullptr, &cmd);
|
||||
WpCmdResult result = wpShellCommanderExecute(WP_SHELL_OUTPUT_DISCARD, nullptr, &cmd);
|
||||
b8 succeeded = result.exited && result.exit_code == EXIT_SUCCESS &&
|
||||
result.error == SHELL_ERR_NO_ERROR;
|
||||
result.error == WP_SHELL_ERR_NO_ERROR;
|
||||
|
||||
return wapp_tester_result(succeeded);
|
||||
return wpTesterResult(succeeded);
|
||||
}
|
||||
|
||||
TestFuncResult test_commander_cmd_failure(void) {
|
||||
Str8List cmd = wapp_dbl_list(Str8);
|
||||
Str8 grep = wapp_str8_lit("grep");
|
||||
wapp_dbl_list_push_back(Str8, &cmd, &grep);
|
||||
WpTestFuncResult test_commander_cmd_failure(void) {
|
||||
WpStr8List cmd = wpDblList(WpStr8);
|
||||
WpStr8 grep = wpStr8Lit("grep");
|
||||
wpDblListPushBack(WpStr8, &cmd, &grep);
|
||||
|
||||
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, nullptr, &cmd);
|
||||
WpCmdResult result = wpShellCommanderExecute(WP_SHELL_OUTPUT_DISCARD, nullptr, &cmd);
|
||||
b8 failed = result.exited && result.exit_code != EXIT_SUCCESS &&
|
||||
result.error == SHELL_ERR_NO_ERROR;
|
||||
result.error == WP_SHELL_ERR_NO_ERROR;
|
||||
|
||||
return wapp_tester_result(failed);
|
||||
return wpTesterResult(failed);
|
||||
}
|
||||
|
||||
TestFuncResult test_commander_cmd_out_buf_success(void) {
|
||||
Str8 buf = wapp_str8_buf(64);
|
||||
Str8 expected = wapp_str8_buf(64);
|
||||
WpTestFuncResult test_commander_cmd_out_buf_success(void) {
|
||||
WpStr8 buf = wpStr8Buf(64);
|
||||
WpStr8 expected = wpStr8Buf(64);
|
||||
char msg[] = "hello world";
|
||||
wapp_str8_copy_cstr_capped(&expected, msg);
|
||||
wpStr8CopyCstrCapped(&expected, msg);
|
||||
|
||||
Str8List cmd = wapp_dbl_list(Str8);
|
||||
Str8 echo = wapp_str8_lit("echo");
|
||||
Str8 arg = wapp_str8_lit(msg);
|
||||
wapp_dbl_list_push_back(Str8, &cmd, &echo);
|
||||
wapp_dbl_list_push_back(Str8, &cmd, &arg);
|
||||
WpStr8List cmd = wpDblList(WpStr8);
|
||||
WpStr8 echo = wpStr8Lit("echo");
|
||||
WpStr8 arg = wpStr8Lit(msg);
|
||||
wpDblListPushBack(WpStr8, &cmd, &echo);
|
||||
wpDblListPushBack(WpStr8, &cmd, &arg);
|
||||
|
||||
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd);
|
||||
WpCmdResult result = wpShellCommanderExecute(WP_SHELL_OUTPUT_CAPTURE, &buf, &cmd);
|
||||
b8 succeeded = result.exited && result.exit_code == EXIT_SUCCESS &&
|
||||
result.error == SHELL_ERR_NO_ERROR && wapp_str8_equal_to_count(&buf, &expected, strlen(msg));
|
||||
result.error == WP_SHELL_ERR_NO_ERROR && wpStr8EqualToCount(&buf, &expected, strlen(msg));
|
||||
|
||||
return wapp_tester_result(succeeded);
|
||||
return wpTesterResult(succeeded);
|
||||
}
|
||||
|
||||
TestFuncResult test_commander_cmd_out_buf_failure(void) {
|
||||
Str8 buf = wapp_str8_buf(4);
|
||||
Str8 expected = wapp_str8_buf(64);
|
||||
WpTestFuncResult test_commander_cmd_out_buf_failure(void) {
|
||||
WpStr8 buf = wpStr8Buf(4);
|
||||
WpStr8 expected = wpStr8Buf(64);
|
||||
char msg[] = "hello world";
|
||||
wapp_str8_copy_cstr_capped(&expected, msg);
|
||||
wpStr8CopyCstrCapped(&expected, msg);
|
||||
|
||||
Str8List cmd = wapp_dbl_list(Str8);
|
||||
Str8 echo = wapp_str8_lit("echo");
|
||||
Str8 arg = wapp_str8_lit(msg);
|
||||
wapp_dbl_list_push_back(Str8, &cmd, &echo);
|
||||
wapp_dbl_list_push_back(Str8, &cmd, &arg);
|
||||
WpStr8List cmd = wpDblList(WpStr8);
|
||||
WpStr8 echo = wpStr8Lit("echo");
|
||||
WpStr8 arg = wpStr8Lit(msg);
|
||||
wpDblListPushBack(WpStr8, &cmd, &echo);
|
||||
wpDblListPushBack(WpStr8, &cmd, &arg);
|
||||
|
||||
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd);
|
||||
WpCmdResult result = wpShellCommanderExecute(WP_SHELL_OUTPUT_CAPTURE, &buf, &cmd);
|
||||
b8 failed = !result.exited && result.exit_code != EXIT_SUCCESS &&
|
||||
result.error == SHELL_ERR_OUT_BUF_FULL && !wapp_str8_equal(&buf, &expected);
|
||||
result.error == WP_SHELL_ERR_OUT_BUF_FULL && !wpStr8Equal(&buf, &expected);
|
||||
|
||||
return wapp_tester_result(failed);
|
||||
return wpTesterResult(failed);
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
#include "wapp.h"
|
||||
|
||||
TestFuncResult test_commander_cmd_success(void);
|
||||
TestFuncResult test_commander_cmd_failure(void);
|
||||
TestFuncResult test_commander_cmd_out_buf_success(void);
|
||||
TestFuncResult test_commander_cmd_out_buf_failure(void);
|
||||
WpTestFuncResult test_commander_cmd_success(void);
|
||||
WpTestFuncResult test_commander_cmd_failure(void);
|
||||
WpTestFuncResult test_commander_cmd_out_buf_success(void);
|
||||
WpTestFuncResult test_commander_cmd_out_buf_failure(void);
|
||||
|
||||
#endif // !TEST_SHELL_COMMANDER_H
|
||||
|
||||
+298
-298
@@ -3,88 +3,88 @@
|
||||
|
||||
#define ARRLEN(ARR) (sizeof(ARR) / sizeof(ARR[0]))
|
||||
|
||||
TestFuncResult test_str8_lit(void) {
|
||||
WpTestFuncResult test_str8_lit(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("Hello world");
|
||||
WpStr8 s1 = wpStr8Lit("Hello world");
|
||||
result = s1.capacity == 22 && s1.capacity != s1.size;
|
||||
|
||||
Str8 s2 = wapp_str8_lit("Different strokes for different folks");
|
||||
WpStr8 s2 = wpStr8Lit("Different strokes for different folks");
|
||||
result = result && s2.capacity == 74 && s2.capacity != s2.size;
|
||||
|
||||
Str8 s3 = wapp_str8_lit("Discretion is the better part of valour");
|
||||
WpStr8 s3 = wpStr8Lit("Discretion is the better part of valour");
|
||||
result = result && s3.capacity == 78 && s3.capacity != s3.size;
|
||||
|
||||
Str8 s4 = wapp_str8_lit("Distance lends enchantment to the view");
|
||||
WpStr8 s4 = wpStr8Lit("Distance lends enchantment to the view");
|
||||
result = result && s4.capacity == 76 && s4.capacity != s4.size;
|
||||
|
||||
Str8 s5 = wapp_str8_lit("Do as I say, not as I do");
|
||||
WpStr8 s5 = wpStr8Lit("Do as I say, not as I do");
|
||||
result = result && s5.capacity == 48 && s5.capacity != s5.size;
|
||||
|
||||
Str8 s6 = wapp_str8_lit("Do as you would be done by");
|
||||
WpStr8 s6 = wpStr8Lit("Do as you would be done by");
|
||||
result = result && s6.capacity == 52 && s6.capacity != s6.size;
|
||||
|
||||
Str8 s7 = wapp_str8_lit("Do unto others as you would have them do to you");
|
||||
WpStr8 s7 = wpStr8Lit("Do unto others as you would have them do to you");
|
||||
result = result && s7.capacity == 94 && s7.capacity != s7.size;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_lit_ro(void) {
|
||||
WpTestFuncResult test_str8_lit_ro(void) {
|
||||
b8 result;
|
||||
|
||||
Str8RO s1 = wapp_str8_lit_ro("Hello world");
|
||||
WpStr8RO s1 = wpStr8LitRo("Hello world");
|
||||
result = s1.capacity == 11 && s1.capacity == s1.size;
|
||||
|
||||
Str8RO s2 = wapp_str8_lit_ro("Different strokes for different folks");
|
||||
WpStr8RO s2 = wpStr8LitRo("Different strokes for different folks");
|
||||
result = result && s2.capacity == 37 && s2.capacity == s2.size;
|
||||
|
||||
Str8RO s3 = wapp_str8_lit_ro("Discretion is the better part of valour");
|
||||
WpStr8RO s3 = wpStr8LitRo("Discretion is the better part of valour");
|
||||
result = result && s3.capacity == 39 && s3.capacity == s3.size;
|
||||
|
||||
Str8RO s4 = wapp_str8_lit_ro("Distance lends enchantment to the view");
|
||||
WpStr8RO s4 = wpStr8LitRo("Distance lends enchantment to the view");
|
||||
result = result && s4.capacity == 38 && s4.capacity == s4.size;
|
||||
|
||||
Str8RO s5 = wapp_str8_lit_ro("Do as I say, not as I do");
|
||||
WpStr8RO s5 = wpStr8LitRo("Do as I say, not as I do");
|
||||
result = result && s5.capacity == 24 && s5.capacity == s5.size;
|
||||
|
||||
Str8RO s6 = wapp_str8_lit_ro("Do as you would be done by");
|
||||
WpStr8RO s6 = wpStr8LitRo("Do as you would be done by");
|
||||
result = result && s6.capacity == 26 && s6.capacity == s6.size;
|
||||
|
||||
Str8RO s7 = wapp_str8_lit_ro("Do unto others as you would have them do to you");
|
||||
WpStr8RO s7 = wpStr8LitRo("Do unto others as you would have them do to you");
|
||||
result = result && s7.capacity == 47 && s7.capacity == s7.size;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_buf(void) {
|
||||
WpTestFuncResult test_str8_buf(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_buf(1024);
|
||||
WpStr8 s1 = wpStr8Buf(1024);
|
||||
result = s1.capacity == 1024 && s1.size == 0;
|
||||
|
||||
Str8 s2 = wapp_str8_buf(2048);
|
||||
WpStr8 s2 = wpStr8Buf(2048);
|
||||
result = result && s2.capacity == 2048 && s2.size == 0;
|
||||
|
||||
Str8 s3 = wapp_str8_buf(4096);
|
||||
WpStr8 s3 = wpStr8Buf(4096);
|
||||
result = result && s3.capacity == 4096 && s3.size == 0;
|
||||
|
||||
Str8 s4 = wapp_str8_buf(8192);
|
||||
WpStr8 s4 = wpStr8Buf(8192);
|
||||
result = result && s4.capacity == 8192 && s4.size == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_alloc_buf(void) {
|
||||
WpTestFuncResult test_str8_alloc_buf(void) {
|
||||
b8 result;
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(KiB(100));
|
||||
if (wapp_mem_allocator_invalid(&allocator)) {
|
||||
return wapp_tester_result(false);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(KiB(100));
|
||||
if (wpMemAllocatorInvalid(&allocator)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
u64 capacity = 4096;
|
||||
|
||||
Str8 *s = wapp_str8_alloc_buf(&allocator, capacity);
|
||||
WpStr8 *s = wpStr8AllocBuf(&allocator, capacity);
|
||||
if (!s) {
|
||||
result = false;
|
||||
goto TEST_ALLOC_BUF_CLEANUP;
|
||||
@@ -93,340 +93,340 @@ TestFuncResult test_str8_alloc_buf(void) {
|
||||
result = s->capacity == capacity;
|
||||
|
||||
const char *cstr = "My name is Abdelrahman";
|
||||
wapp_str8_copy_cstr_capped(s, cstr);
|
||||
wpStr8CopyCstrCapped(s, cstr);
|
||||
|
||||
result = result && s->capacity == capacity && s->size == strlen(cstr) && memcmp(s->buf, cstr, s->size) == 0;
|
||||
|
||||
TEST_ALLOC_BUF_CLEANUP:
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_alloc_cstr(void) {
|
||||
WpTestFuncResult test_str8_alloc_cstr(void) {
|
||||
b8 result;
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(KiB(100));
|
||||
if (wapp_mem_allocator_invalid(&allocator)) {
|
||||
return wapp_tester_result(false);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(KiB(100));
|
||||
if (wpMemAllocatorInvalid(&allocator)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
char *str = "Abdelrahman";
|
||||
u64 length = strlen(str);
|
||||
Str8 *s = wapp_str8_alloc_cstr(&allocator, str);
|
||||
WpStr8 *s = wpStr8AllocCstr(&allocator, str);
|
||||
if (!s) {
|
||||
return wapp_tester_result(false);
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
result = s->size == length && memcmp(s->buf, str, length) == 0;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_alloc_str8(void) {
|
||||
WpTestFuncResult test_str8_alloc_str8(void) {
|
||||
b8 result;
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(KiB(100));
|
||||
if (wapp_mem_allocator_invalid(&allocator)) {
|
||||
return wapp_tester_result(false);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(KiB(100));
|
||||
if (wpMemAllocatorInvalid(&allocator)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
Str8 str = wapp_str8_lit("Abdelrahman");
|
||||
Str8 *s = wapp_str8_alloc_str8(&allocator, &str);
|
||||
WpStr8 str = wpStr8Lit("Abdelrahman");
|
||||
WpStr8 *s = wpStr8AllocStr8(&allocator, &str);
|
||||
if (!s) {
|
||||
return wapp_tester_result(false);
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
result = wapp_str8_equal(s, &str);
|
||||
result = wpStr8Equal(s, &str);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_alloc_substr(void) {
|
||||
WpTestFuncResult test_str8_alloc_substr(void) {
|
||||
b8 result;
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(KiB(100));
|
||||
if (wapp_mem_allocator_invalid(&allocator)) {
|
||||
return wapp_tester_result(false);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(KiB(100));
|
||||
if (wpMemAllocatorInvalid(&allocator)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
Str8 str = wapp_str8_lit("Abdelrahman");
|
||||
Str8 *s = wapp_str8_alloc_substr(&allocator, &str, 3, 8);
|
||||
WpStr8 str = wpStr8Lit("Abdelrahman");
|
||||
WpStr8 *s = wpStr8AllocSubstr(&allocator, &str, 3, 8);
|
||||
if (!s) {
|
||||
return wapp_tester_result(false);
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
result = s->size == 5 && memcmp(s->buf, "elrah", s->size) == 0;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_get_index_within_bounds(void) {
|
||||
WpTestFuncResult test_str8_get_index_within_bounds(void) {
|
||||
b8 result;
|
||||
|
||||
Str8RO s1 = wapp_str8_lit_ro("Hello world");
|
||||
result = wapp_str8_get(&s1, 4) == 'o';
|
||||
WpStr8RO s1 = wpStr8LitRo("Hello world");
|
||||
result = wpStr8Get(&s1, 4) == 'o';
|
||||
|
||||
Str8RO s2 = wapp_str8_lit_ro("Different strokes for different folks");
|
||||
result = result && wapp_str8_get(&s2, 0) == 'D';
|
||||
WpStr8RO s2 = wpStr8LitRo("Different strokes for different folks");
|
||||
result = result && wpStr8Get(&s2, 0) == 'D';
|
||||
|
||||
Str8RO s3 = wapp_str8_lit_ro("Discretion is the better part of valour");
|
||||
result = result && wapp_str8_get(&s3, 13) == ' ';
|
||||
WpStr8RO s3 = wpStr8LitRo("Discretion is the better part of valour");
|
||||
result = result && wpStr8Get(&s3, 13) == ' ';
|
||||
|
||||
Str8RO s4 = wapp_str8_lit_ro("Distance lends enchantment to the view");
|
||||
result = result && wapp_str8_get(&s4, 20) == 'n';
|
||||
WpStr8RO s4 = wpStr8LitRo("Distance lends enchantment to the view");
|
||||
result = result && wpStr8Get(&s4, 20) == 'n';
|
||||
|
||||
Str8RO s5 = wapp_str8_lit_ro("Do as I say, not as I do");
|
||||
result = result && wapp_str8_get(&s5, 11) == ',';
|
||||
WpStr8RO s5 = wpStr8LitRo("Do as I say, not as I do");
|
||||
result = result && wpStr8Get(&s5, 11) == ',';
|
||||
|
||||
Str8RO s6 = wapp_str8_lit_ro("Do as you would be done by");
|
||||
result = result && wapp_str8_get(&s6, 25) == 'y';
|
||||
WpStr8RO s6 = wpStr8LitRo("Do as you would be done by");
|
||||
result = result && wpStr8Get(&s6, 25) == 'y';
|
||||
|
||||
Str8RO s7 = wapp_str8_lit_ro("Do unto others as you would have them do to you");
|
||||
result = result && wapp_str8_get(&s7, 16) == 's';
|
||||
WpStr8RO s7 = wpStr8LitRo("Do unto others as you would have them do to you");
|
||||
result = result && wpStr8Get(&s7, 16) == 's';
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_get_index_out_of_bounds(void) {
|
||||
Str8 s1 = wapp_str8_lit("Hello world");
|
||||
b8 result = wapp_str8_get(&s1, 20) == '\0';
|
||||
return wapp_tester_result(result);
|
||||
WpTestFuncResult test_str8_get_index_out_of_bounds(void) {
|
||||
WpStr8 s1 = wpStr8Lit("Hello world");
|
||||
b8 result = wpStr8Get(&s1, 20) == '\0';
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_set(void) {
|
||||
WpTestFuncResult test_str8_set(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("Hello world");
|
||||
wapp_str8_set(&s1, 4, 'f');
|
||||
result = wapp_str8_get(&s1, 4) == 'f';
|
||||
WpStr8 s1 = wpStr8Lit("Hello world");
|
||||
wpStr8Set(&s1, 4, 'f');
|
||||
result = wpStr8Get(&s1, 4) == 'f';
|
||||
|
||||
Str8 s2 = wapp_str8_lit("Different strokes for different folks");
|
||||
wapp_str8_set(&s2, 0, 'A');
|
||||
result = result && wapp_str8_get(&s2, 0) == 'A';
|
||||
WpStr8 s2 = wpStr8Lit("Different strokes for different folks");
|
||||
wpStr8Set(&s2, 0, 'A');
|
||||
result = result && wpStr8Get(&s2, 0) == 'A';
|
||||
|
||||
Str8 s3 = wapp_str8_lit("Discretion is the better part of valour");
|
||||
wapp_str8_set(&s3, 13, 'u');
|
||||
result = result && wapp_str8_get(&s3, 13) == 'u';
|
||||
WpStr8 s3 = wpStr8Lit("Discretion is the better part of valour");
|
||||
wpStr8Set(&s3, 13, 'u');
|
||||
result = result && wpStr8Get(&s3, 13) == 'u';
|
||||
|
||||
Str8 s4 = wapp_str8_lit("Distance lends enchantment to the view");
|
||||
wapp_str8_set(&s4, 20, 'R');
|
||||
result = result && wapp_str8_get(&s4, 20) == 'R';
|
||||
WpStr8 s4 = wpStr8Lit("Distance lends enchantment to the view");
|
||||
wpStr8Set(&s4, 20, 'R');
|
||||
result = result && wpStr8Get(&s4, 20) == 'R';
|
||||
|
||||
Str8 s5 = wapp_str8_lit("Do as I say, not as I do");
|
||||
wapp_str8_set(&s5, 11, '.');
|
||||
result = result && wapp_str8_get(&s5, 11) == '.';
|
||||
WpStr8 s5 = wpStr8Lit("Do as I say, not as I do");
|
||||
wpStr8Set(&s5, 11, '.');
|
||||
result = result && wpStr8Get(&s5, 11) == '.';
|
||||
|
||||
Str8 s6 = wapp_str8_lit("Do as you would be done by");
|
||||
wapp_str8_set(&s6, 25, 'w');
|
||||
result = result && wapp_str8_get(&s6, 25) == 'w';
|
||||
WpStr8 s6 = wpStr8Lit("Do as you would be done by");
|
||||
wpStr8Set(&s6, 25, 'w');
|
||||
result = result && wpStr8Get(&s6, 25) == 'w';
|
||||
|
||||
Str8 s7 = wapp_str8_lit("Do unto others as you would have them do to you");
|
||||
wapp_str8_set(&s7, 16, 'i');
|
||||
result = result && wapp_str8_get(&s7, 16) == 'i';
|
||||
WpStr8 s7 = wpStr8Lit("Do unto others as you would have them do to you");
|
||||
wpStr8Set(&s7, 16, 'i');
|
||||
result = result && wpStr8Get(&s7, 16) == 'i';
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_push_back(void) {
|
||||
WpTestFuncResult test_str8_push_back(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 expected = wapp_str8_lit("Abdelrahman");
|
||||
Str8 buf = wapp_str8_buf(64);
|
||||
wapp_str8_push_back(&buf, 'A');
|
||||
wapp_str8_push_back(&buf, 'b');
|
||||
wapp_str8_push_back(&buf, 'd');
|
||||
wapp_str8_push_back(&buf, 'e');
|
||||
wapp_str8_push_back(&buf, 'l');
|
||||
wapp_str8_push_back(&buf, 'r');
|
||||
wapp_str8_push_back(&buf, 'a');
|
||||
wapp_str8_push_back(&buf, 'h');
|
||||
wapp_str8_push_back(&buf, 'm');
|
||||
wapp_str8_push_back(&buf, 'a');
|
||||
wapp_str8_push_back(&buf, 'n');
|
||||
WpStr8 expected = wpStr8Lit("Abdelrahman");
|
||||
WpStr8 buf = wpStr8Buf(64);
|
||||
wpStr8PushBack(&buf, 'A');
|
||||
wpStr8PushBack(&buf, 'b');
|
||||
wpStr8PushBack(&buf, 'd');
|
||||
wpStr8PushBack(&buf, 'e');
|
||||
wpStr8PushBack(&buf, 'l');
|
||||
wpStr8PushBack(&buf, 'r');
|
||||
wpStr8PushBack(&buf, 'a');
|
||||
wpStr8PushBack(&buf, 'h');
|
||||
wpStr8PushBack(&buf, 'm');
|
||||
wpStr8PushBack(&buf, 'a');
|
||||
wpStr8PushBack(&buf, 'n');
|
||||
|
||||
result = wapp_str8_equal(&buf, &expected);
|
||||
result = wpStr8Equal(&buf, &expected);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_equal(void) {
|
||||
WpTestFuncResult test_str8_equal(void) {
|
||||
b8 result;
|
||||
|
||||
Str8RO s1 = wapp_str8_lit_ro("hello");
|
||||
Str8RO s2 = wapp_str8_lit_ro("hell");
|
||||
Str8RO s3 = wapp_str8_lit_ro("hello");
|
||||
Str8RO s4 = wapp_str8_lit_ro("goodbye");
|
||||
WpStr8RO s1 = wpStr8LitRo("hello");
|
||||
WpStr8RO s2 = wpStr8LitRo("hell");
|
||||
WpStr8RO s3 = wpStr8LitRo("hello");
|
||||
WpStr8RO s4 = wpStr8LitRo("goodbye");
|
||||
|
||||
result = wapp_str8_equal(&s1, &s2) == false;
|
||||
result = result && wapp_str8_equal(&s1, &s3) == true;
|
||||
result = result && wapp_str8_equal(&s1, &s4) == false;
|
||||
result = wpStr8Equal(&s1, &s2) == false;
|
||||
result = result && wpStr8Equal(&s1, &s3) == true;
|
||||
result = result && wpStr8Equal(&s1, &s4) == false;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_slice(void) {
|
||||
WpTestFuncResult test_str8_slice(void) {
|
||||
b8 result;
|
||||
Str8 s = wapp_str8_lit("Different strokes for different folks");
|
||||
WpStr8 s = wpStr8Lit("Different strokes for different folks");
|
||||
|
||||
Str8RO sub1 = wapp_str8_slice(&s, 3, 9);
|
||||
WpStr8RO sub1 = wpStr8Slice(&s, 3, 9);
|
||||
result = sub1.size == 6 && sub1.capacity == 6;
|
||||
|
||||
Str8RO sub2 = wapp_str8_slice(&s, 18, 21);
|
||||
WpStr8RO sub2 = wpStr8Slice(&s, 18, 21);
|
||||
result = result && sub2.size == 3 && sub2.capacity == 3;
|
||||
|
||||
Str8RO sub3 = wapp_str8_slice(&s, 5, 1);
|
||||
WpStr8RO sub3 = wpStr8Slice(&s, 5, 1);
|
||||
result = result && sub3.size == 0 && sub3.capacity == 0;
|
||||
|
||||
Str8RO sub4 = wapp_str8_slice(&s, 70, 80);
|
||||
WpStr8RO sub4 = wpStr8Slice(&s, 70, 80);
|
||||
result = result && sub4.size == 0 && sub4.capacity == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_alloc_concat(void) {
|
||||
WpTestFuncResult test_str8_alloc_concat(void) {
|
||||
b8 result;
|
||||
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
Str8 str = wapp_str8_lit("Hello world");
|
||||
Str8 suffix1 = wapp_str8_lit(" from me.");
|
||||
Str8 suffix2 = wapp_str8_lit(" This is my code.");
|
||||
Str8 concat1 = wapp_str8_lit("Hello world from me.");
|
||||
Str8 concat2 = wapp_str8_lit("Hello world from me. This is my code.");
|
||||
WpStr8 str = wpStr8Lit("Hello world");
|
||||
WpStr8 suffix1 = wpStr8Lit(" from me.");
|
||||
WpStr8 suffix2 = wpStr8Lit(" This is my code.");
|
||||
WpStr8 concat1 = wpStr8Lit("Hello world from me.");
|
||||
WpStr8 concat2 = wpStr8Lit("Hello world from me. This is my code.");
|
||||
|
||||
Str8 *output;
|
||||
WpStr8 *output;
|
||||
|
||||
output = wapp_str8_alloc_concat(&arena, &str, &suffix1);
|
||||
result = output->size == concat1.size && wapp_str8_equal(output, &concat1);
|
||||
output = wpStr8AllocConcat(&arena, &str, &suffix1);
|
||||
result = output->size == concat1.size && wpStr8Equal(output, &concat1);
|
||||
|
||||
output = wapp_str8_alloc_concat(&arena, output, &suffix2);
|
||||
result = result && output->size == concat2.size && wapp_str8_equal(output, &concat2);
|
||||
output = wpStr8AllocConcat(&arena, output, &suffix2);
|
||||
result = result && output->size == concat2.size && wpStr8Equal(output, &concat2);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_concat_capped(void) {
|
||||
WpTestFuncResult test_str8_concat_capped(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 str = wapp_str8_lit("Hello world");
|
||||
Str8 suffix1 = wapp_str8_lit(" from me.");
|
||||
Str8 suffix2 = wapp_str8_lit(" This is my code.");
|
||||
Str8 concat1 = wapp_str8_lit("Hello world from me.");
|
||||
Str8 concat2 = wapp_str8_lit("Hello world from me. T");
|
||||
WpStr8 str = wpStr8Lit("Hello world");
|
||||
WpStr8 suffix1 = wpStr8Lit(" from me.");
|
||||
WpStr8 suffix2 = wpStr8Lit(" This is my code.");
|
||||
WpStr8 concat1 = wpStr8Lit("Hello world from me.");
|
||||
WpStr8 concat2 = wpStr8Lit("Hello world from me. T");
|
||||
|
||||
wapp_str8_concat_capped(&str, &suffix1);
|
||||
result = str.size == concat1.size && wapp_str8_equal(&str, &concat1);
|
||||
wpStr8ConcatCapped(&str, &suffix1);
|
||||
result = str.size == concat1.size && wpStr8Equal(&str, &concat1);
|
||||
|
||||
wapp_str8_concat_capped(&str, &suffix2);
|
||||
result = result && str.size == concat2.size && wapp_str8_equal(&str, &concat2);
|
||||
wpStr8ConcatCapped(&str, &suffix2);
|
||||
result = result && str.size == concat2.size && wpStr8Equal(&str, &concat2);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_copy_cstr_capped(void) {
|
||||
WpTestFuncResult test_str8_copy_cstr_capped(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 buf = wapp_str8_buf(32);
|
||||
WpStr8 buf = wpStr8Buf(32);
|
||||
const char *src1 = "Hello world";
|
||||
const char *src2 = "Hello world from the Wizard Apprentice standard library";
|
||||
Str8RO src1_cp = wapp_str8_lit_ro("Hello world");
|
||||
Str8RO src2_cp = wapp_str8_lit_ro("Hello world from the Wizard Appr");
|
||||
WpStr8RO src1_cp = wpStr8LitRo("Hello world");
|
||||
WpStr8RO src2_cp = wpStr8LitRo("Hello world from the Wizard Appr");
|
||||
|
||||
wapp_str8_copy_cstr_capped(&buf, src1);
|
||||
result = buf.size == src1_cp.size && wapp_str8_equal(&buf, &src1_cp);
|
||||
wpStr8CopyCstrCapped(&buf, src1);
|
||||
result = buf.size == src1_cp.size && wpStr8Equal(&buf, &src1_cp);
|
||||
|
||||
wapp_str8_copy_cstr_capped(&buf, src2);
|
||||
result = result && buf.size == src2_cp.size && buf.size == buf.capacity && wapp_str8_equal(&buf, &src2_cp);
|
||||
wpStr8CopyCstrCapped(&buf, src2);
|
||||
result = result && buf.size == src2_cp.size && buf.size == buf.capacity && wpStr8Equal(&buf, &src2_cp);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_copy_str8_capped(void) {
|
||||
WpTestFuncResult test_str8_copy_str8_capped(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 buf = wapp_str8_buf(32);
|
||||
Str8RO src1 = wapp_str8_lit_ro("Hello world");
|
||||
Str8RO src2 = wapp_str8_lit_ro("Hello world from the Wizard Apprentice standard library");
|
||||
Str8RO src2_cp = wapp_str8_lit_ro("Hello world from the Wizard Appr");
|
||||
WpStr8 buf = wpStr8Buf(32);
|
||||
WpStr8RO src1 = wpStr8LitRo("Hello world");
|
||||
WpStr8RO src2 = wpStr8LitRo("Hello world from the Wizard Apprentice standard library");
|
||||
WpStr8RO src2_cp = wpStr8LitRo("Hello world from the Wizard Appr");
|
||||
|
||||
wapp_str8_copy_str8_capped(&buf, &src1);
|
||||
result = buf.size == src1.size && wapp_str8_equal(&buf, &src1);
|
||||
wpStr8CopyStr8Capped(&buf, &src1);
|
||||
result = buf.size == src1.size && wpStr8Equal(&buf, &src1);
|
||||
|
||||
wapp_str8_copy_str8_capped(&buf, &src2);
|
||||
result = result && buf.size < src2.size && buf.size == buf.capacity && wapp_str8_equal(&buf, &src2_cp);
|
||||
wpStr8CopyStr8Capped(&buf, &src2);
|
||||
result = result && buf.size < src2.size && buf.size == buf.capacity && wpStr8Equal(&buf, &src2_cp);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_format(void) {
|
||||
WpTestFuncResult test_str8_format(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 buf = wapp_str8_buf(128);
|
||||
Str8 expected = wapp_str8_lit("My name is Abdelrahman and I am 35 years old");
|
||||
WpStr8 buf = wpStr8Buf(128);
|
||||
WpStr8 expected = wpStr8Lit("My name is Abdelrahman and I am 35 years old");
|
||||
|
||||
wapp_str8_format(&buf, "My name is %s and I am %u years old", "Abdelrahman", 35);
|
||||
wpStr8Format(&buf, "My name is %s and I am %u years old", "Abdelrahman", 35);
|
||||
|
||||
result = wapp_str8_equal(&buf, &expected);
|
||||
result = wpStr8Equal(&buf, &expected);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_find(void) {
|
||||
WpTestFuncResult test_str8_find(void) {
|
||||
b8 result;
|
||||
Str8RO s = wapp_str8_lit("Do as I say, not as I do");
|
||||
WpStr8RO s = wpStr8Lit("Do as I say, not as I do");
|
||||
|
||||
result = wapp_str8_find(&s, wapp_str8_lit_ro("d")) != -1;
|
||||
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("not")) != -1);
|
||||
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("as I say")) != -1);
|
||||
result = wpStr8Find(&s, wpStr8LitRo("d")) != -1;
|
||||
result = result && (wpStr8Find(&s, wpStr8LitRo("not")) != -1);
|
||||
result = result && (wpStr8Find(&s, wpStr8LitRo("as I say")) != -1);
|
||||
|
||||
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("f")) == -1);
|
||||
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("hello")) == -1);
|
||||
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("not sa I")) == -1);
|
||||
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("Do unto others as you would have them do to you")) == -1);
|
||||
result = result && (wpStr8Find(&s, wpStr8LitRo("f")) == -1);
|
||||
result = result && (wpStr8Find(&s, wpStr8LitRo("hello")) == -1);
|
||||
result = result && (wpStr8Find(&s, wpStr8LitRo("not sa I")) == -1);
|
||||
result = result && (wpStr8Find(&s, wpStr8LitRo("Do unto others as you would have them do to you")) == -1);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_rfind(void) {
|
||||
WpTestFuncResult test_str8_rfind(void) {
|
||||
b8 result;
|
||||
Str8RO s = wapp_str8_lit("Do as I say, not as I do");
|
||||
WpStr8RO s = wpStr8Lit("Do as I say, not as I do");
|
||||
|
||||
result = wapp_str8_rfind(&s, wapp_str8_lit_ro("d")) != -1;
|
||||
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("not")) != -1);
|
||||
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("as I say")) != -1);
|
||||
result = wpStr8Rfind(&s, wpStr8LitRo("d")) != -1;
|
||||
result = result && (wpStr8Rfind(&s, wpStr8LitRo("not")) != -1);
|
||||
result = result && (wpStr8Rfind(&s, wpStr8LitRo("as I say")) != -1);
|
||||
|
||||
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("f")) == -1);
|
||||
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("hello")) == -1);
|
||||
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("not sa I")) == -1);
|
||||
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("Do unto others as you would have them do to you")) == -1);
|
||||
result = result && (wpStr8Rfind(&s, wpStr8LitRo("f")) == -1);
|
||||
result = result && (wpStr8Rfind(&s, wpStr8LitRo("hello")) == -1);
|
||||
result = result && (wpStr8Rfind(&s, wpStr8LitRo("not sa I")) == -1);
|
||||
result = result && (wpStr8Rfind(&s, wpStr8LitRo("Do unto others as you would have them do to you")) == -1);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_split(void) {
|
||||
WpTestFuncResult test_str8_split(void) {
|
||||
b8 result;
|
||||
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
Str8 str = wapp_str8_lit("hello world from me");
|
||||
Str8 delim1 = wapp_str8_lit(" ");
|
||||
Str8 delim2 = wapp_str8_lit("from");
|
||||
Str8List *list1 = wapp_str8_split(&arena, &str, &delim1);
|
||||
Str8List *list2 = wapp_str8_split(&arena, &str, &delim2);
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim1 = wpStr8Lit(" ");
|
||||
WpStr8 delim2 = wpStr8Lit("from");
|
||||
WpStr8List *list1 = wpStr8Split(&arena, &str, &delim1);
|
||||
WpStr8List *list2 = wpStr8Split(&arena, &str, &delim2);
|
||||
|
||||
Str8RO splits1[] = {
|
||||
wapp_str8_slice(&str, 0, 5),
|
||||
wapp_str8_slice(&str, 6, 11),
|
||||
wapp_str8_slice(&str, 12, 16),
|
||||
wapp_str8_slice(&str, 17, 19),
|
||||
WpStr8RO splits1[] = {
|
||||
wpStr8Slice(&str, 0, 5),
|
||||
wpStr8Slice(&str, 6, 11),
|
||||
wpStr8Slice(&str, 12, 16),
|
||||
wpStr8Slice(&str, 17, 19),
|
||||
};
|
||||
Str8RO splits2[] = {
|
||||
wapp_str8_slice(&str, 0, 12),
|
||||
wapp_str8_slice(&str, 16, 19),
|
||||
WpStr8RO splits2[] = {
|
||||
wpStr8Slice(&str, 0, 12),
|
||||
wpStr8Slice(&str, 16, 19),
|
||||
};
|
||||
|
||||
u64 index1 = 0;
|
||||
@@ -437,14 +437,14 @@ TestFuncResult test_str8_split(void) {
|
||||
u64 count2 = ARRLEN(splits2);
|
||||
b8 running2 = true;
|
||||
|
||||
result = list1->node_count == count1 && wapp_str8_list_total_size(list1) == str.size - 3;
|
||||
result = result && list2->node_count == count2 && wapp_str8_list_total_size(list2) == str.size - 4;
|
||||
result = list1->node_count == count1 && wpStr8ListTotalSize(list1) == str.size - 3;
|
||||
result = result && list2->node_count == count2 && wpStr8ListTotalSize(list2) == str.size - 4;
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running1) {
|
||||
Str8 *node = wapp_dbl_list_get(Str8, list1, index1);
|
||||
result = result && wapp_str8_equal(node, &(splits1[index1]));
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list1, index1);
|
||||
result = result && wpStr8Equal(node, &(splits1[index1]));
|
||||
|
||||
++index1;
|
||||
running1 = index1 < count1;
|
||||
@@ -453,72 +453,72 @@ TestFuncResult test_str8_split(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running2) {
|
||||
Str8 *node = wapp_dbl_list_get(Str8, list2, index2);
|
||||
result = result && wapp_str8_equal(node, &(splits2[index2]));
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list2, index2);
|
||||
result = result && wpStr8Equal(node, &(splits2[index2]));
|
||||
|
||||
++index2;
|
||||
running2 = index2 < count2;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_split_with_max(void) {
|
||||
WpTestFuncResult test_str8_split_with_max(void) {
|
||||
b8 result;
|
||||
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
Str8 str = wapp_str8_lit("hello world from me");
|
||||
Str8 delim = wapp_str8_lit(" ");
|
||||
Str8List *list = wapp_str8_split_with_max(&arena, &str, &delim, 2);
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim = wpStr8Lit(" ");
|
||||
WpStr8List *list = wpStr8SplitWithMax(&arena, &str, &delim, 2);
|
||||
|
||||
Str8RO splits[] = {
|
||||
wapp_str8_slice(&str, 0, 5),
|
||||
wapp_str8_slice(&str, 6, 11),
|
||||
wapp_str8_slice(&str, 12, 19),
|
||||
WpStr8RO splits[] = {
|
||||
wpStr8Slice(&str, 0, 5),
|
||||
wpStr8Slice(&str, 6, 11),
|
||||
wpStr8Slice(&str, 12, 19),
|
||||
};
|
||||
|
||||
u64 index = 0;
|
||||
u64 count = ARRLEN(splits);
|
||||
b8 running = true;
|
||||
|
||||
result = list->node_count == count && wapp_str8_list_total_size(list) == str.size - 2;
|
||||
result = list->node_count == count && wpStr8ListTotalSize(list) == str.size - 2;
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running) {
|
||||
Str8 *node = wapp_dbl_list_get(Str8, list, index);
|
||||
result = result && wapp_str8_equal(node, &(splits[index]));
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list, index);
|
||||
result = result && wpStr8Equal(node, &(splits[index]));
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_rsplit(void) {
|
||||
WpTestFuncResult test_str8_rsplit(void) {
|
||||
b8 result;
|
||||
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
Str8 str = wapp_str8_lit("hello world from me");
|
||||
Str8 delim1 = wapp_str8_lit(" ");
|
||||
Str8 delim2 = wapp_str8_lit("from");
|
||||
Str8List *list1 = wapp_str8_rsplit(&arena, &str, &delim1);
|
||||
Str8List *list2 = wapp_str8_rsplit(&arena, &str, &delim2);
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim1 = wpStr8Lit(" ");
|
||||
WpStr8 delim2 = wpStr8Lit("from");
|
||||
WpStr8List *list1 = wpStr8Rsplit(&arena, &str, &delim1);
|
||||
WpStr8List *list2 = wpStr8Rsplit(&arena, &str, &delim2);
|
||||
|
||||
Str8RO splits1[] = {
|
||||
wapp_str8_slice(&str, 0, 5),
|
||||
wapp_str8_slice(&str, 6, 11),
|
||||
wapp_str8_slice(&str, 12, 16),
|
||||
wapp_str8_slice(&str, 17, 19),
|
||||
WpStr8RO splits1[] = {
|
||||
wpStr8Slice(&str, 0, 5),
|
||||
wpStr8Slice(&str, 6, 11),
|
||||
wpStr8Slice(&str, 12, 16),
|
||||
wpStr8Slice(&str, 17, 19),
|
||||
};
|
||||
Str8RO splits2[] = {
|
||||
wapp_str8_slice(&str, 0, 12),
|
||||
wapp_str8_slice(&str, 16, 19),
|
||||
WpStr8RO splits2[] = {
|
||||
wpStr8Slice(&str, 0, 12),
|
||||
wpStr8Slice(&str, 16, 19),
|
||||
};
|
||||
|
||||
u64 index1 = 0;
|
||||
@@ -529,14 +529,14 @@ TestFuncResult test_str8_rsplit(void) {
|
||||
u64 count2 = ARRLEN(splits2);
|
||||
b8 running2 = true;
|
||||
|
||||
result = list1->node_count == count1 && wapp_str8_list_total_size(list1) == str.size - 3;
|
||||
result = result && list2->node_count == count2 && wapp_str8_list_total_size(list2) == str.size - 4;
|
||||
result = list1->node_count == count1 && wpStr8ListTotalSize(list1) == str.size - 3;
|
||||
result = result && list2->node_count == count2 && wpStr8ListTotalSize(list2) == str.size - 4;
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running1) {
|
||||
Str8 *node = wapp_dbl_list_get(Str8, list1, index1);
|
||||
result = result && wapp_str8_equal(node, &(splits1[index1]));
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list1, index1);
|
||||
result = result && wpStr8Equal(node, &(splits1[index1]));
|
||||
|
||||
++index1;
|
||||
running1 = index1 < count1;
|
||||
@@ -545,82 +545,82 @@ TestFuncResult test_str8_rsplit(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running2) {
|
||||
Str8 *node = wapp_dbl_list_get(Str8, list2, index2);
|
||||
result = result && wapp_str8_equal(node, &(splits2[index2]));
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list2, index2);
|
||||
result = result && wpStr8Equal(node, &(splits2[index2]));
|
||||
|
||||
++index2;
|
||||
running2 = index2 < count2;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_rsplit_with_max(void) {
|
||||
WpTestFuncResult test_str8_rsplit_with_max(void) {
|
||||
b8 result;
|
||||
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
Str8 str = wapp_str8_lit("hello world from me");
|
||||
Str8 delim = wapp_str8_lit(" ");
|
||||
Str8List *list = wapp_str8_rsplit_with_max(&arena, &str, &delim, 2);
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim = wpStr8Lit(" ");
|
||||
WpStr8List *list = wpStr8RsplitWithMax(&arena, &str, &delim, 2);
|
||||
|
||||
Str8RO splits[] = {
|
||||
wapp_str8_slice(&str, 0, 11),
|
||||
wapp_str8_slice(&str, 12, 16),
|
||||
wapp_str8_slice(&str, 17, 19),
|
||||
WpStr8RO splits[] = {
|
||||
wpStr8Slice(&str, 0, 11),
|
||||
wpStr8Slice(&str, 12, 16),
|
||||
wpStr8Slice(&str, 17, 19),
|
||||
};
|
||||
|
||||
u64 index = 0;
|
||||
u64 count = ARRLEN(splits);
|
||||
b8 running = true;
|
||||
|
||||
result = list->node_count == count && wapp_str8_list_total_size(list) == str.size - 2;
|
||||
result = list->node_count == count && wpStr8ListTotalSize(list) == str.size - 2;
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running) {
|
||||
Str8 *node = wapp_dbl_list_get(Str8, list, index);
|
||||
result = result && wapp_str8_equal(node, &(splits[index]));
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list, index);
|
||||
result = result && wpStr8Equal(node, &(splits[index]));
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_join(void) {
|
||||
WpTestFuncResult test_str8_join(void) {
|
||||
b8 result;
|
||||
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
Str8 str = wapp_str8_lit("hello world from me");
|
||||
Str8 delim1 = wapp_str8_lit(" ");
|
||||
Str8 delim2 = wapp_str8_lit("from");
|
||||
Str8List *list1 = wapp_str8_rsplit(&arena, &str, &delim1);
|
||||
Str8List *list2 = wapp_str8_rsplit(&arena, &str, &delim2);
|
||||
Str8 *join1 = wapp_str8_join(&arena, list1, &delim1);
|
||||
Str8 *join2 = wapp_str8_join(&arena, list2, &delim2);
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim1 = wpStr8Lit(" ");
|
||||
WpStr8 delim2 = wpStr8Lit("from");
|
||||
WpStr8List *list1 = wpStr8Rsplit(&arena, &str, &delim1);
|
||||
WpStr8List *list2 = wpStr8Rsplit(&arena, &str, &delim2);
|
||||
WpStr8 *join1 = wpStr8Join(&arena, list1, &delim1);
|
||||
WpStr8 *join2 = wpStr8Join(&arena, list2, &delim2);
|
||||
|
||||
result = join1->size == str.size && wapp_str8_equal(join1, &str);
|
||||
result = result && join2->size == str.size && wapp_str8_equal(join2, &str);
|
||||
result = join1->size == str.size && wpStr8Equal(join1, &str);
|
||||
result = result && join2->size == str.size && wpStr8Equal(join2, &str);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_from_bytes(void) {
|
||||
WpTestFuncResult test_str8_from_bytes(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 str = wapp_str8_buf(1024);
|
||||
U8Array bytes = wapp_array(u8, 'W', 'A', 'P', 'P');
|
||||
wapp_str8_from_bytes(&str, bytes);
|
||||
WpStr8 str = wpStr8Buf(1024);
|
||||
WpU8Array bytes = wpArray(u8, 'W', 'A', 'P', 'P');
|
||||
wpStr8FromBytes(&str, bytes);
|
||||
|
||||
result = str.size == wapp_array_count(bytes) * wapp_array_item_size(bytes);
|
||||
result = result && wapp_str8_equal(&str, &wapp_str8_lit_ro("WAPP"));
|
||||
result = str.size == wpArrayCount(bytes) * wpArrayItemSize(bytes);
|
||||
result = result && wpStr8Equal(&str, &wpStr8LitRo("WAPP"));
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
+301
-301
@@ -3,430 +3,430 @@
|
||||
|
||||
#define ARRLEN(ARR) (sizeof(ARR) / sizeof(ARR[0]))
|
||||
|
||||
TestFuncResult test_str8_lit(void) {
|
||||
WpTestFuncResult test_str8_lit(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("Hello world");
|
||||
WpStr8 s1 = wpStr8Lit("Hello world");
|
||||
result = s1.capacity == 22 && s1.capacity != s1.size;
|
||||
|
||||
Str8 s2 = wapp_str8_lit("Different strokes for different folks");
|
||||
WpStr8 s2 = wpStr8Lit("Different strokes for different folks");
|
||||
result = result && s2.capacity == 74 && s2.capacity != s2.size;
|
||||
|
||||
Str8 s3 = wapp_str8_lit("Discretion is the better part of valour");
|
||||
WpStr8 s3 = wpStr8Lit("Discretion is the better part of valour");
|
||||
result = result && s3.capacity == 78 && s3.capacity != s3.size;
|
||||
|
||||
Str8 s4 = wapp_str8_lit("Distance lends enchantment to the view");
|
||||
WpStr8 s4 = wpStr8Lit("Distance lends enchantment to the view");
|
||||
result = result && s4.capacity == 76 && s4.capacity != s4.size;
|
||||
|
||||
Str8 s5 = wapp_str8_lit("Do as I say, not as I do");
|
||||
WpStr8 s5 = wpStr8Lit("Do as I say, not as I do");
|
||||
result = result && s5.capacity == 48 && s5.capacity != s5.size;
|
||||
|
||||
Str8 s6 = wapp_str8_lit("Do as you would be done by");
|
||||
WpStr8 s6 = wpStr8Lit("Do as you would be done by");
|
||||
result = result && s6.capacity == 52 && s6.capacity != s6.size;
|
||||
|
||||
Str8 s7 = wapp_str8_lit("Do unto others as you would have them do to you");
|
||||
WpStr8 s7 = wpStr8Lit("Do unto others as you would have them do to you");
|
||||
result = result && s7.capacity == 94 && s7.capacity != s7.size;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_lit_ro(void) {
|
||||
WpTestFuncResult test_str8_lit_ro(void) {
|
||||
b8 result;
|
||||
|
||||
Str8RO s1 = wapp_str8_lit_ro("Hello world");
|
||||
WpStr8RO s1 = wpStr8LitRo("Hello world");
|
||||
result = s1.capacity == 11 && s1.capacity == s1.size;
|
||||
|
||||
Str8RO s2 = wapp_str8_lit_ro("Different strokes for different folks");
|
||||
WpStr8RO s2 = wpStr8LitRo("Different strokes for different folks");
|
||||
result = result && s2.capacity == 37 && s2.capacity == s2.size;
|
||||
|
||||
Str8RO s3 = wapp_str8_lit_ro("Discretion is the better part of valour");
|
||||
WpStr8RO s3 = wpStr8LitRo("Discretion is the better part of valour");
|
||||
result = result && s3.capacity == 39 && s3.capacity == s3.size;
|
||||
|
||||
Str8RO s4 = wapp_str8_lit_ro("Distance lends enchantment to the view");
|
||||
WpStr8RO s4 = wpStr8LitRo("Distance lends enchantment to the view");
|
||||
result = result && s4.capacity == 38 && s4.capacity == s4.size;
|
||||
|
||||
Str8RO s5 = wapp_str8_lit_ro("Do as I say, not as I do");
|
||||
WpStr8RO s5 = wpStr8LitRo("Do as I say, not as I do");
|
||||
result = result && s5.capacity == 24 && s5.capacity == s5.size;
|
||||
|
||||
Str8RO s6 = wapp_str8_lit_ro("Do as you would be done by");
|
||||
WpStr8RO s6 = wpStr8LitRo("Do as you would be done by");
|
||||
result = result && s6.capacity == 26 && s6.capacity == s6.size;
|
||||
|
||||
Str8RO s7 = wapp_str8_lit_ro("Do unto others as you would have them do to you");
|
||||
WpStr8RO s7 = wpStr8LitRo("Do unto others as you would have them do to you");
|
||||
result = result && s7.capacity == 47 && s7.capacity == s7.size;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_buf(void) {
|
||||
WpTestFuncResult test_str8_buf(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_buf(1024);
|
||||
WpStr8 s1 = wpStr8Buf(1024);
|
||||
result = s1.capacity == 1024 && s1.size == 0;
|
||||
|
||||
Str8 s2 = wapp_str8_buf(2048);
|
||||
WpStr8 s2 = wpStr8Buf(2048);
|
||||
result = result && s2.capacity == 2048 && s2.size == 0;
|
||||
|
||||
Str8 s3 = wapp_str8_buf(4096);
|
||||
WpStr8 s3 = wpStr8Buf(4096);
|
||||
result = result && s3.capacity == 4096 && s3.size == 0;
|
||||
|
||||
Str8 s4 = wapp_str8_buf(8192);
|
||||
WpStr8 s4 = wpStr8Buf(8192);
|
||||
result = result && s4.capacity == 8192 && s4.size == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_alloc_buf(void) {
|
||||
WpTestFuncResult test_str8_alloc_buf(void) {
|
||||
b8 result;
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(KiB(100));
|
||||
if (wapp_mem_allocator_invalid(&allocator)) {
|
||||
return wapp_tester_result(false);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(KiB(100));
|
||||
if (wpMemAllocatorInvalid(&allocator)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
u64 capacity = 4096;
|
||||
|
||||
Str8 *s = wapp_str8_alloc_buf(&allocator, capacity);
|
||||
WpStr8 *s = wpStr8AllocBuf(&allocator, capacity);
|
||||
if (!s) {
|
||||
result = false;
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
return wapp_tester_result(result);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
result = s->capacity == capacity;
|
||||
|
||||
const char *cstr = "My name is Abdelrahman";
|
||||
wapp_str8_copy_cstr_capped(s, cstr);
|
||||
wpStr8CopyCstrCapped(s, cstr);
|
||||
|
||||
result = result && s->capacity == capacity && s->size == strlen(cstr) && memcmp(s->buf, cstr, s->size) == 0;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_alloc_cstr(void) {
|
||||
WpTestFuncResult test_str8_alloc_cstr(void) {
|
||||
b8 result;
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(KiB(100));
|
||||
if (wapp_mem_allocator_invalid(&allocator)) {
|
||||
return wapp_tester_result(false);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(KiB(100));
|
||||
if (wpMemAllocatorInvalid(&allocator)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
const char *str = "Abdelrahman";
|
||||
u64 length = strlen(str);
|
||||
Str8 *s = wapp_str8_alloc_cstr(&allocator, str);
|
||||
WpStr8 *s = wpStr8AllocCstr(&allocator, str);
|
||||
if (!s) {
|
||||
return wapp_tester_result(false);
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
result = s->size == length && memcmp(s->buf, str, length) == 0;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_alloc_str8(void) {
|
||||
WpTestFuncResult test_str8_alloc_str8(void) {
|
||||
b8 result;
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(KiB(100));
|
||||
if (wapp_mem_allocator_invalid(&allocator)) {
|
||||
return wapp_tester_result(false);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(KiB(100));
|
||||
if (wpMemAllocatorInvalid(&allocator)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
Str8 str = wapp_str8_lit("Abdelrahman");
|
||||
Str8 *s = wapp_str8_alloc_str8(&allocator, &str);
|
||||
WpStr8 str = wpStr8Lit("Abdelrahman");
|
||||
WpStr8 *s = wpStr8AllocStr8(&allocator, &str);
|
||||
if (!s) {
|
||||
return wapp_tester_result(false);
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
result = wapp_str8_equal(s, &str);
|
||||
result = wpStr8Equal(s, &str);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_alloc_substr(void) {
|
||||
WpTestFuncResult test_str8_alloc_substr(void) {
|
||||
b8 result;
|
||||
Allocator allocator = wapp_mem_arena_allocator_init(KiB(100));
|
||||
if (wapp_mem_allocator_invalid(&allocator)) {
|
||||
return wapp_tester_result(false);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(KiB(100));
|
||||
if (wpMemAllocatorInvalid(&allocator)) {
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
Str8 str = wapp_str8_lit("Abdelrahman");
|
||||
Str8 *s = wapp_str8_alloc_substr(&allocator, &str, 3, 8);
|
||||
WpStr8 str = wpStr8Lit("Abdelrahman");
|
||||
WpStr8 *s = wpStr8AllocSubstr(&allocator, &str, 3, 8);
|
||||
if (!s) {
|
||||
return wapp_tester_result(false);
|
||||
return wpTesterResult(false);
|
||||
}
|
||||
|
||||
result = s->size == 5 && memcmp(s->buf, "elrah", s->size) == 0;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_get_index_within_bounds(void) {
|
||||
WpTestFuncResult test_str8_get_index_within_bounds(void) {
|
||||
b8 result;
|
||||
|
||||
Str8RO s1 = wapp_str8_lit_ro("Hello world");
|
||||
result = wapp_str8_get(&s1, 4) == 'o';
|
||||
WpStr8RO s1 = wpStr8LitRo("Hello world");
|
||||
result = wpStr8Get(&s1, 4) == 'o';
|
||||
|
||||
Str8RO s2 = wapp_str8_lit_ro("Different strokes for different folks");
|
||||
result = result && wapp_str8_get(&s2, 0) == 'D';
|
||||
WpStr8RO s2 = wpStr8LitRo("Different strokes for different folks");
|
||||
result = result && wpStr8Get(&s2, 0) == 'D';
|
||||
|
||||
Str8RO s3 = wapp_str8_lit_ro("Discretion is the better part of valour");
|
||||
result = result && wapp_str8_get(&s3, 13) == ' ';
|
||||
WpStr8RO s3 = wpStr8LitRo("Discretion is the better part of valour");
|
||||
result = result && wpStr8Get(&s3, 13) == ' ';
|
||||
|
||||
Str8RO s4 = wapp_str8_lit_ro("Distance lends enchantment to the view");
|
||||
result = result && wapp_str8_get(&s4, 20) == 'n';
|
||||
WpStr8RO s4 = wpStr8LitRo("Distance lends enchantment to the view");
|
||||
result = result && wpStr8Get(&s4, 20) == 'n';
|
||||
|
||||
Str8RO s5 = wapp_str8_lit_ro("Do as I say, not as I do");
|
||||
result = result && wapp_str8_get(&s5, 11) == ',';
|
||||
WpStr8RO s5 = wpStr8LitRo("Do as I say, not as I do");
|
||||
result = result && wpStr8Get(&s5, 11) == ',';
|
||||
|
||||
Str8RO s6 = wapp_str8_lit_ro("Do as you would be done by");
|
||||
result = result && wapp_str8_get(&s6, 25) == 'y';
|
||||
WpStr8RO s6 = wpStr8LitRo("Do as you would be done by");
|
||||
result = result && wpStr8Get(&s6, 25) == 'y';
|
||||
|
||||
Str8RO s7 = wapp_str8_lit_ro("Do unto others as you would have them do to you");
|
||||
result = result && wapp_str8_get(&s7, 16) == 's';
|
||||
WpStr8RO s7 = wpStr8LitRo("Do unto others as you would have them do to you");
|
||||
result = result && wpStr8Get(&s7, 16) == 's';
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_get_index_out_of_bounds(void) {
|
||||
Str8 s1 = wapp_str8_lit("Hello world");
|
||||
b8 result = wapp_str8_get(&s1, 20) == '\0';
|
||||
return wapp_tester_result(result);
|
||||
WpTestFuncResult test_str8_get_index_out_of_bounds(void) {
|
||||
WpStr8 s1 = wpStr8Lit("Hello world");
|
||||
b8 result = wpStr8Get(&s1, 20) == '\0';
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_set(void) {
|
||||
WpTestFuncResult test_str8_set(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("Hello world");
|
||||
wapp_str8_set(&s1, 4, 'f');
|
||||
result = wapp_str8_get(&s1, 4) == 'f';
|
||||
WpStr8 s1 = wpStr8Lit("Hello world");
|
||||
wpStr8Set(&s1, 4, 'f');
|
||||
result = wpStr8Get(&s1, 4) == 'f';
|
||||
|
||||
Str8 s2 = wapp_str8_lit("Different strokes for different folks");
|
||||
wapp_str8_set(&s2, 0, 'A');
|
||||
result = result && wapp_str8_get(&s2, 0) == 'A';
|
||||
WpStr8 s2 = wpStr8Lit("Different strokes for different folks");
|
||||
wpStr8Set(&s2, 0, 'A');
|
||||
result = result && wpStr8Get(&s2, 0) == 'A';
|
||||
|
||||
Str8 s3 = wapp_str8_lit("Discretion is the better part of valour");
|
||||
wapp_str8_set(&s3, 13, 'u');
|
||||
result = result && wapp_str8_get(&s3, 13) == 'u';
|
||||
WpStr8 s3 = wpStr8Lit("Discretion is the better part of valour");
|
||||
wpStr8Set(&s3, 13, 'u');
|
||||
result = result && wpStr8Get(&s3, 13) == 'u';
|
||||
|
||||
Str8 s4 = wapp_str8_lit("Distance lends enchantment to the view");
|
||||
wapp_str8_set(&s4, 20, 'R');
|
||||
result = result && wapp_str8_get(&s4, 20) == 'R';
|
||||
WpStr8 s4 = wpStr8Lit("Distance lends enchantment to the view");
|
||||
wpStr8Set(&s4, 20, 'R');
|
||||
result = result && wpStr8Get(&s4, 20) == 'R';
|
||||
|
||||
Str8 s5 = wapp_str8_lit("Do as I say, not as I do");
|
||||
wapp_str8_set(&s5, 11, '.');
|
||||
result = result && wapp_str8_get(&s5, 11) == '.';
|
||||
WpStr8 s5 = wpStr8Lit("Do as I say, not as I do");
|
||||
wpStr8Set(&s5, 11, '.');
|
||||
result = result && wpStr8Get(&s5, 11) == '.';
|
||||
|
||||
Str8 s6 = wapp_str8_lit("Do as you would be done by");
|
||||
wapp_str8_set(&s6, 25, 'w');
|
||||
result = result && wapp_str8_get(&s6, 25) == 'w';
|
||||
WpStr8 s6 = wpStr8Lit("Do as you would be done by");
|
||||
wpStr8Set(&s6, 25, 'w');
|
||||
result = result && wpStr8Get(&s6, 25) == 'w';
|
||||
|
||||
Str8 s7 = wapp_str8_lit("Do unto others as you would have them do to you");
|
||||
wapp_str8_set(&s7, 16, 'i');
|
||||
result = result && wapp_str8_get(&s7, 16) == 'i';
|
||||
WpStr8 s7 = wpStr8Lit("Do unto others as you would have them do to you");
|
||||
wpStr8Set(&s7, 16, 'i');
|
||||
result = result && wpStr8Get(&s7, 16) == 'i';
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_push_back(void) {
|
||||
WpTestFuncResult test_str8_push_back(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 expected = wapp_str8_lit("Abdelrahman");
|
||||
Str8 buf = wapp_str8_buf(64);
|
||||
wapp_str8_push_back(&buf, 'A');
|
||||
wapp_str8_push_back(&buf, 'b');
|
||||
wapp_str8_push_back(&buf, 'd');
|
||||
wapp_str8_push_back(&buf, 'e');
|
||||
wapp_str8_push_back(&buf, 'l');
|
||||
wapp_str8_push_back(&buf, 'r');
|
||||
wapp_str8_push_back(&buf, 'a');
|
||||
wapp_str8_push_back(&buf, 'h');
|
||||
wapp_str8_push_back(&buf, 'm');
|
||||
wapp_str8_push_back(&buf, 'a');
|
||||
wapp_str8_push_back(&buf, 'n');
|
||||
WpStr8 expected = wpStr8Lit("Abdelrahman");
|
||||
WpStr8 buf = wpStr8Buf(64);
|
||||
wpStr8PushBack(&buf, 'A');
|
||||
wpStr8PushBack(&buf, 'b');
|
||||
wpStr8PushBack(&buf, 'd');
|
||||
wpStr8PushBack(&buf, 'e');
|
||||
wpStr8PushBack(&buf, 'l');
|
||||
wpStr8PushBack(&buf, 'r');
|
||||
wpStr8PushBack(&buf, 'a');
|
||||
wpStr8PushBack(&buf, 'h');
|
||||
wpStr8PushBack(&buf, 'm');
|
||||
wpStr8PushBack(&buf, 'a');
|
||||
wpStr8PushBack(&buf, 'n');
|
||||
|
||||
result = wapp_str8_equal(&buf, &expected);
|
||||
result = wpStr8Equal(&buf, &expected);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_equal(void) {
|
||||
WpTestFuncResult test_str8_equal(void) {
|
||||
b8 result;
|
||||
|
||||
Str8RO s1 = wapp_str8_lit_ro("hello");
|
||||
Str8RO s2 = wapp_str8_lit_ro("hell");
|
||||
Str8RO s3 = wapp_str8_lit_ro("hello");
|
||||
Str8RO s4 = wapp_str8_lit_ro("goodbye");
|
||||
WpStr8RO s1 = wpStr8LitRo("hello");
|
||||
WpStr8RO s2 = wpStr8LitRo("hell");
|
||||
WpStr8RO s3 = wpStr8LitRo("hello");
|
||||
WpStr8RO s4 = wpStr8LitRo("goodbye");
|
||||
|
||||
result = wapp_str8_equal(&s1, &s2) == false;
|
||||
result = result && wapp_str8_equal(&s1, &s3) == (b8)true;
|
||||
result = result && wapp_str8_equal(&s1, &s4) == (b8)false;
|
||||
result = wpStr8Equal(&s1, &s2) == false;
|
||||
result = result && wpStr8Equal(&s1, &s3) == (b8)true;
|
||||
result = result && wpStr8Equal(&s1, &s4) == (b8)false;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_slice(void) {
|
||||
WpTestFuncResult test_str8_slice(void) {
|
||||
b8 result;
|
||||
Str8 s = wapp_str8_lit("Different strokes for different folks");
|
||||
WpStr8 s = wpStr8Lit("Different strokes for different folks");
|
||||
|
||||
Str8RO sub1 = wapp_str8_slice(&s, 3, 9);
|
||||
WpStr8RO sub1 = wpStr8Slice(&s, 3, 9);
|
||||
result = sub1.size == 6 && sub1.capacity == 6;
|
||||
|
||||
Str8RO sub2 = wapp_str8_slice(&s, 18, 21);
|
||||
WpStr8RO sub2 = wpStr8Slice(&s, 18, 21);
|
||||
result = result && sub2.size == 3 && sub2.capacity == 3;
|
||||
|
||||
Str8RO sub3 = wapp_str8_slice(&s, 5, 1);
|
||||
WpStr8RO sub3 = wpStr8Slice(&s, 5, 1);
|
||||
result = result && sub3.size == 0 && sub3.capacity == 0;
|
||||
|
||||
Str8RO sub4 = wapp_str8_slice(&s, 70, 80);
|
||||
WpStr8RO sub4 = wpStr8Slice(&s, 70, 80);
|
||||
result = result && sub4.size == 0 && sub4.capacity == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_alloc_concat(void) {
|
||||
WpTestFuncResult test_str8_alloc_concat(void) {
|
||||
b8 result;
|
||||
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
Str8 str = wapp_str8_lit("Hello world");
|
||||
Str8 suffix1 = wapp_str8_lit(" from me.");
|
||||
Str8 suffix2 = wapp_str8_lit(" This is my code.");
|
||||
Str8 concat1 = wapp_str8_lit("Hello world from me.");
|
||||
Str8 concat2 = wapp_str8_lit("Hello world from me. This is my code.");
|
||||
WpStr8 str = wpStr8Lit("Hello world");
|
||||
WpStr8 suffix1 = wpStr8Lit(" from me.");
|
||||
WpStr8 suffix2 = wpStr8Lit(" This is my code.");
|
||||
WpStr8 concat1 = wpStr8Lit("Hello world from me.");
|
||||
WpStr8 concat2 = wpStr8Lit("Hello world from me. This is my code.");
|
||||
|
||||
Str8 *output;
|
||||
WpStr8 *output;
|
||||
|
||||
output = wapp_str8_alloc_concat(&arena, &str, &suffix1);
|
||||
result = output->size == concat1.size && wapp_str8_equal(output, &concat1);
|
||||
output = wpStr8AllocConcat(&arena, &str, &suffix1);
|
||||
result = output->size == concat1.size && wpStr8Equal(output, &concat1);
|
||||
|
||||
output = wapp_str8_alloc_concat(&arena, output, &suffix2);
|
||||
result = result && output->size == concat2.size && wapp_str8_equal(output, &concat2);
|
||||
output = wpStr8AllocConcat(&arena, output, &suffix2);
|
||||
result = result && output->size == concat2.size && wpStr8Equal(output, &concat2);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_concat_capped(void) {
|
||||
WpTestFuncResult test_str8_concat_capped(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 str = wapp_str8_lit("Hello world");
|
||||
Str8 suffix1 = wapp_str8_lit(" from me.");
|
||||
Str8 suffix2 = wapp_str8_lit(" This is my code.");
|
||||
Str8 concat1 = wapp_str8_lit("Hello world from me.");
|
||||
Str8 concat2 = wapp_str8_lit("Hello world from me. T");
|
||||
WpStr8 str = wpStr8Lit("Hello world");
|
||||
WpStr8 suffix1 = wpStr8Lit(" from me.");
|
||||
WpStr8 suffix2 = wpStr8Lit(" This is my code.");
|
||||
WpStr8 concat1 = wpStr8Lit("Hello world from me.");
|
||||
WpStr8 concat2 = wpStr8Lit("Hello world from me. T");
|
||||
|
||||
wapp_str8_concat_capped(&str, &suffix1);
|
||||
result = str.size == concat1.size && wapp_str8_equal(&str, &concat1);
|
||||
wpStr8ConcatCapped(&str, &suffix1);
|
||||
result = str.size == concat1.size && wpStr8Equal(&str, &concat1);
|
||||
|
||||
wapp_str8_concat_capped(&str, &suffix2);
|
||||
result = result && str.size == concat2.size && wapp_str8_equal(&str, &concat2);
|
||||
wpStr8ConcatCapped(&str, &suffix2);
|
||||
result = result && str.size == concat2.size && wpStr8Equal(&str, &concat2);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_copy_cstr_capped(void) {
|
||||
WpTestFuncResult test_str8_copy_cstr_capped(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 buf = wapp_str8_buf(32);
|
||||
WpStr8 buf = wpStr8Buf(32);
|
||||
const char *src1 = "Hello world";
|
||||
const char *src2 = "Hello world from the Wizard Apprentice standard library";
|
||||
Str8RO src1_cp = wapp_str8_lit_ro("Hello world");
|
||||
Str8RO src2_cp = wapp_str8_lit_ro("Hello world from the Wizard Appr");
|
||||
WpStr8RO src1_cp = wpStr8LitRo("Hello world");
|
||||
WpStr8RO src2_cp = wpStr8LitRo("Hello world from the Wizard Appr");
|
||||
|
||||
wapp_str8_copy_cstr_capped(&buf, src1);
|
||||
result = buf.size == src1_cp.size && wapp_str8_equal(&buf, &src1_cp);
|
||||
wpStr8CopyCstrCapped(&buf, src1);
|
||||
result = buf.size == src1_cp.size && wpStr8Equal(&buf, &src1_cp);
|
||||
|
||||
wapp_str8_copy_cstr_capped(&buf, src2);
|
||||
result = result && buf.size == src2_cp.size && buf.size == buf.capacity && wapp_str8_equal(&buf, &src2_cp);
|
||||
wpStr8CopyCstrCapped(&buf, src2);
|
||||
result = result && buf.size == src2_cp.size && buf.size == buf.capacity && wpStr8Equal(&buf, &src2_cp);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_copy_str8_capped(void) {
|
||||
WpTestFuncResult test_str8_copy_str8_capped(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 buf = wapp_str8_buf(32);
|
||||
Str8RO src1 = wapp_str8_lit_ro("Hello world");
|
||||
Str8RO src2 = wapp_str8_lit_ro("Hello world from the Wizard Apprentice standard library");
|
||||
Str8RO src2_cp = wapp_str8_lit_ro("Hello world from the Wizard Appr");
|
||||
WpStr8 buf = wpStr8Buf(32);
|
||||
WpStr8RO src1 = wpStr8LitRo("Hello world");
|
||||
WpStr8RO src2 = wpStr8LitRo("Hello world from the Wizard Apprentice standard library");
|
||||
WpStr8RO src2_cp = wpStr8LitRo("Hello world from the Wizard Appr");
|
||||
|
||||
wapp_str8_copy_str8_capped(&buf, &src1);
|
||||
result = buf.size == src1.size && wapp_str8_equal(&buf, &src1);
|
||||
wpStr8CopyStr8Capped(&buf, &src1);
|
||||
result = buf.size == src1.size && wpStr8Equal(&buf, &src1);
|
||||
|
||||
wapp_str8_copy_str8_capped(&buf, &src2);
|
||||
result = result && buf.size < src2.size && buf.size == buf.capacity && wapp_str8_equal(&buf, &src2_cp);
|
||||
wpStr8CopyStr8Capped(&buf, &src2);
|
||||
result = result && buf.size < src2.size && buf.size == buf.capacity && wpStr8Equal(&buf, &src2_cp);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_format(void) {
|
||||
WpTestFuncResult test_str8_format(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 buf = wapp_str8_buf(128);
|
||||
Str8 expected = wapp_str8_lit("My name is Abdelrahman and I am 35 years old");
|
||||
WpStr8 buf = wpStr8Buf(128);
|
||||
WpStr8 expected = wpStr8Lit("My name is Abdelrahman and I am 35 years old");
|
||||
|
||||
wapp_str8_format(&buf, "My name is %s and I am %u years old", "Abdelrahman", 35);
|
||||
wpStr8Format(&buf, "My name is %s and I am %u years old", "Abdelrahman", 35);
|
||||
|
||||
result = wapp_str8_equal(&buf, &expected);
|
||||
result = wpStr8Equal(&buf, &expected);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_find(void) {
|
||||
WpTestFuncResult test_str8_find(void) {
|
||||
b8 result;
|
||||
Str8RO s = wapp_str8_lit("Do as I say, not as I do");
|
||||
WpStr8RO s = wpStr8Lit("Do as I say, not as I do");
|
||||
|
||||
result = wapp_str8_find(&s, wapp_str8_lit_ro("d")) != -1;
|
||||
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("not")) != -1);
|
||||
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("as I say")) != -1);
|
||||
result = wpStr8Find(&s, wpStr8LitRo("d")) != -1;
|
||||
result = result && (wpStr8Find(&s, wpStr8LitRo("not")) != -1);
|
||||
result = result && (wpStr8Find(&s, wpStr8LitRo("as I say")) != -1);
|
||||
|
||||
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("f")) == -1);
|
||||
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("hello")) == -1);
|
||||
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("not sa I")) == -1);
|
||||
result = result && (wapp_str8_find(&s, wapp_str8_lit_ro("Do unto others as you would have them do to you")) == -1);
|
||||
result = result && (wpStr8Find(&s, wpStr8LitRo("f")) == -1);
|
||||
result = result && (wpStr8Find(&s, wpStr8LitRo("hello")) == -1);
|
||||
result = result && (wpStr8Find(&s, wpStr8LitRo("not sa I")) == -1);
|
||||
result = result && (wpStr8Find(&s, wpStr8LitRo("Do unto others as you would have them do to you")) == -1);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_rfind(void) {
|
||||
WpTestFuncResult test_str8_rfind(void) {
|
||||
b8 result;
|
||||
Str8RO s = wapp_str8_lit("Do as I say, not as I do");
|
||||
WpStr8RO s = wpStr8Lit("Do as I say, not as I do");
|
||||
|
||||
result = wapp_str8_rfind(&s, wapp_str8_lit_ro("d")) != -1;
|
||||
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("not")) != -1);
|
||||
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("as I say")) != -1);
|
||||
result = wpStr8Rfind(&s, wpStr8LitRo("d")) != -1;
|
||||
result = result && (wpStr8Rfind(&s, wpStr8LitRo("not")) != -1);
|
||||
result = result && (wpStr8Rfind(&s, wpStr8LitRo("as I say")) != -1);
|
||||
|
||||
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("f")) == -1);
|
||||
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("hello")) == -1);
|
||||
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("not sa I")) == -1);
|
||||
result = result && (wapp_str8_rfind(&s, wapp_str8_lit_ro("Do unto others as you would have them do to you")) == -1);
|
||||
result = result && (wpStr8Rfind(&s, wpStr8LitRo("f")) == -1);
|
||||
result = result && (wpStr8Rfind(&s, wpStr8LitRo("hello")) == -1);
|
||||
result = result && (wpStr8Rfind(&s, wpStr8LitRo("not sa I")) == -1);
|
||||
result = result && (wpStr8Rfind(&s, wpStr8LitRo("Do unto others as you would have them do to you")) == -1);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_split(void) {
|
||||
WpTestFuncResult test_str8_split(void) {
|
||||
b8 result;
|
||||
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
Str8 str = wapp_str8_lit("hello world from me");
|
||||
Str8 delim1 = wapp_str8_lit(" ");
|
||||
Str8 delim2 = wapp_str8_lit("from");
|
||||
Str8List *list1 = wapp_str8_split(&arena, &str, &delim1);
|
||||
Str8List *list2 = wapp_str8_split(&arena, &str, &delim2);
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim1 = wpStr8Lit(" ");
|
||||
WpStr8 delim2 = wpStr8Lit("from");
|
||||
WpStr8List *list1 = wpStr8Split(&arena, &str, &delim1);
|
||||
WpStr8List *list2 = wpStr8Split(&arena, &str, &delim2);
|
||||
|
||||
Str8RO splits1[] = {
|
||||
wapp_str8_slice(&str, 0, 5),
|
||||
wapp_str8_slice(&str, 6, 11),
|
||||
wapp_str8_slice(&str, 12, 16),
|
||||
wapp_str8_slice(&str, 17, 19),
|
||||
WpStr8RO splits1[] = {
|
||||
wpStr8Slice(&str, 0, 5),
|
||||
wpStr8Slice(&str, 6, 11),
|
||||
wpStr8Slice(&str, 12, 16),
|
||||
wpStr8Slice(&str, 17, 19),
|
||||
};
|
||||
Str8RO splits2[] = {
|
||||
wapp_str8_slice(&str, 0, 12),
|
||||
wapp_str8_slice(&str, 16, 19),
|
||||
WpStr8RO splits2[] = {
|
||||
wpStr8Slice(&str, 0, 12),
|
||||
wpStr8Slice(&str, 16, 19),
|
||||
};
|
||||
|
||||
u64 index1 = 0;
|
||||
@@ -437,14 +437,14 @@ TestFuncResult test_str8_split(void) {
|
||||
u64 count2 = ARRLEN(splits2);
|
||||
b8 running2 = true;
|
||||
|
||||
result = list1->node_count == count1 && wapp_str8_list_total_size(list1) == str.size - 3;
|
||||
result = result && list2->node_count == count2 && wapp_str8_list_total_size(list2) == str.size - 4;
|
||||
result = list1->node_count == count1 && wpStr8ListTotalSize(list1) == str.size - 3;
|
||||
result = result && list2->node_count == count2 && wpStr8ListTotalSize(list2) == str.size - 4;
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running1) {
|
||||
Str8 *node = wapp_dbl_list_get(Str8, list1, index1);
|
||||
result = result && wapp_str8_equal(node, &(splits1[index1]));
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list1, index1);
|
||||
result = result && wpStr8Equal(node, &(splits1[index1]));
|
||||
|
||||
++index1;
|
||||
running1 = index1 < count1;
|
||||
@@ -453,72 +453,72 @@ TestFuncResult test_str8_split(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running2) {
|
||||
Str8 *node = wapp_dbl_list_get(Str8, list2, index2);
|
||||
result = result && wapp_str8_equal(node, &(splits2[index2]));
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list2, index2);
|
||||
result = result && wpStr8Equal(node, &(splits2[index2]));
|
||||
|
||||
++index2;
|
||||
running2 = index2 < count2;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_split_with_max(void) {
|
||||
WpTestFuncResult test_str8_split_with_max(void) {
|
||||
b8 result;
|
||||
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
Str8 str = wapp_str8_lit("hello world from me");
|
||||
Str8 delim = wapp_str8_lit(" ");
|
||||
Str8List *list = wapp_str8_split_with_max(&arena, &str, &delim, 2);
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim = wpStr8Lit(" ");
|
||||
WpStr8List *list = wpStr8SplitWithMax(&arena, &str, &delim, 2);
|
||||
|
||||
Str8RO splits[] = {
|
||||
wapp_str8_slice(&str, 0, 5),
|
||||
wapp_str8_slice(&str, 6, 11),
|
||||
wapp_str8_slice(&str, 12, 19),
|
||||
WpStr8RO splits[] = {
|
||||
wpStr8Slice(&str, 0, 5),
|
||||
wpStr8Slice(&str, 6, 11),
|
||||
wpStr8Slice(&str, 12, 19),
|
||||
};
|
||||
|
||||
u64 index = 0;
|
||||
u64 count = ARRLEN(splits);
|
||||
b8 running = true;
|
||||
|
||||
result = list->node_count == count && wapp_str8_list_total_size(list) == str.size - 2;
|
||||
result = list->node_count == count && wpStr8ListTotalSize(list) == str.size - 2;
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running) {
|
||||
Str8 *node = wapp_dbl_list_get(Str8, list, index);
|
||||
result = result && wapp_str8_equal(node, &(splits[index]));
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list, index);
|
||||
result = result && wpStr8Equal(node, &(splits[index]));
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_rsplit(void) {
|
||||
WpTestFuncResult test_str8_rsplit(void) {
|
||||
b8 result;
|
||||
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
Str8 str = wapp_str8_lit("hello world from me");
|
||||
Str8 delim1 = wapp_str8_lit(" ");
|
||||
Str8 delim2 = wapp_str8_lit("from");
|
||||
Str8List *list1 = wapp_str8_rsplit(&arena, &str, &delim1);
|
||||
Str8List *list2 = wapp_str8_rsplit(&arena, &str, &delim2);
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim1 = wpStr8Lit(" ");
|
||||
WpStr8 delim2 = wpStr8Lit("from");
|
||||
WpStr8List *list1 = wpStr8Rsplit(&arena, &str, &delim1);
|
||||
WpStr8List *list2 = wpStr8Rsplit(&arena, &str, &delim2);
|
||||
|
||||
Str8RO splits1[] = {
|
||||
wapp_str8_slice(&str, 0, 5),
|
||||
wapp_str8_slice(&str, 6, 11),
|
||||
wapp_str8_slice(&str, 12, 16),
|
||||
wapp_str8_slice(&str, 17, 19),
|
||||
WpStr8RO splits1[] = {
|
||||
wpStr8Slice(&str, 0, 5),
|
||||
wpStr8Slice(&str, 6, 11),
|
||||
wpStr8Slice(&str, 12, 16),
|
||||
wpStr8Slice(&str, 17, 19),
|
||||
};
|
||||
Str8RO splits2[] = {
|
||||
wapp_str8_slice(&str, 0, 12),
|
||||
wapp_str8_slice(&str, 16, 19),
|
||||
WpStr8RO splits2[] = {
|
||||
wpStr8Slice(&str, 0, 12),
|
||||
wpStr8Slice(&str, 16, 19),
|
||||
};
|
||||
|
||||
u64 index1 = 0;
|
||||
@@ -529,14 +529,14 @@ TestFuncResult test_str8_rsplit(void) {
|
||||
u64 count2 = ARRLEN(splits2);
|
||||
b8 running2 = true;
|
||||
|
||||
result = list1->node_count == count1 && wapp_str8_list_total_size(list1) == str.size - 3;
|
||||
result = result && list2->node_count == count2 && wapp_str8_list_total_size(list2) == str.size - 4;
|
||||
result = list1->node_count == count1 && wpStr8ListTotalSize(list1) == str.size - 3;
|
||||
result = result && list2->node_count == count2 && wpStr8ListTotalSize(list2) == str.size - 4;
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running1) {
|
||||
Str8 *node = wapp_dbl_list_get(Str8, list1, index1);
|
||||
result = result && wapp_str8_equal(node, &(splits1[index1]));
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list1, index1);
|
||||
result = result && wpStr8Equal(node, &(splits1[index1]));
|
||||
|
||||
++index1;
|
||||
running1 = index1 < count1;
|
||||
@@ -545,83 +545,83 @@ TestFuncResult test_str8_rsplit(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running2) {
|
||||
Str8 *node = wapp_dbl_list_get(Str8, list2, index2);
|
||||
result = result && wapp_str8_equal(node, &(splits2[index2]));
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list2, index2);
|
||||
result = result && wpStr8Equal(node, &(splits2[index2]));
|
||||
|
||||
++index2;
|
||||
running2 = index2 < count2;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_rsplit_with_max(void) {
|
||||
WpTestFuncResult test_str8_rsplit_with_max(void) {
|
||||
b8 result;
|
||||
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
Str8 str = wapp_str8_lit("hello world from me");
|
||||
Str8 delim = wapp_str8_lit(" ");
|
||||
Str8List *list = wapp_str8_rsplit_with_max(&arena, &str, &delim, 2);
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim = wpStr8Lit(" ");
|
||||
WpStr8List *list = wpStr8RsplitWithMax(&arena, &str, &delim, 2);
|
||||
|
||||
Str8RO splits[] = {
|
||||
wapp_str8_slice(&str, 0, 11),
|
||||
wapp_str8_slice(&str, 12, 16),
|
||||
wapp_str8_slice(&str, 17, 19),
|
||||
WpStr8RO splits[] = {
|
||||
wpStr8Slice(&str, 0, 11),
|
||||
wpStr8Slice(&str, 12, 16),
|
||||
wpStr8Slice(&str, 17, 19),
|
||||
};
|
||||
|
||||
u64 index = 0;
|
||||
u64 count = ARRLEN(splits);
|
||||
b8 running = true;
|
||||
|
||||
result = list->node_count == count && wapp_str8_list_total_size(list) == str.size - 2;
|
||||
result = list->node_count == count && wpStr8ListTotalSize(list) == str.size - 2;
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running) {
|
||||
Str8 *node = wapp_dbl_list_get(Str8, list, index);
|
||||
result = result && wapp_str8_equal(node, &(splits[index]));
|
||||
WpStr8 *node = wpDblListGet(WpStr8, list, index);
|
||||
result = result && wpStr8Equal(node, &(splits[index]));
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_join(void) {
|
||||
WpTestFuncResult test_str8_join(void) {
|
||||
b8 result;
|
||||
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
|
||||
WpAllocator arena = wpMemArenaAllocatorInit(KiB(100));
|
||||
|
||||
Str8 str = wapp_str8_lit("hello world from me");
|
||||
Str8 delim1 = wapp_str8_lit(" ");
|
||||
Str8 delim2 = wapp_str8_lit("from");
|
||||
Str8List *list1 = wapp_str8_rsplit(&arena, &str, &delim1);
|
||||
Str8List *list2 = wapp_str8_rsplit(&arena, &str, &delim2);
|
||||
Str8 *join1 = wapp_str8_join(&arena, list1, &delim1);
|
||||
Str8 *join2 = wapp_str8_join(&arena, list2, &delim2);
|
||||
WpStr8 str = wpStr8Lit("hello world from me");
|
||||
WpStr8 delim1 = wpStr8Lit(" ");
|
||||
WpStr8 delim2 = wpStr8Lit("from");
|
||||
WpStr8List *list1 = wpStr8Rsplit(&arena, &str, &delim1);
|
||||
WpStr8List *list2 = wpStr8Rsplit(&arena, &str, &delim2);
|
||||
WpStr8 *join1 = wpStr8Join(&arena, list1, &delim1);
|
||||
WpStr8 *join2 = wpStr8Join(&arena, list2, &delim2);
|
||||
|
||||
result = join1->size == str.size && wapp_str8_equal(join1, &str);
|
||||
result = result && join2->size == str.size && wapp_str8_equal(join2, &str);
|
||||
result = join1->size == str.size && wpStr8Equal(join1, &str);
|
||||
result = result && join2->size == str.size && wpStr8Equal(join2, &str);
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
wpMemArenaAllocatorDestroy(&arena);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_from_bytes(void) {
|
||||
WpTestFuncResult test_str8_from_bytes(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 str = wapp_str8_buf(1024);
|
||||
Str8 expected = wapp_str8_lit_ro("WAPP");
|
||||
U8Array bytes = wapp_array(u8, 'W', 'A', 'P', 'P');
|
||||
wapp_str8_from_bytes(&str, bytes);
|
||||
WpStr8 str = wpStr8Buf(1024);
|
||||
WpStr8 expected = wpStr8LitRo("WAPP");
|
||||
WpU8Array bytes = wpArray(u8, 'W', 'A', 'P', 'P');
|
||||
wpStr8FromBytes(&str, bytes);
|
||||
|
||||
result = str.size == wapp_array_count(bytes) * wapp_array_item_size(bytes);
|
||||
result = result && wapp_str8_equal(&str, &expected);
|
||||
result = str.size == wpArrayCount(bytes) * wpArrayItemSize(bytes);
|
||||
result = result && wpStr8Equal(&str, &expected);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
+26
-26
@@ -3,31 +3,31 @@
|
||||
|
||||
#include "wapp.h"
|
||||
|
||||
TestFuncResult test_str8_lit(void);
|
||||
TestFuncResult test_str8_lit_ro(void);
|
||||
TestFuncResult test_str8_buf(void);
|
||||
TestFuncResult test_str8_alloc_buf(void);
|
||||
TestFuncResult test_str8_alloc_cstr(void);
|
||||
TestFuncResult test_str8_alloc_str8(void);
|
||||
TestFuncResult test_str8_alloc_substr(void);
|
||||
TestFuncResult test_str8_alloc_concat(void);
|
||||
TestFuncResult test_str8_get_index_within_bounds(void);
|
||||
TestFuncResult test_str8_get_index_out_of_bounds(void);
|
||||
TestFuncResult test_str8_set(void);
|
||||
TestFuncResult test_str8_push_back(void);
|
||||
TestFuncResult test_str8_equal(void);
|
||||
TestFuncResult test_str8_slice(void);
|
||||
TestFuncResult test_str8_concat_capped(void);
|
||||
TestFuncResult test_str8_copy_cstr_capped(void);
|
||||
TestFuncResult test_str8_copy_str8_capped(void);
|
||||
TestFuncResult test_str8_format(void);
|
||||
TestFuncResult test_str8_find(void);
|
||||
TestFuncResult test_str8_rfind(void);
|
||||
TestFuncResult test_str8_split(void);
|
||||
TestFuncResult test_str8_split_with_max(void);
|
||||
TestFuncResult test_str8_rsplit(void);
|
||||
TestFuncResult test_str8_rsplit_with_max(void);
|
||||
TestFuncResult test_str8_join(void);
|
||||
TestFuncResult test_str8_from_bytes(void);
|
||||
WpTestFuncResult test_str8_lit(void);
|
||||
WpTestFuncResult test_str8_lit_ro(void);
|
||||
WpTestFuncResult test_str8_buf(void);
|
||||
WpTestFuncResult test_str8_alloc_buf(void);
|
||||
WpTestFuncResult test_str8_alloc_cstr(void);
|
||||
WpTestFuncResult test_str8_alloc_str8(void);
|
||||
WpTestFuncResult test_str8_alloc_substr(void);
|
||||
WpTestFuncResult test_str8_alloc_concat(void);
|
||||
WpTestFuncResult test_str8_get_index_within_bounds(void);
|
||||
WpTestFuncResult test_str8_get_index_out_of_bounds(void);
|
||||
WpTestFuncResult test_str8_set(void);
|
||||
WpTestFuncResult test_str8_push_back(void);
|
||||
WpTestFuncResult test_str8_equal(void);
|
||||
WpTestFuncResult test_str8_slice(void);
|
||||
WpTestFuncResult test_str8_concat_capped(void);
|
||||
WpTestFuncResult test_str8_copy_cstr_capped(void);
|
||||
WpTestFuncResult test_str8_copy_str8_capped(void);
|
||||
WpTestFuncResult test_str8_format(void);
|
||||
WpTestFuncResult test_str8_find(void);
|
||||
WpTestFuncResult test_str8_rfind(void);
|
||||
WpTestFuncResult test_str8_split(void);
|
||||
WpTestFuncResult test_str8_split_with_max(void);
|
||||
WpTestFuncResult test_str8_rsplit(void);
|
||||
WpTestFuncResult test_str8_rsplit_with_max(void);
|
||||
WpTestFuncResult test_str8_join(void);
|
||||
WpTestFuncResult test_str8_from_bytes(void);
|
||||
|
||||
#endif // !TEST_STR8_H
|
||||
|
||||
+147
-147
@@ -1,230 +1,230 @@
|
||||
#include "test_str8_list.h"
|
||||
#include "wapp.h"
|
||||
|
||||
TestFuncResult test_str8_list_get(void) {
|
||||
WpTestFuncResult test_str8_list_get(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("1");
|
||||
Str8 s2 = wapp_str8_lit("2");
|
||||
Str8 s3 = wapp_str8_lit("3");
|
||||
Str8 s4 = wapp_str8_lit("4");
|
||||
Str8 s5 = wapp_str8_lit("5");
|
||||
WpStr8 s1 = wpStr8Lit("1");
|
||||
WpStr8 s2 = wpStr8Lit("2");
|
||||
WpStr8 s3 = wpStr8Lit("3");
|
||||
WpStr8 s4 = wpStr8Lit("4");
|
||||
WpStr8 s5 = wpStr8Lit("5");
|
||||
|
||||
Str8List list = wapp_dbl_list(Str8);
|
||||
WpStr8List list = wpDblList(WpStr8);
|
||||
|
||||
wapp_dbl_list_push_back(Str8, &list, &s1);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s2);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s3);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s4);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s5);
|
||||
wpDblListPushBack(WpStr8, &list, &s1);
|
||||
wpDblListPushBack(WpStr8, &list, &s2);
|
||||
wpDblListPushBack(WpStr8, &list, &s3);
|
||||
wpDblListPushBack(WpStr8, &list, &s4);
|
||||
wpDblListPushBack(WpStr8, &list, &s5);
|
||||
|
||||
Str8 *node = wapp_dbl_list_get(Str8, &list, 0);
|
||||
result = node == &s1 && wapp_str8_equal(node, &s1);
|
||||
WpStr8 *node = wpDblListGet(WpStr8, &list, 0);
|
||||
result = node == &s1 && wpStr8Equal(node, &s1);
|
||||
|
||||
node = wapp_dbl_list_get(Str8, &list, 1);
|
||||
result = result && node == &s2 && wapp_str8_equal(node, &s2);
|
||||
node = wpDblListGet(WpStr8, &list, 1);
|
||||
result = result && node == &s2 && wpStr8Equal(node, &s2);
|
||||
|
||||
node = wapp_dbl_list_get(Str8, &list, 2);
|
||||
result = result && node == &s3 && wapp_str8_equal(node, &s3);
|
||||
node = wpDblListGet(WpStr8, &list, 2);
|
||||
result = result && node == &s3 && wpStr8Equal(node, &s3);
|
||||
|
||||
node = wapp_dbl_list_get(Str8, &list, 3);
|
||||
result = result && node == &s4 && wapp_str8_equal(node, &s4);
|
||||
node = wpDblListGet(WpStr8, &list, 3);
|
||||
result = result && node == &s4 && wpStr8Equal(node, &s4);
|
||||
|
||||
node = wapp_dbl_list_get(Str8, &list, 4);
|
||||
result = result && node == &s5 && wapp_str8_equal(node, &s5);
|
||||
node = wpDblListGet(WpStr8, &list, 4);
|
||||
result = result && node == &s5 && wpStr8Equal(node, &s5);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_list_push_front(void) {
|
||||
WpTestFuncResult test_str8_list_push_front(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("1");
|
||||
Str8 s2 = wapp_str8_lit("2");
|
||||
Str8 s3 = wapp_str8_lit("3");
|
||||
WpStr8 s1 = wpStr8Lit("1");
|
||||
WpStr8 s2 = wpStr8Lit("2");
|
||||
WpStr8 s3 = wpStr8Lit("3");
|
||||
|
||||
Str8List list = wapp_dbl_list(Str8);
|
||||
WpStr8List list = wpDblList(WpStr8);
|
||||
|
||||
wapp_dbl_list_push_front(Str8, &list, &s1);
|
||||
result = list.first == list.last && list.first->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||
wpDblListPushFront(WpStr8, &list, &s1);
|
||||
result = list.first == list.last && list.first->item == &s1 && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1;
|
||||
|
||||
wapp_dbl_list_push_front(Str8, &list, &s2);
|
||||
result = result && list.first->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||
wpDblListPushFront(WpStr8, &list, &s2);
|
||||
result = result && list.first->item == &s2 && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2;
|
||||
|
||||
wapp_dbl_list_push_front(Str8, &list, &s3);
|
||||
result = result && list.first->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||
wpDblListPushFront(WpStr8, &list, &s3);
|
||||
result = result && list.first->item == &s3 && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_list_push_back(void) {
|
||||
WpTestFuncResult test_str8_list_push_back(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("1");
|
||||
Str8 s2 = wapp_str8_lit("2");
|
||||
Str8 s3 = wapp_str8_lit("3");
|
||||
WpStr8 s1 = wpStr8Lit("1");
|
||||
WpStr8 s2 = wpStr8Lit("2");
|
||||
WpStr8 s3 = wpStr8Lit("3");
|
||||
|
||||
Str8List list = wapp_dbl_list(Str8);
|
||||
WpStr8List list = wpDblList(WpStr8);
|
||||
|
||||
wapp_dbl_list_push_back(Str8, &list, &s1);
|
||||
result = list.first == list.last && list.last->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||
wpDblListPushBack(WpStr8, &list, &s1);
|
||||
result = list.first == list.last && list.last->item == &s1 && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1;
|
||||
|
||||
wapp_dbl_list_push_back(Str8, &list, &s2);
|
||||
result = result && list.last->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||
wpDblListPushBack(WpStr8, &list, &s2);
|
||||
result = result && list.last->item == &s2 && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2;
|
||||
|
||||
wapp_dbl_list_push_back(Str8, &list, &s3);
|
||||
result = result && list.last->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||
wpDblListPushBack(WpStr8, &list, &s3);
|
||||
result = result && list.last->item == &s3 && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_list_insert(void) {
|
||||
WpTestFuncResult test_str8_list_insert(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("1");
|
||||
Str8 s2 = wapp_str8_lit("2");
|
||||
Str8 s3 = wapp_str8_lit("3");
|
||||
Str8 s4 = wapp_str8_lit("4");
|
||||
Str8 s5 = wapp_str8_lit("5");
|
||||
Str8 s6 = wapp_str8_lit("6");
|
||||
Str8 s7 = wapp_str8_lit("7");
|
||||
WpStr8 s1 = wpStr8Lit("1");
|
||||
WpStr8 s2 = wpStr8Lit("2");
|
||||
WpStr8 s3 = wpStr8Lit("3");
|
||||
WpStr8 s4 = wpStr8Lit("4");
|
||||
WpStr8 s5 = wpStr8Lit("5");
|
||||
WpStr8 s6 = wpStr8Lit("6");
|
||||
WpStr8 s7 = wpStr8Lit("7");
|
||||
|
||||
Str8List list = wapp_dbl_list(Str8);
|
||||
WpStr8List list = wpDblList(WpStr8);
|
||||
|
||||
wapp_dbl_list_push_back(Str8, &list, &s1);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s2);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s3);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s4);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s5);
|
||||
wpDblListPushBack(WpStr8, &list, &s1);
|
||||
wpDblListPushBack(WpStr8, &list, &s2);
|
||||
wpDblListPushBack(WpStr8, &list, &s3);
|
||||
wpDblListPushBack(WpStr8, &list, &s4);
|
||||
wpDblListPushBack(WpStr8, &list, &s5);
|
||||
|
||||
Str8 *node;
|
||||
wapp_dbl_list_insert(Str8, &list, &s6, 2);
|
||||
node = wapp_dbl_list_get(Str8, &list, 2);
|
||||
result = node != NULL && node == &s6 && wapp_str8_list_total_size(&list) == 6 && list.node_count == 6;
|
||||
wapp_dbl_list_insert(Str8, &list, &s7, 5);
|
||||
node = wapp_dbl_list_get(Str8, &list, 5);
|
||||
result = result && node != NULL && node == &s7 && wapp_str8_list_total_size(&list) == 7 && list.node_count == 7;
|
||||
WpStr8 *node;
|
||||
wpDblListInsert(WpStr8, &list, &s6, 2);
|
||||
node = wpDblListGet(WpStr8, &list, 2);
|
||||
result = node != NULL && node == &s6 && wpStr8ListTotalSize(&list) == 6 && list.node_count == 6;
|
||||
wpDblListInsert(WpStr8, &list, &s7, 5);
|
||||
node = wpDblListGet(WpStr8, &list, 5);
|
||||
result = result && node != NULL && node == &s7 && wpStr8ListTotalSize(&list) == 7 && list.node_count == 7;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_list_pop_front(void) {
|
||||
WpTestFuncResult test_str8_list_pop_front(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("1");
|
||||
Str8 s2 = wapp_str8_lit("2");
|
||||
Str8 s3 = wapp_str8_lit("3");
|
||||
Str8 s4 = wapp_str8_lit("4");
|
||||
Str8 s5 = wapp_str8_lit("5");
|
||||
WpStr8 s1 = wpStr8Lit("1");
|
||||
WpStr8 s2 = wpStr8Lit("2");
|
||||
WpStr8 s3 = wpStr8Lit("3");
|
||||
WpStr8 s4 = wpStr8Lit("4");
|
||||
WpStr8 s5 = wpStr8Lit("5");
|
||||
|
||||
Str8List list = wapp_dbl_list(Str8);
|
||||
WpStr8List list = wpDblList(WpStr8);
|
||||
|
||||
wapp_dbl_list_push_back(Str8, &list, &s1);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s2);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s3);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s4);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s5);
|
||||
wpDblListPushBack(WpStr8, &list, &s1);
|
||||
wpDblListPushBack(WpStr8, &list, &s2);
|
||||
wpDblListPushBack(WpStr8, &list, &s3);
|
||||
wpDblListPushBack(WpStr8, &list, &s4);
|
||||
wpDblListPushBack(WpStr8, &list, &s5);
|
||||
|
||||
Str8 *node = wapp_dbl_list_pop_front(Str8, &list);
|
||||
result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
|
||||
WpStr8 *node = wpDblListPopFront(WpStr8, &list);
|
||||
result = node == &s1 && wpStr8Equal(node, &s1) && wpStr8ListTotalSize(&list) == 4 && list.node_count == 4;
|
||||
|
||||
node = wapp_dbl_list_pop_front(Str8, &list);
|
||||
result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||
node = wpDblListPopFront(WpStr8, &list);
|
||||
result = result && node == &s2 && wpStr8Equal(node, &s2) && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3;
|
||||
|
||||
node = wapp_dbl_list_pop_front(Str8, &list);
|
||||
result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||
node = wpDblListPopFront(WpStr8, &list);
|
||||
result = result && node == &s3 && wpStr8Equal(node, &s3) && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2;
|
||||
|
||||
node = wapp_dbl_list_pop_front(Str8, &list);
|
||||
result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||
node = wpDblListPopFront(WpStr8, &list);
|
||||
result = result && node == &s4 && wpStr8Equal(node, &s4) && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1;
|
||||
|
||||
node = wapp_dbl_list_pop_front(Str8, &list);
|
||||
result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
|
||||
node = wpDblListPopFront(WpStr8, &list);
|
||||
result = result && node == &s5 && wpStr8Equal(node, &s5) && wpStr8ListTotalSize(&list) == 0 && list.node_count == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_list_pop_back(void) {
|
||||
WpTestFuncResult test_str8_list_pop_back(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("1");
|
||||
Str8 s2 = wapp_str8_lit("2");
|
||||
Str8 s3 = wapp_str8_lit("3");
|
||||
Str8 s4 = wapp_str8_lit("4");
|
||||
Str8 s5 = wapp_str8_lit("5");
|
||||
WpStr8 s1 = wpStr8Lit("1");
|
||||
WpStr8 s2 = wpStr8Lit("2");
|
||||
WpStr8 s3 = wpStr8Lit("3");
|
||||
WpStr8 s4 = wpStr8Lit("4");
|
||||
WpStr8 s5 = wpStr8Lit("5");
|
||||
|
||||
Str8List list = wapp_dbl_list(Str8);
|
||||
WpStr8List list = wpDblList(WpStr8);
|
||||
|
||||
wapp_dbl_list_push_front(Str8, &list, &s1);
|
||||
wapp_dbl_list_push_front(Str8, &list, &s2);
|
||||
wapp_dbl_list_push_front(Str8, &list, &s3);
|
||||
wapp_dbl_list_push_front(Str8, &list, &s4);
|
||||
wapp_dbl_list_push_front(Str8, &list, &s5);
|
||||
wpDblListPushFront(WpStr8, &list, &s1);
|
||||
wpDblListPushFront(WpStr8, &list, &s2);
|
||||
wpDblListPushFront(WpStr8, &list, &s3);
|
||||
wpDblListPushFront(WpStr8, &list, &s4);
|
||||
wpDblListPushFront(WpStr8, &list, &s5);
|
||||
|
||||
Str8 *node = wapp_dbl_list_pop_back(Str8, &list);
|
||||
result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
|
||||
WpStr8 *node = wpDblListPopBack(WpStr8, &list);
|
||||
result = node == &s1 && wpStr8Equal(node, &s1) && wpStr8ListTotalSize(&list) == 4 && list.node_count == 4;
|
||||
|
||||
node = wapp_dbl_list_pop_back(Str8, &list);
|
||||
result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||
node = wpDblListPopBack(WpStr8, &list);
|
||||
result = result && node == &s2 && wpStr8Equal(node, &s2) && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3;
|
||||
|
||||
node = wapp_dbl_list_pop_back(Str8, &list);
|
||||
result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||
node = wpDblListPopBack(WpStr8, &list);
|
||||
result = result && node == &s3 && wpStr8Equal(node, &s3) && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2;
|
||||
|
||||
node = wapp_dbl_list_pop_back(Str8, &list);
|
||||
result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||
node = wpDblListPopBack(WpStr8, &list);
|
||||
result = result && node == &s4 && wpStr8Equal(node, &s4) && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1;
|
||||
|
||||
node = wapp_dbl_list_pop_back(Str8, &list);
|
||||
result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
|
||||
node = wpDblListPopBack(WpStr8, &list);
|
||||
result = result && node == &s5 && wpStr8Equal(node, &s5) && wpStr8ListTotalSize(&list) == 0 && list.node_count == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_list_remove(void) {
|
||||
WpTestFuncResult test_str8_list_remove(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("1");
|
||||
Str8 s2 = wapp_str8_lit("2");
|
||||
Str8 s3 = wapp_str8_lit("3");
|
||||
Str8 s4 = wapp_str8_lit("4");
|
||||
Str8 s5 = wapp_str8_lit("5");
|
||||
WpStr8 s1 = wpStr8Lit("1");
|
||||
WpStr8 s2 = wpStr8Lit("2");
|
||||
WpStr8 s3 = wpStr8Lit("3");
|
||||
WpStr8 s4 = wpStr8Lit("4");
|
||||
WpStr8 s5 = wpStr8Lit("5");
|
||||
|
||||
Str8List list = wapp_dbl_list(Str8);
|
||||
WpStr8List list = wpDblList(WpStr8);
|
||||
|
||||
wapp_dbl_list_push_back(Str8, &list, &s1);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s2);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s3);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s4);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s5);
|
||||
wpDblListPushBack(WpStr8, &list, &s1);
|
||||
wpDblListPushBack(WpStr8, &list, &s2);
|
||||
wpDblListPushBack(WpStr8, &list, &s3);
|
||||
wpDblListPushBack(WpStr8, &list, &s4);
|
||||
wpDblListPushBack(WpStr8, &list, &s5);
|
||||
|
||||
Str8 *node = wapp_dbl_list_remove(Str8, &list, 0);
|
||||
result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
|
||||
WpStr8 *node = wpDblListRemove(WpStr8, &list, 0);
|
||||
result = node == &s1 && wpStr8Equal(node, &s1) && wpStr8ListTotalSize(&list) == 4 && list.node_count == 4;
|
||||
|
||||
node = wapp_dbl_list_remove(Str8, &list, 0);
|
||||
result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||
node = wpDblListRemove(WpStr8, &list, 0);
|
||||
result = result && node == &s2 && wpStr8Equal(node, &s2) && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3;
|
||||
|
||||
node = wapp_dbl_list_remove(Str8, &list, 0);
|
||||
result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||
node = wpDblListRemove(WpStr8, &list, 0);
|
||||
result = result && node == &s3 && wpStr8Equal(node, &s3) && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2;
|
||||
|
||||
node = wapp_dbl_list_remove(Str8, &list, 0);
|
||||
result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||
node = wpDblListRemove(WpStr8, &list, 0);
|
||||
result = result && node == &s4 && wpStr8Equal(node, &s4) && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1;
|
||||
|
||||
node = wapp_dbl_list_remove(Str8, &list, 0);
|
||||
result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
|
||||
node = wpDblListRemove(WpStr8, &list, 0);
|
||||
result = result && node == &s5 && wpStr8Equal(node, &s5) && wpStr8ListTotalSize(&list) == 0 && list.node_count == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_list_empty(void) {
|
||||
WpTestFuncResult test_str8_list_empty(void) {
|
||||
b8 result;
|
||||
|
||||
Str8List list = wapp_dbl_list(Str8);
|
||||
wapp_dbl_list_push_back(Str8, &list, &wapp_str8_lit("Hello"));
|
||||
wapp_dbl_list_push_back(Str8, &list, &wapp_str8_lit("from"));
|
||||
wapp_dbl_list_push_back(Str8, &list, &wapp_str8_lit("wizapp"));
|
||||
wapp_dbl_list_push_back(Str8, &list, &wapp_str8_lit("stdlib"));
|
||||
WpStr8List list = wpDblList(WpStr8);
|
||||
wpDblListPushBack(WpStr8, &list, &wpStr8Lit("Hello"));
|
||||
wpDblListPushBack(WpStr8, &list, &wpStr8Lit("from"));
|
||||
wpDblListPushBack(WpStr8, &list, &wpStr8Lit("wizapp"));
|
||||
wpDblListPushBack(WpStr8, &list, &wpStr8Lit("stdlib"));
|
||||
|
||||
wapp_dbl_list_empty(Str8, &list);
|
||||
wpDblListEmpty(WpStr8, &list);
|
||||
|
||||
result = list.first == NULL && list.last == NULL && list.node_count == 0 && wapp_str8_list_total_size(&list) == 0;
|
||||
result = list.first == NULL && list.last == NULL && list.node_count == 0 && wpStr8ListTotalSize(&list) == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
+151
-151
@@ -1,238 +1,238 @@
|
||||
#include "test_str8_list.h"
|
||||
#include "wapp.h"
|
||||
|
||||
TestFuncResult test_str8_list_get(void) {
|
||||
WpTestFuncResult test_str8_list_get(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("1");
|
||||
Str8 s2 = wapp_str8_lit("2");
|
||||
Str8 s3 = wapp_str8_lit("3");
|
||||
Str8 s4 = wapp_str8_lit("4");
|
||||
Str8 s5 = wapp_str8_lit("5");
|
||||
WpStr8 s1 = wpStr8Lit("1");
|
||||
WpStr8 s2 = wpStr8Lit("2");
|
||||
WpStr8 s3 = wpStr8Lit("3");
|
||||
WpStr8 s4 = wpStr8Lit("4");
|
||||
WpStr8 s5 = wpStr8Lit("5");
|
||||
|
||||
Str8List list = wapp_dbl_list(Str8);
|
||||
WpStr8List list = wpDblList(WpStr8);
|
||||
|
||||
wapp_dbl_list_push_back(Str8, &list, &s1);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s2);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s3);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s4);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s5);
|
||||
wpDblListPushBack(WpStr8, &list, &s1);
|
||||
wpDblListPushBack(WpStr8, &list, &s2);
|
||||
wpDblListPushBack(WpStr8, &list, &s3);
|
||||
wpDblListPushBack(WpStr8, &list, &s4);
|
||||
wpDblListPushBack(WpStr8, &list, &s5);
|
||||
|
||||
Str8 *node = wapp_dbl_list_get(Str8, &list, 0);
|
||||
result = node == &s1 && wapp_str8_equal(node, &s1);
|
||||
WpStr8 *node = wpDblListGet(WpStr8, &list, 0);
|
||||
result = node == &s1 && wpStr8Equal(node, &s1);
|
||||
|
||||
node = wapp_dbl_list_get(Str8, &list, 1);
|
||||
result = result && node == &s2 && wapp_str8_equal(node, &s2);
|
||||
node = wpDblListGet(WpStr8, &list, 1);
|
||||
result = result && node == &s2 && wpStr8Equal(node, &s2);
|
||||
|
||||
node = wapp_dbl_list_get(Str8, &list, 2);
|
||||
result = result && node == &s3 && wapp_str8_equal(node, &s3);
|
||||
node = wpDblListGet(WpStr8, &list, 2);
|
||||
result = result && node == &s3 && wpStr8Equal(node, &s3);
|
||||
|
||||
node = wapp_dbl_list_get(Str8, &list, 3);
|
||||
result = result && node == &s4 && wapp_str8_equal(node, &s4);
|
||||
node = wpDblListGet(WpStr8, &list, 3);
|
||||
result = result && node == &s4 && wpStr8Equal(node, &s4);
|
||||
|
||||
node = wapp_dbl_list_get(Str8, &list, 4);
|
||||
result = result && node == &s5 && wapp_str8_equal(node, &s5);
|
||||
node = wpDblListGet(WpStr8, &list, 4);
|
||||
result = result && node == &s5 && wpStr8Equal(node, &s5);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_list_push_front(void) {
|
||||
WpTestFuncResult test_str8_list_push_front(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("1");
|
||||
Str8 s2 = wapp_str8_lit("2");
|
||||
Str8 s3 = wapp_str8_lit("3");
|
||||
WpStr8 s1 = wpStr8Lit("1");
|
||||
WpStr8 s2 = wpStr8Lit("2");
|
||||
WpStr8 s3 = wpStr8Lit("3");
|
||||
|
||||
Str8List list = wapp_dbl_list(Str8);
|
||||
WpStr8List list = wpDblList(WpStr8);
|
||||
|
||||
wapp_dbl_list_push_front(Str8, &list, &s1);
|
||||
result = list.first == list.last && list.first->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||
wpDblListPushFront(WpStr8, &list, &s1);
|
||||
result = list.first == list.last && list.first->item == &s1 && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1;
|
||||
|
||||
wapp_dbl_list_push_front(Str8, &list, &s2);
|
||||
result = result && list.first->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||
wpDblListPushFront(WpStr8, &list, &s2);
|
||||
result = result && list.first->item == &s2 && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2;
|
||||
|
||||
wapp_dbl_list_push_front(Str8, &list, &s3);
|
||||
result = result && list.first->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||
wpDblListPushFront(WpStr8, &list, &s3);
|
||||
result = result && list.first->item == &s3 && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_list_push_back(void) {
|
||||
WpTestFuncResult test_str8_list_push_back(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("1");
|
||||
Str8 s2 = wapp_str8_lit("2");
|
||||
Str8 s3 = wapp_str8_lit("3");
|
||||
WpStr8 s1 = wpStr8Lit("1");
|
||||
WpStr8 s2 = wpStr8Lit("2");
|
||||
WpStr8 s3 = wpStr8Lit("3");
|
||||
|
||||
Str8List list = wapp_dbl_list(Str8);
|
||||
WpStr8List list = wpDblList(WpStr8);
|
||||
|
||||
wapp_dbl_list_push_back(Str8, &list, &s1);
|
||||
result = list.first == list.last && list.last->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||
wpDblListPushBack(WpStr8, &list, &s1);
|
||||
result = list.first == list.last && list.last->item == &s1 && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1;
|
||||
|
||||
wapp_dbl_list_push_back(Str8, &list, &s2);
|
||||
result = result && list.last->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||
wpDblListPushBack(WpStr8, &list, &s2);
|
||||
result = result && list.last->item == &s2 && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2;
|
||||
|
||||
wapp_dbl_list_push_back(Str8, &list, &s3);
|
||||
result = result && list.last->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||
wpDblListPushBack(WpStr8, &list, &s3);
|
||||
result = result && list.last->item == &s3 && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_list_insert(void) {
|
||||
WpTestFuncResult test_str8_list_insert(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("1");
|
||||
Str8 s2 = wapp_str8_lit("2");
|
||||
Str8 s3 = wapp_str8_lit("3");
|
||||
Str8 s4 = wapp_str8_lit("4");
|
||||
Str8 s5 = wapp_str8_lit("5");
|
||||
Str8 s6 = wapp_str8_lit("6");
|
||||
Str8 s7 = wapp_str8_lit("7");
|
||||
WpStr8 s1 = wpStr8Lit("1");
|
||||
WpStr8 s2 = wpStr8Lit("2");
|
||||
WpStr8 s3 = wpStr8Lit("3");
|
||||
WpStr8 s4 = wpStr8Lit("4");
|
||||
WpStr8 s5 = wpStr8Lit("5");
|
||||
WpStr8 s6 = wpStr8Lit("6");
|
||||
WpStr8 s7 = wpStr8Lit("7");
|
||||
|
||||
Str8List list = wapp_dbl_list(Str8);
|
||||
WpStr8List list = wpDblList(WpStr8);
|
||||
|
||||
wapp_dbl_list_push_back(Str8, &list, &s1);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s2);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s3);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s4);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s5);
|
||||
wpDblListPushBack(WpStr8, &list, &s1);
|
||||
wpDblListPushBack(WpStr8, &list, &s2);
|
||||
wpDblListPushBack(WpStr8, &list, &s3);
|
||||
wpDblListPushBack(WpStr8, &list, &s4);
|
||||
wpDblListPushBack(WpStr8, &list, &s5);
|
||||
|
||||
Str8 *node;
|
||||
wapp_dbl_list_insert(Str8, &list, &s6, 2);
|
||||
node = wapp_dbl_list_get(Str8, &list, 2);
|
||||
result = node != NULL && node == &s6 && wapp_str8_list_total_size(&list) == 6 && list.node_count == 6;
|
||||
wapp_dbl_list_insert(Str8, &list, &s7, 5);
|
||||
node = wapp_dbl_list_get(Str8, &list, 5);
|
||||
result = result && node != NULL && node == &s7 && wapp_str8_list_total_size(&list) == 7 && list.node_count == 7;
|
||||
WpStr8 *node;
|
||||
wpDblListInsert(WpStr8, &list, &s6, 2);
|
||||
node = wpDblListGet(WpStr8, &list, 2);
|
||||
result = node != NULL && node == &s6 && wpStr8ListTotalSize(&list) == 6 && list.node_count == 6;
|
||||
wpDblListInsert(WpStr8, &list, &s7, 5);
|
||||
node = wpDblListGet(WpStr8, &list, 5);
|
||||
result = result && node != NULL && node == &s7 && wpStr8ListTotalSize(&list) == 7 && list.node_count == 7;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_list_pop_front(void) {
|
||||
WpTestFuncResult test_str8_list_pop_front(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("1");
|
||||
Str8 s2 = wapp_str8_lit("2");
|
||||
Str8 s3 = wapp_str8_lit("3");
|
||||
Str8 s4 = wapp_str8_lit("4");
|
||||
Str8 s5 = wapp_str8_lit("5");
|
||||
WpStr8 s1 = wpStr8Lit("1");
|
||||
WpStr8 s2 = wpStr8Lit("2");
|
||||
WpStr8 s3 = wpStr8Lit("3");
|
||||
WpStr8 s4 = wpStr8Lit("4");
|
||||
WpStr8 s5 = wpStr8Lit("5");
|
||||
|
||||
Str8List list = wapp_dbl_list(Str8);
|
||||
WpStr8List list = wpDblList(WpStr8);
|
||||
|
||||
wapp_dbl_list_push_back(Str8, &list, &s1);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s2);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s3);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s4);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s5);
|
||||
wpDblListPushBack(WpStr8, &list, &s1);
|
||||
wpDblListPushBack(WpStr8, &list, &s2);
|
||||
wpDblListPushBack(WpStr8, &list, &s3);
|
||||
wpDblListPushBack(WpStr8, &list, &s4);
|
||||
wpDblListPushBack(WpStr8, &list, &s5);
|
||||
|
||||
Str8 *node = wapp_dbl_list_pop_front(Str8, &list);
|
||||
result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
|
||||
WpStr8 *node = wpDblListPopFront(WpStr8, &list);
|
||||
result = node == &s1 && wpStr8Equal(node, &s1) && wpStr8ListTotalSize(&list) == 4 && list.node_count == 4;
|
||||
|
||||
node = wapp_dbl_list_pop_front(Str8, &list);
|
||||
result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||
node = wpDblListPopFront(WpStr8, &list);
|
||||
result = result && node == &s2 && wpStr8Equal(node, &s2) && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3;
|
||||
|
||||
node = wapp_dbl_list_pop_front(Str8, &list);
|
||||
result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||
node = wpDblListPopFront(WpStr8, &list);
|
||||
result = result && node == &s3 && wpStr8Equal(node, &s3) && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2;
|
||||
|
||||
node = wapp_dbl_list_pop_front(Str8, &list);
|
||||
result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||
node = wpDblListPopFront(WpStr8, &list);
|
||||
result = result && node == &s4 && wpStr8Equal(node, &s4) && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1;
|
||||
|
||||
node = wapp_dbl_list_pop_front(Str8, &list);
|
||||
result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
|
||||
node = wpDblListPopFront(WpStr8, &list);
|
||||
result = result && node == &s5 && wpStr8Equal(node, &s5) && wpStr8ListTotalSize(&list) == 0 && list.node_count == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_list_pop_back(void) {
|
||||
WpTestFuncResult test_str8_list_pop_back(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("1");
|
||||
Str8 s2 = wapp_str8_lit("2");
|
||||
Str8 s3 = wapp_str8_lit("3");
|
||||
Str8 s4 = wapp_str8_lit("4");
|
||||
Str8 s5 = wapp_str8_lit("5");
|
||||
WpStr8 s1 = wpStr8Lit("1");
|
||||
WpStr8 s2 = wpStr8Lit("2");
|
||||
WpStr8 s3 = wpStr8Lit("3");
|
||||
WpStr8 s4 = wpStr8Lit("4");
|
||||
WpStr8 s5 = wpStr8Lit("5");
|
||||
|
||||
Str8List list = wapp_dbl_list(Str8);
|
||||
WpStr8List list = wpDblList(WpStr8);
|
||||
|
||||
wapp_dbl_list_push_front(Str8, &list, &s1);
|
||||
wapp_dbl_list_push_front(Str8, &list, &s2);
|
||||
wapp_dbl_list_push_front(Str8, &list, &s3);
|
||||
wapp_dbl_list_push_front(Str8, &list, &s4);
|
||||
wapp_dbl_list_push_front(Str8, &list, &s5);
|
||||
wpDblListPushFront(WpStr8, &list, &s1);
|
||||
wpDblListPushFront(WpStr8, &list, &s2);
|
||||
wpDblListPushFront(WpStr8, &list, &s3);
|
||||
wpDblListPushFront(WpStr8, &list, &s4);
|
||||
wpDblListPushFront(WpStr8, &list, &s5);
|
||||
|
||||
Str8 *node = wapp_dbl_list_pop_back(Str8, &list);
|
||||
result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
|
||||
WpStr8 *node = wpDblListPopBack(WpStr8, &list);
|
||||
result = node == &s1 && wpStr8Equal(node, &s1) && wpStr8ListTotalSize(&list) == 4 && list.node_count == 4;
|
||||
|
||||
node = wapp_dbl_list_pop_back(Str8, &list);
|
||||
result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||
node = wpDblListPopBack(WpStr8, &list);
|
||||
result = result && node == &s2 && wpStr8Equal(node, &s2) && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3;
|
||||
|
||||
node = wapp_dbl_list_pop_back(Str8, &list);
|
||||
result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||
node = wpDblListPopBack(WpStr8, &list);
|
||||
result = result && node == &s3 && wpStr8Equal(node, &s3) && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2;
|
||||
|
||||
node = wapp_dbl_list_pop_back(Str8, &list);
|
||||
result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||
node = wpDblListPopBack(WpStr8, &list);
|
||||
result = result && node == &s4 && wpStr8Equal(node, &s4) && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1;
|
||||
|
||||
node = wapp_dbl_list_pop_back(Str8, &list);
|
||||
result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
|
||||
node = wpDblListPopBack(WpStr8, &list);
|
||||
result = result && node == &s5 && wpStr8Equal(node, &s5) && wpStr8ListTotalSize(&list) == 0 && list.node_count == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_list_remove(void) {
|
||||
WpTestFuncResult test_str8_list_remove(void) {
|
||||
b8 result;
|
||||
|
||||
Str8 s1 = wapp_str8_lit("1");
|
||||
Str8 s2 = wapp_str8_lit("2");
|
||||
Str8 s3 = wapp_str8_lit("3");
|
||||
Str8 s4 = wapp_str8_lit("4");
|
||||
Str8 s5 = wapp_str8_lit("5");
|
||||
WpStr8 s1 = wpStr8Lit("1");
|
||||
WpStr8 s2 = wpStr8Lit("2");
|
||||
WpStr8 s3 = wpStr8Lit("3");
|
||||
WpStr8 s4 = wpStr8Lit("4");
|
||||
WpStr8 s5 = wpStr8Lit("5");
|
||||
|
||||
Str8List list = wapp_dbl_list(Str8);
|
||||
WpStr8List list = wpDblList(WpStr8);
|
||||
|
||||
wapp_dbl_list_push_back(Str8, &list, &s1);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s2);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s3);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s4);
|
||||
wapp_dbl_list_push_back(Str8, &list, &s5);
|
||||
wpDblListPushBack(WpStr8, &list, &s1);
|
||||
wpDblListPushBack(WpStr8, &list, &s2);
|
||||
wpDblListPushBack(WpStr8, &list, &s3);
|
||||
wpDblListPushBack(WpStr8, &list, &s4);
|
||||
wpDblListPushBack(WpStr8, &list, &s5);
|
||||
|
||||
Str8 *node = wapp_dbl_list_remove(Str8, &list, 0);
|
||||
result = node == &s1 && wapp_str8_equal(node, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
|
||||
WpStr8 *node = wpDblListRemove(WpStr8, &list, 0);
|
||||
result = node == &s1 && wpStr8Equal(node, &s1) && wpStr8ListTotalSize(&list) == 4 && list.node_count == 4;
|
||||
|
||||
node = wapp_dbl_list_remove(Str8, &list, 0);
|
||||
result = result && node == &s2 && wapp_str8_equal(node, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||
node = wpDblListRemove(WpStr8, &list, 0);
|
||||
result = result && node == &s2 && wpStr8Equal(node, &s2) && wpStr8ListTotalSize(&list) == 3 && list.node_count == 3;
|
||||
|
||||
node = wapp_dbl_list_remove(Str8, &list, 0);
|
||||
result = result && node == &s3 && wapp_str8_equal(node, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||
node = wpDblListRemove(WpStr8, &list, 0);
|
||||
result = result && node == &s3 && wpStr8Equal(node, &s3) && wpStr8ListTotalSize(&list) == 2 && list.node_count == 2;
|
||||
|
||||
node = wapp_dbl_list_remove(Str8, &list, 0);
|
||||
result = result && node == &s4 && wapp_str8_equal(node, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||
node = wpDblListRemove(WpStr8, &list, 0);
|
||||
result = result && node == &s4 && wpStr8Equal(node, &s4) && wpStr8ListTotalSize(&list) == 1 && list.node_count == 1;
|
||||
|
||||
node = wapp_dbl_list_remove(Str8, &list, 0);
|
||||
result = result && node == &s5 && wapp_str8_equal(node, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
|
||||
node = wpDblListRemove(WpStr8, &list, 0);
|
||||
result = result && node == &s5 && wpStr8Equal(node, &s5) && wpStr8ListTotalSize(&list) == 0 && list.node_count == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_str8_list_empty(void) {
|
||||
WpTestFuncResult test_str8_list_empty(void) {
|
||||
b8 result;
|
||||
|
||||
Str8List list = wapp_dbl_list(Str8);
|
||||
WpStr8List list = wpDblList(WpStr8);
|
||||
|
||||
Str8 hello = wapp_str8_lit("Hello");
|
||||
wapp_dbl_list_push_back(Str8, &list, &hello);
|
||||
WpStr8 hello = wpStr8Lit("Hello");
|
||||
wpDblListPushBack(WpStr8, &list, &hello);
|
||||
|
||||
Str8 from = wapp_str8_lit("from");
|
||||
wapp_dbl_list_push_back(Str8, &list, &from);
|
||||
WpStr8 from = wpStr8Lit("from");
|
||||
wpDblListPushBack(WpStr8, &list, &from);
|
||||
|
||||
Str8 wizapp = wapp_str8_lit("wizapp");
|
||||
wapp_dbl_list_push_back(Str8, &list, &wizapp);
|
||||
WpStr8 wizapp = wpStr8Lit("wizapp");
|
||||
wpDblListPushBack(WpStr8, &list, &wizapp);
|
||||
|
||||
Str8 stdlib = wapp_str8_lit("stdlib");
|
||||
wapp_dbl_list_push_back(Str8, &list, &stdlib);
|
||||
WpStr8 stdlib = wpStr8Lit("stdlib");
|
||||
wpDblListPushBack(WpStr8, &list, &stdlib);
|
||||
|
||||
wapp_dbl_list_empty(Str8, &list);
|
||||
wpDblListEmpty(WpStr8, &list);
|
||||
|
||||
result = list.first == NULL && list.last == NULL && list.node_count == 0 && wapp_str8_list_total_size(&list) == 0;
|
||||
result = list.first == NULL && list.last == NULL && list.node_count == 0 && wpStr8ListTotalSize(&list) == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
#include "wapp.h"
|
||||
|
||||
TestFuncResult test_str8_list_get(void);
|
||||
TestFuncResult test_str8_list_push_front(void);
|
||||
TestFuncResult test_str8_list_push_back(void);
|
||||
TestFuncResult test_str8_list_insert(void);
|
||||
TestFuncResult test_str8_list_pop_front(void);
|
||||
TestFuncResult test_str8_list_pop_back(void);
|
||||
TestFuncResult test_str8_list_remove(void);
|
||||
TestFuncResult test_str8_list_empty(void);
|
||||
WpTestFuncResult test_str8_list_get(void);
|
||||
WpTestFuncResult test_str8_list_push_front(void);
|
||||
WpTestFuncResult test_str8_list_push_back(void);
|
||||
WpTestFuncResult test_str8_list_insert(void);
|
||||
WpTestFuncResult test_str8_list_pop_front(void);
|
||||
WpTestFuncResult test_str8_list_pop_back(void);
|
||||
WpTestFuncResult test_str8_list_remove(void);
|
||||
WpTestFuncResult test_str8_list_empty(void);
|
||||
|
||||
#endif // !TEST_STR8_LIST_H
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
wapp_tester_run_tests(
|
||||
wpTesterRun(
|
||||
test_arena_allocator,
|
||||
test_arena_allocator_with_buffer,
|
||||
test_arena_allocator_temp_begin,
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
wapp_tester_run_tests(
|
||||
wpTesterRun(
|
||||
test_arena_allocator,
|
||||
test_arena_allocator_with_buffer,
|
||||
test_arena_allocator_temp_begin,
|
||||
|
||||
Reference in New Issue
Block a user