1 | #include <iostream> |
---|
2 | #include "RpLibObj.h" |
---|
3 | #include "RpInt.h" |
---|
4 | #include "RpChain.h" |
---|
5 | #include "RpTest.h" |
---|
6 | |
---|
7 | int library_0_0 () |
---|
8 | { |
---|
9 | const char *testdesc = "test creating library object with loadFile()"; |
---|
10 | const char *testname = "library_0_0"; |
---|
11 | const char *filePath = "library_0_0_in.xml"; |
---|
12 | int retVal = 0; |
---|
13 | |
---|
14 | Rappture::Library lib; |
---|
15 | |
---|
16 | lib.loadFile(filePath); |
---|
17 | |
---|
18 | const char *expected = NULL; |
---|
19 | |
---|
20 | readFile(filePath, &expected); |
---|
21 | const char *received = lib.xml(); |
---|
22 | |
---|
23 | retVal |= testStringVal(testname,testdesc,expected,received); |
---|
24 | |
---|
25 | delete expected; |
---|
26 | |
---|
27 | return retVal; |
---|
28 | } |
---|
29 | |
---|
30 | int library_0_1 () |
---|
31 | { |
---|
32 | const char *testdesc = "test creating library object with loadXml()"; |
---|
33 | const char *testname = "library_0_1"; |
---|
34 | int retVal = 0; |
---|
35 | |
---|
36 | Rappture::Library lib; |
---|
37 | |
---|
38 | const char *buf = |
---|
39 | "<?xml version=\"1.0\"?>\n\ |
---|
40 | <run>\n\ |
---|
41 | <input>\n\ |
---|
42 | <number id=\"Ef\">\n\ |
---|
43 | <about>\n\ |
---|
44 | <label>Fermi Level</label>\n\ |
---|
45 | <description>Energy at center of distribution.</description>\n\ |
---|
46 | </about>\n\ |
---|
47 | <units>eV</units>\n\ |
---|
48 | <min>-10eV</min>\n\ |
---|
49 | <max>10eV</max>\n\ |
---|
50 | <default>0eV</default>\n\ |
---|
51 | <current>5eV</current>\n\ |
---|
52 | <preset>\n\ |
---|
53 | <label>300K (room temperature)</label>\n\ |
---|
54 | <value>300K</value>\n\ |
---|
55 | </preset>\n\ |
---|
56 | <preset>\n\ |
---|
57 | <label>77K (liquid nitrogen)</label>\n\ |
---|
58 | <value>77K</value>\n\ |
---|
59 | </preset>\n\ |
---|
60 | <preset>\n\ |
---|
61 | <label>4.2K (liquid helium)</label>\n\ |
---|
62 | <value>4.2K</value>\n\ |
---|
63 | </preset>\n\ |
---|
64 | </number>\n\ |
---|
65 | </input>\n\ |
---|
66 | </run>\n\ |
---|
67 | "; |
---|
68 | |
---|
69 | lib.loadXml(buf); |
---|
70 | |
---|
71 | const char *expected = buf; |
---|
72 | const char *received = lib.xml(); |
---|
73 | |
---|
74 | retVal |= testStringVal(testname,testdesc,expected,received); |
---|
75 | |
---|
76 | return retVal; |
---|
77 | } |
---|
78 | |
---|
79 | int library_1_0 () |
---|
80 | { |
---|
81 | const char *testdesc = "test contains() function on empty library"; |
---|
82 | const char *testname = "library_1_0"; |
---|
83 | int retVal = 0; |
---|
84 | |
---|
85 | Rappture::Library lib; |
---|
86 | const Rp_Chain *contents = NULL; |
---|
87 | contents = lib.contains(); |
---|
88 | |
---|
89 | int expected = 0; |
---|
90 | int received = Rp_ChainGetLength(contents); |
---|
91 | |
---|
92 | retVal |= testDoubleVal(testname,testdesc,expected,received); |
---|
93 | |
---|
94 | return retVal; |
---|
95 | } |
---|
96 | |
---|
97 | int library_1_1 () |
---|
98 | { |
---|
99 | const char *testdesc = "test contains() function on populated library"; |
---|
100 | const char *testname = "library_1_1"; |
---|
101 | int retVal = 0; |
---|
102 | |
---|
103 | Rappture::Library lib; |
---|
104 | const Rp_Chain *contents = NULL; |
---|
105 | const char *buf = |
---|
106 | "<?xml version=\"1.0\"?>\ |
---|
107 | <run>\ |
---|
108 | <input>\ |
---|
109 | <number id=\"Ef\">\ |
---|
110 | <about>\ |
---|
111 | <label>Fermi Level</label>\ |
---|
112 | <description>Energy at center of distribution.</description>\ |
---|
113 | </about>\ |
---|
114 | <units>eV</units>\ |
---|
115 | <min>-10eV</min>\ |
---|
116 | <max>10eV</max>\ |
---|
117 | <default>0eV</default>\ |
---|
118 | <current>5eV</current>\ |
---|
119 | <preset>\ |
---|
120 | <value>300K</value>\ |
---|
121 | <label>300K (room temperature)</label>\ |
---|
122 | </preset>\ |
---|
123 | <preset>\ |
---|
124 | <value>77K</value>\ |
---|
125 | <label>77K (liquid nitrogen)</label>\ |
---|
126 | </preset>\ |
---|
127 | <preset>\ |
---|
128 | <value>4.2K</value>\ |
---|
129 | <label>4.2K (liquid helium)</label>\ |
---|
130 | </preset>\ |
---|
131 | </number>\ |
---|
132 | </input>\ |
---|
133 | </run>"; |
---|
134 | |
---|
135 | lib.loadXml(buf); |
---|
136 | contents = lib.contains(); |
---|
137 | |
---|
138 | int expected = 1; |
---|
139 | int received = Rp_ChainGetLength(contents); |
---|
140 | |
---|
141 | retVal |= testDoubleVal(testname,testdesc,expected,received); |
---|
142 | |
---|
143 | return retVal; |
---|
144 | } |
---|
145 | |
---|
146 | int library_2_0 () |
---|
147 | { |
---|
148 | const char *testdesc = "test value(), 0 hints"; |
---|
149 | const char *testname = "library_2_0"; |
---|
150 | int retVal = 0; |
---|
151 | |
---|
152 | Rappture::Library lib; |
---|
153 | const char *buf = |
---|
154 | "<?xml version=\"1.0\"?>\ |
---|
155 | <run>\ |
---|
156 | <input>\ |
---|
157 | <number id=\"temperature\">\ |
---|
158 | <about>\ |
---|
159 | <label>Ambient temperature</label>\ |
---|
160 | <description>Temperature of the environment.</description>\ |
---|
161 | </about>\ |
---|
162 | <units>K</units>\ |
---|
163 | <min>0K</min>\ |
---|
164 | <max>500K</max>\ |
---|
165 | <default>300K</default>\ |
---|
166 | </number>\ |
---|
167 | <number id=\"Ef\">\ |
---|
168 | <about>\ |
---|
169 | <label>Fermi Level</label>\ |
---|
170 | <description>Energy at center of distribution.</description>\ |
---|
171 | </about>\ |
---|
172 | <units>eV</units>\ |
---|
173 | <min>-10eV</min>\ |
---|
174 | <max>10eV</max>\ |
---|
175 | <default>4eV</default>\ |
---|
176 | </number>\ |
---|
177 | </input>\ |
---|
178 | </run>"; |
---|
179 | |
---|
180 | lib.loadXml(buf); |
---|
181 | |
---|
182 | double expected = 4.0; |
---|
183 | double received = 0.0; |
---|
184 | lib.value("Ef",&received,0); |
---|
185 | |
---|
186 | retVal |= testDoubleVal(testname,testdesc,expected,received); |
---|
187 | |
---|
188 | return retVal; |
---|
189 | } |
---|
190 | |
---|
191 | int library_2_1 () |
---|
192 | { |
---|
193 | const char *testdesc = "test value(), 1 hint, units=eV"; |
---|
194 | const char *testname = "library_2_1"; |
---|
195 | int retVal = 0; |
---|
196 | |
---|
197 | Rappture::Library lib; |
---|
198 | const char *buf = |
---|
199 | "<?xml version=\"1.0\"?>\ |
---|
200 | <run>\ |
---|
201 | <input>\ |
---|
202 | <number id=\"temperature\">\ |
---|
203 | <about>\ |
---|
204 | <label>Ambient temperature</label>\ |
---|
205 | <description>Temperature of the environment.</description>\ |
---|
206 | </about>\ |
---|
207 | <units>K</units>\ |
---|
208 | <min>0K</min>\ |
---|
209 | <max>500K</max>\ |
---|
210 | <default>300K</default>\ |
---|
211 | </number>\ |
---|
212 | <number id=\"Ef\">\ |
---|
213 | <about>\ |
---|
214 | <label>Fermi Level</label>\ |
---|
215 | <description>Energy at center of distribution.</description>\ |
---|
216 | </about>\ |
---|
217 | <units>eV</units>\ |
---|
218 | <min>-10eV</min>\ |
---|
219 | <max>10eV</max>\ |
---|
220 | <default>4eV</default>\ |
---|
221 | </number>\ |
---|
222 | </input>\ |
---|
223 | </run>"; |
---|
224 | |
---|
225 | lib.loadXml(buf); |
---|
226 | |
---|
227 | double expected = 4.0; |
---|
228 | double received = 0.0; |
---|
229 | lib.value("Ef",&received,1,"units=eV"); |
---|
230 | |
---|
231 | retVal |= testDoubleVal(testname,testdesc,expected,received); |
---|
232 | |
---|
233 | return retVal; |
---|
234 | } |
---|
235 | |
---|
236 | int library_2_2 () |
---|
237 | { |
---|
238 | const char *testdesc = "test value(), 1 hint, units=J"; |
---|
239 | const char *testname = "library_2_2"; |
---|
240 | int retVal = 0; |
---|
241 | |
---|
242 | Rappture::Library lib; |
---|
243 | const char *buf = |
---|
244 | "<?xml version=\"1.0\"?>\ |
---|
245 | <run>\ |
---|
246 | <input>\ |
---|
247 | <number id=\"temperature\">\ |
---|
248 | <about>\ |
---|
249 | <label>Ambient temperature</label>\ |
---|
250 | <description>Temperature of the environment.</description>\ |
---|
251 | </about>\ |
---|
252 | <units>K</units>\ |
---|
253 | <min>0K</min>\ |
---|
254 | <max>500K</max>\ |
---|
255 | <default>300K</default>\ |
---|
256 | </number>\ |
---|
257 | <number id=\"Ef\">\ |
---|
258 | <about>\ |
---|
259 | <label>Fermi Level</label>\ |
---|
260 | <description>Energy at center of distribution.</description>\ |
---|
261 | </about>\ |
---|
262 | <units>eV</units>\ |
---|
263 | <min>-10eV</min>\ |
---|
264 | <max>10eV</max>\ |
---|
265 | <default>4eV</default>\ |
---|
266 | </number>\ |
---|
267 | </input>\ |
---|
268 | </run>"; |
---|
269 | |
---|
270 | lib.loadXml(buf); |
---|
271 | |
---|
272 | // double expected = 6.40871e-19; |
---|
273 | double expected = 4*1.602177e-19; |
---|
274 | double received = 0.0; |
---|
275 | lib.value("Ef",&received,1,"units=J"); |
---|
276 | |
---|
277 | retVal |= testDoubleVal(testname,testdesc,expected,received); |
---|
278 | |
---|
279 | return retVal; |
---|
280 | } |
---|
281 | |
---|
282 | int library_2_3 () |
---|
283 | { |
---|
284 | const char *testdesc = "test value(), object does not exist"; |
---|
285 | const char *testname = "library_2_3"; |
---|
286 | int retVal = 0; |
---|
287 | |
---|
288 | Rappture::Library lib; |
---|
289 | const char *buf = |
---|
290 | "<?xml version=\"1.0\"?>\ |
---|
291 | <run>\ |
---|
292 | <input>\ |
---|
293 | <number id=\"temperature\">\ |
---|
294 | <about>\ |
---|
295 | <label>Ambient temperature</label>\ |
---|
296 | <description>Temperature of the environment.</description>\ |
---|
297 | </about>\ |
---|
298 | <units>K</units>\ |
---|
299 | <min>0K</min>\ |
---|
300 | <max>500K</max>\ |
---|
301 | <default>300K</default>\ |
---|
302 | </number>\ |
---|
303 | <number id=\"Ef\">\ |
---|
304 | <about>\ |
---|
305 | <label>Fermi Level</label>\ |
---|
306 | <description>Energy at center of distribution.</description>\ |
---|
307 | </about>\ |
---|
308 | <units>eV</units>\ |
---|
309 | <min>-10eV</min>\ |
---|
310 | <max>10eV</max>\ |
---|
311 | <default>4eV</default>\ |
---|
312 | </number>\ |
---|
313 | </input>\ |
---|
314 | </run>"; |
---|
315 | |
---|
316 | lib.loadXml(buf); |
---|
317 | |
---|
318 | // library should not change the value of received |
---|
319 | // if it cannot find the requested object |
---|
320 | double expected = -101.01; |
---|
321 | double received = -101.01; |
---|
322 | lib.value("EF",&received,1,"units=J"); |
---|
323 | |
---|
324 | retVal |= testDoubleVal(testname,testdesc,1,lib.error()); |
---|
325 | retVal |= testDoubleVal(testname,testdesc,expected,received); |
---|
326 | |
---|
327 | return retVal; |
---|
328 | } |
---|
329 | |
---|
330 | int main() |
---|
331 | { |
---|
332 | library_0_0(); |
---|
333 | library_0_1(); |
---|
334 | library_1_0(); |
---|
335 | library_2_0(); |
---|
336 | library_2_1(); |
---|
337 | library_2_2(); |
---|
338 | library_2_3(); |
---|
339 | |
---|
340 | return 0; |
---|
341 | } |
---|