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
|
#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()
#define LILY_FILE_END
#include LILY_REGISTER_TESTS()
|