1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
#include <string.h>
#include <kalmia.h>
#include "xml.h"
#include "test/test.h"
LILY_FILE_BEGIN(xml_suite)
LILY_TEST("get xml attributes")
{
struct kai_tag_t *t = kai_parse_string(
"<tag attr1=\"hello\" attr2=\"world\"></tag>"
);
char *attr1 = kai_tag_get_attr(t, "attr1");
REQUIRE_NEQ(attr1, NULL, "%p");
CHECK_EQS(attr1, "hello");
char *attr2 = kai_tag_get_attr(t, "attr2");
REQUIRE_NEQ(attr2, NULL, "%p");
CHECK_EQS(attr2, "world");
char *attr3 = kai_tag_get_attr(t, "attr3");
CHECK_EQ(attr3, NULL, "%p");
kai_tag_destroy(t);
}
#include LILY_PUSH_TEST()
LILY_TEST("convert xml attribute to long")
{
struct kai_tag_t *t = kai_parse_string(
"<tag attr1=\"10\" qq=\"12\"></tag>"
);
int n = kai_tag_attr_to_long(t, "attr1", 0);
CHECK_EQ(n, 10, "%d");
int m = kai_tag_attr_to_long(t, "attr2", 14);
CHECK_EQ(m, 14, "%d");
kai_tag_destroy(t);
}
#include LILY_PUSH_TEST()
LILY_TEST("duplicate xml attributes")
{
struct kai_tag_t *t = kai_parse_string(
"<tag attr1=\"hello\"></tag>"
);
char *a = kai_tag_attr_to_dup(t, "attr1");
char *b = kai_tag_attr_to_dup(t, "attr1");
char *c = kai_tag_attr_to_dup(t, "dne");
kai_tag_destroy(t);
REQUIRE_NEQ(a, NULL, "%p");
REQUIRE_NEQ(b, NULL, "%p");
CHECK_EQ(c, NULL, "%p");
CHECK_EQS(a, "hello");
CHECK_EQS(b, "hello");
CHECK_NEQ(a, b, "%p");
free(a); free(b);
}
#include LILY_PUSH_TEST()
LILY_TEST("count xml tag children")
{
struct kai_tag_t *t = kai_parse_string(
"<no_kids />"
);
int child_count = kai_tag_num_children(t);
CHECK_EQ(child_count, 0, "%d");
kai_tag_destroy(t);
t = kai_parse_string(
"<one_child>"
" <child />"
"</one_child>"
);
child_count = kai_tag_num_children(t);
CHECK_EQ(child_count, 1, "%d");
kai_tag_destroy(t);
t = kai_parse_string(
"<six_kids>"
" <child />"
" <child />"
" <child />"
" <child />"
" <child />"
" <child />"
"</six_kids>"
);
child_count = kai_tag_num_children(t);
CHECK_EQ(child_count, 6, "%d");
kai_tag_destroy(t);
}
#include LILY_PUSH_TEST()
#define LILY_FILE_END
#include LILY_REGISTER_TESTS()
|