source: trunk/test/src/RpLibraryC_test.c @ 157

Last change on this file since 157 was 157, checked in by dkearney, 16 years ago

added adjustments for new rappture libray c api which returns error information describing function success or failure

File size: 6.9 KB
Line 
1/*
2 * ======================================================================
3 *  Copyright (c) 2004-2005  Purdue Research Foundation
4 *
5 *  See the file "license.terms" for information on usage and
6 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7 * ======================================================================
8 */
9#include <stdio.h>
10#include "RpLibraryCInterface.h"
11
12int test_lib(RpLibrary** lib, const char* path);
13int test_element (RpLibrary* lib, const char* path );
14int test_get (RpLibrary* lib, const char* path );
15int test_getString (RpLibrary* lib, const char* path );
16int test_getDouble (RpLibrary* lib, const char* path );
17int test_putString (RpLibrary* lib,
18                    const char* path,
19                    const char* value,
20                    int append );
21int test_putDouble (RpLibrary* lib,
22                    const char* path,
23                    double value,
24                    int append );
25int test_children (RpLibrary* lib, const char* path);
26int test_childrenByType (RpLibrary* lib, const char* path, const char* type );
27
28int test_lib (RpLibrary** lib, const char* path) {
29
30    int retVal = 0;
31
32    *lib = NULL;
33    *lib = rpLibrary(path);
34
35    printf("TESTING LIBRARY: path = %s\n", path);
36
37    if (*lib != NULL) {
38        printf("creation of library successful\n");
39    }
40    else {
41        printf("creation of library failed\n");
42        retVal += 1;
43    }
44
45    printf ("lib = %x\n",(unsigned int)(*lib));
46
47    return retVal;
48}
49
50int test_element (RpLibrary* lib, const char* path )
51{
52    int retVal = 0;
53    RpLibrary* searchEle = NULL;
54    const char* type = NULL;
55    const char* comp = NULL;
56    const char* id = NULL;
57
58    printf("TESTING ELEMENT: path = %s\n", path);
59
60    searchEle = rpElement(lib,path);
61    retVal += rpElementAsType(lib,path,&type);
62    retVal += rpElementAsComp(lib,path,&comp);
63    retVal += rpElementAsId(lib,path,&id);
64
65    if (!searchEle) {
66        printf("searchEle is NULL\n");
67        retVal += 1;
68    }
69    else {
70        printf("searchEle comp = :%s:\n", comp);
71        printf("searchEle   id = :%s:\n", id);
72        printf("searchEle type = :%s:\n", type);
73
74        retVal += rpNodeComp(searchEle,&comp);
75        retVal += rpNodeId(searchEle,&id);
76        retVal += rpNodeType(searchEle,&type);
77
78        printf("searchEle comp = :%s:\n", comp);
79        printf("searchEle   id = :%s:\n", id);
80        printf("searchEle type = :%s:\n", type);
81
82    }
83
84    return retVal;
85}
86
87int test_getString (RpLibrary* lib, const char* path )
88{
89    int retVal = 0;
90    const char* searchVal = NULL;
91
92    printf("TESTING GET String: path = %s\n", path);
93
94    retVal += rpGetString(lib,path,&searchVal);
95
96    if ( (retVal) || !searchVal || *searchVal == '\0') {
97        printf("searchVal is EMPTY STRING\n");
98        retVal += 1;
99    }
100    else {
101        printf("searchVal = :%s:\n", searchVal);
102        retVal = 0;
103    }
104
105    return retVal;
106}
107
108int test_getDouble (RpLibrary* lib, const char* path )
109{
110    int retVal = 0;
111    double searchVal = 0.0;
112
113    printf("TESTING GET Double: path = %s\n", path);
114
115    retVal = rpGetDouble(lib,path,&searchVal);
116
117    if (!retVal) {
118        printf("searchVal = :%f:\n", searchVal);
119    }
120    else {
121        printf("GET Double: FAILED\n");
122    }
123
124    return retVal;
125}
126
127int test_children (RpLibrary* lib, const char* path)
128{
129    int retVal = 0;
130    RpLibrary* childEle = NULL;
131    const char* id = NULL;
132    const char* comp = NULL;
133    const char* type = NULL;
134
135    printf("TESTING CHILDREN: path = %s\n", path);
136
137    while ( (childEle = rpChildren(lib,path,childEle)) ) {
138        retVal += rpNodeComp(childEle,&comp);
139        retVal += rpNodeId(childEle,&id);
140        retVal += rpNodeType(childEle,&type);
141
142        printf("childEle comp = :%s:\n",comp);
143        printf("childEle   id = :%s:\n",id);
144        printf("childEle type = :%s:\n",type);
145    }
146
147    return retVal;
148}
149
150int test_childrenByType (RpLibrary* lib, const char* path, const char* searchType )
151{
152    int retVal = 0;
153    RpLibrary* childEle = NULL;
154    const char* id = NULL;
155    const char* comp = NULL;
156    const char* type = NULL;
157
158    printf("TESTING CHILDREN: path = %s\n", path);
159
160    while ( (childEle = rpChildrenByType(lib,path,childEle,searchType)) ) {
161        retVal += rpNodeComp(childEle,&comp);
162        retVal += rpNodeId(childEle,&id);
163        retVal += rpNodeType(childEle,&type);
164
165        printf("childEle comp = :%s:\n",comp);
166        printf("childEle   id = :%s:\n",id);
167        printf("childEle type = :%s:\n",type);
168    }
169
170    return retVal;
171}
172
173int test_putString (RpLibrary* lib, const char* path, const char* value, int append)
174{
175    int retVal = 0;
176    const char* searchVal = NULL;
177
178    printf("TESTING PUT String: path = %s\n", path);
179
180    retVal += rpPutString(lib,path,value,append);
181    if (!retVal) {
182        retVal += rpGetString(lib, path, &searchVal);
183    }
184
185    if (retVal || !searchVal || *searchVal == '\0') {
186        printf("searchVal is EMPTY STRING, or there was an error\n");
187    }
188    else {
189        printf("searchVal = :%s:\n", searchVal);
190    }
191
192    return retVal;
193}
194
195int test_putDouble (RpLibrary* lib, const char* path, double value, int append)
196{
197    int retVal = 0;
198    double searchVal = 0.0;
199
200    printf("TESTING PUT String: path = %s\n", path);
201
202    retVal += rpPutDouble(lib,path,value,append);
203    if (!retVal) {
204        retVal += rpGetDouble(lib, path,&searchVal);
205    }
206
207    if ( retVal ){
208        printf("ERROR while retrieving searchVal\n");
209    }
210    else {
211        printf("searchVal = :%f:\n", searchVal);
212    }
213
214    return retVal;
215}
216
217int
218main(int argc, char** argv)
219{
220    RpLibrary* lib = NULL;
221    int err = 0;
222    const char* retStr = NULL;
223
224    if (argc < 2)
225    {
226        printf("usage: %s driver.xml\n", argv[0]);
227        return -1;
228    }
229
230    test_lib(&lib,argv[1]);
231
232    test_element(lib,"input.number(min)");
233    test_element(lib,"input.number(max)");
234    test_element(lib,"output.curve(result)");
235
236    test_getString(lib, "input.number(min).default");
237    test_getString(lib, "input.(min).current");
238    test_getString(lib, "input.number(max).current");
239    test_getString(lib, "output.curve.about.label");
240
241    test_putString(lib,"input.number(test).default", "1000", 0);
242    test_putDouble(lib, "input.number(test).preset", 1, 0);
243    test_putDouble(lib, "input.number(test).current", 2000, 0);
244    test_putDouble(lib, "input.number(test).preset(p1)", 100, 0);
245    test_putDouble(lib, "input.number(test).preset(p2)", 200, 0);
246    test_putDouble(lib, "input.number(test).preset(p3)", 300, 0);
247    test_putDouble(lib, "input.number(test).preset(p4)", 400, 0);
248    test_putDouble(lib, "input.number(test).preset(p5)", 500, 0);
249
250
251    test_children(lib,"");
252    test_children(lib,"input.number(test)");
253    test_childrenByType(lib,"input.number(test)","preset");
254
255    err = rpXml(lib,&retStr);
256
257    if ( !err ) {
258        printf("XML = \n%s\n",retStr);
259    }
260    else {
261        printf("rpXML failed\n");
262    }
263
264    rpFreeLibrary(&lib);
265
266    return 0;
267}
Note: See TracBrowser for help on using the repository browser.