From 63a9014383c17c0f6c4556f7119afb64fdfd4419 Mon Sep 17 00:00:00 2001 From: Marvin Scholz Date: Fri, 4 Sep 2020 02:08:11 +0200 Subject: [PATCH] Update: Add tests for error functions --- src/tests/Makefile.am | 5 ++++ src/tests/ctest_errors.c | 60 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/tests/ctest_errors.c diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index bfa9497b..871f200a 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -35,6 +35,11 @@ ctest_refobject_test_LDADD = libice_ctest.la \ icecast-refobject.o check_PROGRAMS += ctest_refobject.test +ctest_errors_test_SOURCES = %reldir%/ctest_errors.c +ctest_errors_test_LDADD = libice_ctest.la \ + icecast-errors.o +check_PROGRAMS += ctest_errors.test + ctest_buffer_test_SOURCES = %reldir%/ctest_buffer.c ctest_buffer_test_LDADD = libice_ctest.la \ common/thread/libicethread.la \ diff --git a/src/tests/ctest_errors.c b/src/tests/ctest_errors.c new file mode 100644 index 00000000..fa633211 --- /dev/null +++ b/src/tests/ctest_errors.c @@ -0,0 +1,60 @@ +/* Icecast + * + * This program is distributed under the GNU General Public License, version 2. + * A copy of this license is included with this source. + * + * Copyright 2020, Marvin Scholz , + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "ctest_lib.h" + +#include "../errors.h" + +int main (void) { + int ret = 1; + + ctest_init(); + + /* Verify all error IDs have a table entry */ + { + for (int i = 0; i < ICECAST_ERROR_END_SENTINEL; ++i) + { + const icecast_error_t *error = error_get_by_id(i); + + if (error == NULL || error->uuid == NULL) { + ret = 0; + break; + } + + error = error_get_by_uuid(error->uuid); + if (error == NULL) { + ret = 0; + break; + } + } + ctest_test("error table completeness", ret); + } + + /* Verify invalid ID lookup fails */ + { + const icecast_error_t *error = error_get_by_id(ICECAST_ERROR_END_SENTINEL + 1); + + ctest_test("invalid id lookup should fail", (error == NULL)); + } + + /* Verify invalid UUID lookup fails */ + { + const icecast_error_t *error = error_get_by_uuid("c0225973-cd02-4faa-9720-01665ea400a7"); + + ctest_test("invalid uuid lookup should fail", (error == NULL)); + } + + ctest_fin(); + return 0; +}