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

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

Updated all copyright notices.

File size: 5.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
12
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_element (RpLibrary* lib, const char* path )
29{
30    int retVal = 1;
31    RpLibrary* searchEle = NULL;
32    const char* type = NULL;
33    const char* comp = NULL;
34    const char* id = NULL;
35
36    printf("TESTING ELEMENT: path = %s\n", path);
37
38    searchEle = rpElement(lib,path);
39    type = rpElementAsType(lib,path);
40    comp = rpElementAsComp(lib,path);
41    id = rpElementAsId(lib,path);
42
43    if (!searchEle) {
44        printf("searchEle is NULL\n");
45        retVal = 1;
46    }
47    else {
48        printf("searchEle comp = :%s:\n", comp);
49        printf("searchEle   id = :%s:\n", id);
50        printf("searchEle type = :%s:\n", type);
51
52        comp = rpNodeComp(searchEle);
53        id   = rpNodeId(searchEle);
54        type = rpNodeType(searchEle);
55
56        printf("searchEle comp = :%s:\n", comp);
57        printf("searchEle   id = :%s:\n", id);
58        printf("searchEle type = :%s:\n", type);
59
60        retVal = 0;
61    }
62
63    return retVal;
64}
65
66int test_getString (RpLibrary* lib, const char* path )
67{
68    int retVal = 1;
69    const char* searchVal = NULL;
70
71    printf("TESTING GET String: path = %s\n", path);
72
73    searchVal = rpGetString(lib,path);
74
75    if (!searchVal || *searchVal == '\0') {
76        printf("searchVal is EMPTY STRING\n");
77        retVal = 1;
78    }
79    else {
80        printf("searchVal = :%s:\n", searchVal);
81        retVal = 0;
82    }
83
84    return retVal;
85}
86
87int test_getDouble (RpLibrary* lib, const char* path )
88{
89    int retVal = 1;
90    double searchVal = 0.0;
91
92    printf("TESTING GET Double: path = %s\n", path);
93
94    searchVal = rpGetDouble(lib,path);
95
96    printf("searchVal = :%f:\n", searchVal);
97    retVal = 0;
98
99    return retVal;
100}
101
102int test_children (RpLibrary* lib, const char* path)
103{
104    int retVal = 1;
105    RpLibrary* childEle = NULL;
106    const char* id = NULL;
107    const char* comp = NULL;
108    const char* type = NULL;
109
110    printf("TESTING CHILDREN: path = %s\n", path);
111
112    while ( (childEle = rpChildren(lib,path,childEle)) ) {
113        comp = rpNodeComp(childEle);
114        id   = rpNodeId(childEle);
115        type = rpNodeType(childEle);
116
117        printf("childEle comp = :%s:\n",comp);
118        printf("childEle   id = :%s:\n",id);
119        printf("childEle type = :%s:\n",type);
120
121    }
122
123    retVal = 0;
124
125    return retVal;
126}
127
128int test_childrenByType (RpLibrary* lib, const char* path, const char* searchType )
129{
130    int retVal = 1;
131    RpLibrary* childEle = NULL;
132    const char* id = NULL;
133    const char* comp = NULL;
134    const char* type = NULL;
135
136    printf("TESTING CHILDREN: path = %s\n", path);
137
138    while ( (childEle = rpChildrenByType(lib,path,childEle,searchType)) ) {
139        comp = rpNodeComp(childEle);
140        id   = rpNodeId(childEle);
141        type = rpNodeType(childEle);
142
143        printf("childEle comp = :%s:\n",comp);
144        printf("childEle   id = :%s:\n",id);
145        printf("childEle type = :%s:\n",type);
146
147    }
148
149    retVal = 0;
150
151    return retVal;
152}
153
154int test_putString (RpLibrary* lib, const char* path, const char* value, int append)
155{
156    int retVal = 1;
157    const char* searchVal = NULL;
158
159    printf("TESTING PUT String: path = %s\n", path);
160
161    rpPutString(lib,path,value,append);
162    searchVal = rpGetString(lib, path);
163
164    if (!searchVal || *searchVal == '\0') {
165        printf("searchVal is EMPTY STRING\n");
166        retVal = 1;
167    }
168    else {
169        printf("searchVal = :%s:\n", searchVal);
170        retVal = 0;
171    }
172
173    return retVal;
174}
175
176int test_putDouble (RpLibrary* lib, const char* path, double value, int append)
177{
178    int retVal = 1;
179    double searchVal = 0.0;
180
181    printf("TESTING PUT String: path = %s\n", path);
182
183    rpPutDouble(lib,path,value,append);
184    searchVal = rpGetDouble(lib, path);
185    printf("searchVal = :%f:\n", searchVal);
186    retVal = 0;
187
188    return retVal;
189}
190
191int
192main(int argc, char** argv)
193{
194    RpLibrary* lib = NULL;
195
196    if (argc < 2)
197    {
198        printf("usage: %s driver.xml\n", argv[0]);
199        return -1;
200    }
201
202    lib = rpLibrary(argv[1]);
203
204    test_element(lib,"input.number(min)");
205    test_element(lib,"input.number(max)");
206    test_element(lib,"output.curve(result)");
207
208    test_getString(lib, "input.number(min).default");
209    test_getString(lib, "input.(min).current");
210    test_getString(lib, "input.number(max).current");
211    test_getString(lib, "output.curve.about.label");
212
213    test_putString(lib,"input.number(test).default", "1000", 0);
214    test_putDouble(lib, "input.number(test).preset", 1, 0);
215    test_putDouble(lib, "input.number(test).current", 2000, 0);
216    test_putDouble(lib, "input.number(test).preset(p1)", 100, 0);
217    test_putDouble(lib, "input.number(test).preset(p2)", 200, 0);
218    test_putDouble(lib, "input.number(test).preset(p3)", 300, 0);
219    test_putDouble(lib, "input.number(test).preset(p4)", 400, 0);
220    test_putDouble(lib, "input.number(test).preset(p5)", 500, 0);
221
222   
223    test_children(lib,"");
224    test_children(lib,"input.number(test)");
225    test_childrenByType(lib,"input.number(test)","preset");
226
227    printf("XML = \n%s\n",rpXml(lib));
228   
229    rpFreeLibrary(lib);
230
231    return 0;
232}
Note: See TracBrowser for help on using the repository browser.