From b9d58f74ea1d072e7a2d1c862dc7a1e0fe5fccb0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 18 Aug 2022 16:44:41 -0400 Subject: Factor out converting errno codes to ZixStatus --- test/test_status.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ test/test_strerror.c | 31 --------------------------- 2 files changed, 60 insertions(+), 31 deletions(-) create mode 100644 test/test_status.c delete mode 100644 test/test_strerror.c (limited to 'test') diff --git a/test/test_status.c b/test/test_status.c new file mode 100644 index 0000000..eb11bc1 --- /dev/null +++ b/test/test_status.c @@ -0,0 +1,60 @@ +// Copyright 2021 David Robillard +// SPDX-License-Identifier: ISC + +#undef NDEBUG + +#include "zix/common.h" + +#include +#include +#include +#include +#include + +static void +test_errno_status(void) +{ + assert(zix_errno_status(0) == ZIX_STATUS_SUCCESS); + assert(zix_errno_status(INT_MAX) == ZIX_STATUS_ERROR); + +#ifdef EAGAIN + assert(zix_errno_status(EAGAIN) == ZIX_STATUS_NO_MEM); +#endif +#ifdef EEXIST + assert(zix_errno_status(EEXIST) == ZIX_STATUS_EXISTS); +#endif +#ifdef EINVAL + assert(zix_errno_status(EINVAL) == ZIX_STATUS_BAD_ARG); +#endif +#ifdef EPERM + assert(zix_errno_status(EPERM) == ZIX_STATUS_BAD_PERMS); +#endif +} + +static void +test_strerror(void) +{ + const char* msg = zix_strerror(ZIX_STATUS_SUCCESS); + assert(!strcmp(msg, "Success")); + + for (int i = ZIX_STATUS_ERROR; i <= ZIX_STATUS_REACHED_END; ++i) { + msg = zix_strerror((ZixStatus)i); + assert(strcmp(msg, "Success")); + } + + msg = zix_strerror((ZixStatus)-1); + assert(!strcmp(msg, "Unknown error")); + + msg = zix_strerror((ZixStatus)1000000); + assert(!strcmp(msg, "Unknown error")); + + printf("Success\n"); +} + +int +main(void) +{ + test_errno_status(); + test_strerror(); + return 0; +} diff --git a/test/test_strerror.c b/test/test_strerror.c deleted file mode 100644 index 2f4c090..0000000 --- a/test/test_strerror.c +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2021 David Robillard -// SPDX-License-Identifier: ISC - -#undef NDEBUG - -#include "zix/common.h" - -#include -#include -#include - -int -main(void) -{ - const char* msg = zix_strerror(ZIX_STATUS_SUCCESS); - assert(!strcmp(msg, "Success")); - - for (int i = ZIX_STATUS_ERROR; i <= ZIX_STATUS_REACHED_END; ++i) { - msg = zix_strerror((ZixStatus)i); - assert(strcmp(msg, "Success")); - } - - msg = zix_strerror((ZixStatus)-1); - assert(!strcmp(msg, "Unknown error")); - - msg = zix_strerror((ZixStatus)1000000); - assert(!strcmp(msg, "Unknown error")); - - printf("Success\n"); - return 0; -} -- cgit v1.2.1