From: Johan Malm Date: Mon, 8 Jun 2020 20:10:45 +0000 (+0100) Subject: Add tests/t1000-rcxml-simple-parse.c X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=40c0b169efffdfa4a7615041c12373bbadf2d0cc;p=proto%2Flabwc.git Add tests/t1000-rcxml-simple-parse.c --- diff --git a/meson.build b/meson.build index 9c2d8a5e..fe4feeb0 100644 --- a/meson.build +++ b/meson.build @@ -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 index 00000000..aa0c5a36 --- /dev/null +++ b/tests/meson.build @@ -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 index 00000000..d3f98c0f --- /dev/null +++ b/tests/t1000-rcxml-simple-parse.c @@ -0,0 +1,36 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include + +#include "rcxml.h" +#include "tap.h" + +struct rcxml rc = { 0 }; + +static char src[] = +"\n" +"\n" +"\n" +" yes\n" +"\n" +"\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 index 00000000..7b0c3419 --- /dev/null +++ b/tests/tap.c @@ -0,0 +1,73 @@ +#include +#include +#include +#include +#include +#include + +#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 index 00000000..0f59d581 --- /dev/null +++ b/tests/tap.h @@ -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 */