Add Glk unit test framework
[projects/chimara/chimara.git] / tests / unit / glkunit.h
diff --git a/tests/unit/glkunit.h b/tests/unit/glkunit.h
new file mode 100644 (file)
index 0000000..3828987
--- /dev/null
@@ -0,0 +1,25 @@
+#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 */