aboutsummaryrefslogtreecommitdiff
path: root/c/test.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-15 22:22:20 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-15 22:22:20 +0200
commit8877627ee3fcd5a8f0ce2fcccec7688973e9cb2d (patch)
tree6a57fcb19aa77dfece89b000ae656c9549e7c156 /c/test.cpp
parent509c461498f0e68a62c004778df890d56ebb2a09 (diff)
downloadEpisodeBrowser-8877627ee3fcd5a8f0ce2fcccec7688973e9cb2d.tar.gz
Add testing system.HEADmaster
Diffstat (limited to 'c/test.cpp')
-rw-r--r--c/test.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/c/test.cpp b/c/test.cpp
new file mode 100644
index 0000000..9230974
--- /dev/null
+++ b/c/test.cpp
@@ -0,0 +1,50 @@
+#include "data.h"
+#include "test.h"
+#include "util.h"
+#include "win.h"
+
+Test::Test(const char* name_) : name(name_) {}
+
+#define CAT(a, b) a##b
+#define APPLY(a, ...) a(__VA_ARGS__)
+#define TESTS struct APPLY(CAT, tests_, __COUNTER__)
+#define TEST(id) }; struct id : public Test { id() : Test(#id)
+#define FAIL(...) do { Sprintf(error, __VA_ARGS__); return; } while (0)
+
+TESTS
+{
+ TEST(StrcpyWithSmallerDestination)
+ {
+ char src[15], dst[10];
+ Sprintf(src, "abcdefghijklmn");
+ Strcpy(dst, src);
+ if (dst[8] != 'i')
+ FAIL("dst[8] is not 'i', but '%c'", dst[8]);
+ if (dst[9] != 0)
+ FAIL("dst is not NUL-terminated");
+ }
+};
+
+int RunTests()
+{
+ const Test tests[] = {
+ StrcpyWithSmallerDestination{},
+ };
+
+ printf("Results (%llu tests):\n", sizeof(tests)/sizeof(*tests));
+
+ int cFailed = 0;
+ for (const Test& t : tests)
+ {
+ const char* msg;
+ if (t.error[0]) {
+ msg = t.error;
+ cFailed++;
+ } else
+ msg = const_cast<char*>("SUCCESS");
+ printf("%s: %s\n", t.name, msg);
+ }
+ printf("%d tests failed.\n", cFailed);
+
+ return cFailed;
+}