all repos — mgba @ 57894955a2741b2a96d91fc40d31cc9c87b41d05

mGBA Game Boy Advance Emulator

Util: Fix TBL control characters
Jeffrey Pfau jeffrey@endrift.com
Tue, 01 Nov 2016 15:51:14 -0700
commit

57894955a2741b2a96d91fc40d31cc9c87b41d05

parent

e4c8b617095d0e1603d7636eaa36e05cfe9b21e9

2 files changed, 63 insertions(+), 4 deletions(-)

jump to
M src/util/test/text-codec.csrc/util/test/text-codec.c

@@ -766,6 +766,64 @@ TextCodecDeinit(&codec);

vf->close(vf); } +M_TEST_DEFINE(controlCodes) { + static const char file[] = + "*=01\n" + "/=02\n" + "\\=03"; + struct VFile* vf = VFileFromConstMemory(file, sizeof(file) - 1); + struct TextCodec codec; + assert_true(TextCodecLoadTBL(&codec, vf, true)); + struct TextCodecIterator iter; + uint8_t output[16] = {}; + size_t len; + + len = 0; + TextCodecStartDecode(&codec, &iter); + len += TextCodecAdvance(&iter, 1, output + len, sizeof(output) - len); + len += TextCodecFinish(&iter, output + len, sizeof(output) - len); + assert_int_equal(len, 1); + assert_memory_equal(output, "\n", 1); + + len = 0; + TextCodecStartDecode(&codec, &iter); + len += TextCodecAdvance(&iter, 2, output + len, sizeof(output) - len); + len += TextCodecFinish(&iter, output + len, sizeof(output) - len); + assert_int_equal(len, 1); + assert_memory_equal(output, "\x1F", 1); + + len = 0; + TextCodecStartDecode(&codec, &iter); + len += TextCodecAdvance(&iter, 3, output + len, sizeof(output) - len); + len += TextCodecFinish(&iter, output + len, sizeof(output) - len); + assert_int_equal(len, 1); + assert_memory_equal(output, "\x1E", 1); + + len = 0; + TextCodecStartEncode(&codec, &iter); + len += TextCodecAdvance(&iter, '\n', output + len, sizeof(output) - len); + len += TextCodecFinish(&iter, output + len, sizeof(output) - len); + assert_int_equal(len, 1); + assert_memory_equal(output, "\1", 1); + + len = 0; + TextCodecStartEncode(&codec, &iter); + len += TextCodecAdvance(&iter, '\x1F', output + len, sizeof(output) - len); + len += TextCodecFinish(&iter, output + len, sizeof(output) - len); + assert_int_equal(len, 1); + assert_memory_equal(output, "\2", 1); + + len = 0; + TextCodecStartEncode(&codec, &iter); + len += TextCodecAdvance(&iter, '\x1E', output + len, sizeof(output) - len); + len += TextCodecFinish(&iter, output + len, sizeof(output) - len); + assert_int_equal(len, 1); + assert_memory_equal(output, "\3", 1); + + TextCodecDeinit(&codec); + vf->close(vf); +} + M_TEST_SUITE_DEFINE(TextCodec, cmocka_unit_test(emptyCodec), cmocka_unit_test(singleEntry),

@@ -775,4 +833,5 @@ cmocka_unit_test(longEntry),

cmocka_unit_test(longEntryReverse), cmocka_unit_test(overlappingEntry), cmocka_unit_test(overlappingEntryReverse), - cmocka_unit_test(raggedEntry)) + cmocka_unit_test(raggedEntry), + cmocka_unit_test(controlCodes))
M src/util/text-codec.csrc/util/text-codec.c

@@ -79,13 +79,13 @@ uint8_t value;

if (!hex8(lineBuffer, &value)) { switch (lineBuffer[0]) { case '*': - wordBuffer[0] = '\n'; + lineBuffer[0] = '\n'; break; case '\\': - wordBuffer[0] = '\x30'; + lineBuffer[0] = '\x1E'; break; case '/': - wordBuffer[0] = '\x31'; + lineBuffer[0] = '\x1F'; break; default: return false;