MAINTAINERCLEANFILES = ABOUT-NLS INSTALL aclocal.m4 compile config.guess \
config.h.in config.rpath config.sub depcomp gtk-doc.make install-sh \
intltool-extract.in intltool-merge.in intltool-update.in ltmain.sh missing \
- ylwrap autom4te.cache \
+ ylwrap autom4te.cache test-driver \
$(addprefix 'm4/',$(addsuffix '.m4', $(macros_ignore)))
ACLOCAL_AMFLAGS = -I m4
interpreters/git/Makefile
interpreters/bocfel/Makefile
tests/Makefile
+tests/unit/Makefile
player/Makefile
player/config.py
docs/Makefile
+SUBDIRS = unit
+
AM_CFLAGS = -Wall
AM_CPPFLAGS = -I$(top_srcdir)
--- /dev/null
+# The rpath is necessary for check_ too (see rant in ../Makefile.am)
+TEST_PLUGIN_LIBTOOL_FLAGS = \
+ -module \
+ -shared \
+ -avoid-version \
+ -export-symbols-regex "^glk_main$$" \
+ -rpath $(abs_builddir) \
+ $(NULL)
+
+# Set up include dirs so that #include "glk.h" works
+AM_CPPFLAGS = -I$(top_srcdir)/libchimara $(CPPFLAGS)
+
+check_LTLIBRARIES = datetime.la
+datetime_la_SOURCES = datetime.c glkunit.c glkunit.h
+datetime_la_LDFLAGS = $(TEST_PLUGIN_LIBTOOL_FLAGS)
+
+TESTS = datetime.la
+TEST_EXTENSIONS = .la
+LA_LOG_COMPILER = $(builddir)/../plugin-loader
+
+CLEANFILES = \
+ test-suite.log \
+ $(TESTS) \
+ $(TESTS:.la=.log) \
+ $(TESTS:.la=.trs) \
+ $(NULL)
+
+-include $(top_srcdir)/git.mk
--- /dev/null
+#include "glk.h"
+#include "glkunit.h"
+
+static int
+test_current_time_equals_current_simple_time(void)
+{
+ glktimeval_t timeval;
+
+ /* This test will fail if the following two operations do not occur within
+ a second of each other. That is not a robust test, but you could argue that
+ there is a serious bug if either operation takes more than one second. */
+ glk_current_time(&timeval);
+ glsi32 simple_time = glk_current_simple_time(1);
+ ASSERT_EQUAL(simple_time, timeval.low_sec);
+
+ glk_current_time(&timeval);
+ glsi32 simple_time_high_bits = glk_current_simple_time(0xFFFFFFFF);
+ ASSERT_EQUAL(simple_time_high_bits, timeval.high_sec);
+
+ SUCCEED;
+}
+
+struct TestDescription tests[] = {
+ { "current time equals simple time", test_current_time_equals_current_simple_time },
+ { NULL, NULL }
+};
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include "glk.h"
+#include "glkunit.h"
+
+extern struct TestDescription tests[];
+
+void
+glk_main(void)
+{
+ struct TestDescription *test = tests;
+ int tested = 0, succeeded = 0, failed = 0;
+ while(test->name != NULL) {
+ tested++;
+ /* Use stdio.h to print to stdout, Glk can't do that */
+ printf(" Testing %s... ", test->name);
+ if( test->testfunc() ) {
+ succeeded++;
+ printf("PASS\n");
+ } else {
+ failed++;
+ printf("FAIL\n");
+ }
+ test++;
+ }
+ printf("%d tests run, %d failures\n", tested, failed);
+ exit(failed > 0);
+}
--- /dev/null
+#ifndef GLKUNIT_H
+#define GLKUNIT_H
+
+#include <stdio.h>
+
+#define _BEGIN do {
+#define _END } while(0);
+
+/* msg must be a string literal */
+#define _ASSERT(expr, msg, ...) _BEGIN \
+ if( !(expr) ) { \
+ fprintf(stderr, "Assertion failed: " msg "\n", __VA_ARGS__); \
+ return 0; \
+ } _END
+
+#define SUCCEED _BEGIN return 1; _END
+#define ASSERT(expr) _ASSERT(expr, "%s", #expr)
+#define ASSERT_EQUAL(expected, actual) _ASSERT((expected) == (actual), "%s == %s", #expected, #actual);
+
+struct TestDescription {
+ char *name;
+ int (*testfunc)(void);
+};
+
+#endif /* GLKUNIT_H */