]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Add tests/t1000-rcxml-simple-parse.c
authorJohan Malm <jgm323@gmail.com>
Mon, 8 Jun 2020 20:10:45 +0000 (21:10 +0100)
committerJohan Malm <jgm323@gmail.com>
Mon, 8 Jun 2020 20:10:45 +0000 (21:10 +0100)
meson.build
tests/meson.build [new file with mode: 0644]
tests/t1000-rcxml-simple-parse.c [new file with mode: 0644]
tests/tap.c [new file with mode: 0644]
tests/tap.h [new file with mode: 0644]

index 9c2d8a5ebb1067864a121c9f5be13caedf2aa8df..fe4feeb09c19226b11cb86bbf5a31d22ca4428e9 100644 (file)
@@ -46,6 +46,7 @@ labwc_inc       = include_directories('include')
 
 subdir('protocols')
 subdir('src')
+subdir('tests')
 
 labwc_deps      = [
   server_protos, wayland_server, wlroots, xkbcommon, xml2
diff --git a/tests/meson.build b/tests/meson.build
new file mode 100644 (file)
index 0000000..aa0c5a3
--- /dev/null
@@ -0,0 +1,15 @@
+rcxml_lib = static_library(
+  'rcxml',
+  sources: ['../src/config/rcxml.c'],
+  dependencies: xml2,
+  include_directories: [labwc_inc],
+  link_with: library('libxml-2.0'),
+)
+
+t1000 = executable(
+  't1000-rcxml-simple-parse',
+  sources: ['t1000-rcxml-simple-parse.c', 'tap.c'],
+  include_directories: [labwc_inc],
+  link_with: rcxml_lib,
+)
+test('t1000', t1000)
diff --git a/tests/t1000-rcxml-simple-parse.c b/tests/t1000-rcxml-simple-parse.c
new file mode 100644 (file)
index 0000000..d3f98c0
--- /dev/null
@@ -0,0 +1,36 @@
+#define _POSIX_C_SOURCE 200809L
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdbool.h>
+
+#include "rcxml.h"
+#include "tap.h"
+
+struct rcxml rc = { 0 };
+
+static char src[] =
+"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+"<openbox_config>\n"
+"<lab>\n"
+"  <csd>yes</csd>\n"
+"</lab>\n"
+"</openbox_config>\n";
+
+int main(int argc, char **argv)
+{
+       plan(1);
+
+       char template[] = "temp_file_XXXXXX";
+       int fd = mkstemp(template);
+       if (fd < 0)
+               exit(1);
+       write(fd, src, sizeof(src) - 1);
+
+       rcxml_init(&rc);
+       rcxml_read(template);
+       unlink(template);
+
+       diag("Simple parse rc.xml");
+       ok1(rc.client_side_decorations);
+}
diff --git a/tests/tap.c b/tests/tap.c
new file mode 100644 (file)
index 0000000..7b0c341
--- /dev/null
@@ -0,0 +1,73 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <stdbool.h>
+
+#include "tap.h"
+
+static int nr_tests_run;
+static int nr_tests_expected;
+static int nr_tests_failed;
+
+void plan(int nr_tests)
+{
+       static bool run_once;
+
+       if (run_once)
+               return;
+       run_once = true;
+       printf("1..%d\n", nr_tests);
+       nr_tests_expected = nr_tests;
+}
+
+void diag(const char *fmt, ...)
+{
+       va_list params;
+
+       fprintf(stdout, "# ");
+       va_start(params, fmt);
+       vfprintf(stdout, fmt, params);
+       va_end(params);
+       fprintf(stdout, "\n");
+}
+
+int ok(int result, const char *testname, ...)
+{
+       va_list params;
+
+       ++nr_tests_run;
+       if (!result) {
+               printf("not ");
+               nr_tests_failed++;
+       }
+       printf("ok %d", nr_tests_run);
+       if (testname) {
+               printf(" - ");
+               va_start(params, testname);
+               vfprintf(stdout, testname, params);
+               va_end(params);
+       }
+       printf("\n");
+       if (!result)
+               diag("    Failed test");
+       return result ? 1 : 0;
+}
+
+int exit_status(void)
+{
+       int ret;
+
+       if (nr_tests_expected != nr_tests_run) {
+               diag("expected=%d; run=%d; failed=%d", nr_tests_expected,
+                    nr_tests_run, nr_tests_failed);
+       }
+       if (nr_tests_expected < nr_tests_run)
+               ret = nr_tests_run - nr_tests_expected;
+       else
+               ret = nr_tests_failed + nr_tests_expected - nr_tests_run;
+       if (ret > 255)
+               ret = 255;
+       return ret;
+}
diff --git a/tests/tap.h b/tests/tap.h
new file mode 100644 (file)
index 0000000..0f59d58
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Minimalist, partial TAP implementation
+ *
+ * Copyright Johan Malm 2020
+ */
+
+#ifndef TAP_H
+#define TAP_H
+
+#define ok1(__x__) (ok(__x__, "%s", #__x__))
+
+void plan(int nr_tests);
+void diag(const char *fmt, ...);
+int ok(int result, const char *test_name, ...);
+int exit_status(void);
+
+#endif /* TAP_H */