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

Last change on this file since 83 was 83, checked in by dkearney, 19 years ago
  1. More cleaning of RpUnits and RpLibrary? code
  2. added rp_result code to c++/fortran/c code
  3. added rp_children, rp_lib_node[comp,type,id] for fortran code (need to test)
  4. adjusted convert function to recognize statements as follows:

convert("5J","neV")
convert("3.12075e+28neV","J")

  1. made joules a metric unit in RpUnits.cc
  2. tested examples/app-fermi/fortran/fermi.f with new rappture library.

added units conversion.

File size: 7.7 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 */
9
10#include "RpLibrary.h"
11
12int test_element (RpLibrary* lib, std::string path );
13int test_get (RpLibrary* lib, std::string path );
14
15int 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
36int 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
55int 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/*
69int 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
104int 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
127int
128main(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    lib2.result();
191
192    return 0;
193}
194
195    /*
196    put(lib, "element3.sub_element(value3)", "put_element3", NULL, 1);
197   
198    search_element = _find(lib->element,"element3.sub_element(value3)",0);
199    printf("search_element name = %s\n", scew_element_name(search_element));
200
201    // search_element2 = element(root->element, "element3.sub_element(value3)", "object");
202
203    search_element2 = element(lib, "element3.sub_element(value3)", OBJECT);
204    printf("search_element2 name = %s\n", scew_element_name(search_element2->element));
205    freeRpLibrary(&search_element2);
206
207    search_element2 = element(lib, "element3.sub_element(value3)", COMPONENT);
208    printf("search_element2 comp = %s\n", search_element2->stringVal);
209    freeRpLibrary(&search_element2);
210   
211    search_element2 = element(lib, "element3.sub_element(value3)", ID);
212    printf("search_element2 id = %s\n", search_element2->stringVal);
213    freeRpLibrary(&search_element2);
214   
215    search_element2 = element(lib, "element3.sub_element(value3)", TYPE);
216    printf("search_element2 type = %s\n", search_element2->xml_char);
217    freeRpLibrary(&search_element2);
218   
219   
220    get_element = get(lib, "element");
221    printf("get element's contents = %s\n", get_element->xml_char);
222    freeRpLibrary(&get_element);
223
224
225       
226    put(lib, "element4.sub_element(value)", "put1_element", NULL, 0);
227    put(lib, "element4.sub_element(value2)", "put2_element", NULL, 0);
228    put(lib, "element4.sub_element(value3)", "put3_element", NULL, 0);
229    put(lib, "element4.sub_element(value4)", "put4_element", NULL, 0);
230    get_element = get(lib, "element4.sub_element(value)");
231    printf("put1 element's contents = %s\n", get_element->xml_char);
232    get_element = get(lib, "element4.sub_element(value2)");
233    printf("put2 element's contents = %s\n", get_element->xml_char);
234    get_element = get(lib, "element4.sub_element(value3)");
235    printf("put3 element's contents = %s\n", get_element->xml_char);
236    get_element = get(lib, "element4.sub_element(value4)");
237    printf("put4 element's contents = %s\n", get_element->xml_char);
238
239    */
240    /**
241     * Save an XML tree to a file.
242     */
243    /*
244    if (!scew_writer_tree_file(lib->tree, argv[2]))
245    {
246        printf("Unable to create %s\n", argv[2]);
247        return EXIT_FAILURE;
248    }
249    */
250
251
252    /*
253   
254    freeRpLibrary(&search_element2);
255    freeRpLibrary(&get_element);
256    freeRpLibrary(&lib);
257
258    if (tagName) { free (tagName); }
259    if (id) { free(id); }
260    */
Note: See TracBrowser for help on using the repository browser.