From 26b1449d19bbb7776adeee1b5f089b9b63740c11 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Mon, 14 Mar 2022 08:35:04 +0000 Subject: [PATCH] Cleanup: Migrated to libigloo's TAP support --- src/tests/Makefile.am | 14 +- src/tests/ctest_buffer.c | 230 +++++++++++++++++--------------- src/tests/ctest_lib.c | 84 ------------ src/tests/ctest_lib.h | 21 --- src/tests/ctest_refobject.c | 139 ++++++++++--------- src/tests/ctest_resourcematch.c | 32 +++-- src/tests/ctest_suite.c | 13 +- 7 files changed, 226 insertions(+), 307 deletions(-) delete mode 100644 src/tests/ctest_lib.c delete mode 100644 src/tests/ctest_lib.h diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index f5d03860..ea49f546 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -9,34 +9,26 @@ TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \ check_PROGRAMS = -# -# Helper library for TAP tests -# - -libice_ctest_la_SOURCES = tests/ctest_lib.c %reldir%/ctest_lib.h -noinst_LTLIBRARIES = libice_ctest.la - # # Test programs # ctest_suite_test_SOURCES = tests/ctest_suite.c -ctest_suite_test_LDADD = libice_ctest.la check_PROGRAMS += ctest_suite.test ctest_resourcematch_test_SOURCES = tests/ctest_resourcematch.c -ctest_resourcematch_test_LDADD = libice_ctest.la icecast-resourcematch.o +ctest_resourcematch_test_LDADD = icecast-resourcematch.o check_PROGRAMS += ctest_resourcematch.test ctest_refobject_test_SOURCES = tests/ctest_refobject.c -ctest_refobject_test_LDADD = libice_ctest.la \ +ctest_refobject_test_LDADD = \ common/thread/libicethread.la \ common/avl/libiceavl.la \ icecast-refobject.o check_PROGRAMS += ctest_refobject.test ctest_buffer_test_SOURCES = tests/ctest_buffer.c -ctest_buffer_test_LDADD = libice_ctest.la \ +ctest_buffer_test_LDADD = \ common/thread/libicethread.la \ common/avl/libiceavl.la \ icecast-refobject.o \ diff --git a/src/tests/ctest_buffer.c b/src/tests/ctest_buffer.c index 682d3e00..15e6c82a 100644 --- a/src/tests/ctest_buffer.c +++ b/src/tests/ctest_buffer.c @@ -11,23 +11,39 @@ #endif #include +#include +#include /* for EXIT_FAILURE */ +#include -#include "ctest_lib.h" +#include #include "../src/buffer.h" #include "../src/refobject.h" +static void ctest_diagnostic_printf(const char *format, ...) +{ + char buf[1024]; + va_list ap; + va_start(ap, format); + + vsnprintf(buf, sizeof(buf), format, ap); + + va_end(ap); + + igloo_tap_diagnostic(buf); +} + static void test_create_ref_unref(void) { buffer_t *a; a = buffer_new(-1, NULL, NULL, REFOBJECT_NULL); - ctest_test("buffer created", a != NULL); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("buffer created", a != NULL); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); a = refobject_new(buffer_t); - ctest_test("buffer created", a != NULL); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("buffer created", a != NULL); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } @@ -38,13 +54,13 @@ static void test_name(void) const char *ret; a = buffer_new(-1, NULL, name, REFOBJECT_NULL); - ctest_test("buffer created", a != NULL); + igloo_tap_test("buffer created", a != NULL); ret = refobject_get_name(a); - ctest_test("get name", ret != NULL); - ctest_test("name match", strcmp(name, ret) == 0); + igloo_tap_test("get name", ret != NULL); + igloo_tap_test("name match", strcmp(name, ret) == 0); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_userdata(void) @@ -55,27 +71,27 @@ static void test_userdata(void) void *ret; a = buffer_new(-1, NULL, NULL, REFOBJECT_NULL); - ctest_test("buffer created", a != NULL); + igloo_tap_test("buffer created", a != NULL); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == NULL); - ctest_test("set userdata", refobject_set_userdata(a, userdata) == 0); + igloo_tap_test("get userdata", ret == NULL); + igloo_tap_test("set userdata", refobject_set_userdata(a, userdata) == 0); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == userdata); - ctest_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); + igloo_tap_test("get userdata", ret == userdata); + igloo_tap_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == NULL); + igloo_tap_test("get userdata", ret == NULL); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); a = buffer_new(-1, userdata, NULL, REFOBJECT_NULL); - ctest_test("buffer created", a != NULL); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("buffer created", a != NULL); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == userdata); - ctest_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); + igloo_tap_test("get userdata", ret == userdata); + igloo_tap_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == NULL); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("get userdata", ret == NULL); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_associated(void) @@ -84,14 +100,14 @@ static void test_associated(void) buffer_t *b; a = refobject_new(refobject_base_t); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); b = buffer_new(-1, NULL, NULL, a); - ctest_test("buffer created with associated", !REFOBJECT_IS_NULL(b)); + igloo_tap_test("buffer created with associated", !REFOBJECT_IS_NULL(b)); - ctest_test("un-referenced (1 of 2)", refobject_unref(b) == 0); - ctest_test("un-referenced (2 of 2)", refobject_unref(a) == 0); + igloo_tap_test("un-referenced (1 of 2)", refobject_unref(b) == 0); + igloo_tap_test("un-referenced (2 of 2)", refobject_unref(a) == 0); } static void test_empty(void) @@ -103,39 +119,39 @@ static void test_empty(void) int ret; a = refobject_new(buffer_t); - ctest_test("buffer created", a != NULL); + igloo_tap_test("buffer created", a != NULL); ret = buffer_get_data(a, &data, &length); - ctest_test("got data and length from buffer", ret == 0); + igloo_tap_test("got data and length from buffer", ret == 0); if (ret == 0) { - ctest_test("data is updated", data != &data); - ctest_test("length is zero", length == 0); + igloo_tap_test("data is updated", data != &data); + igloo_tap_test("length is zero", length == 0); } data = &data; ret = buffer_get_data(a, &data, NULL); - ctest_test("got data from buffer", ret == 0); + igloo_tap_test("got data from buffer", ret == 0); if (ret == 0) { - ctest_test("data is updated", data != &data); + igloo_tap_test("data is updated", data != &data); } length = 5; ret = buffer_get_data(a, NULL, &length); - ctest_test("got length from buffer", ret == 0); + igloo_tap_test("got length from buffer", ret == 0); if (ret == 0) { - ctest_test("length is zero", length == 0); + igloo_tap_test("length is zero", length == 0); } ret = buffer_get_string(a, &string); - ctest_test("got string from buffer", ret == 0); + igloo_tap_test("got string from buffer", ret == 0); if (ret == 0) { - ctest_test("string is non-NULL", string != NULL); + igloo_tap_test("string is non-NULL", string != NULL); if (string != NULL) { - ctest_test("string is empty", *string == 0); + igloo_tap_test("string is empty", *string == 0); } } - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_string(void) @@ -148,29 +164,29 @@ static void test_string(void) int ret; a = refobject_new(buffer_t); - ctest_test("buffer created", a != NULL); - ctest_test("pushed string", buffer_push_string(a, hw) == 0); + igloo_tap_test("buffer created", a != NULL); + igloo_tap_test("pushed string", buffer_push_string(a, hw) == 0); ret = buffer_get_string(a, &string); - ctest_test("got strong", ret == 0); + igloo_tap_test("got strong", ret == 0); if (ret == 0) { - ctest_test("string is non-NULL", string != NULL); + igloo_tap_test("string is non-NULL", string != NULL); if (string != NULL) { - ctest_test("string matches input", strcmp(string, hw) == 0); + igloo_tap_test("string matches input", strcmp(string, hw) == 0); } } - ctest_test("pushed string", buffer_push_string(a, count) == 0); + igloo_tap_test("pushed string", buffer_push_string(a, count) == 0); string = NULL; ret = buffer_get_string(a, &string); - ctest_test("got strong", ret == 0); + igloo_tap_test("got strong", ret == 0); if (ret == 0) { - ctest_test("string is non-NULL", string != NULL); + igloo_tap_test("string is non-NULL", string != NULL); if (string != NULL) { - ctest_test("string matches combined input", strcmp(string, combined) == 0); + igloo_tap_test("string matches combined input", strcmp(string, combined) == 0); } } - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_binary(void) @@ -183,38 +199,38 @@ static void test_binary(void) const void *data; a = refobject_new(buffer_t); - ctest_test("buffer created", a != NULL); + igloo_tap_test("buffer created", a != NULL); - ctest_test("pushed data pattern a", buffer_push_data(a, pattern_a, sizeof(pattern_a)) == 0); + igloo_tap_test("pushed data pattern a", buffer_push_data(a, pattern_a, sizeof(pattern_a)) == 0); length = sizeof(pattern_a) + 42; data = &data; ret = buffer_get_data(a, &data, &length); - ctest_test("got data", ret == 0); + igloo_tap_test("got data", ret == 0); if (ret == 0) { - ctest_test("correct length was returned", length == sizeof(pattern_a)); - ctest_test("data is non-NULL", data != NULL); - ctest_test("data has been set", data != &data); + igloo_tap_test("correct length was returned", length == sizeof(pattern_a)); + igloo_tap_test("data is non-NULL", data != NULL); + igloo_tap_test("data has been set", data != &data); if (length == sizeof(pattern_a) && data != NULL && data != &data) { - ctest_test("data matches pattern", memcmp(data, pattern_a, sizeof(pattern_a)) == 0); + igloo_tap_test("data matches pattern", memcmp(data, pattern_a, sizeof(pattern_a)) == 0); } } - ctest_test("pushed data pattern b", buffer_push_data(a, pattern_b, sizeof(pattern_b)) == 0); + igloo_tap_test("pushed data pattern b", buffer_push_data(a, pattern_b, sizeof(pattern_b)) == 0); length = sizeof(pattern_a) + sizeof(pattern_b) + 42; data = &data; ret = buffer_get_data(a, &data, &length); - ctest_test("got data", ret == 0); + igloo_tap_test("got data", ret == 0); if (ret == 0) { - ctest_test("correct length was returned", length == (sizeof(pattern_a) + sizeof(pattern_b))); - ctest_test("data is non-NULL", data != NULL); - ctest_test("data has been set", data != &data); + igloo_tap_test("correct length was returned", length == (sizeof(pattern_a) + sizeof(pattern_b))); + igloo_tap_test("data is non-NULL", data != NULL); + igloo_tap_test("data has been set", data != &data); if (length == (sizeof(pattern_a) + sizeof(pattern_b)) && data != NULL && data != &data) { - ctest_test("data matches combined pattern", memcmp(data, pattern_a, sizeof(pattern_a)) == 0 && memcmp(data + sizeof(pattern_a), pattern_b, sizeof(pattern_b)) == 0); + igloo_tap_test("data matches combined pattern", memcmp(data, pattern_a, sizeof(pattern_a)) == 0 && memcmp(data + sizeof(pattern_a), pattern_b, sizeof(pattern_b)) == 0); } } - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test__compare_to_string(buffer_t *a, const char *testname, const char *pattern) @@ -223,11 +239,11 @@ static void test__compare_to_string(buffer_t *a, const char *testname, const cha int ret; ret = buffer_get_string(a, &string); - ctest_test("got strong", ret == 0); + igloo_tap_test("got strong", ret == 0); if (ret == 0) { - ctest_test("string is non-NULL", string != NULL); + igloo_tap_test("string is non-NULL", string != NULL); if (string != NULL) { - ctest_test(testname, strcmp(string, pattern) == 0); + igloo_tap_test(testname, strcmp(string, pattern) == 0); ctest_diagnostic_printf("string=\"%s\", pattern=\"%s\"", string, pattern); } } @@ -239,21 +255,21 @@ static void test_shift(void) const char *pattern = "AABBBCC"; a = refobject_new(buffer_t); - ctest_test("buffer created", a != NULL); + igloo_tap_test("buffer created", a != NULL); - ctest_test("pushed string", buffer_push_string(a, pattern) == 0); + igloo_tap_test("pushed string", buffer_push_string(a, pattern) == 0); test__compare_to_string(a, "string matches input", pattern); - ctest_test("shifted data by 0 bytes", buffer_shift(a, 0) == 0); + igloo_tap_test("shifted data by 0 bytes", buffer_shift(a, 0) == 0); test__compare_to_string(a, "string matches input (no shift happened)", pattern); - ctest_test("shifted data by 2 bytes", buffer_shift(a, 2) == 0); + igloo_tap_test("shifted data by 2 bytes", buffer_shift(a, 2) == 0); test__compare_to_string(a, "string matches shifted input", pattern + 2); - ctest_test("shifted data by 3 bytes", buffer_shift(a, 3) == 0); + igloo_tap_test("shifted data by 3 bytes", buffer_shift(a, 3) == 0); test__compare_to_string(a, "string matches shifted input", pattern + 2 + 3); - ctest_test("shifted data by 3 bytes", buffer_shift(a, 2) == 0); + igloo_tap_test("shifted data by 3 bytes", buffer_shift(a, 2) == 0); test__compare_to_string(a, "string matches shifted input", pattern + 2 + 3 + 2); - ctest_test("shifted data beyond end (42 bytes)", buffer_shift(a, 42) != 0); + igloo_tap_test("shifted data beyond end (42 bytes)", buffer_shift(a, 42) != 0); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_length(void) @@ -265,20 +281,20 @@ static void test_length(void) const char *match_c = ""; a = refobject_new(buffer_t); - ctest_test("buffer created", a != NULL); + igloo_tap_test("buffer created", a != NULL); - ctest_test("pushed string", buffer_push_string(a, pattern) == 0); + igloo_tap_test("pushed string", buffer_push_string(a, pattern) == 0); test__compare_to_string(a, "string matches input", pattern); - ctest_test("Set length to match pattern a", buffer_set_length(a, strlen(match_a)) == 0); + igloo_tap_test("Set length to match pattern a", buffer_set_length(a, strlen(match_a)) == 0); test__compare_to_string(a, "string matches pattern a", match_a); - ctest_test("Set length to match pattern b", buffer_set_length(a, strlen(match_b)) == 0); + igloo_tap_test("Set length to match pattern b", buffer_set_length(a, strlen(match_b)) == 0); test__compare_to_string(a, "string matches pattern a", match_b); - ctest_test("Set length to match pattern c", buffer_set_length(a, strlen(match_c)) == 0); + igloo_tap_test("Set length to match pattern c", buffer_set_length(a, strlen(match_c)) == 0); test__compare_to_string(a, "string matches pattern a", match_c); - ctest_test("Set length to match pattern a (again)", buffer_set_length(a, strlen(match_a)) != 0); + igloo_tap_test("Set length to match pattern a (again)", buffer_set_length(a, strlen(match_a)) != 0); test__compare_to_string(a, "string still matches pattern c", match_c); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_printf(void) @@ -291,16 +307,16 @@ static void test_printf(void) const char *match_c = ":Hello World!:<-127 >? +127?"; a = refobject_new(buffer_t); - ctest_test("buffer created", a != NULL); + igloo_tap_test("buffer created", a != NULL); - ctest_test("Set length to match pattern a", buffer_push_printf(a, ":%s:", str) == 0); + igloo_tap_test("Set length to match pattern a", buffer_push_printf(a, ":%s:", str) == 0); test__compare_to_string(a, "string matches pattern a", match_a); - ctest_test("Set length to match pattern a", buffer_push_printf(a, "<%-5i>", num) == 0); + igloo_tap_test("Set length to match pattern a", buffer_push_printf(a, "<%-5i>", num) == 0); test__compare_to_string(a, "string matches pattern b", match_b); - ctest_test("Set length to match pattern a", buffer_push_printf(a, "?%+5i?", -num) == 0); + igloo_tap_test("Set length to match pattern a", buffer_push_printf(a, "?%+5i?", -num) == 0); test__compare_to_string(a, "string matches pattern c", match_c); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_push_buffer(void) @@ -311,45 +327,45 @@ static void test_push_buffer(void) const char *match_a = "AABBBCCAABBBCC"; a = refobject_new(buffer_t); - ctest_test("buffer a created", a != NULL); + igloo_tap_test("buffer a created", a != NULL); b = refobject_new(buffer_t); - ctest_test("buffer b created", b != NULL); + igloo_tap_test("buffer b created", b != NULL); - ctest_test("pushed string", buffer_push_string(a, pattern) == 0); + igloo_tap_test("pushed string", buffer_push_string(a, pattern) == 0); test__compare_to_string(a, "string matches input", pattern); - ctest_test("pushed buffer a to b", buffer_push_buffer(b, a) == 0); + igloo_tap_test("pushed buffer a to b", buffer_push_buffer(b, a) == 0); test__compare_to_string(b, "string matches input", pattern); - ctest_test("pushed buffer a to b", buffer_push_buffer(b, a) == 0); + igloo_tap_test("pushed buffer a to b", buffer_push_buffer(b, a) == 0); test__compare_to_string(b, "string matches pattern a", match_a); - ctest_test("un-referenced b", refobject_unref(b) == 0); - ctest_test("un-referenced a", refobject_unref(a) == 0); + igloo_tap_test("un-referenced b", refobject_unref(b) == 0); + igloo_tap_test("un-referenced a", refobject_unref(a) == 0); } int main (void) { - ctest_init(); + igloo_tap_init(); + igloo_tap_exit_on(igloo_TAP_EXIT_ON_FIN, NULL); + igloo_tap_group_run("create-ref-unref", test_create_ref_unref); - test_create_ref_unref(); + igloo_tap_group_run("name", test_name); + igloo_tap_group_run("userdata", test_userdata); + igloo_tap_group_run("associated", test_associated); - test_name(); - test_userdata(); - test_associated(); + igloo_tap_group_run("empty", test_empty); + igloo_tap_group_run("string", test_string); + igloo_tap_group_run("binary", test_binary); - test_empty(); - test_string(); - test_binary(); + igloo_tap_group_run("shift", test_shift); + igloo_tap_group_run("length", test_length); - test_shift(); - test_length(); + igloo_tap_group_run("printf", test_printf); + igloo_tap_group_run("push_buffer", test_push_buffer); - test_printf(); - test_push_buffer(); + igloo_tap_fin(); - ctest_fin(); - - return 0; + return EXIT_FAILURE; // return failure as we should never reach this point! } diff --git a/src/tests/ctest_lib.c b/src/tests/ctest_lib.c deleted file mode 100644 index 176a7df2..00000000 --- a/src/tests/ctest_lib.c +++ /dev/null @@ -1,84 +0,0 @@ -/* 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 - -#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_diagnostic_printf(const char *format, ...) -{ - va_list ap; - va_start(ap, format); - - printf("# "); - vprintf(format, ap); - printf("\n"); - - va_end(ap); -} - -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/src/tests/ctest_lib.h b/src/tests/ctest_lib.h deleted file mode 100644 index 69eb22ab..00000000 --- a/src/tests/ctest_lib.h +++ /dev/null @@ -1,21 +0,0 @@ -/* 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 , - */ - -#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_diagnostic_printf(const char *format, ...); -void ctest_bail_out(const char *reason); -int ctest_bailed_out(void); - -#endif diff --git a/src/tests/ctest_refobject.c b/src/tests/ctest_refobject.c index 36cb292e..f507894e 100644 --- a/src/tests/ctest_refobject.c +++ b/src/tests/ctest_refobject.c @@ -11,8 +11,9 @@ #endif #include +#include /* for EXIT_FAILURE */ -#include "ctest_lib.h" +#include #include "../refobject.h" @@ -21,10 +22,10 @@ static void test_ptr(void) refobject_t a; a = REFOBJECT_NULL; - ctest_test("NULL is NULL", REFOBJECT_IS_NULL(a)); + igloo_tap_test("NULL is NULL", REFOBJECT_IS_NULL(a)); if (!REFOBJECT_IS_NULL(a)) - ctest_bailed_out(); + igloo_tap_bail_out(NULL); } static void test_create_ref_unref(void) @@ -32,11 +33,11 @@ static void test_create_ref_unref(void) refobject_base_t *a; a = refobject_new(refobject_base_t); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); - ctest_test("referenced", refobject_ref(a) == 0); - ctest_test("un-referenced (1 of 2)", refobject_unref(a) == 0); - ctest_test("un-referenced (2 of 2)", refobject_unref(a) == 0); + igloo_tap_test("referenced", refobject_ref(a) == 0); + igloo_tap_test("un-referenced (1 of 2)", refobject_unref(a) == 0); + igloo_tap_test("un-referenced (2 of 2)", refobject_unref(a) == 0); } static void test_typename(void) @@ -45,13 +46,13 @@ static void test_typename(void) const char *typename; a = refobject_new(refobject_base_t); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); typename = REFOBJECT_GET_TYPENAME(a); - ctest_test("got typename", typename != NULL); - ctest_test("typename matches", strcmp(typename, "refobject_base_t") == 0); + igloo_tap_test("got typename", typename != NULL); + igloo_tap_test("typename matches", strcmp(typename, "refobject_base_t") == 0); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_valid(void) @@ -64,15 +65,15 @@ static void test_valid(void) REFOBJECT_DEFINE_PRIVATE_TYPE(ctest_test_type_t); - ctest_test("NULL is not valid", !REFOBJECT_IS_VALID(REFOBJECT_NULL, refobject_base_t)); + igloo_tap_test("NULL is not valid", !REFOBJECT_IS_VALID(REFOBJECT_NULL, refobject_base_t)); a = refobject_new(refobject_base_t); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); - ctest_test("is valid", REFOBJECT_IS_VALID(a, refobject_base_t)); - ctest_test("is valid as diffrent type", !REFOBJECT_IS_VALID(a, ctest_test_type_t)); + igloo_tap_test("is valid", REFOBJECT_IS_VALID(a, refobject_base_t)); + igloo_tap_test("is valid as diffrent type", !REFOBJECT_IS_VALID(a, ctest_test_type_t)); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_sizes(void) @@ -110,23 +111,23 @@ static void test_sizes(void) ); a = REFOBJECT_FROM_TYPE(refobject_new(ctest_test_type_a_t)); - ctest_test("refobject created with size=sizeof(refobject_base_t) + 1024", !REFOBJECT_IS_NULL(a)); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("refobject created with size=sizeof(refobject_base_t) + 1024", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); a = REFOBJECT_FROM_TYPE(refobject_new(ctest_test_type_b_t)); - ctest_test("refobject created with size=sizeof(refobject_base_t) + 131072", !REFOBJECT_IS_NULL(a)); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("refobject created with size=sizeof(refobject_base_t) + 131072", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); a = REFOBJECT_FROM_TYPE(refobject_new(ctest_test_type_c_t)); - ctest_test("refobject created with size=sizeof(refobject_base_t) - 1", REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created with size=sizeof(refobject_base_t) - 1", REFOBJECT_IS_NULL(a)); if (!REFOBJECT_IS_NULL(a)) { - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } a = REFOBJECT_FROM_TYPE(refobject_new(ctest_test_type_d_t)); - ctest_test("refobject created with size=0", REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created with size=0", REFOBJECT_IS_NULL(a)); if (!REFOBJECT_IS_NULL(a)) { - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } } @@ -137,13 +138,13 @@ static void test_name(void) const char *ret; a = refobject_new_ext(refobject_base_t, NULL, name, REFOBJECT_NULL); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); ret = refobject_get_name(a); - ctest_test("get name", ret != NULL); - ctest_test("name match", strcmp(name, ret) == 0); + igloo_tap_test("get name", ret != NULL); + igloo_tap_test("name match", strcmp(name, ret) == 0); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_userdata(void) @@ -154,27 +155,27 @@ static void test_userdata(void) void *ret; a = refobject_new(refobject_base_t); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == NULL); - ctest_test("set userdata", refobject_set_userdata(a, userdata) == 0); + igloo_tap_test("get userdata", ret == NULL); + igloo_tap_test("set userdata", refobject_set_userdata(a, userdata) == 0); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == userdata); - ctest_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); + igloo_tap_test("get userdata", ret == userdata); + igloo_tap_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == NULL); + igloo_tap_test("get userdata", ret == NULL); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); a = refobject_new_ext(refobject_base_t, userdata, NULL, REFOBJECT_NULL); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == userdata); - ctest_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); + igloo_tap_test("get userdata", ret == userdata); + igloo_tap_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == NULL); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("get userdata", ret == NULL); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_associated(void) @@ -182,13 +183,13 @@ static void test_associated(void) refobject_base_t *a, *b; a = refobject_new(refobject_base_t); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); b = refobject_new_ext(refobject_base_t, NULL, NULL, a); - ctest_test("refobject created with associated", !REFOBJECT_IS_NULL(b)); + igloo_tap_test("refobject created with associated", !REFOBJECT_IS_NULL(b)); - ctest_test("un-referenced (1 of 2)", refobject_unref(b) == 0); - ctest_test("un-referenced (2 of 2)", refobject_unref(a) == 0); + igloo_tap_test("un-referenced (1 of 2)", refobject_unref(b) == 0); + igloo_tap_test("un-referenced (2 of 2)", refobject_unref(a) == 0); } static size_t test_freecb__called; @@ -211,45 +212,41 @@ static void test_freecb(void) test_freecb__called = 0; a = refobject_new(ctest_test_type_t); - ctest_test("refobject created", a != NULL); - ctest_test("un-referenced", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0); - ctest_test("freecb called", test_freecb__called == 1); + igloo_tap_test("refobject created", a != NULL); + igloo_tap_test("un-referenced", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0); + igloo_tap_test("freecb called", test_freecb__called == 1); test_freecb__called = 0; a = refobject_new(ctest_test_type_t); - ctest_test("refobject created", a != NULL); - ctest_test("referenced", refobject_ref(REFOBJECT_FROM_TYPE(a)) == 0); - ctest_test("freecb uncalled", test_freecb__called == 0); - ctest_test("un-referenced (1 of 2)", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0); - ctest_test("freecb uncalled", test_freecb__called == 0); - ctest_test("un-referenced (2 of 2)", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0); - ctest_test("freecb called", test_freecb__called == 1); + igloo_tap_test("refobject created", a != NULL); + igloo_tap_test("referenced", refobject_ref(REFOBJECT_FROM_TYPE(a)) == 0); + igloo_tap_test("freecb uncalled", test_freecb__called == 0); + igloo_tap_test("un-referenced (1 of 2)", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0); + igloo_tap_test("freecb uncalled", test_freecb__called == 0); + igloo_tap_test("un-referenced (2 of 2)", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0); + igloo_tap_test("freecb called", test_freecb__called == 1); } int main (void) { - ctest_init(); + igloo_tap_init(); + igloo_tap_exit_on(igloo_TAP_EXIT_ON_FIN|igloo_TAP_EXIT_ON_BAIL_OUT, NULL); - test_ptr(); + igloo_tap_group_run("ptr", test_ptr); - if (ctest_bailed_out()) { - ctest_fin(); - return 1; - } + igloo_tap_group_run("ref-unref", test_create_ref_unref); - test_create_ref_unref(); + igloo_tap_group_run("typename", test_typename); + igloo_tap_group_run("valid", test_valid); - test_typename(); - test_valid(); + igloo_tap_group_run("sizes", test_sizes); - test_sizes(); + igloo_tap_group_run("name", test_name); + igloo_tap_group_run("userdata", test_userdata); + igloo_tap_group_run("associated", test_associated); + igloo_tap_group_run("freecb", test_freecb); - test_name(); - test_userdata(); - test_associated(); - test_freecb(); + igloo_tap_fin(); - ctest_fin(); - - return 0; + return EXIT_FAILURE; // return failure as we should never reach this point! } diff --git a/src/tests/ctest_resourcematch.c b/src/tests/ctest_resourcematch.c index e3094269..8c3ae70d 100644 --- a/src/tests/ctest_resourcematch.c +++ b/src/tests/ctest_resourcematch.c @@ -11,12 +11,27 @@ #endif #include /* for NULL */ -#include /* for snprintf() */ +#include /* for snprintf() */ +#include /* for EXIT_FAILURE */ +#include -#include "ctest_lib.h" +#include #include "../resourcematch.h" +static void ctest_diagnostic_printf(const char *format, ...) +{ + char buf[1024]; + va_list ap; + va_start(ap, format); + + vsnprintf(buf, sizeof(buf), format, ap); + + va_end(ap); + + igloo_tap_diagnostic(buf); +} + struct test { const char *pattern; const char *string; @@ -103,16 +118,16 @@ static inline resourcematch_result_t run_test_base(const struct test *test, reso if (extract) { if (test->expected_result == RESOURCEMATCH_MATCH) { if (*extract) { - ctest_diagnostic(" got extract"); + igloo_tap_diagnostic(" got extract"); } else { - ctest_diagnostic(" got no extract"); + igloo_tap_diagnostic(" got no extract"); ok = 0; } } } snprintf(name, sizeof(name), "pattern \"%s\" and string \"%s\" %s extract", test->pattern, test->string, extract ? "with" : "without"); - ctest_test(name, test->expected_result == ret && ok); + igloo_tap_test(name, test->expected_result == ret && ok); ctest_diagnostic_printf("Expected: %s, Got: %s, Ok: %i", res2str(test->expected_result), res2str(ret), ok); @@ -165,11 +180,12 @@ int main (void) { size_t i; - ctest_init(); + igloo_tap_init(); + igloo_tap_exit_on(igloo_TAP_EXIT_ON_FIN, NULL); for (i = 0; i < (sizeof(tests)/sizeof(*tests)); i++) { run_test(&(tests[i])); } - ctest_fin(); + igloo_tap_fin(); - return 0; + return EXIT_FAILURE; // return failure as we should never reach this point! } diff --git a/src/tests/ctest_suite.c b/src/tests/ctest_suite.c index 91f75873..5e2dfeeb 100644 --- a/src/tests/ctest_suite.c +++ b/src/tests/ctest_suite.c @@ -9,12 +9,15 @@ #ifdef HAVE_CONFIG_H #include #endif +#include /* for EXIT_FAILURE */ -#include "ctest_lib.h" +#include int main (void) { - ctest_init(); - ctest_test("suite working", 1); - ctest_fin(); - return 0; + igloo_tap_init(); + igloo_tap_exit_on(igloo_TAP_EXIT_ON_FIN, NULL); + igloo_tap_test("suite working", true); + igloo_tap_fin(); + + return EXIT_FAILURE; // return failure as we should never reach this point! }