Debian Codegraph @

skeletons/tests/check-XER.c

raw symbols SCIP
1 #include <stdio.h>
2 #include <assert.h>
3
4 #include <asn_internal.h>
5 #include <xer_decoder.h>
6
7 static void
8 check(char *tag, char *name, xer_check_tag_e value) {
9 xer_check_tag_e xct;
10
11 xct = xer_check_tag(tag, strlen(tag), name);
12 printf("[%s] vs [%s]: %d == %d\n",
13 tag, name, xct, value);
14 assert(xct == value);
15 }
16
17 static void
18 check_next(char *xerbuf, int expected_chunk_size, pxer_chunk_type_e expected_chunk_type) {
19 int xerbuf_len = strlen(xerbuf);
20 pxer_chunk_type_e ch_type;
21 ssize_t ch_size;
22 int state = 0;
23
24 if(expected_chunk_size == -1)
25 expected_chunk_size = xerbuf_len;
26 ch_size = xer_next_token(&state, xerbuf, xerbuf_len, &ch_type);
27
28 printf("[%s]:%d\n", xerbuf, xerbuf_len);
29 printf("chunk sizes: %ld vs %ld, chunk types: %d vs %ld\n",
30 (long)ch_size, (long)expected_chunk_size,
31 ch_type, (long)expected_chunk_type
32 );
33
34 if(expected_chunk_type == PXER_WMORE) {
35 assert(ch_size == 0);
36 } else {
37 assert(ch_size == expected_chunk_size);
38 assert(ch_type == expected_chunk_type);
39 }
40 }
41
42 int
43 main() {
44
45 check("", "", XCT_BROKEN);
46 check("<", "", XCT_BROKEN);
47 check(">", "", XCT_BROKEN);
48 check("</", "", XCT_BROKEN);
49 check("/>", "", XCT_BROKEN);
50
51 check("<>", "", XCT_UNKNOWN_OP);
52 check("</>", "", XCT_UNKNOWN_CL);
53
54 check("", "a", XCT_BROKEN);
55 check("<>", "a", XCT_UNKNOWN_OP);
56 check("</>", "a", XCT_UNKNOWN_CL);
57
58 check("a", "a", XCT_BROKEN);
59 check("<a>", "a", XCT_OPENING);
60 check("</a>", "a", XCT_CLOSING);
61 check("</a/>", "a", XCT_BROKEN);
62 check("<a/>", "a", XCT_BOTH);
63
64 check("<a>", "a", XCT_OPENING);
65 check("</a>", "a", XCT_CLOSING);
66 check("</a/>", "a", XCT_BROKEN);
67 check("<a/>", "a", XCT_BOTH);
68
69 check("<tag>", "a", XCT_UNKNOWN_OP);
70 check("<tag>", "tag", XCT_OPENING);
71 check("</tag>", "tag", XCT_CLOSING);
72 check("</tag/>", "tag", XCT_BROKEN);
73 check("<tag/>", "tag", XCT_BOTH);
74
75
76 check("<tag>", "ta", XCT_UNKNOWN_OP);
77 check("</tag>", "ta", XCT_UNKNOWN_CL);
78 check("</tag/>", "ta", XCT_BROKEN);
79 check("<tag/>", "ta", XCT_UNKNOWN_BO);
80
81 check("<tag attribute=\"value\"/>", "tag", XCT_BOTH);
82
83 check_next("<tag/>", -1, PXER_TAG);
84 check_next("<tag", -1, PXER_WMORE);
85 check_next("tag", -1, PXER_TEXT);
86 check_next("tag<s", 3, PXER_TEXT);
87 check_next("</a/>la", 5, PXER_TAG);
88 check_next("<!--blah", -1, PXER_COMMENT);
89 check_next("<!--blah-", -1, PXER_WMORE);
90 check_next("<!--blah--", -1, PXER_WMORE);
91 check_next("<!--blah-->", -1, PXER_COMMENT);
92
93 return 0;
94 }