source: trunk/examples/objects/number/number.cc

Last change on this file was 5673, checked in by ldelgass, 9 years ago

Fix line endings, set eol-style to native on all C/C++ sources.

  • Property svn:eol-style set to native
File size: 25.4 KB
Line 
1#include <iostream>
2#include "RpNumber.h"
3#include "RpTest.h"
4
5int
6printNumber(Rappture::Number *n)
7{
8    std::cout << "name: " << n->name() << std::endl;
9    std::cout << "path: " << n->path() << std::endl;
10    std::cout << "label: " << n->label() << std::endl;
11    std::cout << "desc: " << n->desc() << std::endl;
12    std::cout << "default: " << n->def() << std::endl;
13    std::cout << "current: " << n->cur() << std::endl;
14    std::cout << "min: " << n->min() << std::endl;
15    std::cout << "max: " << n->max() << std::endl;
16    std::cout << "units: " << n->units() << std::endl;
17    // std::cout << "xml:\n" << n->xml(indent,tabstop) << std::endl;
18    return 0;
19}
20
21int number_0_0 ()
22{
23    const char *testdesc = "test number full constructor";
24    const char *testname = "number_0_0";
25    int retVal = 0;
26
27    const char *name = "temp";
28    const char *units = "K";
29    double def = 300;
30    double min = 0;
31    double max = 1000;
32    const char *label = "mylabel";
33    const char *desc = "mydesc";
34
35    Rappture::Number *n = NULL;
36
37    n = new Rappture::Number(name,units,def,min,max,label,desc);
38
39    if (n == NULL) {
40        printf("Error: %s\n", testname);
41        printf("\t%s\n", testdesc);
42        printf("\terror creating number object\n");
43        retVal = 1;
44    }
45
46    retVal |= testStringVal(testname,testdesc,name,n->name());
47    retVal |= testStringVal(testname,testdesc,units,n->units());
48    retVal |= testDoubleVal(testname,testdesc,def,n->def());
49    retVal |= testDoubleVal(testname,testdesc,min,n->min());
50    retVal |= testDoubleVal(testname,testdesc,max,n->max());
51    retVal |= testStringVal(testname,testdesc,label,n->label());
52    retVal |= testStringVal(testname,testdesc,desc,n->desc());
53
54    if (n != NULL) {
55        delete n;
56    }
57
58    return retVal;
59}
60
61int number_0_1 ()
62{
63    const char *testdesc = "test number constuctor";
64    const char *testname = "number_0_0";
65    int retVal = 0;
66
67    const char *name = "eV";
68    const char *units = "eV";
69    double def = 1.4;
70
71    Rappture::Number *n = NULL;
72
73    n = new Rappture::Number(name,units,def);
74
75    if (n == NULL) {
76        printf("Error: %s\n", testname);
77        printf("\t%s\n", testdesc);
78        printf("\terror creating number object\n");
79        retVal = 1;
80    }
81
82    retVal |= testStringVal(testname,testdesc,name,n->name());
83    retVal |= testStringVal(testname,testdesc,units,n->units());
84    retVal |= testDoubleVal(testname,testdesc,def,n->def());
85
86    if (n != NULL) {
87        delete n;
88    }
89
90    return retVal;
91}
92
93int number_1_0 ()
94{
95    const char *testdesc = "test constructing number from xml";
96    const char *testname = "number_1_0";
97    int retVal = 0;
98
99    const char *buf =
100"<?xml version=\"1.0\"?>\
101<number id=\"Ef\">\
102    <about>\
103        <label>Fermi Level</label>\
104        <description>Energy at center of distribution.</description>\
105    </about>\
106    <units>eV</units>\
107    <min>-10eV</min>\
108    <max>10eV</max>\
109    <default>0eV</default>\
110    <current>5eV</current>\
111    <preset>\
112        <value>300K</value>\
113        <label>300K (room temperature)</label>\
114    </preset>\
115    <preset>\
116        <value>77K</value>\
117        <label>77K (liquid nitrogen)</label>\
118    </preset>\
119    <preset>\
120        <value>4.2K</value>\
121        <label>4.2K (liquid helium)</label>\
122    </preset>\
123</number>";
124
125    const char *name = "Ef";
126    const char *units = "eV";
127    double def = 0;
128    double cur = 5;
129    double min = -10;
130    double max = 10;
131    const char *label = "Fermi Level";
132    const char *desc = "Energy at center of distribution.";
133
134    Rappture::Number n;
135
136    n.configure(Rappture::RPCONFIG_XML,(void*)buf);
137
138    retVal |= testStringVal(testname,testdesc,name,n.name());
139    retVal |= testStringVal(testname,testdesc,units,n.units());
140    retVal |= testDoubleVal(testname,testdesc,def,n.def());
141    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
142    if (n.minset()) {
143        retVal |= testDoubleVal(testname,testdesc,min,n.min());
144    }
145    if (n.maxset()) {
146        retVal |= testDoubleVal(testname,testdesc,max,n.max());
147    }
148    retVal |= testStringVal(testname,testdesc,label,n.label());
149    retVal |= testStringVal(testname,testdesc,desc,n.desc());
150
151    return retVal;
152}
153
154int number_1_1 ()
155{
156    const char *testdesc = "test constructing number from xml, no min";
157    const char *testname = "number_1_1";
158    int retVal = 0;
159
160    const char *buf =
161"<?xml version=\"1.0\"?>\
162<number id=\"Ef\">\
163    <about>\
164        <label>Fermi Level</label>\
165        <description>Energy at center of distribution.</description>\
166    </about>\
167    <units>eV</units>\
168    <max>10eV</max>\
169    <default>0eV</default>\
170    <current>5eV</current>\
171</number>";
172
173    const char *name = "Ef";
174    const char *units = "eV";
175    double def = 0;
176    double cur = 5;
177    double min = -10;
178    double max = 10;
179    const char *label = "Fermi Level";
180    const char *desc = "Energy at center of distribution.";
181
182    Rappture::Number n;
183
184    n.configure(Rappture::RPCONFIG_XML,(void*)buf);
185
186    retVal |= testStringVal(testname,testdesc,name,n.name());
187    retVal |= testStringVal(testname,testdesc,units,n.units());
188    retVal |= testDoubleVal(testname,testdesc,def,n.def());
189    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
190    if (n.minset()) {
191        retVal |= testDoubleVal(testname,testdesc,min,n.min());
192    }
193    if (n.maxset()) {
194        retVal |= testDoubleVal(testname,testdesc,max,n.max());
195    }
196    retVal |= testStringVal(testname,testdesc,label,n.label());
197    retVal |= testStringVal(testname,testdesc,desc,n.desc());
198
199    return retVal;
200}
201
202int number_1_2 ()
203{
204    const char *testdesc = "test constructing number from xml, no max";
205    const char *testname = "number_1_2";
206    int retVal = 0;
207
208    const char *buf =
209"<?xml version=\"1.0\"?>\
210<number id=\"Ef\">\
211    <about>\
212        <label>Fermi Level</label>\
213        <description>Energy at center of distribution.</description>\
214    </about>\
215    <units>eV</units>\
216    <min>-10eV</min>\
217    <default>0eV</default>\
218    <current>5eV</current>\
219</number>";
220
221
222    const char *name = "Ef";
223    const char *units = "eV";
224    double def = 0;
225    double cur = 5;
226    double min = -10;
227    double max = 10;
228    const char *label = "Fermi Level";
229    const char *desc = "Energy at center of distribution.";
230
231    Rappture::Number n;
232
233    n.configure(Rappture::RPCONFIG_XML,(void*)buf);
234
235    retVal |= testStringVal(testname,testdesc,name,n.name());
236    retVal |= testStringVal(testname,testdesc,units,n.units());
237    retVal |= testDoubleVal(testname,testdesc,def,n.def());
238    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
239    if (n.minset()) {
240        retVal |= testDoubleVal(testname,testdesc,min,n.min());
241    }
242    if (n.maxset()) {
243        retVal |= testDoubleVal(testname,testdesc,max,n.max());
244    }
245    retVal |= testStringVal(testname,testdesc,label,n.label());
246    retVal |= testStringVal(testname,testdesc,desc,n.desc());
247
248    return retVal;
249}
250
251int number_1_3 ()
252{
253    const char *testdesc = "test constructing number from xml, no min, no max";
254    const char *testname = "number_1_3";
255    int retVal = 0;
256
257    const char *buf =
258"<?xml version=\"1.0\"?>\
259<number id=\"Ef\">\
260    <about>\
261        <label>Fermi Level</label>\
262        <description>Energy at center of distribution.</description>\
263    </about>\
264    <units>eV</units>\
265    <default>0eV</default>\
266    <current>5eV</current>\
267</number>";
268
269
270    const char *name = "Ef";
271    const char *units = "eV";
272    double def = 0;
273    double cur = 5;
274    double min = -10;
275    double max = 10;
276    const char *label = "Fermi Level";
277    const char *desc = "Energy at center of distribution.";
278
279    Rappture::Number n;
280
281    n.configure(Rappture::RPCONFIG_XML,(void*)buf);
282
283    retVal |= testStringVal(testname,testdesc,name,n.name());
284    retVal |= testStringVal(testname,testdesc,units,n.units());
285    retVal |= testDoubleVal(testname,testdesc,def,n.def());
286    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
287    if (n.minset()) {
288        retVal |= testDoubleVal(testname,testdesc,min,n.min());
289    }
290    if (n.maxset()) {
291        retVal |= testDoubleVal(testname,testdesc,max,n.max());
292    }
293    retVal |= testStringVal(testname,testdesc,label,n.label());
294    retVal |= testStringVal(testname,testdesc,desc,n.desc());
295
296    return retVal;
297}
298
299int number_1_4 ()
300{
301    const char *testdesc = "test constructing number from xml, no cur";
302    const char *testname = "number_1_4";
303    int retVal = 0;
304
305    const char *buf =
306"<?xml version=\"1.0\"?>\
307<number id=\"Ef\">\
308    <about>\
309        <label>Fermi Level</label>\
310        <description>Energy at center of distribution.</description>\
311    </about>\
312    <units>eV</units>\
313    <min>-10eV</min>\
314    <max>10eV</max>\
315    <default>0eV</default>\
316</number>";
317
318
319    const char *name = "Ef";
320    const char *units = "eV";
321    double def = 0;
322    double cur = 0;
323    double min = -10;
324    double max = 10;
325    const char *label = "Fermi Level";
326    const char *desc = "Energy at center of distribution.";
327
328    Rappture::Number n;
329
330    n.configure(Rappture::RPCONFIG_XML,(void*)buf);
331
332    retVal |= testStringVal(testname,testdesc,name,n.name());
333    retVal |= testStringVal(testname,testdesc,units,n.units());
334    retVal |= testDoubleVal(testname,testdesc,def,n.def());
335    // if no current value is provided it defaults to 0.0.
336    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
337    if (n.minset()) {
338        retVal |= testDoubleVal(testname,testdesc,min,n.min());
339    }
340    if (n.maxset()) {
341        retVal |= testDoubleVal(testname,testdesc,max,n.max());
342    }
343    retVal |= testStringVal(testname,testdesc,label,n.label());
344    retVal |= testStringVal(testname,testdesc,desc,n.desc());
345
346    return retVal;
347}
348
349int number_1_5 ()
350{
351    const char *testdesc = "test constructing number from xml, no def";
352    const char *testname = "number_1_5";
353    int retVal = 0;
354
355    const char *buf =
356"<?xml version=\"1.0\"?>\
357<number id=\"Ef\">\
358    <about>\
359        <label>Fermi Level</label>\
360        <description>Energy at center of distribution.</description>\
361    </about>\
362    <units>eV</units>\
363    <min>-10eV</min>\
364    <max>10eV</max>\
365    <current>5eV</current>\
366</number>";
367
368
369    const char *name = "Ef";
370    const char *units = "eV";
371    double def = 0;
372    double cur = 5;
373    double min = -10;
374    double max = 10;
375    const char *label = "Fermi Level";
376    const char *desc = "Energy at center of distribution.";
377
378    Rappture::Number n;
379
380    n.configure(Rappture::RPCONFIG_XML,(void*)buf);
381
382    retVal |= testStringVal(testname,testdesc,name,n.name());
383    retVal |= testStringVal(testname,testdesc,units,n.units());
384    // if no default value is provided it defaults to 0.0.
385    retVal |= testDoubleVal(testname,testdesc,def,n.def());
386    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
387    if (n.minset()) {
388        retVal |= testDoubleVal(testname,testdesc,min,n.min());
389    }
390    if (n.maxset()) {
391        retVal |= testDoubleVal(testname,testdesc,max,n.max());
392    }
393    retVal |= testStringVal(testname,testdesc,label,n.label());
394    retVal |= testStringVal(testname,testdesc,desc,n.desc());
395
396    return retVal;
397}
398
399int number_1_6 ()
400{
401    const char *testdesc = "test constructing number from xml, no def, no cur";
402    const char *testname = "number_1_6";
403    int retVal = 0;
404
405    const char *buf =
406"<?xml version=\"1.0\"?>\
407<number id=\"Ef\">\
408    <about>\
409        <label>Fermi Level</label>\
410        <description>Energy at center of distribution.</description>\
411    </about>\
412    <units>eV</units>\
413    <min>-10eV</min>\
414    <max>10eV</max>\
415</number>";
416
417
418    const char *name = "Ef";
419    const char *units = "eV";
420    double def = 0;
421    double cur = 0;
422    double min = -10;
423    double max = 10;
424    const char *label = "Fermi Level";
425    const char *desc = "Energy at center of distribution.";
426
427    Rappture::Number n;
428
429    n.configure(Rappture::RPCONFIG_XML,(void*)buf);
430
431    retVal |= testStringVal(testname,testdesc,name,n.name());
432    retVal |= testStringVal(testname,testdesc,units,n.units());
433    retVal |= testDoubleVal(testname,testdesc,def,n.def());
434    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
435    if (n.minset()) {
436        retVal |= testDoubleVal(testname,testdesc,min,n.min());
437    }
438    if (n.maxset()) {
439        retVal |= testDoubleVal(testname,testdesc,max,n.max());
440    }
441    retVal |= testStringVal(testname,testdesc,label,n.label());
442    retVal |= testStringVal(testname,testdesc,desc,n.desc());
443
444    return retVal;
445}
446
447int number_1_7 ()
448{
449    const char *testdesc = "test constructing number from xml, no def cur min max";
450    const char *testname = "number_1_7";
451    int retVal = 0;
452
453    const char *buf =
454"<?xml version=\"1.0\"?>\
455<number id=\"Ef\">\
456    <about>\
457        <label>Fermi Level</label>\
458        <description>Energy at center of distribution.</description>\
459    </about>\
460    <units>eV</units>\
461</number>";
462
463
464    const char *name = "Ef";
465    const char *units = "eV";
466    double def = 0;
467    double cur = 0;
468    double min = 0;
469    double max = 0;
470    const char *label = "Fermi Level";
471    const char *desc = "Energy at center of distribution.";
472
473    Rappture::Number n;
474
475    n.configure(Rappture::RPCONFIG_XML,(void*)buf);
476
477    retVal |= testStringVal(testname,testdesc,name,n.name());
478    retVal |= testStringVal(testname,testdesc,units,n.units());
479    retVal |= testDoubleVal(testname,testdesc,def,n.def());
480    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
481    retVal |= testDoubleVal(testname,testdesc,min,n.min());
482    retVal |= testDoubleVal(testname,testdesc,max,n.max());
483    retVal |= testStringVal(testname,testdesc,label,n.label());
484    retVal |= testStringVal(testname,testdesc,desc,n.desc());
485
486    return retVal;
487}
488
489int number_1_8 ()
490{
491    const char *testdesc = "test constructing number from xml, no explicit units";
492    const char *testname = "number_1_8";
493    int retVal = 0;
494
495    const char *buf =
496"<?xml version=\"1.0\"?>\
497<number id=\"Ef\">\
498    <about>\
499        <label>Fermi Level</label>\
500        <description>Energy at center of distribution.</description>\
501    </about>\
502    <min>-10eV</min>\
503    <max>10eV</max>\
504    <default>0eV</default>\
505    <current>5eV</current>\
506</number>";
507
508    const char *name = "Ef";
509    const char *units = "eV";
510    double def = 0;
511    double cur = 5;
512    double min = -10;
513    double max = 10;
514    const char *label = "Fermi Level";
515    const char *desc = "Energy at center of distribution.";
516
517    Rappture::Number n;
518
519    n.configure(Rappture::RPCONFIG_XML,(void*)buf);
520
521    retVal |= testStringVal(testname,testdesc,name,n.name());
522    // units are implied from min, max, def, cur values
523    retVal |= testStringVal(testname,testdesc,units,n.units());
524    retVal |= testDoubleVal(testname,testdesc,def,n.def());
525    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
526    if (n.minset()) {
527        retVal |= testDoubleVal(testname,testdesc,min,n.min());
528    }
529    if (n.maxset()) {
530        retVal |= testDoubleVal(testname,testdesc,max,n.max());
531    }
532    retVal |= testStringVal(testname,testdesc,label,n.label());
533    retVal |= testStringVal(testname,testdesc,desc,n.desc());
534
535    return retVal;
536}
537
538int number_1_9 ()
539{
540    const char *testdesc = "test constructing number from xml, no description";
541    const char *testname = "number_1_9";
542    int retVal = 0;
543
544    const char *buf =
545"<?xml version=\"1.0\"?>\
546<number id=\"Ef\">\
547    <about>\
548        <label>Fermi Level</label>\
549    </about>\
550    <units>eV</units>\
551    <min>-10eV</min>\
552    <max>10eV</max>\
553    <default>0eV</default>\
554    <current>5eV</current>\
555</number>";
556
557    const char *name = "Ef";
558    const char *units = "eV";
559    double def = 0;
560    double cur = 5;
561    double min = -10;
562    double max = 10;
563    const char *label = "Fermi Level";
564    const char *desc = "";
565
566    Rappture::Number n;
567
568    n.configure(Rappture::RPCONFIG_XML,(void*)buf);
569
570    retVal |= testStringVal(testname,testdesc,name,n.name());
571    retVal |= testStringVal(testname,testdesc,units,n.units());
572    retVal |= testDoubleVal(testname,testdesc,def,n.def());
573    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
574    if (n.minset()) {
575        retVal |= testDoubleVal(testname,testdesc,min,n.min());
576    }
577    if (n.maxset()) {
578        retVal |= testDoubleVal(testname,testdesc,max,n.max());
579    }
580    retVal |= testStringVal(testname,testdesc,label,n.label());
581    retVal |= testStringVal(testname,testdesc,desc,n.desc());
582
583    return retVal;
584}
585
586int number_1_10 ()
587{
588    const char *testdesc = "test constructing number from xml, no label";
589    const char *testname = "number_1_10";
590    int retVal = 0;
591
592    const char *buf =
593"<?xml version=\"1.0\"?>\
594<number id=\"Ef\">\
595    <about>\
596        <description>Energy at center of distribution.</description>\
597    </about>\
598    <units>eV</units>\
599    <min>-10eV</min>\
600    <max>10eV</max>\
601    <default>0eV</default>\
602    <current>5eV</current>\
603</number>";
604
605    const char *name = "Ef";
606    const char *units = "eV";
607    double def = 0;
608    double cur = 5;
609    double min = -10;
610    double max = 10;
611    const char *label = "";
612    const char *desc = "Energy at center of distribution.";
613
614    Rappture::Number n;
615
616    n.configure(Rappture::RPCONFIG_XML,(void*)buf);
617
618    retVal |= testStringVal(testname,testdesc,name,n.name());
619    retVal |= testStringVal(testname,testdesc,units,n.units());
620    retVal |= testDoubleVal(testname,testdesc,def,n.def());
621    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
622    if (n.minset()) {
623        retVal |= testDoubleVal(testname,testdesc,min,n.min());
624    }
625    if (n.maxset()) {
626        retVal |= testDoubleVal(testname,testdesc,max,n.max());
627    }
628    retVal |= testStringVal(testname,testdesc,label,n.label());
629    retVal |= testStringVal(testname,testdesc,desc,n.desc());
630
631    return retVal;
632}
633
634int number_1_11 ()
635{
636    const char *testdesc = "test constructing number from xml, no label description";
637    const char *testname = "number_1_11";
638    int retVal = 0;
639
640    const char *buf =
641"<?xml version=\"1.0\"?>\
642<number id=\"Ef\">\
643    <about>\
644    </about>\
645    <units>eV</units>\
646    <min>-10eV</min>\
647    <max>10eV</max>\
648    <default>0eV</default>\
649    <current>5eV</current>\
650</number>";
651
652    const char *name = "Ef";
653    const char *units = "eV";
654    double def = 0;
655    double cur = 5;
656    double min = -10;
657    double max = 10;
658    const char *label = "";
659    const char *desc = "";
660
661    Rappture::Number n;
662
663    n.configure(Rappture::RPCONFIG_XML,(void*)buf);
664
665    retVal |= testStringVal(testname,testdesc,name,n.name());
666    retVal |= testStringVal(testname,testdesc,units,n.units());
667    // if no default value and no current value is provided
668    // both default to 0.0.
669    retVal |= testDoubleVal(testname,testdesc,def,n.def());
670    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
671    retVal |= testDoubleVal(testname,testdesc,min,n.min());
672    retVal |= testDoubleVal(testname,testdesc,max,n.max());
673    retVal |= testStringVal(testname,testdesc,label,n.label());
674    retVal |= testStringVal(testname,testdesc,desc,n.desc());
675
676    return retVal;
677}
678
679int number_1_12 ()
680{
681    const char *testdesc = "test constructing number from xml, no about label description";
682    const char *testname = "number_1_12";
683    int retVal = 0;
684
685    const char *buf =
686"<?xml version=\"1.0\"?>\
687<number id=\"Ef\">\
688    <units>eV</units>\
689    <min>-10eV</min>\
690    <max>10eV</max>\
691    <default>0eV</default>\
692    <current>5eV</current>\
693</number>";
694
695    const char *name = "Ef";
696    const char *units = "eV";
697    double def = 0;
698    double cur = 5;
699    double min = -10;
700    double max = 10;
701    const char *label = "";
702    const char *desc = "";
703
704    Rappture::Number n;
705
706    n.configure(Rappture::RPCONFIG_XML,(void*)buf);
707
708    retVal |= testStringVal(testname,testdesc,name,n.name());
709    retVal |= testStringVal(testname,testdesc,units,n.units());
710    // if no default value and no current value is provided
711    // both default to 0.0.
712    retVal |= testDoubleVal(testname,testdesc,def,n.def());
713    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
714    retVal |= testDoubleVal(testname,testdesc,min,n.min());
715    retVal |= testDoubleVal(testname,testdesc,max,n.max());
716    retVal |= testStringVal(testname,testdesc,label,n.label());
717    retVal |= testStringVal(testname,testdesc,desc,n.desc());
718
719    return retVal;
720}
721
722int number_1_13 ()
723{
724    const char *testdesc = "test constructing number from xml, no def cur min max units";
725    const char *testname = "number_1_13";
726    int retVal = 0;
727
728    const char *buf =
729"<?xml version=\"1.0\"?>\
730<number id=\"Ef\">\
731    <about>\
732        <label>Fermi Level</label>\
733        <description>Energy at center of distribution.</description>\
734    </about>\
735</number>";
736
737
738    const char *name = "Ef";
739    const char *units = NULL;
740    double def = 0;
741    double cur = 0;
742    double min = 0;
743    double max = 0;
744    const char *label = "Fermi Level";
745    const char *desc = "Energy at center of distribution.";
746
747    Rappture::Number n;
748
749    n.configure(Rappture::RPCONFIG_XML,(void*)buf);
750
751    retVal |= testStringVal(testname,testdesc,name,n.name());
752    retVal |= testStringVal(testname,testdesc,units,n.units());
753    // if no default value and no current value is provided
754    // both default to 0.0.
755    retVal |= testDoubleVal(testname,testdesc,def,n.def());
756    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
757    retVal |= testDoubleVal(testname,testdesc,min,n.min());
758    retVal |= testDoubleVal(testname,testdesc,max,n.max());
759    retVal |= testStringVal(testname,testdesc,label,n.label());
760    retVal |= testStringVal(testname,testdesc,desc,n.desc());
761
762    return retVal;
763}
764
765int number_1_14 ()
766{
767    const char *testdesc = "test constructing number from xml, only name";
768    const char *testname = "number_1_14";
769    int retVal = 0;
770
771    const char *buf =
772"<?xml version=\"1.0\"?>\
773<number id=\"Ef\">\
774</number>";
775
776
777    const char *name = "Ef";
778    const char *units = NULL;
779    double def = 0;
780    double cur = 0;
781    double min = 0;
782    double max = 0;
783    const char *label = "";
784    const char *desc = "";
785
786    Rappture::Number n;
787
788    n.configure(Rappture::RPCONFIG_XML,(void*)buf);
789
790    retVal |= testStringVal(testname,testdesc,name,n.name());
791    retVal |= testStringVal(testname,testdesc,units,n.units());
792    retVal |= testDoubleVal(testname,testdesc,def,n.def());
793    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
794    retVal |= testDoubleVal(testname,testdesc,min,n.min());
795    retVal |= testDoubleVal(testname,testdesc,max,n.max());
796    retVal |= testStringVal(testname,testdesc,label,n.label());
797    retVal |= testStringVal(testname,testdesc,desc,n.desc());
798
799    return retVal;
800}
801
802int number_1_15 ()
803{
804    const char *testdesc = "test constructing number from xml, no info";
805    const char *testname = "number_1_15";
806    int retVal = 0;
807
808    const char *buf =
809"<?xml version=\"1.0\"?>\
810<number>\
811</number>";
812
813
814    const char *name = "";
815    const char *units = NULL;
816    double def = 0;
817    double cur = 0;
818    double min = 0;
819    double max = 0;
820    const char *label = "";
821    const char *desc = "";
822
823    Rappture::Number n;
824
825    n.configure(Rappture::RPCONFIG_XML,(void*)buf);
826
827    retVal |= testStringVal(testname,testdesc,name,n.name());
828    retVal |= testStringVal(testname,testdesc,units,n.units());
829    retVal |= testDoubleVal(testname,testdesc,def,n.def());
830    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
831    retVal |= testDoubleVal(testname,testdesc,min,n.min());
832    retVal |= testDoubleVal(testname,testdesc,max,n.max());
833    retVal |= testStringVal(testname,testdesc,label,n.label());
834    retVal |= testStringVal(testname,testdesc,desc,n.desc());
835
836    return retVal;
837}
838
839int number_1_16 ()
840{
841    const char *testdesc = "test constructing number from xml, no explicit or implied units";
842    const char *testname = "number_1_16";
843    int retVal = 0;
844
845    const char *buf =
846"<?xml version=\"1.0\"?>\
847<number id=\"Ef\">\
848    <about>\
849        <label>Fermi Level</label>\
850        <description>Energy at center of distribution.</description>\
851    </about>\
852    <min>-10</min>\
853    <max>10</max>\
854    <default>0</default>\
855    <current>5</current>\
856</number>";
857
858    const char *name = "Ef";
859    const char *units = NULL;
860    double def = 0;
861    double cur = 5;
862    double min = -10;
863    double max = 10;
864    const char *label = "Fermi Level";
865    const char *desc = "Energy at center of distribution.";
866
867    Rappture::Number n;
868
869    n.configure(Rappture::RPCONFIG_XML,(void*)buf);
870
871    retVal |= testStringVal(testname,testdesc,name,n.name());
872    retVal |= testStringVal(testname,testdesc,units,n.units());
873    retVal |= testDoubleVal(testname,testdesc,def,n.def());
874    retVal |= testDoubleVal(testname,testdesc,cur,n.cur());
875    if (n.minset()) {
876        retVal |= testDoubleVal(testname,testdesc,min,n.min());
877    }
878    if (n.maxset()) {
879        retVal |= testDoubleVal(testname,testdesc,max,n.max());
880    }
881    retVal |= testStringVal(testname,testdesc,label,n.label());
882    retVal |= testStringVal(testname,testdesc,desc,n.desc());
883
884    return retVal;
885}
886
887// FIXME: more tests:
888// what if units in min, max, def, cur differ from units()
889// what if you can't convert from units in min, max, def, cur to units()
890// what if units in presets differ from units()
891// test case for value() function when only cur was configured
892// test case for value() function when only def was configured
893// test case for vvalue() function with no hints
894// test case for vvalue() function with "units=" hint
895// test case for setting up object, what is cur when only def is provided
896// test case for setting up object, what is def when only cur is provided
897
898int main()
899{
900    number_0_0();
901    number_0_1();
902    number_1_0();
903    number_1_1();
904    number_1_2();
905    number_1_3();
906    number_1_4();
907    number_1_5();
908    number_1_6();
909    number_1_7();
910    number_1_8();
911    number_1_9();
912    number_1_10();
913    number_1_11();
914    number_1_12();
915    number_1_13();
916    number_1_14();
917    number_1_15();
918    number_1_16();
919
920    return 0;
921}
Note: See TracBrowser for help on using the repository browser.