]> git.mxchange.org Git - simgear.git/commitdiff
PropertyObject ::create tests.
authorJames Turner <zakalawe@mac.com>
Sat, 20 Nov 2010 12:25:11 +0000 (04:25 -0800)
committerJames Turner <zakalawe@mac.com>
Sat, 20 Nov 2010 12:25:11 +0000 (04:25 -0800)
simgear/props/propertyObject.hxx
simgear/props/propertyObject_test.cxx

index 33921c7a9b2ebc3461e68d8432c553d563c14ed6..5cc1588ba0514dd8f264b419ace108b6472e6e2c 100644 (file)
@@ -143,7 +143,34 @@ public:
   
   }
   
+// copy-constructor
+  PropertyObject(const PropertyObject<std::string>& aOther) :
+    PropertyObjectBase(aOther)
+  {
+  }
 
+// create form
+  static PropertyObject<std::string> create(const char* aPath, const std::string& aValue)
+  {
+    PropertyObject<std::string> p(aPath);
+    p = aValue;
+    return p;
+  }
+  
+  static PropertyObject<std::string> create(SGPropertyNode* aNode, const std::string& aValue)
+  {
+    PropertyObject<std::string> p(aNode);
+    p = aValue;
+    return p;
+  }
+
+  static PropertyObject<std::string> create(SGPropertyNode* aNode, const char* aChild, const std::string& aValue)
+  {
+    PropertyObject<std::string> p(aNode, aChild);
+    p = aValue;
+    return p;
+  }
+  
   
   operator std::string () const
   {
index 2b2ee1ec01060eb86200ab9c62546f2c105bdf0b..b2c458ad5a12da9b33a52c601451fe1c35b0568e 100644 (file)
@@ -149,6 +149,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();
@@ -170,6 +191,7 @@ int main(int argc, char* argv[])
   testString();
   testAssignment();
   testSTLContainer();
+  testCreate();
 
   return EXIT_SUCCESS;
 }