From 4e81cb177ab77904e7a21ce70b9a5506bf09ad6e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 25 Sep 2026 23:42:55 +0200 Subject: Add tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- librecrypt_concat_uint_.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'librecrypt_concat_uint_.c') diff --git a/librecrypt_concat_uint_.c b/librecrypt_concat_uint_.c index a492e0b..2f74272 100644 --- a/librecrypt_concat_uint_.c +++ b/librecrypt_concat_uint_.c @@ -28,10 +28,25 @@ librecrypt_concat_uint_(struct concat_state *state, uintmax_t value) int main(void) { + char buf[sizeof("0") + 3u * sizeof(uintmax_t)]; + char expected[sizeof(buf)]; + struct concat_state state = {buf, sizeof(buf), 0u}; + SET_UP_ALARM(); INIT_RESOURCE_TEST(); - /* TODO test */ + memset(buf, 'x', sizeof(buf)); + assert(sprintf(expected, "0%ju", UINTMAX_MAX) > 0); + + librecrypt_concat_uint_(&state, 0u); + librecrypt_concat_uint_(&state, UINTMAX_MAX); + assert(state.len == strlen(expected)); + assert(!strcmp(buf, expected)); + + state = (struct concat_state){buf, 3u, 0u}; + librecrypt_concat_uint_(&state, 123u); + assert(!strcmp(buf, "12")); + assert(state.len == 3u); STOP_RESOURCE_TEST(); return 0; -- cgit v1.3.1