diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index ab842bc..84f5500 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -73,5 +73,10 @@ ctest_logmsg_test_LDADD = libice_ctest.la \ src/logmsg.o check_PROGRAMS += ctest_logmsg.test +ctest_timing_test_SOURCES = %reldir%/ctest_timing.c +ctest_timing_test_LDADD = libice_ctest.la \ + src/timing.o +check_PROGRAMS += ctest_timing.test + # Add all programs to TESTS TESTS = $(check_PROGRAMS) diff --git a/src/tests/ctest_timing.c b/src/tests/ctest_timing.c new file mode 100644 index 0000000..ca0d612 --- /dev/null +++ b/src/tests/ctest_timing.c @@ -0,0 +1,48 @@ +/* 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" + +#include + +static void test_get_time(void) +{ + uint64_t a, b; + + a = igloo_timing_get_time(); + b = igloo_timing_get_time(); + ctest_test("Time increases", a <= b); +} + +static void test_sleep(void) +{ + uint64_t a, b; + + a = igloo_timing_get_time(); + igloo_timing_sleep(128); + b = igloo_timing_get_time(); + ctest_test("Slept", (a < b) && ((a + 256) > b)); +} + +int main (void) +{ + ctest_init(); + + test_get_time(); + test_sleep(); + + ctest_fin(); + + return 0; +}