]> git.mxchange.org Git - simgear.git/blobdiff - simgear/props/propertyObject_test.cxx
scenery: Use correct property root in xml loading.
[simgear.git] / simgear / props / propertyObject_test.cxx
index 38e925e8ad4e70bf2f41d717951137a356695f3e..b366d27af0ef65e927b44ec97fc2e900420be6c0 100644 (file)
@@ -1,3 +1,12 @@
+#ifdef HAVE_CONFIG_H
+#  include <simgear_config.h>
+#endif
+
+#ifdef NDEBUG
+// Always enable DEBUG mode in test application, otherwise "assert" test
+// statements have no effect and don't actually test anything (catch 17 ;-) ).
+#undef NDEBUG
+#endif
 
 #include <simgear/compiler.h>
 
 #include <cassert>
 #include <cstring>
 
+// working around MSVC weirdness with props.hxx and SGMathFwd
+#include <simgear/math/SGMath.hxx>
+
 #include "propertyObject.hxx"
 
+#include <simgear/structure/exception.hxx>
+
 using std::cout;
 using std::cerr;
 using std::endl;
 
 using namespace simgear;
 
+
 SGPropertyNode* testRoot = NULL;
 
 bool testBasic()
@@ -34,13 +49,32 @@ bool testBasic()
 
   double ff(aFoo);
   assert(ff == 12.0); // comparison with literal
+  if (ff != 12.0) cout << "Error: a/foo != 12!" << endl;
   
   const float fff(12.0f);
   assert(fff == aFoo); // comparion with float value
+  if (fff != aFoo) cout << "Error: 12 != a/foo" << endl;
 
   return true;
 }
 
+void testRelative()
+{
+  SGPropertyNode* n = testRoot->getNode("a");
+  assert(n);
+
+  PropertyObject<int> a1(n, "bar");
+  assert(a1 == 1234);
+
+  PropertyObject<int> a5(n, "some/child/path");
+  a5 = 4321;
+  assert(n->getIntValue("some/child/path") == 4321);
+
+  SGPropertyNode* m = testRoot->getNode("a/alice");
+  PropertyObject<std::string> a4(m);
+  assert(a4 == "aaaa");
+}
+
 void testString()
 {
   PropertyObject<std::string> sp("a/alice");
@@ -115,8 +149,9 @@ void testReadMissing()
   PropertyObject<bool> b("not/found/honest");
 
   try {
-    bool v = b;    
+    bool v = b;
     assert(false && "read of missing property didn't throw");
+    (void) v; // don't warn about unused variable
   } catch (sg_exception& e) {
     // expected
   }
@@ -129,6 +164,27 @@ void testReadMissing()
   }
 }
 
+void testCreate()
+{
+  PropertyObject<bool> a = PropertyObject<bool>::create("a/lemon", true);
+  assert(a == true);
+  assert(testRoot->getBoolValue("a/lemon") == true);
+  
+
+  PropertyObject<int> b(PropertyObject<int>::create("a/pear", 3142));
+  assert(b == 3142);
+  
+  PropertyObject<std::string> c(PropertyObject<std::string>::create("a/lime", "fofofo"));
+  assert(c == "fofofo");
+
+// check overloads for string version
+  SGPropertyNode* n = testRoot->getNode("b", true);
+  PropertyObject<std::string> d(PropertyObject<std::string>::create(n, "grape", "xyz"));
+  assert(!strcmp(testRoot->getStringValue("b/grape"), "xyz"));
+  
+  
+}
+
 int main(int argc, char* argv[])
 {
        testRoot = new SGPropertyNode();
@@ -145,10 +201,12 @@ int main(int argc, char* argv[])
                return EXIT_FAILURE;            
        }
 
+  testRelative();
   testReadMissing();
   testString();
   testAssignment();
   testSTLContainer();
+  testCreate();
 
   return EXIT_SUCCESS;
 }