From 9134c5553b753b7dda71feb51c705f3e4d1e1ef2 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Fri, 27 Jul 2018 13:02:09 +0000 Subject: [PATCH] Feature: Added a basic test suite for testing parts of the C code --- tests/Makefile.am | 8 ++++- tests/ctest_lib.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ tests/ctest_lib.h | 20 +++++++++++++ tests/ctest_suite.c | 20 +++++++++++++ 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 tests/ctest_lib.c create mode 100644 tests/ctest_lib.h create mode 100644 tests/ctest_suite.c diff --git a/tests/Makefile.am b/tests/Makefile.am index e445847d..fa1aecb5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -5,10 +5,16 @@ TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \ TESTS = \ startup.test \ - admin.test + admin.test \ + ctest_suite.test EXTRA_DIST = $(TESTS) EXTRA_DIST += \ icecast.xml \ on-connect.sh + +check_PROGRAMS = ctest_suite.test +noinst_HEADERS = ctest_lib.h + +ctest_suite_test_SOURCES=ctest_suite.c ctest_lib.c diff --git a/tests/ctest_lib.c b/tests/ctest_lib.c new file mode 100644 index 00000000..ae9c9542 --- /dev/null +++ b/tests/ctest_lib.c @@ -0,0 +1,71 @@ +/* Icecast + * + * This program is distributed under the GNU General Public License, version 2. + * A copy of this license is included with this source. + * + * Copyright 2018, Philipp "ph3-der-loewe" Schafft , + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "ctest_lib.h" + +static size_t ctest_g_test_num; +static int ctest_g_bailed_out; + +void ctest_init(void) +{ + ctest_g_test_num = 0; + ctest_g_bailed_out = 0; +} + +void ctest_fin(void) +{ + printf("1..%zu\n", ctest_g_test_num); +} + +void ctest_test(const char *desc, int res) +{ + const char *prefix = NULL; + + if (ctest_bailed_out()) + return; + + ctest_g_test_num++; + + if (res) { + prefix = "ok"; + } else { + prefix = "not ok"; + } + + if (desc) { + printf("%s %zu %s\n", prefix, ctest_g_test_num, desc); + } else { + printf("%s %zu\n", prefix, ctest_g_test_num); + } +} + +void ctest_diagnostic(const char *line) +{ + printf("# %s\n", line); +} + +void ctest_bail_out(const char *reason) +{ + ctest_g_bailed_out = 1; + if (reason) { + printf("Bail out! %s\n", reason); + } else { + printf("Bail out!\n"); + } +} + +int ctest_bailed_out(void) +{ + return ctest_g_bailed_out; +} diff --git a/tests/ctest_lib.h b/tests/ctest_lib.h new file mode 100644 index 00000000..f4ad203b --- /dev/null +++ b/tests/ctest_lib.h @@ -0,0 +1,20 @@ +/* Icecast + * + * This program is distributed under the GNU General Public License, version 2. + * A copy of this license is included with this source. + * + * Copyright 2014, Philipp "ph3-der-loewe" Schafft , + */ + +#ifndef __CTEST_LIB_H__ +#define __CTEST_LIB_H__ + +void ctest_init(void); +void ctest_fin(void); + +void ctest_test(const char *desc, int res); +void ctest_diagnostic(const char *line); +void ctest_bail_out(const char *reason); +int ctest_bailed_out(void); + +#endif diff --git a/tests/ctest_suite.c b/tests/ctest_suite.c new file mode 100644 index 00000000..91f75873 --- /dev/null +++ b/tests/ctest_suite.c @@ -0,0 +1,20 @@ +/* Icecast + * + * This program is distributed under the GNU General Public License, version 2. + * A copy of this license is included with this source. + * + * Copyright 2018, Philipp "ph3-der-loewe" Schafft , + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "ctest_lib.h" + +int main (void) { + ctest_init(); + ctest_test("suite working", 1); + ctest_fin(); + return 0; +}