]> git.mxchange.org Git - simgear.git/blob - simgear/structure/expression_test.cxx
Add smart pointer tests (finally using Boost.Test)
[simgear.git] / simgear / structure / expression_test.cxx
1 #ifdef HAVE_CONFIG_H
2 #  include <simgear_config.h>
3 #endif
4
5 #ifdef NDEBUG
6 // Always enable DEBUG mode in test application, otherwise "assert" test
7 // statements have no effect and don't actually test anything (catch 17 ;-) ).
8 #undef NDEBUG
9 #endif
10
11 #include <simgear/compiler.h>
12
13 #include <iostream>
14 #include <cassert>
15 #include <cstdlib>
16 #include <cstring>
17
18 #include <simgear/misc/test_macros.hxx>
19 #include <simgear/structure/exception.hxx>
20 #include <simgear/structure/SGExpression.hxx>
21 #include <simgear/props/condition.hxx>
22 #include <simgear/props/props.hxx>
23 #include <simgear/props/props_io.hxx>
24
25 using namespace std;    
26 using namespace simgear;
27
28 SGPropertyNode_ptr propertyTree;
29
30 void initPropTree()
31 {
32   const char* xml = "<?xml version=\"1.0\"?>"
33       "<PropertyList>"
34           "<group-a>"
35               "<foo>one</foo>"
36               "<bar>2</bar>"
37               "<zot>99</zot>"
38           "</group-a>"
39           "<group-b>"
40               "<thing-1 type=\"bool\">false</thing-1>"
41           "</group-b>"
42       "</PropertyList>";
43   
44   propertyTree = new SGPropertyNode;
45   readProperties(xml, strlen(xml), propertyTree.ptr());
46 }
47
48 void testBasic()
49 {
50   
51 }
52
53 void testParse()
54 {
55     initPropTree();
56 #if 0
57     const char* xml = "<?xml version=\"1.0\"?>"
58         "<PropertyList>"
59             "<expression>"
60               "<and>"
61               "<greater-than>"
62                 "<property>/group-a/bar</property>"
63                 "<value>42</value>"
64               "</greater-than>"
65               "<less-than>"
66                 "<property>/group-a/zot</property>"
67                 "<value>50</value>"
68               "</less-than>"
69               "</and>"
70             "</expression>"
71         "</PropertyList>";
72 #endif
73     const char* xml2 = "<?xml version=\"1.0\"?>"
74         "<PropertyList>"
75               "<sqr>"
76                 "<max>"
77                   "<property>/group-a/bar</property>"
78                   "<property>/group-a/zot</property>"
79                   "<property>/group-b/thing-1</property>"    
80                 "</max>"
81               "</sqr>"
82         "</PropertyList>";
83     
84     SGPropertyNode* desc = new SGPropertyNode;
85     readProperties(xml2, strlen(xml2), desc);
86     
87     SGSharedPtr<SGExpressiond> expr = SGReadDoubleExpression(propertyTree, desc->getChild(0));
88     
89     std::set<const SGPropertyNode*> deps;
90     expr->collectDependentProperties(deps);
91     
92     COMPARE(deps.size(), 3);
93     SGPropertyNode* barProp = propertyTree->getNode("group-a/bar");
94     VERIFY(deps.find(barProp) != deps.end());
95
96     VERIFY(deps.find(propertyTree->getNode("group-a/zot")) != deps.end());
97     VERIFY(deps.find(propertyTree->getNode("group-b/thing-1")) != deps.end());
98 }
99
100 int main(int argc, char* argv[])
101 {
102     sglog().setLogLevels( SG_ALL, SG_INFO );
103   
104     testBasic();
105     testParse();
106     
107     cout << __FILE__ << ": All tests passed" << endl;
108     return EXIT_SUCCESS;
109 }
110