Files
wizapp-stdlib/tests/file/test_file.c
T
abdelrahman a998f6b981
Release / release (push) Successful in 8s
Standardize naming conventions (#12)
## 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>
2026-06-26 17:17:27 +00:00

119 lines
3.9 KiB
C

// vim:fileencoding=utf-8:foldmethod=marker
#include "test_file.h"
#define DST_CAPACITY 5
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};
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);
}
WpTestFuncResult test_wapp_file_get_current_position(void) {
i64 pos = wpFileGetCurrentPosition(test_fp);
return wpTesterResult(pos == 0);
}
WpTestFuncResult test_wapp_file_seek(void) {
wpFileWriteArray((WpArray)src_array1, test_fp, wpArrayCount(src_array1));
i64 seek_result = wpFileSeek(test_fp, 0, WP_SEEK_END);
b8 result = seek_result == (i64)(wpArrayCount(src_array1) * wpArrayItemSize(src_array1));
wpFileSeek(test_fp, 0, WP_SEEK_START);
return wpTesterResult(result);
}
WpTestFuncResult test_wapp_file_get_length(void) {
i64 length = wpFileGetLength(test_fp);
return wpTesterResult(length == (i64)(wpArrayCount(src_array1) * wpArrayItemSize(src_array1)));
}
WpTestFuncResult test_wapp_file_read(void) {
wpFileSeek(test_fp, 0, WP_SEEK_START);
u64 byte_count = DST_CAPACITY * sizeof(i32);
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
// MSVC Spectre mitigation warnings
u64 index = 0;
b8 running = true;
while (running) {
result = result && (dst_buf[index] == *wpArrayGet(i32, src_array1, index));
++index;
running = index < DST_CAPACITY;
}
return wpTesterResult(result);
}
WpTestFuncResult test_wapp_file_write(void) {
wpFileSeek(test_fp, 0, WP_SEEK_END);
u64 expected_count = wpArrayCount(src_array2) * wpArrayItemSize(src_array2);
i64 count = wpFileWrite((void *)src_array2, test_fp, expected_count);
return wpTesterResult(count >= 0 && (u64)count == expected_count);
}
WpTestFuncResult test_wapp_file_read_array(void) {
wpFileSeek(test_fp, 0, WP_SEEK_START);
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 && (*wpArrayGet(i32, dst_array, index) == *wpArrayGet(i32, src_array1, index));
++index;
running = index < wpArrayCount(dst_array);
}
return wpTesterResult(result);
}
WpTestFuncResult test_wapp_file_write_array(void) {
wpFileSeek(test_fp, 0, WP_SEEK_END);
i64 count = wpFileWriteArray((WpArray)src_array3, test_fp, wpArrayCount(src_array3));
return wpTesterResult(count >= 0 && (u64)count == wpArrayCount(src_array3));
}
WpTestFuncResult test_wapp_file_flush(void) {
i32 flush_result = wpFileFlush(test_fp);
return wpTesterResult(flush_result == 0);
}
WpTestFuncResult test_wapp_file_close(void) {
i32 close_result = wpFileClose(test_fp);
return wpTesterResult(close_result == 0);
}
WpTestFuncResult test_wapp_file_rename(void) {
i32 rename_result = wpFileRename(&test_filename, &new_filename);
return wpTesterResult(rename_result == 0);
}
WpTestFuncResult test_wapp_file_remove(void) {
i32 remove_result = wpFileRemove(&new_filename);
return wpTesterResult(remove_result == 0);
}