Files
wizapp-stdlib/tests/cpath/test_cpath.cc
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

202 lines
5.5 KiB
C++

#include "test_cpath.h"
#include "wapp.h"
#include <string.h>
#include <stdio.h>
#define MAIN_BUF_SIZE 4096
#define TMP_BUF_SIZE 1024
WpTestFuncResult test_cpath_join_path(void) {
b8 result;
WpStr8 expected = wpStr8Buf(MAIN_BUF_SIZE);
WpStr8 out = wpStr8Buf(MAIN_BUF_SIZE);
WpStr8 tmp = wpStr8Buf(TMP_BUF_SIZE);
wpStr8Format(&expected, "%chome%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
wpStr8Format(&tmp, "%c", WP_PATH_SEP);
WpStr8List parts = wpDblList(WpStr8);
wpDblListPushBack(WpStr8, &parts, &tmp);
WpStr8 home = wpStr8Lit("home");
wpDblListPushBack(WpStr8, &parts, &home);
WpStr8 user = wpStr8Lit("abdelrahman");
wpDblListPushBack(WpStr8, &parts, &user);
WpStr8 docs = wpStr8Lit("Documents");
wpDblListPushBack(WpStr8, &parts, &docs);
wpCpathJoinPath(&out, &parts);
result = wpStr8Equal(&out, &expected);
wpDblListPopFront(WpStr8, &parts);
wpStr8Format(&expected, "home%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP);
wpCpathJoinPath(&out, &parts);
result = result && wpStr8Equal(&out, &expected);
WpStr8RO str = wpStr8LitRo("home");
wpStr8ConcatCapped(&tmp, &str);
wpDblListPopFront(WpStr8, &parts);
wpDblListPushFront(WpStr8, &parts, &tmp);
wpStr8Format(&expected, "%chome%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
wpCpathJoinPath(&out, &parts);
result = result && wpStr8Equal(&out, &expected);
wpStr8Format(&tmp, "home%c", WP_PATH_SEP);
wpDblListPopFront(WpStr8, &parts);
WpStr8 home_2 = wpStr8Lit("home");
wpDblListPushFront(WpStr8, &parts, &home_2);
wpStr8Format(&expected, "home%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP);
wpCpathJoinPath(&out, &parts);
result = result && wpStr8Equal(&out, &expected);
wpDblListEmpty(WpStr8, &parts);
wpStr8Format(&tmp, "%chome", WP_PATH_SEP);
wpDblListPushBack(WpStr8, &parts, &tmp);
WpStr8 empty = wpStr8Lit("");
wpDblListPushBack(WpStr8, &parts, &empty);
wpStr8Format(&expected, "%chome", WP_PATH_SEP);
wpCpathJoinPath(&out, &parts);
result = result && wpStr8Equal(&out, &expected);
wpDblListPopFront(WpStr8, &parts);
WpStr8 empty_2 = wpStr8Lit("");
wpDblListPushBack(WpStr8, &parts, &empty_2);
wpStr8Format(&expected, "%s", "");
wpCpathJoinPath(&out, &parts);
result = result && wpStr8Equal(&out, &expected);
wpDblListPopBack(WpStr8, &parts);
WpStr8 home_3 = wpStr8Lit("home");
wpDblListPushBack(WpStr8, &parts, &home_3);
wpStr8CopyCstrCapped(&expected, "home");
wpCpathJoinPath(&out, &parts);
result = result && wpStr8Equal(&out, &expected);
return wpTesterResult(result);
}
WpTestFuncResult test_cpath_dirname(void) {
WpAllocator arena = wpMemArenaAllocatorInit(MiB(8));
if (wpMemAllocatorInvalid(&arena)) {
return wpTesterResult(false);
}
b8 result;
WpStr8 *output = nullptr;
WpStr8 expected = wpStr8Buf(MAIN_BUF_SIZE);
WpStr8 tmp = wpStr8Buf(TMP_BUF_SIZE);
// CASE 1
wpStr8Format(&tmp, "%c", WP_PATH_SEP);
wpStr8Format(&expected, "%c", WP_PATH_SEP);
output = wpCpathDirname(&arena, &tmp);
result = output != nullptr && wpStr8Equal(output, &expected);
// CASE 2
wpStr8Format(&expected, "%s", ".");
WpStr8 path = wpStr8Lit("home");
output = wpCpathDirname(&arena, &path);
result = result && output != nullptr && wpStr8Equal(output, &expected);
// CASE 3
path = wpStr8Lit("");
output = wpCpathDirname(&arena, &path);
result = result && output != nullptr && wpStr8Equal(output, &expected);
// CASE 4
wpStr8Format(&tmp, "%chome%ctest", WP_PATH_SEP, WP_PATH_SEP);
wpStr8Format(&expected, "%chome", WP_PATH_SEP);
output = wpCpathDirname(&arena, &tmp);
result = result && output != nullptr && wpStr8Equal(output, &expected);
// CASE 5
wpStr8Format(&tmp, "%chome%ctest%c", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
wpStr8Format(&expected, "%chome", WP_PATH_SEP);
output = wpCpathDirname(&arena, &tmp);
result = result && output != nullptr && wpStr8Equal(output, &expected);
wpMemArenaAllocatorDestroy(&arena);
return wpTesterResult(result);
}
WpTestFuncResult test_cpath_dirup(void) {
WpAllocator arena = wpMemArenaAllocatorInit(MiB(8));
if (wpMemAllocatorInvalid(&arena)) {
return wpTesterResult(false);
}
b8 result;
WpStr8 *output = nullptr;
WpStr8 expected = wpStr8Buf(MAIN_BUF_SIZE);
WpStr8 tmp = wpStr8Buf(TMP_BUF_SIZE);
// CASE 1
wpStr8Format(&tmp, "%c", WP_PATH_SEP);
wpStr8Format(&expected, "%c", WP_PATH_SEP);
output = wpCpathDirup(&arena, &tmp, 3);
result = output != nullptr && wpStr8Equal(output, &expected);
// CASE 2
wpStr8Format(&tmp, "%chome%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
wpStr8Format(&expected, "%c", WP_PATH_SEP);
output = wpCpathDirup(&arena, &tmp, 3);
result = result && output != nullptr && wpStr8Equal(output, &expected);
// CASE 3
wpStr8Format(&tmp, "home%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP);
wpStr8CopyCstrCapped(&expected, ".");
output = wpCpathDirup(&arena, &tmp, 3);
result = result && output != nullptr && wpStr8Equal(output, &expected);
// CASE 4
wpStr8Format(&tmp, "%chome%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP, WP_PATH_SEP);
wpStr8Format(&expected, "%chome", WP_PATH_SEP);
output = wpCpathDirup(&arena, &tmp, 2);
result = result && output != nullptr && wpStr8Equal(output, &expected);
// CASE 5
wpStr8Format(&tmp, "home%cabdelrahman%cDocuments", WP_PATH_SEP, WP_PATH_SEP);
wpStr8CopyCstrCapped(&expected, "home");
output = wpCpathDirup(&arena, &tmp, 2);
result = result && output != nullptr && wpStr8Equal(output, &expected);
wpMemArenaAllocatorDestroy(&arena);
return wpTesterResult(result);
}