all repos — mgba @ d0f404a6ba7c0588d3a3c7b43225a32f4fc2d8a6

mGBA Game Boy Advance Emulator

Util Test: Add VFile memory truncate tests
Jeffrey Pfau jeffrey@endrift.com
Fri, 21 Oct 2016 23:08:01 -0700
commit

d0f404a6ba7c0588d3a3c7b43225a32f4fc2d8a6

parent

8561c80a1c43392523ca3be614f2ae8d72b3a469

1 files changed, 40 insertions(+), 1 deletions(-)

jump to
M src/util/test/vfs.csrc/util/test/vfs.c

@@ -71,6 +71,42 @@ assert_int_equal(vf->size(vf), 32);

vf->close(vf); } +M_TEST_DEFINE(resizeMem) { + uint8_t bytes[32]; + struct VFile* vf = VFileFromMemory(bytes, 32); + assert_non_null(vf); + assert_int_equal(vf->size(vf), 32); + vf->truncate(vf, 64); + assert_int_equal(vf->size(vf), 32); + vf->truncate(vf, 16); + assert_int_equal(vf->size(vf), 32); + vf->close(vf); +} + +M_TEST_DEFINE(resizeConstMem) { + uint8_t bytes[32]; + struct VFile* vf = VFileFromConstMemory(bytes, 32); + assert_non_null(vf); + assert_int_equal(vf->size(vf), 32); + vf->truncate(vf, 64); + assert_int_equal(vf->size(vf), 32); + vf->truncate(vf, 16); + assert_int_equal(vf->size(vf), 32); + vf->close(vf); +} + +M_TEST_DEFINE(resizeMemChunk) { + uint8_t bytes[32]; + struct VFile* vf = VFileMemChunk(bytes, 32); + assert_non_null(vf); + assert_int_equal(vf->size(vf), 32); + vf->truncate(vf, 64); + assert_int_equal(vf->size(vf), 64); + vf->truncate(vf, 16); + assert_int_equal(vf->size(vf), 16); + vf->close(vf); +} + M_TEST_SUITE_DEFINE(VFS, #if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 cmocka_unit_test(openNullPathR),

@@ -84,4 +120,7 @@ cmocka_unit_test(openNullConstMem0),

cmocka_unit_test(openNullConstMemNonzero), cmocka_unit_test(openNullMemChunk0), cmocka_unit_test(openNonNullMemChunk0), - cmocka_unit_test(openNullMemChunkNonzero)) + cmocka_unit_test(openNullMemChunkNonzero), + cmocka_unit_test(resizeMem), + cmocka_unit_test(resizeConstMem), + cmocka_unit_test(resizeMemChunk))