diff --git a/tests/unit/include/unit_test.h b/tests/unit/include/unit_test.h index b62c2d901d..bf5b5cae01 100644 --- a/tests/unit/include/unit_test.h +++ b/tests/unit/include/unit_test.h @@ -1,7 +1,7 @@ // Copyright © 2024 Rot127 // SPDX-License-Identifier: BSD-3 -#define CHECK_EQUAL_RET_FALSE(OS, str) \ +#define CHECK_OS_EQUAL_RET_FALSE(OS, str) \ do { \ if (strcmp(OS.buffer, str) != 0) { \ printf("OS.buffer != str\n"); \ diff --git a/tests/unit/sstream.c b/tests/unit/sstream.c index f43fef1cbf..8f60485759 100644 --- a/tests/unit/sstream.c +++ b/tests/unit/sstream.c @@ -65,22 +65,22 @@ static bool test_markup_os() SStream OS = { 0 }; SStream_Init(&OS); SStream_concat0(&OS, "0"); - CHECK_EQUAL_RET_FALSE(OS, "0"); + CHECK_OS_EQUAL_RET_FALSE(OS, "0"); OS.markup_stream = true; printUInt64(&OS, 0); - CHECK_EQUAL_RET_FALSE(OS, "00"); + CHECK_OS_EQUAL_RET_FALSE(OS, "00"); markup_OS(&OS, Markup_Immediate); printUInt64(&OS, 0); - CHECK_EQUAL_RET_FALSE(OS, "00"); + CHECK_OS_EQUAL_RET_FALSE(OS, "00"); markup_OS(&OS, Markup_Memory); printUInt32(&OS, 0); - CHECK_EQUAL_RET_FALSE(OS, "00"); + CHECK_OS_EQUAL_RET_FALSE(OS, "00"); markup_OS(&OS, Markup_Target); printUInt32(&OS, 0); - CHECK_EQUAL_RET_FALSE(OS, "00"); + CHECK_OS_EQUAL_RET_FALSE(OS, "00"); markup_OS(&OS, Markup_Register); SStream_concat0(&OS, "r19"); - CHECK_EQUAL_RET_FALSE(OS, "00"); + CHECK_OS_EQUAL_RET_FALSE(OS, "00"); return true; } @@ -91,27 +91,27 @@ bool test_printint8() SStream OS = { 0 }; SStream_Init(&OS); printInt8(&OS, HEX_THRESHOLD + 1); - CHECK_EQUAL_RET_FALSE(OS, "0xa"); + CHECK_OS_EQUAL_RET_FALSE(OS, "0xa"); SStream_Flush(&OS, NULL); printInt8(&OS, HEX_THRESHOLD); - CHECK_EQUAL_RET_FALSE(OS, "9"); + CHECK_OS_EQUAL_RET_FALSE(OS, "9"); SStream_Flush(&OS, NULL); printInt8(&OS, -(HEX_THRESHOLD + 1)); - CHECK_EQUAL_RET_FALSE(OS, "-0xa"); + CHECK_OS_EQUAL_RET_FALSE(OS, "-0xa"); SStream_Flush(&OS, NULL); printInt8(&OS, -HEX_THRESHOLD); - CHECK_EQUAL_RET_FALSE(OS, "-9"); + CHECK_OS_EQUAL_RET_FALSE(OS, "-9"); SStream_Flush(&OS, NULL); printInt8(&OS, INT8_MAX); - CHECK_EQUAL_RET_FALSE(OS, "0x7f"); + CHECK_OS_EQUAL_RET_FALSE(OS, "0x7f"); SStream_Flush(&OS, NULL); printInt8(&OS, INT8_MIN); - CHECK_EQUAL_RET_FALSE(OS, "-0x80"); + CHECK_OS_EQUAL_RET_FALSE(OS, "-0x80"); SStream_Flush(&OS, NULL); return true; } @@ -123,27 +123,27 @@ bool test_printint16() SStream OS = { 0 }; SStream_Init(&OS); printInt16(&OS, HEX_THRESHOLD + 1); - CHECK_EQUAL_RET_FALSE(OS, "0xa"); + CHECK_OS_EQUAL_RET_FALSE(OS, "0xa"); SStream_Flush(&OS, NULL); printInt16(&OS, HEX_THRESHOLD); - CHECK_EQUAL_RET_FALSE(OS, "9"); + CHECK_OS_EQUAL_RET_FALSE(OS, "9"); SStream_Flush(&OS, NULL); printInt16(&OS, -(HEX_THRESHOLD + 1)); - CHECK_EQUAL_RET_FALSE(OS, "-0xa"); + CHECK_OS_EQUAL_RET_FALSE(OS, "-0xa"); SStream_Flush(&OS, NULL); printInt16(&OS, -HEX_THRESHOLD); - CHECK_EQUAL_RET_FALSE(OS, "-9"); + CHECK_OS_EQUAL_RET_FALSE(OS, "-9"); SStream_Flush(&OS, NULL); printInt16(&OS, INT16_MAX); - CHECK_EQUAL_RET_FALSE(OS, "0x7fff"); + CHECK_OS_EQUAL_RET_FALSE(OS, "0x7fff"); SStream_Flush(&OS, NULL); printInt16(&OS, INT16_MIN); - CHECK_EQUAL_RET_FALSE(OS, "-0x8000"); + CHECK_OS_EQUAL_RET_FALSE(OS, "-0x8000"); SStream_Flush(&OS, NULL); return true; } @@ -155,27 +155,27 @@ bool test_printint32() SStream OS = { 0 }; SStream_Init(&OS); printInt32(&OS, HEX_THRESHOLD + 1); - CHECK_EQUAL_RET_FALSE(OS, "0xa"); + CHECK_OS_EQUAL_RET_FALSE(OS, "0xa"); SStream_Flush(&OS, NULL); printInt32(&OS, HEX_THRESHOLD); - CHECK_EQUAL_RET_FALSE(OS, "9"); + CHECK_OS_EQUAL_RET_FALSE(OS, "9"); SStream_Flush(&OS, NULL); printInt32(&OS, -(HEX_THRESHOLD + 1)); - CHECK_EQUAL_RET_FALSE(OS, "-0xa"); + CHECK_OS_EQUAL_RET_FALSE(OS, "-0xa"); SStream_Flush(&OS, NULL); printInt32(&OS, -HEX_THRESHOLD); - CHECK_EQUAL_RET_FALSE(OS, "-9"); + CHECK_OS_EQUAL_RET_FALSE(OS, "-9"); SStream_Flush(&OS, NULL); printInt32(&OS, INT32_MAX); - CHECK_EQUAL_RET_FALSE(OS, "0x7fffffff"); + CHECK_OS_EQUAL_RET_FALSE(OS, "0x7fffffff"); SStream_Flush(&OS, NULL); printInt32(&OS, INT32_MIN); - CHECK_EQUAL_RET_FALSE(OS, "-0x80000000"); + CHECK_OS_EQUAL_RET_FALSE(OS, "-0x80000000"); SStream_Flush(&OS, NULL); return true; } @@ -187,27 +187,27 @@ bool test_printint64() SStream OS = { 0 }; SStream_Init(&OS); printInt64(&OS, HEX_THRESHOLD + 1); - CHECK_EQUAL_RET_FALSE(OS, "0xa"); + CHECK_OS_EQUAL_RET_FALSE(OS, "0xa"); SStream_Flush(&OS, NULL); printInt64(&OS, HEX_THRESHOLD); - CHECK_EQUAL_RET_FALSE(OS, "9"); + CHECK_OS_EQUAL_RET_FALSE(OS, "9"); SStream_Flush(&OS, NULL); printInt64(&OS, -(HEX_THRESHOLD + 1)); - CHECK_EQUAL_RET_FALSE(OS, "-0xa"); + CHECK_OS_EQUAL_RET_FALSE(OS, "-0xa"); SStream_Flush(&OS, NULL); printInt64(&OS, -HEX_THRESHOLD); - CHECK_EQUAL_RET_FALSE(OS, "-9"); + CHECK_OS_EQUAL_RET_FALSE(OS, "-9"); SStream_Flush(&OS, NULL); printInt64(&OS, INT64_MAX); - CHECK_EQUAL_RET_FALSE(OS, "0x7fffffffffffffff"); + CHECK_OS_EQUAL_RET_FALSE(OS, "0x7fffffffffffffff"); SStream_Flush(&OS, NULL); printInt64(&OS, INT64_MIN); - CHECK_EQUAL_RET_FALSE(OS, "-0x8000000000000000"); + CHECK_OS_EQUAL_RET_FALSE(OS, "-0x8000000000000000"); SStream_Flush(&OS, NULL); return true; } @@ -219,27 +219,27 @@ bool test_printint32_bang() SStream OS = { 0 }; SStream_Init(&OS); printInt32Bang(&OS, HEX_THRESHOLD + 1); - CHECK_EQUAL_RET_FALSE(OS, "#0xa"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#0xa"); SStream_Flush(&OS, NULL); printInt32Bang(&OS, HEX_THRESHOLD); - CHECK_EQUAL_RET_FALSE(OS, "#9"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#9"); SStream_Flush(&OS, NULL); printInt32Bang(&OS, -(HEX_THRESHOLD + 1)); - CHECK_EQUAL_RET_FALSE(OS, "#-0xa"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#-0xa"); SStream_Flush(&OS, NULL); printInt32Bang(&OS, -HEX_THRESHOLD); - CHECK_EQUAL_RET_FALSE(OS, "#-9"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#-9"); SStream_Flush(&OS, NULL); printInt32Bang(&OS, INT32_MAX); - CHECK_EQUAL_RET_FALSE(OS, "#0x7fffffff"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#0x7fffffff"); SStream_Flush(&OS, NULL); printInt32Bang(&OS, INT32_MIN); - CHECK_EQUAL_RET_FALSE(OS, "#-0x80000000"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#-0x80000000"); SStream_Flush(&OS, NULL); return true; } @@ -251,27 +251,27 @@ bool test_printint64_bang() SStream OS = { 0 }; SStream_Init(&OS); printInt64Bang(&OS, HEX_THRESHOLD + 1); - CHECK_EQUAL_RET_FALSE(OS, "#0xa"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#0xa"); SStream_Flush(&OS, NULL); printInt64Bang(&OS, HEX_THRESHOLD); - CHECK_EQUAL_RET_FALSE(OS, "#9"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#9"); SStream_Flush(&OS, NULL); printInt64Bang(&OS, -(HEX_THRESHOLD + 1)); - CHECK_EQUAL_RET_FALSE(OS, "#-0xa"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#-0xa"); SStream_Flush(&OS, NULL); printInt64Bang(&OS, -HEX_THRESHOLD); - CHECK_EQUAL_RET_FALSE(OS, "#-9"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#-9"); SStream_Flush(&OS, NULL); printInt64Bang(&OS, INT64_MAX); - CHECK_EQUAL_RET_FALSE(OS, "#0x7fffffffffffffff"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#0x7fffffffffffffff"); SStream_Flush(&OS, NULL); printInt64Bang(&OS, INT64_MIN); - CHECK_EQUAL_RET_FALSE(OS, "#-0x8000000000000000"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#-0x8000000000000000"); SStream_Flush(&OS, NULL); return true; } @@ -283,15 +283,15 @@ bool test_printuint32_bang() SStream OS = { 0 }; SStream_Init(&OS); printUInt32Bang(&OS, HEX_THRESHOLD + 1); - CHECK_EQUAL_RET_FALSE(OS, "#0xa"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#0xa"); SStream_Flush(&OS, NULL); printUInt32Bang(&OS, HEX_THRESHOLD); - CHECK_EQUAL_RET_FALSE(OS, "#9"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#9"); SStream_Flush(&OS, NULL); printUInt32Bang(&OS, UINT32_MAX); - CHECK_EQUAL_RET_FALSE(OS, "#0xffffffff"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#0xffffffff"); SStream_Flush(&OS, NULL); return true; } @@ -303,15 +303,15 @@ bool test_printuint64_bang() SStream OS = { 0 }; SStream_Init(&OS); printUInt64Bang(&OS, HEX_THRESHOLD + 1); - CHECK_EQUAL_RET_FALSE(OS, "#0xa"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#0xa"); SStream_Flush(&OS, NULL); printUInt64Bang(&OS, HEX_THRESHOLD); - CHECK_EQUAL_RET_FALSE(OS, "#9"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#9"); SStream_Flush(&OS, NULL); printUInt64Bang(&OS, UINT64_MAX); - CHECK_EQUAL_RET_FALSE(OS, "#0xffffffffffffffff"); + CHECK_OS_EQUAL_RET_FALSE(OS, "#0xffffffffffffffff"); SStream_Flush(&OS, NULL); return true; } @@ -323,28 +323,28 @@ bool test_trimls() { SStream_Init(&OS); SStream_concat0(&OS, "AAA"); SStream_trimls(&OS); - CHECK_EQUAL_RET_FALSE(OS, "AAA"); + CHECK_OS_EQUAL_RET_FALSE(OS, "AAA"); SStream_Flush(&OS, NULL); SStream_concat0(&OS, "\t AAA"); SStream_trimls(&OS); - CHECK_EQUAL_RET_FALSE(OS, "AAA"); + CHECK_OS_EQUAL_RET_FALSE(OS, "AAA"); // Don't remove middle tabs and spaces SStream_concat0(&OS, "\t AAA"); SStream_trimls(&OS); - CHECK_EQUAL_RET_FALSE(OS, "AAA\t AAA"); + CHECK_OS_EQUAL_RET_FALSE(OS, "AAA\t AAA"); SStream_Flush(&OS, NULL); // Test do nothing SStream_trimls(&OS); - CHECK_EQUAL_RET_FALSE(OS, ""); + CHECK_OS_EQUAL_RET_FALSE(OS, ""); // Everywhere tabs char cmp_buf[SSTREAM_BUF_LEN] = { 0 }; memset(cmp_buf, '\t', sizeof(cmp_buf) - 1); SStream_trimls(&OS); - CHECK_EQUAL_RET_FALSE(OS, ""); + CHECK_OS_EQUAL_RET_FALSE(OS, ""); CHECK_INT_EQUAL_RET_FALSE(OS.index, 0); return true; } @@ -415,17 +415,17 @@ bool test_replc() cmp_buf[0] = 'B'; const char *next = SStream_replc(&OS, 'A', 'B'); CHECK_PTR_EQUAL_RET_FALSE(SStream_rbuf(&OS) + 1, next); - CHECK_EQUAL_RET_FALSE(OS, cmp_buf); + CHECK_OS_EQUAL_RET_FALSE(OS, cmp_buf); cmp_buf[1] = 'B'; next = SStream_replc(&OS, 'A', 'B'); CHECK_PTR_EQUAL_RET_FALSE(SStream_rbuf(&OS) + 2, next); - CHECK_EQUAL_RET_FALSE(OS, cmp_buf); + CHECK_OS_EQUAL_RET_FALSE(OS, cmp_buf); cmp_buf[100] = 'A'; // Replace the C from before next = SStream_replc(&OS, 'C', 'A'); CHECK_PTR_EQUAL_RET_FALSE(SStream_rbuf(&OS) + 101, next); - CHECK_EQUAL_RET_FALSE(OS, cmp_buf); + CHECK_OS_EQUAL_RET_FALSE(OS, cmp_buf); // X doesn't exist next = SStream_replc(&OS, 'X', 'A'); @@ -439,7 +439,7 @@ bool test_replc() SStream_Flush(&OS, NULL); next = SStream_replc(&OS, '\0', 'A'); CHECK_PTR_EQUAL_RET_FALSE(SStream_rbuf(&OS) + 1, next); - CHECK_EQUAL_RET_FALSE(OS, "A"); + CHECK_OS_EQUAL_RET_FALSE(OS, "A"); return true; } @@ -453,20 +453,20 @@ bool test_replc_str() SStream_Init(&OS); SStream_replc_str(&OS, 'A', "REPLACED"); - CHECK_EQUAL_RET_FALSE(OS, ""); + CHECK_OS_EQUAL_RET_FALSE(OS, ""); CHECK_INT_EQUAL_RET_FALSE(OS.index, 0); SStream_replc_str(&OS, '\0', "REPLACED"); - CHECK_EQUAL_RET_FALSE(OS, "REPLACED"); + CHECK_OS_EQUAL_RET_FALSE(OS, "REPLACED"); CHECK_INT_EQUAL_RET_FALSE(OS.index, 8); SStream_Flush(&OS, NULL); SStream_concat0(&OS, "\tA--X"); SStream_replc_str(&OS, 'A', "REPLACED"); - CHECK_EQUAL_RET_FALSE(OS, "\tREPLACED--X"); + CHECK_OS_EQUAL_RET_FALSE(OS, "\tREPLACED--X"); CHECK_INT_EQUAL_RET_FALSE(OS.index, 12); SStream_replc_str(&OS, 'X', "REPLACED"); - CHECK_EQUAL_RET_FALSE(OS, "\tREPLACED--REPLACED"); + CHECK_OS_EQUAL_RET_FALSE(OS, "\tREPLACED--REPLACED"); CHECK_INT_EQUAL_RET_FALSE(OS.index, 19); /// Too big strings are ignored. @@ -475,7 +475,7 @@ bool test_replc_str() SStream_Flush(&OS, NULL); SStream_concat0(&OS, "\tA--"); SStream_replc_str(&OS, 'A', repl); - CHECK_EQUAL_RET_FALSE(OS, "\tA--"); + CHECK_OS_EQUAL_RET_FALSE(OS, "\tA--"); CHECK_INT_EQUAL_RET_FALSE(OS.index, 4); /// Last null byte is not replaced. @@ -483,7 +483,7 @@ bool test_replc_str() SStream_Flush(&OS, NULL); SStream_concat0(&OS, repl); SStream_replc_str(&OS, '\0', repl); - CHECK_EQUAL_RET_FALSE(OS, repl); + CHECK_OS_EQUAL_RET_FALSE(OS, repl); CHECK_INT_EQUAL_RET_FALSE(OS.index, 511); /// Last char is replaced. @@ -493,7 +493,7 @@ bool test_replc_str() SStream_concat0(&OS, repl); SStream_replc_str(&OS, 'X', "Y"); repl[sizeof(repl) - 2] = 'Y'; - CHECK_EQUAL_RET_FALSE(OS, repl); + CHECK_OS_EQUAL_RET_FALSE(OS, repl); CHECK_INT_EQUAL_RET_FALSE(OS.index, 511); // Possible overflow @@ -502,7 +502,7 @@ bool test_replc_str() SStream_Flush(&OS, NULL); SStream_concat0(&OS, "\tA--"); SStream_replc_str(&OS, 'A', too_long); - CHECK_EQUAL_RET_FALSE(OS, "\tA--"); + CHECK_OS_EQUAL_RET_FALSE(OS, "\tA--"); CHECK_INT_EQUAL_RET_FALSE(OS.index, 4); return true;