From 203d1c2b45a3b45319c38c5302dfcdee6fd42ee4 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 20 Nov 2010 04:25:11 -0800 Subject: [PATCH] PropertyObject ::create tests. --- simgear/props/propertyObject.hxx | 27 +++++++++++++++++++++++++++ simgear/props/propertyObject_test.cxx | 22 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) 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; } -- 2.39.5