Implement Windows file IO

This commit is contained in:
2026-01-03 03:15:25 +00:00
parent fac9cb57eb
commit b372447a46
6 changed files with 236 additions and 20 deletions

View File

@@ -15,12 +15,12 @@ wapp_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_BIN_EX);
test_fp = wapp_file_open(&arena, &test_filename, WAPP_ACCESS_WRITE_EX);
return wapp_tester_result(test_fp != NULL);
}
TestFuncResult test_wapp_file_get_current_position(void) {
u64 pos = wapp_file_get_current_position(test_fp);
i64 pos = wapp_file_get_current_position(test_fp);
return wapp_tester_result(pos == 0);
}
@@ -47,8 +47,14 @@ TestFuncResult test_wapp_file_read(void) {
u64 count = wapp_file_read((void *)dst_buf, test_fp, byte_count);
b8 result = count == byte_count;
for (u64 i = 0; i < DST_CAPACITY; ++i) {
result = result && (dst_buf[i] == *wapp_array_get(i32, src_array1, i));
// 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] == *wapp_array_get(i32, src_array1, index));
++index;
running = index < DST_CAPACITY;
}
return wapp_tester_result(result);
@@ -58,9 +64,9 @@ TestFuncResult test_wapp_file_write(void) {
wapp_file_seek(test_fp, 0, WAPP_SEEK_END);
u64 expected_count = wapp_array_count(src_array2) * wapp_array_item_size(src_array2);
u64 count = wapp_file_write((void *)src_array2, test_fp, expected_count);
i64 count = wapp_file_write((void *)src_array2, test_fp, expected_count);
return wapp_tester_result(count == expected_count);
return wapp_tester_result(count >= 0 && (u64)count == expected_count);
}
TestFuncResult test_wapp_file_read_array(void) {
@@ -70,8 +76,14 @@ TestFuncResult test_wapp_file_read_array(void) {
b8 result = count == wapp_array_count(src_array1) &&
wapp_array_count(dst_array) == wapp_array_count(src_array1);
for (u64 i = 0; i < wapp_array_count(dst_array); ++i) {
result = result && (*wapp_array_get(i32, dst_array, i) == *wapp_array_get(i32, src_array1, i));
// 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));
++index;
running = index < wapp_array_count(dst_array);
}
return wapp_tester_result(result);
@@ -80,9 +92,9 @@ TestFuncResult test_wapp_file_read_array(void) {
TestFuncResult test_wapp_file_write_array(void) {
wapp_file_seek(test_fp, 0, WAPP_SEEK_END);
u64 count = wapp_file_write_array((GenericArray)src_array3, test_fp, wapp_array_count(src_array3));
i64 count = wapp_file_write_array((GenericArray)src_array3, test_fp, wapp_array_count(src_array3));
return wapp_tester_result(count == wapp_array_count(src_array3));
return wapp_tester_result(count >= 0 && (u64)count == wapp_array_count(src_array3));
}
TestFuncResult test_wapp_file_flush(void) {

View File

@@ -19,12 +19,12 @@ TestFuncResult test_wapp_file_open(void) {
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_BIN_EX);
test_fp = wapp_file_open(&arena, &test_filename, WAPP_ACCESS_WRITE_EX);
return wapp_tester_result(test_fp != NULL);
}
TestFuncResult test_wapp_file_get_current_position(void) {
u64 pos = wapp_file_get_current_position(test_fp);
i64 pos = wapp_file_get_current_position(test_fp);
return wapp_tester_result(pos == 0);
}
@@ -51,8 +51,14 @@ TestFuncResult test_wapp_file_read(void) {
u64 count = wapp_file_read((void *)dst_buf, test_fp, byte_count);
b8 result = count == byte_count;
for (u64 i = 0; i < DST_CAPACITY; ++i) {
result = result && (dst_buf[i] == *wapp_array_get(i32, src_array1, i));
// 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] == *wapp_array_get(i32, src_array1, index));
++index;
running = index < DST_CAPACITY;
}
return wapp_tester_result(result);
@@ -62,9 +68,9 @@ TestFuncResult test_wapp_file_write(void) {
wapp_file_seek(test_fp, 0, WAPP_SEEK_END);
u64 expected_count = wapp_array_count(src_array2) * wapp_array_item_size(src_array2);
u64 count = wapp_file_write((void *)src_array2, test_fp, expected_count);
i64 count = wapp_file_write((void *)src_array2, test_fp, expected_count);
return wapp_tester_result(count == expected_count);
return wapp_tester_result(count >= 0 && (u64)count == expected_count);
}
TestFuncResult test_wapp_file_read_array(void) {
@@ -74,8 +80,14 @@ TestFuncResult test_wapp_file_read_array(void) {
b8 result = count == wapp_array_count(src_array1) &&
wapp_array_count(dst_array) == wapp_array_count(src_array1);
for (u64 i = 0; i < wapp_array_count(dst_array); ++i) {
result = result && (*wapp_array_get(i32, dst_array, i) == *wapp_array_get(i32, src_array1, i));
// 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));
++index;
running = index < wapp_array_count(dst_array);
}
return wapp_tester_result(result);
@@ -84,9 +96,9 @@ TestFuncResult test_wapp_file_read_array(void) {
TestFuncResult test_wapp_file_write_array(void) {
wapp_file_seek(test_fp, 0, WAPP_SEEK_END);
u64 count = wapp_file_write_array((GenericArray)src_array3, test_fp, wapp_array_count(src_array3));
i64 count = wapp_file_write_array((GenericArray)src_array3, test_fp, wapp_array_count(src_array3));
return wapp_tester_result(count == wapp_array_count(src_array3));
return wapp_tester_result(count >= 0 && (u64)count == wapp_array_count(src_array3));
}
TestFuncResult test_wapp_file_flush(void) {