]> git.mxchange.org Git - flightgear.git/blob - utils/xmlgrep/testxml.c
318002ba92dc9024424db8c14596b56c84097303
[flightgear.git] / utils / xmlgrep / testxml.c
1 #include <stdio.h>
2 #include <malloc.h>
3 #include "xml.h"
4
5 #define ROOTNODE        "/Configuration/output/menu"
6 #define LEAFNODE        "name"
7 #define PATH            ROOTNODE"/"LEAFNODE
8 #define BUFLEN          4096
9 int main()
10 {
11    void *root_id;
12
13    root_id = xmlOpen("sample.xml");
14    if (root_id)
15    {
16       void *path_id, *node_id;
17
18       path_id = xmlNodeGet(root_id, PATH);
19       node_id = xmlNodeGet(root_id, ROOTNODE);
20
21       if (path_id && node_id)
22       {
23          char buf[BUFLEN];
24          size_t len;
25          char *s;
26      
27          len = xmlNodeCopyString(root_id, PATH, buf, BUFLEN);
28          printf("%s = '%s'\n", PATH, buf);
29
30          printf("Testing value of /Configuration/output/test:\t\t\t\t");
31          s = xmlNodeGetString(root_id , "/Configuration/output/test");
32          if (s)
33          {
34             printf("failed.\n\t'%s' shoudl be empty\n", s);
35             free(s);
36          }
37          else
38             printf("succes.\n");
39
40          printf("Testing xmlNodeCopyString against xmlGetString:\t\t\t\t");
41          if ((s = xmlGetString(path_id)) != 0)
42          {
43             if (strcmp(s, buf)) /* not the same */
44                printf("failed.\n\t'%s' differs from '%s'\n", s, buf);
45             else
46                printf("succes.\n");
47
48             printf("Testing xmlCopyString against xmlGetString:\t\t\t\t");
49             xmlCopyString(path_id, buf, BUFLEN);
50             if (strcmp(s, buf)) /* not the same */
51                printf("failed.\n\t'%s' differs from '%s'\n", s, buf);
52             else
53                printf("succes.\n");
54             free(s);
55          }
56          else
57             printf("Error while fetching node's value.\n");
58
59          printf("Testing xmlCopyString against xmlCompareString:\t\t\t\t");
60          if (xmlCompareString(path_id, buf)) /* not the same */
61             printf ("failed.\n\t'%s' differs\n", buf);
62          else
63             printf("succes.\n");
64
65          printf("Testing xmlCopyString against xmlNodeCompareString:\t\t\t");
66          if (xmlNodeCompareString(node_id, LEAFNODE, buf)) /* not the same */
67             printf ("failed.\n\t'%s' differs\n", buf);
68          else
69             printf("succes.\n");
70  
71          printf("Testing xmlCopyString against xmlNodeGetString:\t\t\t\t");
72          if ((s = xmlNodeGetString(node_id, LEAFNODE)) != 0)
73          {
74             if (strcmp(s, buf)) /* not the same */
75                printf("failed.\n\t'%s' differs from '%s'\n", s, buf);
76             else
77                printf("succes.\n");
78             free(s);
79          }
80          else
81             printf("Error while fetching value from node.\n");
82
83          free(path_id);
84          path_id = xmlNodeGet(root_id, "/Configuration/backend/name");
85          if (path_id)
86          {
87             xmlAttributeCopyString(path_id, "type", buf, BUFLEN);
88             
89             printf("Testing xmlAttributeCopyString against xmlAttributeCompareString:\t");
90             if (xmlAttributeCompareString(path_id, "type", buf)) /* no match */
91                printf("failed.\n\t'%s' differs\n", buf);
92             else
93                printf("succes.\n");
94
95             printf("Testing xmlAttributeCopyString against xmlAttributeGetString:\t\t");
96             if ((s = xmlAttributeGetString(path_id, "type")) != 0)
97             {
98                 if (strcmp(s, buf)) /* not the same */
99                    printf("failed.\n\t'%s' differs from '%s'\n", s, buf);
100                 else
101                    printf("succes.\n");
102                 free(s);
103             }
104             else
105             printf("Error while fetching value from attribute.\n");
106
107          }
108          else
109             printf("Error while fetching node's attribute.\n");
110
111          free(node_id);
112          free(path_id);
113       }
114       else
115       {
116          printf("Error: %s\n", xmlErrorGetString(root_id, 1));
117       }
118
119       xmlClose(root_id);
120    }
121
122    return 0;
123 }