mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2025-02-02 15:07:36 -05:00
Cleanup: Migrated to libigloo's TAP support
This commit is contained in:
parent
ac5d17cbdb
commit
26b1449d19
@ -9,34 +9,26 @@ TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
|
|||||||
|
|
||||||
check_PROGRAMS =
|
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
|
# Test programs
|
||||||
#
|
#
|
||||||
|
|
||||||
ctest_suite_test_SOURCES = tests/ctest_suite.c
|
ctest_suite_test_SOURCES = tests/ctest_suite.c
|
||||||
ctest_suite_test_LDADD = libice_ctest.la
|
|
||||||
check_PROGRAMS += ctest_suite.test
|
check_PROGRAMS += ctest_suite.test
|
||||||
|
|
||||||
ctest_resourcematch_test_SOURCES = tests/ctest_resourcematch.c
|
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
|
check_PROGRAMS += ctest_resourcematch.test
|
||||||
|
|
||||||
ctest_refobject_test_SOURCES = tests/ctest_refobject.c
|
ctest_refobject_test_SOURCES = tests/ctest_refobject.c
|
||||||
ctest_refobject_test_LDADD = libice_ctest.la \
|
ctest_refobject_test_LDADD = \
|
||||||
common/thread/libicethread.la \
|
common/thread/libicethread.la \
|
||||||
common/avl/libiceavl.la \
|
common/avl/libiceavl.la \
|
||||||
icecast-refobject.o
|
icecast-refobject.o
|
||||||
check_PROGRAMS += ctest_refobject.test
|
check_PROGRAMS += ctest_refobject.test
|
||||||
|
|
||||||
ctest_buffer_test_SOURCES = tests/ctest_buffer.c
|
ctest_buffer_test_SOURCES = tests/ctest_buffer.c
|
||||||
ctest_buffer_test_LDADD = libice_ctest.la \
|
ctest_buffer_test_LDADD = \
|
||||||
common/thread/libicethread.la \
|
common/thread/libicethread.la \
|
||||||
common/avl/libiceavl.la \
|
common/avl/libiceavl.la \
|
||||||
icecast-refobject.o \
|
icecast-refobject.o \
|
||||||
|
@ -11,23 +11,39 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h> /* for EXIT_FAILURE */
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "ctest_lib.h"
|
#include <igloo/tap.h>
|
||||||
|
|
||||||
#include "../src/buffer.h"
|
#include "../src/buffer.h"
|
||||||
#include "../src/refobject.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)
|
static void test_create_ref_unref(void)
|
||||||
{
|
{
|
||||||
buffer_t *a;
|
buffer_t *a;
|
||||||
|
|
||||||
a = buffer_new(-1, NULL, NULL, REFOBJECT_NULL);
|
a = buffer_new(-1, NULL, NULL, REFOBJECT_NULL);
|
||||||
ctest_test("buffer created", a != NULL);
|
igloo_tap_test("buffer created", a != NULL);
|
||||||
ctest_test("un-referenced", refobject_unref(a) == 0);
|
igloo_tap_test("un-referenced", refobject_unref(a) == 0);
|
||||||
|
|
||||||
a = refobject_new(buffer_t);
|
a = refobject_new(buffer_t);
|
||||||
ctest_test("buffer created", a != NULL);
|
igloo_tap_test("buffer created", a != NULL);
|
||||||
ctest_test("un-referenced", refobject_unref(a) == 0);
|
igloo_tap_test("un-referenced", refobject_unref(a) == 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,13 +54,13 @@ static void test_name(void)
|
|||||||
const char *ret;
|
const char *ret;
|
||||||
|
|
||||||
a = buffer_new(-1, NULL, name, REFOBJECT_NULL);
|
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);
|
ret = refobject_get_name(a);
|
||||||
ctest_test("get name", ret != NULL);
|
igloo_tap_test("get name", ret != NULL);
|
||||||
ctest_test("name match", strcmp(name, ret) == 0);
|
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)
|
static void test_userdata(void)
|
||||||
@ -55,27 +71,27 @@ static void test_userdata(void)
|
|||||||
void *ret;
|
void *ret;
|
||||||
|
|
||||||
a = buffer_new(-1, NULL, NULL, REFOBJECT_NULL);
|
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);
|
ret = refobject_get_userdata(a);
|
||||||
ctest_test("get userdata", ret == NULL);
|
igloo_tap_test("get userdata", ret == NULL);
|
||||||
ctest_test("set userdata", refobject_set_userdata(a, userdata) == 0);
|
igloo_tap_test("set userdata", refobject_set_userdata(a, userdata) == 0);
|
||||||
ret = refobject_get_userdata(a);
|
ret = refobject_get_userdata(a);
|
||||||
ctest_test("get userdata", ret == userdata);
|
igloo_tap_test("get userdata", ret == userdata);
|
||||||
ctest_test("clearing userdata", refobject_set_userdata(a, NULL) == 0);
|
igloo_tap_test("clearing userdata", refobject_set_userdata(a, NULL) == 0);
|
||||||
ret = refobject_get_userdata(a);
|
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);
|
a = buffer_new(-1, userdata, NULL, REFOBJECT_NULL);
|
||||||
ctest_test("buffer created", a != NULL);
|
igloo_tap_test("buffer created", a != NULL);
|
||||||
ctest_test("refobject created", !REFOBJECT_IS_NULL(a));
|
igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a));
|
||||||
ret = refobject_get_userdata(a);
|
ret = refobject_get_userdata(a);
|
||||||
ctest_test("get userdata", ret == userdata);
|
igloo_tap_test("get userdata", ret == userdata);
|
||||||
ctest_test("clearing userdata", refobject_set_userdata(a, NULL) == 0);
|
igloo_tap_test("clearing userdata", refobject_set_userdata(a, NULL) == 0);
|
||||||
ret = refobject_get_userdata(a);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_associated(void)
|
static void test_associated(void)
|
||||||
@ -84,14 +100,14 @@ static void test_associated(void)
|
|||||||
buffer_t *b;
|
buffer_t *b;
|
||||||
|
|
||||||
a = refobject_new(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));
|
||||||
|
|
||||||
|
|
||||||
b = buffer_new(-1, NULL, 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);
|
igloo_tap_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 (2 of 2)", refobject_unref(a) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_empty(void)
|
static void test_empty(void)
|
||||||
@ -103,39 +119,39 @@ static void test_empty(void)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
a = refobject_new(buffer_t);
|
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);
|
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) {
|
if (ret == 0) {
|
||||||
ctest_test("data is updated", data != &data);
|
igloo_tap_test("data is updated", data != &data);
|
||||||
ctest_test("length is zero", length == 0);
|
igloo_tap_test("length is zero", length == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
data = &data;
|
data = &data;
|
||||||
ret = buffer_get_data(a, &data, NULL);
|
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) {
|
if (ret == 0) {
|
||||||
ctest_test("data is updated", data != &data);
|
igloo_tap_test("data is updated", data != &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
length = 5;
|
length = 5;
|
||||||
ret = buffer_get_data(a, NULL, &length);
|
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) {
|
if (ret == 0) {
|
||||||
ctest_test("length is zero", length == 0);
|
igloo_tap_test("length is zero", length == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = buffer_get_string(a, &string);
|
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) {
|
if (ret == 0) {
|
||||||
ctest_test("string is non-NULL", string != NULL);
|
igloo_tap_test("string is non-NULL", string != NULL);
|
||||||
if (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)
|
static void test_string(void)
|
||||||
@ -148,29 +164,29 @@ static void test_string(void)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
a = refobject_new(buffer_t);
|
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, hw) == 0);
|
igloo_tap_test("pushed string", buffer_push_string(a, hw) == 0);
|
||||||
ret = buffer_get_string(a, &string);
|
ret = buffer_get_string(a, &string);
|
||||||
ctest_test("got strong", ret == 0);
|
igloo_tap_test("got strong", ret == 0);
|
||||||
if (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) {
|
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;
|
string = NULL;
|
||||||
ret = buffer_get_string(a, &string);
|
ret = buffer_get_string(a, &string);
|
||||||
ctest_test("got strong", ret == 0);
|
igloo_tap_test("got strong", ret == 0);
|
||||||
if (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) {
|
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)
|
static void test_binary(void)
|
||||||
@ -183,38 +199,38 @@ static void test_binary(void)
|
|||||||
const void *data;
|
const void *data;
|
||||||
|
|
||||||
a = refobject_new(buffer_t);
|
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;
|
length = sizeof(pattern_a) + 42;
|
||||||
data = &data;
|
data = &data;
|
||||||
ret = buffer_get_data(a, &data, &length);
|
ret = buffer_get_data(a, &data, &length);
|
||||||
ctest_test("got data", ret == 0);
|
igloo_tap_test("got data", ret == 0);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
ctest_test("correct length was returned", length == sizeof(pattern_a));
|
igloo_tap_test("correct length was returned", length == sizeof(pattern_a));
|
||||||
ctest_test("data is non-NULL", data != NULL);
|
igloo_tap_test("data is non-NULL", data != NULL);
|
||||||
ctest_test("data has been set", data != &data);
|
igloo_tap_test("data has been set", data != &data);
|
||||||
if (length == sizeof(pattern_a) && data != NULL && 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;
|
length = sizeof(pattern_a) + sizeof(pattern_b) + 42;
|
||||||
data = &data;
|
data = &data;
|
||||||
ret = buffer_get_data(a, &data, &length);
|
ret = buffer_get_data(a, &data, &length);
|
||||||
ctest_test("got data", ret == 0);
|
igloo_tap_test("got data", ret == 0);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
ctest_test("correct length was returned", length == (sizeof(pattern_a) + sizeof(pattern_b)));
|
igloo_tap_test("correct length was returned", length == (sizeof(pattern_a) + sizeof(pattern_b)));
|
||||||
ctest_test("data is non-NULL", data != NULL);
|
igloo_tap_test("data is non-NULL", data != NULL);
|
||||||
ctest_test("data has been set", data != &data);
|
igloo_tap_test("data has been set", data != &data);
|
||||||
if (length == (sizeof(pattern_a) + sizeof(pattern_b)) && data != NULL && 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)
|
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;
|
int ret;
|
||||||
|
|
||||||
ret = buffer_get_string(a, &string);
|
ret = buffer_get_string(a, &string);
|
||||||
ctest_test("got strong", ret == 0);
|
igloo_tap_test("got strong", ret == 0);
|
||||||
if (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) {
|
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);
|
ctest_diagnostic_printf("string=\"%s\", pattern=\"%s\"", string, pattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -239,21 +255,21 @@ static void test_shift(void)
|
|||||||
const char *pattern = "AABBBCC";
|
const char *pattern = "AABBBCC";
|
||||||
|
|
||||||
a = refobject_new(buffer_t);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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)
|
static void test_length(void)
|
||||||
@ -265,20 +281,20 @@ static void test_length(void)
|
|||||||
const char *match_c = "";
|
const char *match_c = "";
|
||||||
|
|
||||||
a = refobject_new(buffer_t);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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)
|
static void test_printf(void)
|
||||||
@ -291,16 +307,16 @@ static void test_printf(void)
|
|||||||
const char *match_c = ":Hello World!:<-127 >? +127?";
|
const char *match_c = ":Hello World!:<-127 >? +127?";
|
||||||
|
|
||||||
a = refobject_new(buffer_t);
|
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);
|
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);
|
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);
|
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)
|
static void test_push_buffer(void)
|
||||||
@ -311,45 +327,45 @@ static void test_push_buffer(void)
|
|||||||
const char *match_a = "AABBBCCAABBBCC";
|
const char *match_a = "AABBBCCAABBBCC";
|
||||||
|
|
||||||
a = refobject_new(buffer_t);
|
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);
|
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);
|
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);
|
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);
|
test__compare_to_string(b, "string matches pattern a", match_a);
|
||||||
|
|
||||||
ctest_test("un-referenced b", refobject_unref(b) == 0);
|
igloo_tap_test("un-referenced b", refobject_unref(b) == 0);
|
||||||
ctest_test("un-referenced a", refobject_unref(a) == 0);
|
igloo_tap_test("un-referenced a", refobject_unref(a) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (void)
|
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();
|
igloo_tap_group_run("empty", test_empty);
|
||||||
test_userdata();
|
igloo_tap_group_run("string", test_string);
|
||||||
test_associated();
|
igloo_tap_group_run("binary", test_binary);
|
||||||
|
|
||||||
test_empty();
|
igloo_tap_group_run("shift", test_shift);
|
||||||
test_string();
|
igloo_tap_group_run("length", test_length);
|
||||||
test_binary();
|
|
||||||
|
|
||||||
test_shift();
|
igloo_tap_group_run("printf", test_printf);
|
||||||
test_length();
|
igloo_tap_group_run("push_buffer", test_push_buffer);
|
||||||
|
|
||||||
test_printf();
|
igloo_tap_fin();
|
||||||
test_push_buffer();
|
|
||||||
|
|
||||||
ctest_fin();
|
return EXIT_FAILURE; // return failure as we should never reach this point!
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -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 <lion@lion.leolix.org>,
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
#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;
|
|
||||||
}
|
|
@ -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 <lion@lion.leolix.org>,
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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
|
|
@ -11,8 +11,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h> /* for EXIT_FAILURE */
|
||||||
|
|
||||||
#include "ctest_lib.h"
|
#include <igloo/tap.h>
|
||||||
|
|
||||||
#include "../refobject.h"
|
#include "../refobject.h"
|
||||||
|
|
||||||
@ -21,10 +22,10 @@ static void test_ptr(void)
|
|||||||
refobject_t a;
|
refobject_t a;
|
||||||
|
|
||||||
a = REFOBJECT_NULL;
|
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))
|
if (!REFOBJECT_IS_NULL(a))
|
||||||
ctest_bailed_out();
|
igloo_tap_bail_out(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_create_ref_unref(void)
|
static void test_create_ref_unref(void)
|
||||||
@ -32,11 +33,11 @@ static void test_create_ref_unref(void)
|
|||||||
refobject_base_t *a;
|
refobject_base_t *a;
|
||||||
|
|
||||||
a = refobject_new(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("referenced", refobject_ref(a) == 0);
|
igloo_tap_test("referenced", refobject_ref(a) == 0);
|
||||||
ctest_test("un-referenced (1 of 2)", refobject_unref(a) == 0);
|
igloo_tap_test("un-referenced (1 of 2)", refobject_unref(a) == 0);
|
||||||
ctest_test("un-referenced (2 of 2)", refobject_unref(a) == 0);
|
igloo_tap_test("un-referenced (2 of 2)", refobject_unref(a) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_typename(void)
|
static void test_typename(void)
|
||||||
@ -45,13 +46,13 @@ static void test_typename(void)
|
|||||||
const char *typename;
|
const char *typename;
|
||||||
|
|
||||||
a = refobject_new(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));
|
||||||
|
|
||||||
typename = REFOBJECT_GET_TYPENAME(a);
|
typename = REFOBJECT_GET_TYPENAME(a);
|
||||||
ctest_test("got typename", typename != NULL);
|
igloo_tap_test("got typename", typename != NULL);
|
||||||
ctest_test("typename matches", strcmp(typename, "refobject_base_t") == 0);
|
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)
|
static void test_valid(void)
|
||||||
@ -64,15 +65,15 @@ static void test_valid(void)
|
|||||||
|
|
||||||
REFOBJECT_DEFINE_PRIVATE_TYPE(ctest_test_type_t);
|
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);
|
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));
|
igloo_tap_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 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)
|
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));
|
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));
|
igloo_tap_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("un-referenced", refobject_unref(a) == 0);
|
||||||
|
|
||||||
a = REFOBJECT_FROM_TYPE(refobject_new(ctest_test_type_b_t));
|
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));
|
igloo_tap_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("un-referenced", refobject_unref(a) == 0);
|
||||||
|
|
||||||
a = REFOBJECT_FROM_TYPE(refobject_new(ctest_test_type_c_t));
|
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)) {
|
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));
|
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)) {
|
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;
|
const char *ret;
|
||||||
|
|
||||||
a = refobject_new_ext(refobject_base_t, NULL, name, REFOBJECT_NULL);
|
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);
|
ret = refobject_get_name(a);
|
||||||
ctest_test("get name", ret != NULL);
|
igloo_tap_test("get name", ret != NULL);
|
||||||
ctest_test("name match", strcmp(name, ret) == 0);
|
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)
|
static void test_userdata(void)
|
||||||
@ -154,27 +155,27 @@ static void test_userdata(void)
|
|||||||
void *ret;
|
void *ret;
|
||||||
|
|
||||||
a = refobject_new(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));
|
||||||
|
|
||||||
ret = refobject_get_userdata(a);
|
ret = refobject_get_userdata(a);
|
||||||
ctest_test("get userdata", ret == NULL);
|
igloo_tap_test("get userdata", ret == NULL);
|
||||||
ctest_test("set userdata", refobject_set_userdata(a, userdata) == 0);
|
igloo_tap_test("set userdata", refobject_set_userdata(a, userdata) == 0);
|
||||||
ret = refobject_get_userdata(a);
|
ret = refobject_get_userdata(a);
|
||||||
ctest_test("get userdata", ret == userdata);
|
igloo_tap_test("get userdata", ret == userdata);
|
||||||
ctest_test("clearing userdata", refobject_set_userdata(a, NULL) == 0);
|
igloo_tap_test("clearing userdata", refobject_set_userdata(a, NULL) == 0);
|
||||||
ret = refobject_get_userdata(a);
|
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);
|
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);
|
ret = refobject_get_userdata(a);
|
||||||
ctest_test("get userdata", ret == userdata);
|
igloo_tap_test("get userdata", ret == userdata);
|
||||||
ctest_test("clearing userdata", refobject_set_userdata(a, NULL) == 0);
|
igloo_tap_test("clearing userdata", refobject_set_userdata(a, NULL) == 0);
|
||||||
ret = refobject_get_userdata(a);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_associated(void)
|
static void test_associated(void)
|
||||||
@ -182,13 +183,13 @@ static void test_associated(void)
|
|||||||
refobject_base_t *a, *b;
|
refobject_base_t *a, *b;
|
||||||
|
|
||||||
a = refobject_new(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));
|
||||||
|
|
||||||
b = refobject_new_ext(refobject_base_t, NULL, 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);
|
igloo_tap_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 (2 of 2)", refobject_unref(a) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t test_freecb__called;
|
static size_t test_freecb__called;
|
||||||
@ -211,45 +212,41 @@ static void test_freecb(void)
|
|||||||
|
|
||||||
test_freecb__called = 0;
|
test_freecb__called = 0;
|
||||||
a = refobject_new(ctest_test_type_t);
|
a = refobject_new(ctest_test_type_t);
|
||||||
ctest_test("refobject created", a != NULL);
|
igloo_tap_test("refobject created", a != NULL);
|
||||||
ctest_test("un-referenced", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0);
|
igloo_tap_test("un-referenced", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0);
|
||||||
ctest_test("freecb called", test_freecb__called == 1);
|
igloo_tap_test("freecb called", test_freecb__called == 1);
|
||||||
|
|
||||||
test_freecb__called = 0;
|
test_freecb__called = 0;
|
||||||
a = refobject_new(ctest_test_type_t);
|
a = refobject_new(ctest_test_type_t);
|
||||||
ctest_test("refobject created", a != NULL);
|
igloo_tap_test("refobject created", a != NULL);
|
||||||
ctest_test("referenced", refobject_ref(REFOBJECT_FROM_TYPE(a)) == 0);
|
igloo_tap_test("referenced", refobject_ref(REFOBJECT_FROM_TYPE(a)) == 0);
|
||||||
ctest_test("freecb uncalled", test_freecb__called == 0);
|
igloo_tap_test("freecb uncalled", test_freecb__called == 0);
|
||||||
ctest_test("un-referenced (1 of 2)", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0);
|
igloo_tap_test("un-referenced (1 of 2)", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0);
|
||||||
ctest_test("freecb uncalled", test_freecb__called == 0);
|
igloo_tap_test("freecb uncalled", test_freecb__called == 0);
|
||||||
ctest_test("un-referenced (2 of 2)", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0);
|
igloo_tap_test("un-referenced (2 of 2)", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0);
|
||||||
ctest_test("freecb called", test_freecb__called == 1);
|
igloo_tap_test("freecb called", test_freecb__called == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (void)
|
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()) {
|
igloo_tap_group_run("ref-unref", test_create_ref_unref);
|
||||||
ctest_fin();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
test_create_ref_unref();
|
igloo_tap_group_run("typename", test_typename);
|
||||||
|
igloo_tap_group_run("valid", test_valid);
|
||||||
|
|
||||||
test_typename();
|
igloo_tap_group_run("sizes", test_sizes);
|
||||||
test_valid();
|
|
||||||
|
|
||||||
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();
|
igloo_tap_fin();
|
||||||
test_userdata();
|
|
||||||
test_associated();
|
|
||||||
test_freecb();
|
|
||||||
|
|
||||||
ctest_fin();
|
return EXIT_FAILURE; // return failure as we should never reach this point!
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,27 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stddef.h> /* for NULL */
|
#include <stddef.h> /* for NULL */
|
||||||
#include <stdio.h> /* for snprintf() */
|
#include <stdio.h> /* for snprintf() */
|
||||||
|
#include <stdlib.h> /* for EXIT_FAILURE */
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "ctest_lib.h"
|
#include <igloo/tap.h>
|
||||||
|
|
||||||
#include "../resourcematch.h"
|
#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 {
|
struct test {
|
||||||
const char *pattern;
|
const char *pattern;
|
||||||
const char *string;
|
const char *string;
|
||||||
@ -103,16 +118,16 @@ static inline resourcematch_result_t run_test_base(const struct test *test, reso
|
|||||||
if (extract) {
|
if (extract) {
|
||||||
if (test->expected_result == RESOURCEMATCH_MATCH) {
|
if (test->expected_result == RESOURCEMATCH_MATCH) {
|
||||||
if (*extract) {
|
if (*extract) {
|
||||||
ctest_diagnostic(" got extract");
|
igloo_tap_diagnostic(" got extract");
|
||||||
} else {
|
} else {
|
||||||
ctest_diagnostic(" got no extract");
|
igloo_tap_diagnostic(" got no extract");
|
||||||
ok = 0;
|
ok = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(name, sizeof(name), "pattern \"%s\" and string \"%s\" %s extract", test->pattern, test->string, extract ? "with" : "without");
|
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);
|
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;
|
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++) {
|
for (i = 0; i < (sizeof(tests)/sizeof(*tests)); i++) {
|
||||||
run_test(&(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!
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,15 @@
|
|||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <stdlib.h> /* for EXIT_FAILURE */
|
||||||
|
|
||||||
#include "ctest_lib.h"
|
#include <igloo/tap.h>
|
||||||
|
|
||||||
int main (void) {
|
int main (void) {
|
||||||
ctest_init();
|
igloo_tap_init();
|
||||||
ctest_test("suite working", 1);
|
igloo_tap_exit_on(igloo_TAP_EXIT_ON_FIN, NULL);
|
||||||
ctest_fin();
|
igloo_tap_test("suite working", true);
|
||||||
return 0;
|
igloo_tap_fin();
|
||||||
|
|
||||||
|
return EXIT_FAILURE; // return failure as we should never reach this point!
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user