Skip to content

Commit 5e103a2

Browse files
committed
Add tests/t1001-nodenames.c
1 parent be320f1 commit 5e103a2

File tree

2 files changed

+54
-11
lines changed

2 files changed

+54
-11
lines changed

tests/meson.build

+6-11
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@ test_lib = static_library(
66
dependencies: [dependency('libxml-2.0'), dependency('glib-2.0')],
77
)
88

9-
tests = [
10-
't1000-add-xpath-node.c',
11-
]
9+
t = 't1000-add-xpath-node.c'
10+
testname = t.split('.')[0].underscorify()
11+
exe = executable(testname, sources: [t, 'tap.c'], dependencies: [dependency('glib-2.0')], link_with: [test_lib])
12+
test(testname, exe)
1213

13-
foreach t : tests
14+
t = 't1001-nodenames.c'
1415
testname = t.split('.')[0].underscorify()
15-
exe = executable(
16-
testname,
17-
sources: [t, 'tap.c'],
18-
dependencies: [dependency('glib-2.0')],
19-
link_with: [test_lib],
20-
)
16+
exe = executable(testname, sources: [t, 'tap.c'], dependencies: [dependency('libxml-2.0'), dependency('glib-2.0')])
2117
test(testname, exe)
22-
endforeach
2318

tests/t1001-nodenames.c

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#define _POSIX_C_SOURCE 200809L
2+
#include <glib.h>
3+
#include <stdbool.h>
4+
#include <stdio.h>
5+
#include <unistd.h>
6+
#include "tap.h"
7+
#include "../xml.c"
8+
9+
static char template[] =
10+
"<?xml version=\"1.0\"?>\n"
11+
"<labwc_config>\n"
12+
" <core>\n"
13+
" <gap/>\n"
14+
" </core>\n"
15+
"</labwc_config>\n";
16+
17+
void test(const char *nodename, const char *expect)
18+
{
19+
bool is_equal = strcmp(nodename, expect) == 0;
20+
ok1(is_equal);
21+
if (!is_equal)
22+
fprintf(stderr, "%s\n%s\n", nodename, expect);
23+
}
24+
25+
int main(int argc, char **argv)
26+
{
27+
char in[] = "/tmp/t1001-expect_XXXXXX";
28+
static char buffer[256] = { 0 };
29+
30+
plan(1);
31+
32+
int fd = mkstemp(in);
33+
if (fd < 0)
34+
exit(EXIT_FAILURE);
35+
write(fd, template, sizeof(template) - 1);
36+
37+
/* test 1 */
38+
diag("generate simple xpath style nodename");
39+
xml_init(in);
40+
xmlNode *node = get_node((xmlChar *)"/labwc_config/core/gap");
41+
char *name = nodename(node, buffer, sizeof(buffer), false);
42+
xml_finish();
43+
test(name, "/labwc_config/core/gap");
44+
45+
unlink(in);
46+
return exit_status();
47+
}
48+

0 commit comments

Comments
 (0)