1 | #include <stdio.h> |
---|
2 | #include "RpLibraryCInterface.h" |
---|
3 | |
---|
4 | |
---|
5 | int test_element (RpLibrary* lib, const char* path ); |
---|
6 | int test_get (RpLibrary* lib, const char* path ); |
---|
7 | int test_getString (RpLibrary* lib, const char* path ); |
---|
8 | int test_getDouble (RpLibrary* lib, const char* path ); |
---|
9 | int test_putString (RpLibrary* lib, |
---|
10 | const char* path, |
---|
11 | const char* value, |
---|
12 | int append ); |
---|
13 | int test_putDouble (RpLibrary* lib, |
---|
14 | const char* path, |
---|
15 | double value, |
---|
16 | int append ); |
---|
17 | int test_children (RpLibrary* lib, const char* path); |
---|
18 | int test_childrenByType (RpLibrary* lib, const char* path, const char* type ); |
---|
19 | |
---|
20 | int test_element (RpLibrary* lib, const char* path ) |
---|
21 | { |
---|
22 | int retVal = 1; |
---|
23 | RpLibrary* searchEle = NULL; |
---|
24 | const char* type = NULL; |
---|
25 | const char* comp = NULL; |
---|
26 | const char* id = NULL; |
---|
27 | |
---|
28 | printf("TESTING ELEMENT: path = %s\n", path); |
---|
29 | |
---|
30 | searchEle = element(lib,path); |
---|
31 | type = elementAsType(lib,path); |
---|
32 | comp = elementAsComp(lib,path); |
---|
33 | id = elementAsId(lib,path); |
---|
34 | |
---|
35 | if (!searchEle) { |
---|
36 | printf("searchEle is NULL\n"); |
---|
37 | retVal = 1; |
---|
38 | } |
---|
39 | else { |
---|
40 | printf("searchEle comp = :%s:\n", comp); |
---|
41 | printf("searchEle id = :%s:\n", id); |
---|
42 | printf("searchEle type = :%s:\n", type); |
---|
43 | |
---|
44 | comp = nodeComp(searchEle); |
---|
45 | id = nodeId(searchEle); |
---|
46 | type = nodeType(searchEle); |
---|
47 | |
---|
48 | printf("searchEle comp = :%s:\n", comp); |
---|
49 | printf("searchEle id = :%s:\n", id); |
---|
50 | printf("searchEle type = :%s:\n", type); |
---|
51 | |
---|
52 | retVal = 0; |
---|
53 | } |
---|
54 | |
---|
55 | return retVal; |
---|
56 | } |
---|
57 | |
---|
58 | int test_getString (RpLibrary* lib, const char* path ) |
---|
59 | { |
---|
60 | int retVal = 1; |
---|
61 | const char* searchVal = NULL; |
---|
62 | |
---|
63 | printf("TESTING GET String: path = %s\n", path); |
---|
64 | |
---|
65 | searchVal = getString(lib,path); |
---|
66 | |
---|
67 | if (!searchVal || *searchVal == '\0') { |
---|
68 | printf("searchVal is EMPTY STRING\n"); |
---|
69 | retVal = 1; |
---|
70 | } |
---|
71 | else { |
---|
72 | printf("searchVal = :%s:\n", searchVal); |
---|
73 | retVal = 0; |
---|
74 | } |
---|
75 | |
---|
76 | return retVal; |
---|
77 | } |
---|
78 | |
---|
79 | int test_getDouble (RpLibrary* lib, const char* path ) |
---|
80 | { |
---|
81 | int retVal = 1; |
---|
82 | double searchVal = 0.0; |
---|
83 | |
---|
84 | printf("TESTING GET Double: path = %s\n", path); |
---|
85 | |
---|
86 | searchVal = getDouble(lib,path); |
---|
87 | |
---|
88 | printf("searchVal = :%f:\n", searchVal); |
---|
89 | retVal = 0; |
---|
90 | |
---|
91 | return retVal; |
---|
92 | } |
---|
93 | |
---|
94 | int test_children (RpLibrary* lib, const char* path) |
---|
95 | { |
---|
96 | int retVal = 1; |
---|
97 | RpLibrary* childEle = NULL; |
---|
98 | const char* id = NULL; |
---|
99 | const char* comp = NULL; |
---|
100 | const char* type = NULL; |
---|
101 | |
---|
102 | printf("TESTING CHILDREN: path = %s\n", path); |
---|
103 | |
---|
104 | while ( (childEle = children(lib,path,childEle)) ) { |
---|
105 | comp = nodeComp(childEle); |
---|
106 | id = nodeId(childEle); |
---|
107 | type = nodeType(childEle); |
---|
108 | |
---|
109 | printf("childEle comp = :%s:\n",comp); |
---|
110 | printf("childEle id = :%s:\n",id); |
---|
111 | printf("childEle type = :%s:\n",type); |
---|
112 | |
---|
113 | } |
---|
114 | |
---|
115 | retVal = 0; |
---|
116 | |
---|
117 | return retVal; |
---|
118 | } |
---|
119 | |
---|
120 | int test_childrenByType (RpLibrary* lib, const char* path, const char* searchType ) |
---|
121 | { |
---|
122 | int retVal = 1; |
---|
123 | RpLibrary* childEle = NULL; |
---|
124 | const char* id = NULL; |
---|
125 | const char* comp = NULL; |
---|
126 | const char* type = NULL; |
---|
127 | |
---|
128 | printf("TESTING CHILDREN: path = %s\n", path); |
---|
129 | |
---|
130 | while ( (childEle = childrenByType(lib,path,childEle,searchType)) ) { |
---|
131 | comp = nodeComp(childEle); |
---|
132 | id = nodeId(childEle); |
---|
133 | type = nodeType(childEle); |
---|
134 | |
---|
135 | printf("childEle comp = :%s:\n",comp); |
---|
136 | printf("childEle id = :%s:\n",id); |
---|
137 | printf("childEle type = :%s:\n",type); |
---|
138 | |
---|
139 | } |
---|
140 | |
---|
141 | retVal = 0; |
---|
142 | |
---|
143 | return retVal; |
---|
144 | } |
---|
145 | |
---|
146 | int test_putString (RpLibrary* lib, const char* path, const char* value, int append) |
---|
147 | { |
---|
148 | int retVal = 1; |
---|
149 | const char* searchVal = NULL; |
---|
150 | |
---|
151 | printf("TESTING PUT String: path = %s\n", path); |
---|
152 | |
---|
153 | putString(lib,path,value,append); |
---|
154 | searchVal = getString(lib, path); |
---|
155 | |
---|
156 | if (!searchVal || *searchVal == '\0') { |
---|
157 | printf("searchVal is EMPTY STRING\n"); |
---|
158 | retVal = 1; |
---|
159 | } |
---|
160 | else { |
---|
161 | printf("searchVal = :%s:\n", searchVal); |
---|
162 | retVal = 0; |
---|
163 | } |
---|
164 | |
---|
165 | return retVal; |
---|
166 | } |
---|
167 | |
---|
168 | int test_putDouble (RpLibrary* lib, const char* path, double value, int append) |
---|
169 | { |
---|
170 | int retVal = 1; |
---|
171 | double searchVal = 0.0; |
---|
172 | |
---|
173 | printf("TESTING PUT String: path = %s\n", path); |
---|
174 | |
---|
175 | putDouble(lib,path,value,append); |
---|
176 | searchVal = getDouble(lib, path); |
---|
177 | printf("searchVal = :%f:\n", searchVal); |
---|
178 | retVal = 0; |
---|
179 | |
---|
180 | return retVal; |
---|
181 | } |
---|
182 | |
---|
183 | int |
---|
184 | main(int argc, char** argv) |
---|
185 | { |
---|
186 | RpLibrary* lib = NULL; |
---|
187 | |
---|
188 | if (argc < 3) |
---|
189 | { |
---|
190 | printf("usage: RpLibrary_test infile.xml outfile.xml\n"); |
---|
191 | return -1; |
---|
192 | } |
---|
193 | |
---|
194 | lib = library(argv[1]); |
---|
195 | |
---|
196 | test_element(lib,"input.number(min)"); |
---|
197 | test_element(lib,"input.number(max)"); |
---|
198 | test_element(lib,"output.curve(result)"); |
---|
199 | |
---|
200 | test_getString(lib, "input.number(min).default"); |
---|
201 | test_getString(lib, "input.(min).current"); |
---|
202 | test_getString(lib, "input.number(max).current"); |
---|
203 | test_getString(lib, "output.curve.about.label"); |
---|
204 | |
---|
205 | test_putString(lib,"input.number(test).default", "1000", 0); |
---|
206 | test_putDouble(lib, "input.number(test).preset", 1, 0); |
---|
207 | test_putDouble(lib, "input.number(test).current", 2000, 0); |
---|
208 | test_putDouble(lib, "input.number(test).preset(p1)", 100, 0); |
---|
209 | test_putDouble(lib, "input.number(test).preset(p2)", 200, 0); |
---|
210 | test_putDouble(lib, "input.number(test).preset(p3)", 300, 0); |
---|
211 | test_putDouble(lib, "input.number(test).preset(p4)", 400, 0); |
---|
212 | test_putDouble(lib, "input.number(test).preset(p5)", 500, 0); |
---|
213 | |
---|
214 | |
---|
215 | test_children(lib,""); |
---|
216 | test_children(lib,"input.number(test)"); |
---|
217 | test_childrenByType(lib,"input.number(test)","preset"); |
---|
218 | |
---|
219 | printf("XML = \n%s\n",xml(lib)); |
---|
220 | |
---|
221 | freeLibrary(lib); |
---|
222 | |
---|
223 | return 0; |
---|
224 | } |
---|