]> git.mxchange.org Git - simgear.git/blob - simgear/misc/tabbed_values_test.cxx
Removal of PLIB/SG from SimGear
[simgear.git] / simgear / misc / tabbed_values_test.cxx
1 ////////////////////////////////////////////////////////////////////////
2 // Test harness.
3 ////////////////////////////////////////////////////////////////////////
4
5 #include <simgear/compiler.h>
6
7 #include <iostream>
8 #include "tabbed_values.hxx"
9
10 using std::cout;
11 using std::cerr;
12 using std::endl;
13
14
15 int main (int ac, char ** av)
16 {
17         const char* string1 = "Hello\tWorld\t34\tZ\t\tThere Is No Spoon";
18         
19         SGTabbedValues tv(string1);
20         
21         if (tv[0] != "Hello") {
22                 cerr << "failed to read string at index 0" << endl;
23                 return 1;
24         }
25         
26         if (tv[1] != "World") {
27                 cerr << "failed to read string at index 1" << endl;
28                 return 1;
29         }
30         
31         if (tv[2] != "34") {
32                 cerr << "failed to read string at index 2" << endl;
33                 return 1;
34         }
35         
36         double dval = tv.getDoubleAt(2);
37         if (dval != 34.0) {
38                 cerr << "failed to read double at index 2" << endl;
39                 return 2;
40         }
41         
42         char cval = tv.getCharAt(3);
43         if (cval != 'Z') {
44                 cerr << "failed to read char at index 3" << endl;
45                 return 1;
46         }
47         
48         cval = tv.getCharAt(0);
49         if (cval != 'H') {
50                 cerr << "failed to read char at index 0" << endl;
51                 return 1;
52         }
53         
54         if (tv.isValueAt(4)) {
55                 cerr << "didn't identify skipped value correctly" << endl;
56                 return 3;
57         }
58         
59         if (!tv.isValueAt(3)) {
60                 cerr << "didn't identify present value correctly" << endl;
61                 return 3;
62         }
63         
64         if (tv[5] != "There Is No Spoon") {
65                 cerr << "failed to read string at index 5 (got [" << tv[5] << "]" << endl;
66                 return 1;
67         }
68         
69         cout << "all tests passed successfully!" << endl;
70         return 0;
71 }