6 #define ROOTNODE "/Configuration/output/menu"
7 #define LEAFNODE "name"
8 #define PATH ROOTNODE"/"LEAFNODE
11 #define PRINT_ERROR_AND_EXIT(id) \
12 if (xmlErrorGetNo(id, 0) != XML_NO_ERROR) { \
13 const char *errstr = xmlErrorGetString(id, 0); \
14 size_t column = xmlErrorGetColumnNo(id, 0); \
15 size_t lineno = xmlErrorGetLineNo(id, 1); \
16 printf("Error at line %i, column %i: %s\n", lineno, column, errstr); \
24 root_id = xmlOpen("sample.xml");
27 void *path_id, *node_id;
30 printf("\nTesting xmlNodeGetString for /*/*/test:\t\t\t\t\t");
31 s = xmlNodeGetString(root_id , "/*/*/test");
34 printf("failed.\n\t'%s' should be empty\n", s);
40 printf("Testing xmlGetString for /Configuration/output/test:\t\t\t");
41 path_id = xmlNodeGet(root_id, "/Configuration/output/test");
44 s = xmlGetString(path_id);
47 printf("failed.\n\t'%s' should be empty\n", s);
54 PRINT_ERROR_AND_EXIT(root_id);
56 path_id = xmlNodeGet(root_id, PATH);
57 node_id = xmlNodeGet(root_id, ROOTNODE);
59 if (path_id && node_id)
64 xmlCopyString(path_id, buf, BUFLEN);
65 printf("Testing xmlNodeCopyString against xmlGetString:\t\t\t\t");
66 if ((s = xmlGetString(path_id)) != 0)
68 if (strcmp(s, buf)) /* not the same */
69 printf("failed.\n\t'%s' differs from '%s'\n", s, buf);
73 printf("Testing xmlCopyString against xmlGetString:\t\t\t\t");
74 xmlCopyString(path_id, buf, BUFLEN);
75 if (strcmp(s, buf)) /* not the same */
76 printf("failed.\n\t'%s' differs from\n\t'%s'\n", s, buf);
81 PRINT_ERROR_AND_EXIT(path_id);
83 printf("Testing xmlCopyString against xmlCompareString:\t\t\t\t");
84 if (xmlCompareString(path_id, buf)) /* not the same */
85 printf ("failed.\n\t'%s' differs from\n\t'%s'\n", s, buf);
89 printf("Testing xmlCopyString against xmlNodeCompareString:\t\t\t");
90 if (xmlNodeCompareString(node_id, LEAFNODE, buf)) /* not the same */
91 printf("failed.\n\t'%s' differs from\n\t'%s'\n", s, buf);
97 printf("Testing xmlCopyString against xmlNodeGetString:\t\t\t\t");
98 if ((s = xmlNodeGetString(node_id, LEAFNODE)) != 0)
100 if (strcmp(s, buf)) /* not the same */
101 printf("failed.\n\t'%s' differs from\n\t'%s'\n", s, buf);
107 PRINT_ERROR_AND_EXIT(node_id);
110 path_id = xmlNodeGet(root_id, "/Configuration/backend/name");
113 printf("Testing xmlAttributeCopyString against xmlAttributeCompareString:\t");
114 xmlAttributeCopyString(path_id, "type", buf, BUFLEN);
115 if (xmlAttributeCompareString(path_id, "type", buf)) /* no match */
116 printf("failed.\n\t'%s' differs\n", buf);
120 printf("Testing xmlAttributeCopyString against xmlAttributeGetString:\t\t");
121 if ((s = xmlAttributeGetString(path_id, "type")) != 0)
123 if (strcmp(s, buf)) /* not the same */
124 printf("failed.\n\t'%s' differs from '%s'\n", s, buf);
130 PRINT_ERROR_AND_EXIT(path_id);
134 PRINT_ERROR_AND_EXIT(root_id);
139 path_id = xmlNodeGet(root_id, "Configuration/output/sample/test");
142 xmlNodeCopyString(root_id ,"Configuration/output/menu/name", buf, BUFLEN);
143 printf("Testing xmlCompareString against a fixed string: \t\t\t");
144 if (xmlCompareString(path_id, buf)) /* no match */
145 printf("failed.\n\t'%s' differs\n", buf);
149 s = xmlGetString(path_id);
152 printf("Testing xmlGetString against a fixed string: \t\t\t\t");
153 if (strcmp(s, buf)) /* mismatch */
154 printf("failed.\n\t'%s' differs from\n\t'%s'\n", s, buf);
158 printf("Testing xmlCopyString gainst a fixed string: \t\t\t\t");
159 xmlCopyString(path_id, buf, BUFLEN);
160 if (strcmp(s, buf)) /* mismatch */
161 printf("failed.\n\t'%s' differs from\n\t'%s'\n", s, buf);
168 PRINT_ERROR_AND_EXIT(path_id);
174 if (xmlErrorGetNo(root_id, 0) != XML_NO_ERROR)
176 const char *errstr = xmlErrorGetString(root_id, 0);
177 size_t column = xmlErrorGetColumnNo(root_id, 0);
178 size_t lineno = xmlErrorGetLineNo(root_id, 1);
180 printf("Error at line %i, column %i: %s\n", lineno, column, errstr);