From 68d533e7fdbbd33d720412aaab1848200b6c8863 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 8 Jan 2023 22:39:00 +0100 Subject: m + add tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libfonts_parse_uint32__.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'libfonts_parse_uint32__.c') diff --git a/libfonts_parse_uint32__.c b/libfonts_parse_uint32__.c index f87f19e..d35ddd3 100644 --- a/libfonts_parse_uint32__.c +++ b/libfonts_parse_uint32__.c @@ -11,7 +11,7 @@ libfonts_parse_uint32__(uint32_t *outp, const char *value) if (!*value) return 0; while (isdigit(*value)) { - digit = (*value & 15); + digit = (*value++ & 15); if (out > (UINT32_C(0xFFFFFFFF) - digit) / 10) return 0; out = out * 10 + digit; @@ -29,7 +29,41 @@ libfonts_parse_uint32__(uint32_t *outp, const char *value) int main(void) { - return 0; /* TODO add test */ + uint32_t res; + +#define F(S)\ + do {\ + res = 999;\ + ASSERT(libfonts_parse_uint32__(&res, S) == 0);\ + ASSERT(res == 999);\ + } while (0) + +#define T(N)\ + do {\ + res = (uint32_t)(UINT32_C(N) ^ UINT32_C(0x87654321));\ + ASSERT(libfonts_parse_uint32__(&res, #N) == 1);\ + ASSERT(res == UINT32_C(N));\ + res ^= UINT32_C(0x87654321);\ + ASSERT(libfonts_parse_uint32__(&res, "+"#N) == 1);\ + ASSERT(res == UINT32_C(N));\ + F("-"#N);\ + } while (0) + + T(0); + T(10); + T(12); + T(1235); + T(53251); + T(4294967294); + T(4294967295); + + F("4294967296"); + F("11111111111"); + F("+"); + F("100x"); + F("a"); + + return 0; } -- cgit v1.2.3-70-g09d2