1 | /** |
---|
2 | * |
---|
3 | * RpParser_test.c |
---|
4 | * |
---|
5 | * test file for the RpParser.so library based off of the scew |
---|
6 | * libaray, a simple wrapper around the expat parser |
---|
7 | * |
---|
8 | */ |
---|
9 | |
---|
10 | #include "RpLibrary.h" |
---|
11 | |
---|
12 | int test_element (RpLibrary* lib, std::string path ); |
---|
13 | int test_get (RpLibrary* lib, std::string path ); |
---|
14 | |
---|
15 | int test_element (RpLibrary* lib, std::string path ) |
---|
16 | { |
---|
17 | int retVal = 1; |
---|
18 | RpLibrary* searchEle = lib->element(path); |
---|
19 | |
---|
20 | std::cout << "TESTING ELEMENT: path = " << path << std::endl; |
---|
21 | |
---|
22 | if (!searchEle) { |
---|
23 | std::cout << "searchEle is NULL" << std::endl; |
---|
24 | retVal = 1; |
---|
25 | } |
---|
26 | else { |
---|
27 | std::cout << "searchEle comp = :" << searchEle->nodeComp() << ":" << std::endl; |
---|
28 | std::cout << "searchEle id = :" << searchEle->nodeId() << ":" << std::endl; |
---|
29 | std::cout << "searchEle type = :" << searchEle->nodeType() << ":" << std::endl; |
---|
30 | retVal = 0; |
---|
31 | } |
---|
32 | |
---|
33 | return retVal; |
---|
34 | } |
---|
35 | |
---|
36 | int test_getString (RpLibrary* lib, std::string path ) |
---|
37 | { |
---|
38 | int retVal = 1; |
---|
39 | std::string searchVal = lib->getString(path); |
---|
40 | |
---|
41 | std::cout << "TESTING GET String: path = " << path << std::endl; |
---|
42 | |
---|
43 | if (searchVal.empty()) { |
---|
44 | std::cout << "searchVal is EMPTY STRING" << std::endl; |
---|
45 | retVal = 1; |
---|
46 | } |
---|
47 | else { |
---|
48 | std::cout << "searchVal = :" << searchVal << ":" << std::endl; |
---|
49 | retVal = 0; |
---|
50 | } |
---|
51 | |
---|
52 | return retVal; |
---|
53 | } |
---|
54 | |
---|
55 | int test_getDouble (RpLibrary* lib, std::string path ) |
---|
56 | { |
---|
57 | int retVal = 1; |
---|
58 | double searchVal = lib->getDouble(path); |
---|
59 | |
---|
60 | std::cout << "TESTING GET Double: path = " << path << std::endl; |
---|
61 | |
---|
62 | std::cout << "searchVal = :" << searchVal << ":" << std::endl; |
---|
63 | retVal = 0; |
---|
64 | |
---|
65 | return retVal; |
---|
66 | } |
---|
67 | |
---|
68 | /* |
---|
69 | int test_children (RpLibrary* lib, std::string path, std::string type ) |
---|
70 | { |
---|
71 | int retVal = 1; |
---|
72 | int childNum = -1; |
---|
73 | |
---|
74 | std::cout << "TESTING CHILDREN: path = " << path << std::endl; |
---|
75 | RpLibrary** searchEle = lib->children(path,"",type); |
---|
76 | |
---|
77 | if (!searchEle || !*searchEle) { |
---|
78 | std::cout << "searchEle is NULL -> NO CHILDREN" << std::endl; |
---|
79 | retVal = 1; |
---|
80 | } |
---|
81 | else { |
---|
82 | |
---|
83 | while (searchEle[++childNum]) { |
---|
84 | std::cout << "searchEle comp = :" << searchEle[childNum]->nodeComp() |
---|
85 | << ":" << std::endl; |
---|
86 | std::cout << "searchEle id = :" << searchEle[childNum]->nodeId() |
---|
87 | << ":" << std::endl; |
---|
88 | std::cout << "searchEle type = :" << searchEle[childNum]->nodeType() |
---|
89 | << ":" << std::endl; |
---|
90 | delete (searchEle[childNum]); |
---|
91 | searchEle[childNum] = NULL; |
---|
92 | } |
---|
93 | |
---|
94 | retVal = 0; |
---|
95 | |
---|
96 | } |
---|
97 | |
---|
98 | delete[] searchEle; |
---|
99 | |
---|
100 | return retVal; |
---|
101 | } |
---|
102 | */ |
---|
103 | |
---|
104 | int test_children (RpLibrary* lib, std::string path, std::string type ) |
---|
105 | { |
---|
106 | int retVal = 1; |
---|
107 | RpLibrary* childEle = NULL; |
---|
108 | |
---|
109 | std::cout << "TESTING CHILDREN: path = " << path << std::endl; |
---|
110 | |
---|
111 | while ( (childEle = lib->children(path,childEle,type)) ) { |
---|
112 | |
---|
113 | std::cout << "childEle comp = :" << childEle->nodeComp() |
---|
114 | << ":" << std::endl; |
---|
115 | std::cout << "childEle id = :" << childEle->nodeId() |
---|
116 | << ":" << std::endl; |
---|
117 | std::cout << "childEle type = :" << childEle->nodeType() |
---|
118 | << ":" << std::endl; |
---|
119 | |
---|
120 | retVal = 0; |
---|
121 | |
---|
122 | } |
---|
123 | |
---|
124 | return retVal; |
---|
125 | } |
---|
126 | |
---|
127 | int |
---|
128 | main(int argc, char** argv) |
---|
129 | { |
---|
130 | RpLibrary* lib = NULL; |
---|
131 | RpLibrary lib2; |
---|
132 | |
---|
133 | if (argc < 3) |
---|
134 | { |
---|
135 | printf("usage: RpLibrary_test infile.xml outfile.xml\n"); |
---|
136 | return EXIT_FAILURE; |
---|
137 | } |
---|
138 | |
---|
139 | lib = new RpLibrary(std::string(argv[1])); |
---|
140 | |
---|
141 | test_element(lib,"input.number(min)"); |
---|
142 | test_element(lib,"input.number(max)"); |
---|
143 | test_element(lib,"output.curve(result)"); |
---|
144 | |
---|
145 | test_getString(lib, "input.number(min).default"); |
---|
146 | test_getString(lib, "input.(min).current"); |
---|
147 | test_getString(lib, "input.number(max).current"); |
---|
148 | test_getString(lib, "output.curve.about.label"); |
---|
149 | |
---|
150 | lib->put("input.number(test).default", "1000"); |
---|
151 | test_getString(lib, "input.number(test).default"); |
---|
152 | lib->put("input.number(test).current", 2000); |
---|
153 | test_getDouble(lib, "input.number(test).current"); |
---|
154 | |
---|
155 | |
---|
156 | test_children(lib,"",""); |
---|
157 | test_children(lib,"input.number(test)",""); |
---|
158 | |
---|
159 | std::cout << lib->xml() << std::endl; |
---|
160 | |
---|
161 | // test copy assignment operator |
---|
162 | lib2 = *lib; |
---|
163 | |
---|
164 | delete lib; |
---|
165 | |
---|
166 | lib2.put("input.output.curve(curve1).xy.default", "1e-4 0.0\n"); |
---|
167 | lib2.put("input.output.curve(curve1).xy.default", "1e-2 1.0\n","",1); |
---|
168 | lib2.put("input.output.curve(curve1).xy.default", "1e-30 2.0\n","",1); |
---|
169 | lib2.put("input.output.curve(curve1).xy.default", "1e+4 3.0\n","",1); |
---|
170 | lib2.put("input.output.curve(curve1).xy.default", "1.7e-4 4.0\n","",1); |
---|
171 | lib2.put("input.output.curve(curve1).xy.default", "15e-4 5.0\n","",1); |
---|
172 | |
---|
173 | |
---|
174 | // test copy constructor |
---|
175 | RpLibrary lib3 = lib2; |
---|
176 | |
---|
177 | lib2.put("input.output.curve(curve2).xy.current", "1e-4 0.0\n"); |
---|
178 | lib2.put("input.output.curve(curve2).xy.current", "1e-2 1.0\n","",1); |
---|
179 | lib2.put("input.output.curve(curve2).xy.current", "1e-30 2.0\n","",1); |
---|
180 | lib2.put("input.output.curve(curve2).xy.current", "1e+4 3.0\n","",1); |
---|
181 | lib2.put("input.output.curve(curve2).xy.current", "1.7e-4 4.0\n","",1); |
---|
182 | lib2.put("input.output.curve(curve2).xy.current", "15e-4 5.0\n","",1); |
---|
183 | |
---|
184 | |
---|
185 | std::cout << "//////////////////// LIB 2 ////////////////////" << std::endl; |
---|
186 | std::cout << lib2.xml() << std::endl; |
---|
187 | std::cout << "//////////////////// LIB 3 ////////////////////" << std::endl; |
---|
188 | std::cout << lib3.xml() << std::endl; |
---|
189 | |
---|
190 | return 0; |
---|
191 | } |
---|
192 | |
---|
193 | /* |
---|
194 | put(lib, "element3.sub_element(value3)", "put_element3", NULL, 1); |
---|
195 | |
---|
196 | search_element = _find(lib->element,"element3.sub_element(value3)",0); |
---|
197 | printf("search_element name = %s\n", scew_element_name(search_element)); |
---|
198 | |
---|
199 | // search_element2 = element(root->element, "element3.sub_element(value3)", "object"); |
---|
200 | |
---|
201 | search_element2 = element(lib, "element3.sub_element(value3)", OBJECT); |
---|
202 | printf("search_element2 name = %s\n", scew_element_name(search_element2->element)); |
---|
203 | freeRpLibrary(&search_element2); |
---|
204 | |
---|
205 | search_element2 = element(lib, "element3.sub_element(value3)", COMPONENT); |
---|
206 | printf("search_element2 comp = %s\n", search_element2->stringVal); |
---|
207 | freeRpLibrary(&search_element2); |
---|
208 | |
---|
209 | search_element2 = element(lib, "element3.sub_element(value3)", ID); |
---|
210 | printf("search_element2 id = %s\n", search_element2->stringVal); |
---|
211 | freeRpLibrary(&search_element2); |
---|
212 | |
---|
213 | search_element2 = element(lib, "element3.sub_element(value3)", TYPE); |
---|
214 | printf("search_element2 type = %s\n", search_element2->xml_char); |
---|
215 | freeRpLibrary(&search_element2); |
---|
216 | |
---|
217 | |
---|
218 | get_element = get(lib, "element"); |
---|
219 | printf("get element's contents = %s\n", get_element->xml_char); |
---|
220 | freeRpLibrary(&get_element); |
---|
221 | |
---|
222 | |
---|
223 | |
---|
224 | put(lib, "element4.sub_element(value)", "put1_element", NULL, 0); |
---|
225 | put(lib, "element4.sub_element(value2)", "put2_element", NULL, 0); |
---|
226 | put(lib, "element4.sub_element(value3)", "put3_element", NULL, 0); |
---|
227 | put(lib, "element4.sub_element(value4)", "put4_element", NULL, 0); |
---|
228 | get_element = get(lib, "element4.sub_element(value)"); |
---|
229 | printf("put1 element's contents = %s\n", get_element->xml_char); |
---|
230 | get_element = get(lib, "element4.sub_element(value2)"); |
---|
231 | printf("put2 element's contents = %s\n", get_element->xml_char); |
---|
232 | get_element = get(lib, "element4.sub_element(value3)"); |
---|
233 | printf("put3 element's contents = %s\n", get_element->xml_char); |
---|
234 | get_element = get(lib, "element4.sub_element(value4)"); |
---|
235 | printf("put4 element's contents = %s\n", get_element->xml_char); |
---|
236 | |
---|
237 | */ |
---|
238 | /** |
---|
239 | * Save an XML tree to a file. |
---|
240 | */ |
---|
241 | /* |
---|
242 | if (!scew_writer_tree_file(lib->tree, argv[2])) |
---|
243 | { |
---|
244 | printf("Unable to create %s\n", argv[2]); |
---|
245 | return EXIT_FAILURE; |
---|
246 | } |
---|
247 | */ |
---|
248 | |
---|
249 | |
---|
250 | /* |
---|
251 | |
---|
252 | freeRpLibrary(&search_element2); |
---|
253 | freeRpLibrary(&get_element); |
---|
254 | freeRpLibrary(&lib); |
---|
255 | |
---|
256 | if (tagName) { free (tagName); } |
---|
257 | if (id) { free(id); } |
---|
258 | */ |
---|