String.h
Some checks failed
Build Dusk / run-tests (push) Successful in 2m2s
Build Dusk / build-linux (push) Successful in 2m1s
Build Dusk / build-psp (push) Failing after 1m21s

This commit is contained in:
2026-01-05 17:20:17 -06:00
parent a793ac2ff7
commit 83b799caa8
7 changed files with 1007 additions and 18 deletions

View File

@@ -65,6 +65,12 @@ static void test_memoryCopy(void **state) {
// Cannot copy to itself
expect_assert_failure(memoryCopy(src, src, size));
// Overlapping regions (should assert)
void *overlap = memoryAllocate(size * 2);
expect_assert_failure(memoryCopy((uint8_t*)overlap, (uint8_t*)overlap + 8, size));
expect_assert_failure(memoryCopy((uint8_t*)overlap + 8, (uint8_t*)overlap, size));
memoryFree(overlap);
memoryFree(src);
memoryFree(dest);
}
@@ -91,6 +97,12 @@ static void test_memorySet(void **state) {
// Canot set 0 bytes
expect_assert_failure(memorySet(ptr, 0x00, 0));
// Set with value outside 0-255 (should be cast to uint8_t)
memorySet(ptr, 0x1FF, size);
for(size_t i = 0; i < size; i++) {
assert_int_equal(((uint8_t*)ptr)[i], 0xFF);
}
memoryFree(ptr);
}
@@ -139,6 +151,10 @@ static void test_memoryCopyRangeSafe(void **state) {
uint8_t expected[10] = {3, 4, 5, 6, 7}; // Expected data in dest
assert_memory_equal(dest, expected, 5);
// Copy entire buffer
memoryCopyRangeSafe(dest, src, (uint8_t*)src + size, size);
assert_memory_equal(dest, src, size);
// Cannot copy to NULL destination
expect_assert_failure(memoryCopyRangeSafe(NULL, src, (uint8_t*)src + 5, size));
@@ -187,6 +203,15 @@ static void test_memoryMove(void **state) {
}
assert_memory_equal(ptr, expected, size + 5);
// Overlap backward: move ptr[5..19] to ptr[0..14]
for(size_t i = 0; i < size + 5; i++) {
((uint8_t*)ptr)[i] = (uint8_t)(i + 1);
}
memoryMove(ptr, (uint8_t*)ptr + 5, size);
for(size_t i = 0; i < size; i++) {
assert_int_equal(((uint8_t*)ptr)[i], (uint8_t)(i + 6));
}
// Cannot move to NULL
expect_assert_failure(memoryMove(NULL, ptr, size));
@@ -243,6 +268,9 @@ static void test_memoryCompare(void **state) {
// Cannot compare 0 bytes
expect_assert_failure(memoryCompare(a, b, 0));
// Compare different sizes (should assert, so we only test the API contract)
// Not possible with current API, as size is explicit, but document intent.
memoryFree(a);
memoryFree(b);
}