mirror of
https://github.com/labwc/labwc.git
synced 2025-10-29 05:40:24 -04:00
Add tests/t1000-rcxml-simple-parse.c
This commit is contained in:
parent
91ce33dd0d
commit
40c0b169ef
5 changed files with 142 additions and 0 deletions
|
|
@ -46,6 +46,7 @@ labwc_inc = include_directories('include')
|
|||
|
||||
subdir('protocols')
|
||||
subdir('src')
|
||||
subdir('tests')
|
||||
|
||||
labwc_deps = [
|
||||
server_protos, wayland_server, wlroots, xkbcommon, xml2
|
||||
|
|
|
|||
15
tests/meson.build
Normal file
15
tests/meson.build
Normal file
|
|
@ -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)
|
||||
36
tests/t1000-rcxml-simple-parse.c
Normal file
36
tests/t1000-rcxml-simple-parse.c
Normal file
|
|
@ -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);
|
||||
}
|
||||
73
tests/tap.c
Normal file
73
tests/tap.c
Normal file
|
|
@ -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;
|
||||
}
|
||||
17
tests/tap.h
Normal file
17
tests/tap.h
Normal file
|
|
@ -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 */
|
||||
Loading…
Add table
Add a link
Reference in a new issue