From f4e7e7116b0fcd104fa3859c92ec998468030ace Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 10 Sep 2021 21:31:51 -0400 Subject: Add test for zix_strerror() --- test/strerror_test.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/strerror_test.c (limited to 'test/strerror_test.c') diff --git a/test/strerror_test.c b/test/strerror_test.c new file mode 100644 index 0000000..1173c3a --- /dev/null +++ b/test/strerror_test.c @@ -0,0 +1,47 @@ +/* + Copyright 2021 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#undef NDEBUG + +#include "zix/common.h" + +#include +#include + +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")); +} + +int +main(void) +{ + test_strerror(); + return 0; +} -- cgit v1.2.1