From: James Turner Date: Sat, 20 Nov 2010 12:25:11 +0000 (-0800) Subject: PropertyObject ::create tests. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=203d1c2b45a3b45319c38c5302dfcdee6fd42ee4;p=simgear.git PropertyObject ::create tests. --- diff --git a/simgear/props/propertyObject.hxx b/simgear/props/propertyObject.hxx index 33921c7a..5cc1588b 100644 --- a/simgear/props/propertyObject.hxx +++ b/simgear/props/propertyObject.hxx @@ -143,7 +143,34 @@ public: } +// copy-constructor + PropertyObject(const PropertyObject& aOther) : + PropertyObjectBase(aOther) + { + } +// create form + static PropertyObject create(const char* aPath, const std::string& aValue) + { + PropertyObject p(aPath); + p = aValue; + return p; + } + + static PropertyObject create(SGPropertyNode* aNode, const std::string& aValue) + { + PropertyObject p(aNode); + p = aValue; + return p; + } + + static PropertyObject create(SGPropertyNode* aNode, const char* aChild, const std::string& aValue) + { + PropertyObject p(aNode, aChild); + p = aValue; + return p; + } + operator std::string () const { diff --git a/simgear/props/propertyObject_test.cxx b/simgear/props/propertyObject_test.cxx index 2b2ee1ec..b2c458ad 100644 --- a/simgear/props/propertyObject_test.cxx +++ b/simgear/props/propertyObject_test.cxx @@ -149,6 +149,27 @@ void testReadMissing() } } +void testCreate() +{ + PropertyObject a = PropertyObject::create("a/lemon", true); + assert(a == true); + assert(testRoot->getBoolValue("a/lemon") == true); + + + PropertyObject b(PropertyObject::create("a/pear", 3142)); + assert(b == 3142); + + PropertyObject c(PropertyObject::create("a/lime", "fofofo")); + assert(c == "fofofo"); + +// check overloads for string version + SGPropertyNode* n = testRoot->getNode("b", true); + PropertyObject d(PropertyObject::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; }