mirror of
https://gitlab.xiph.org/xiph/icecast-common.git
synced 2024-12-04 14:46:31 -05:00
Feature: Added basic test framework
This commit is contained in:
parent
d196273440
commit
81780410aa
@ -40,3 +40,5 @@ AM_CFLAGS = -I$(top_srcdir)/include
|
||||
|
||||
static:
|
||||
$(MAKE) all LDFLAGS="${LDFLAGS} -all-static"
|
||||
|
||||
include $(srcdir)/src/tests/Makefile.am
|
||||
|
@ -147,6 +147,8 @@ CFLAGS="${CFLAGS} ${PTHREAD_CFLAGS}"
|
||||
CPPFLAGS="${CPPFLAGS} ${PTHREAD_CPPFLAGS}"
|
||||
LIBS="${LIBS} ${PTHREAD_LIBS}"
|
||||
|
||||
AC_REQUIRE_AUX_FILE([tap-driver.sh])
|
||||
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
AX_PREFIX_CONFIG_H([include/igloo/config.h], [igloo_CTC])
|
||||
|
||||
|
28
src/tests/Makefile.am
Normal file
28
src/tests/Makefile.am
Normal file
@ -0,0 +1,28 @@
|
||||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
#######################
|
||||
# libigloo unit tests #
|
||||
#######################
|
||||
|
||||
TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
|
||||
$(top_srcdir)/build-aux/tap-driver.sh
|
||||
|
||||
check_PROGRAMS =
|
||||
|
||||
#
|
||||
# Helper library for TAP tests
|
||||
#
|
||||
|
||||
libice_ctest_la_SOURCES = %reldir%/ctest_lib.c %reldir%/ctest_lib.h
|
||||
noinst_LTLIBRARIES = libice_ctest.la
|
||||
|
||||
#
|
||||
# Test programs
|
||||
#
|
||||
|
||||
ctest_suite_test_SOURCES = %reldir%/ctest_suite.c
|
||||
ctest_suite_test_LDADD = libice_ctest.la
|
||||
check_PROGRAMS += ctest_suite.test
|
||||
|
||||
# Add all programs to TESTS
|
||||
TESTS = $(check_PROGRAMS)
|
84
src/tests/ctest_lib.c
Normal file
84
src/tests/ctest_lib.c
Normal file
@ -0,0 +1,84 @@
|
||||
/* 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;
|
||||
}
|
21
src/tests/ctest_lib.h
Normal file
21
src/tests/ctest_lib.h
Normal file
@ -0,0 +1,21 @@
|
||||
/* 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
|
20
src/tests/ctest_suite.c
Normal file
20
src/tests/ctest_suite.c
Normal file
@ -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 <lion@lion.leolix.org>,
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "ctest_lib.h"
|
||||
|
||||
int main (void) {
|
||||
ctest_init();
|
||||
ctest_test("suite working", 1);
|
||||
ctest_fin();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user