source: trunk/test/src/RpLibrary_test.cc @ 115

Last change on this file since 115 was 115, checked in by mmc, 19 years ago

Updated all copyright notices.

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