From 90403204911c97ce083ad1ef78ff3bef3666a8ab Mon Sep 17 00:00:00 2001 From: Stephanie Gawroriski Date: Sun, 15 Sep 2024 06:12:11 +0000 Subject: [PATCH] Add tests for the charseq and stream variants for string pool locating. --- .../{testStringPoolUtf.c => testStringPoolSeq.c} | 39 +++++++-------- ...{testStringPoolUtf.c => testStringPoolStream.c} | 55 ++++++++++++---------- nanocoat/tests/testStringPoolUtf.c | 2 +- 3 files changed, 50 insertions(+), 46 deletions(-) copy nanocoat/tests/{testStringPoolUtf.c => testStringPoolSeq.c} (70%) copy nanocoat/tests/{testStringPoolUtf.c => testStringPoolStream.c} (65%) diff --git a/nanocoat/tests/testStringPoolUtf.c b/nanocoat/tests/testStringPoolSeq.c similarity index 70% copy from nanocoat/tests/testStringPoolUtf.c copy to nanocoat/tests/testStringPoolSeq.c index ceae5494e0..5090f9c2b3 100644 --- a/nanocoat/tests/testStringPoolUtf.c +++ b/nanocoat/tests/testStringPoolSeq.c @@ -7,6 +7,8 @@ // See license.mkd for licensing and copyright information. // -------------------------------------------------------------------------*/ +#include + #include "sjme/nvm/stringPool.h" #include "test.h" #include "proto.h" @@ -16,14 +18,15 @@ static const sjme_lpcstr testUtf = "Squirrels!"; /** - * Tests UTF string pooling. + * Tests sequence based string pool. * * @since 2024/09/14 */ -SJME_TEST_DECLARE(testStringPoolUtf) +SJME_TEST_DECLARE(testStringPoolSeq) { sjme_stringPool stringPool; - sjme_stringPool_string string, stringTwo; + sjme_stringPool_string string; + sjme_charSeq seq; /* Create string pool. */ stringPool = NULL; @@ -32,41 +35,35 @@ SJME_TEST_DECLARE(testStringPoolUtf) stringPool == NULL) return sjme_unit_fail(test, "Could not create pool."); + /* Open char sequence over the data. */ + memset(&seq, 0, sizeof(seq)); + if (sjme_error_is(test->error = sjme_charSeq_newUtfStatic( + &seq, testUtf))) + return sjme_unit_fail(test, "Could not create char sequence."); + /* Locate string. */ string = NULL; - if (sjme_error_is(test->error = sjme_stringPool_locateUtf( - stringPool, testUtf, + if (sjme_error_is(test->error = sjme_stringPool_locateSeq( + stringPool, &seq, &string)) || string == NULL) return sjme_unit_fail(test, "Could not locate string?"); /* Check to make sure it is valid. */ - sjme_unit_equalI(test, 10, string->length, + sjme_unit_equalI(test, 9, string->length, "Length incorrect?"); sjme_unit_notEqualP(test, testUtf, string->seq.context, "Copy was not made?"); + sjme_unit_notEqualI(test, 0, strcmp("Squirrels!", string->seq.context), + "String not equal?"); /* Should be first. */ sjme_unit_equalP(test, string, stringPool->strings->elements[0], "Not placed in first pool spot?"); - - /* Locate string, again. */ - string = NULL; - if (sjme_error_is(test->error = sjme_stringPool_locateUtf( - stringPool, testUtf, - &stringTwo)) || string == NULL) - return sjme_unit_fail(test, "Could not locate string?"); - - /* Should be the same. */ - sjme_unit_equalP(test, string, stringTwo, - "Different string?"); - /* Close both. */ + /* Close string. */ if (sjme_error_is(test->error = sjme_closeable_close( SJME_AS_CLOSEABLE(string)))) return sjme_unit_fail(test, "Could not close first string?"); - if (sjme_error_is(test->error = sjme_closeable_close( - SJME_AS_CLOSEABLE(stringTwo)))) - return sjme_unit_fail(test, "Could not close second string?"); /* Close string pool. */ if (sjme_error_is(test->error = sjme_closeable_close( diff --git a/nanocoat/tests/testStringPoolUtf.c b/nanocoat/tests/testStringPoolStream.c similarity index 65% copy from nanocoat/tests/testStringPoolUtf.c copy to nanocoat/tests/testStringPoolStream.c index ceae5494e0..9075a4c6ae 100644 --- a/nanocoat/tests/testStringPoolUtf.c +++ b/nanocoat/tests/testStringPoolStream.c @@ -7,23 +7,32 @@ // See license.mkd for licensing and copyright information. // -------------------------------------------------------------------------*/ +#include + #include "sjme/nvm/stringPool.h" #include "test.h" #include "proto.h" #include "mock.h" #include "unit.h" -static const sjme_lpcstr testUtf = "Squirrels!"; +#define TEST_LEN 12 + +static const sjme_cchar testData[TEST_LEN] = +{ + 0, 10, 'S', 'q', 'u', 'i', + 'r', 'r', 'e', 'l', 's', '!' +}; /** - * Tests UTF string pooling. + * Tests stream based string pooling. * * @since 2024/09/14 */ -SJME_TEST_DECLARE(testStringPoolUtf) +SJME_TEST_DECLARE(testStringPoolStream) { sjme_stringPool stringPool; - sjme_stringPool_string string, stringTwo; + sjme_stringPool_string string; + sjme_stream_input stream; /* Create string pool. */ stringPool = NULL; @@ -32,41 +41,39 @@ SJME_TEST_DECLARE(testStringPoolUtf) stringPool == NULL) return sjme_unit_fail(test, "Could not create pool."); + /* Open stream over the data. */ + stream = NULL; + if (sjme_error_is(test->error = sjme_stream_inputOpenMemory( + test->pool, &stream, + &testData[0], TEST_LEN)) || stream == NULL) + return sjme_unit_fail(test, "Could not open stream."); + /* Locate string. */ string = NULL; - if (sjme_error_is(test->error = sjme_stringPool_locateUtf( - stringPool, testUtf, + if (sjme_error_is(test->error = sjme_stringPool_locateStream( + stringPool, stream, &string)) || string == NULL) return sjme_unit_fail(test, "Could not locate string?"); + /* Close stream. */ + if (sjme_error_is(test->error = sjme_closeable_close( + SJME_AS_CLOSEABLE(stream)))) + return sjme_unit_fail(test, "Could not close stream."); + /* Check to make sure it is valid. */ - sjme_unit_equalI(test, 10, string->length, + sjme_unit_equalI(test, 9, string->length, "Length incorrect?"); - sjme_unit_notEqualP(test, testUtf, string->seq.context, - "Copy was not made?"); + sjme_unit_notEqualI(test, 0, strcmp("Squirrels!", string->seq.context), + "String not equal?"); /* Should be first. */ sjme_unit_equalP(test, string, stringPool->strings->elements[0], "Not placed in first pool spot?"); - - /* Locate string, again. */ - string = NULL; - if (sjme_error_is(test->error = sjme_stringPool_locateUtf( - stringPool, testUtf, - &stringTwo)) || string == NULL) - return sjme_unit_fail(test, "Could not locate string?"); - /* Should be the same. */ - sjme_unit_equalP(test, string, stringTwo, - "Different string?"); - - /* Close both. */ + /* Close string. */ if (sjme_error_is(test->error = sjme_closeable_close( SJME_AS_CLOSEABLE(string)))) return sjme_unit_fail(test, "Could not close first string?"); - if (sjme_error_is(test->error = sjme_closeable_close( - SJME_AS_CLOSEABLE(stringTwo)))) - return sjme_unit_fail(test, "Could not close second string?"); /* Close string pool. */ if (sjme_error_is(test->error = sjme_closeable_close( diff --git a/nanocoat/tests/testStringPoolUtf.c b/nanocoat/tests/testStringPoolUtf.c index ceae5494e0..483e38fd99 100644 --- a/nanocoat/tests/testStringPoolUtf.c +++ b/nanocoat/tests/testStringPoolUtf.c @@ -40,7 +40,7 @@ SJME_TEST_DECLARE(testStringPoolUtf) return sjme_unit_fail(test, "Could not locate string?"); /* Check to make sure it is valid. */ - sjme_unit_equalI(test, 10, string->length, + sjme_unit_equalI(test, 9, string->length, "Length incorrect?"); sjme_unit_notEqualP(test, testUtf, string->seq.context, "Copy was not made?"); -- 2.11.4.GIT