]> git.mxchange.org Git - simgear.git/blobdiff - simgear/props/props_test.cxx
Revert to c++98
[simgear.git] / simgear / props / props_test.cxx
index ccbf1afe951903fa2f7b9620cf07a6a95e0e4053..debf79d78debb7a09ce1797ee32a726d5a058370 100644 (file)
@@ -3,18 +3,23 @@
 // Test harness.
 ////////////////////////////////////////////////////////////////////////
 
+#ifdef HAVE_CONFIG_H
+#  include <simgear_config.h>
+#endif
+
 #include <simgear/compiler.h>
 
 #include <iostream>
+
 #include "props.hxx"
 #include "props_io.hxx"
 
-SG_USING_STD(cout);
-SG_USING_STD(cerr);
-SG_USING_STD(endl);
+using std::cout;
+using std::cerr;
+using std::endl;
+
 
 
-\f
 ////////////////////////////////////////////////////////////////////////
 // Sample object.
 ////////////////////////////////////////////////////////////////////////
@@ -33,7 +38,7 @@ private:
 };
 
 
-\f
+
 ////////////////////////////////////////////////////////////////////////
 // Sample function.
 ////////////////////////////////////////////////////////////////////////
@@ -43,7 +48,7 @@ static int get100 () { return 100; }
 static double getNum (int index) { return 1.0 / index; }
 
 
-\f
+
 ////////////////////////////////////////////////////////////////////////
 // Show a value.
 ////////////////////////////////////////////////////////////////////////
@@ -59,7 +64,7 @@ show_values (const SGPropertyNode * node)
 }
 
 
-\f
+
 ////////////////////////////////////////////////////////////////////////
 // Test individual values.
 ////////////////////////////////////////////////////////////////////////
@@ -265,7 +270,7 @@ test_value ()
 }
 
 
-\f
+
 ////////////////////////////////////////////////////////////////////////
 // Check property nodes.
 ////////////////////////////////////////////////////////////////////////
@@ -319,11 +324,66 @@ test_property_nodes ()
 
   cout << "Testing addition of a totally empty node" << endl;
   if (root.getNode("/a/b/c", true) == 0)
-    cerr << "** failed to create /a/b/c" << endl;
+    cerr << "** FAILED to create /a/b/c" << endl;
   dump_node(&root);
   cout << endl;
 }
 
+void test_addChild()
+{
+  SGPropertyNode root;
+
+  cout << "Testing the addChild function " << endl;
+  cout << "Created root node " << root.getPath() << endl;
+
+  SGPropertyNode *test = root.getChild("test", 0, true);
+  SGPropertyNode *n = test->getNode("foo", true);
+
+  cout << "Testing appending initial child node" << endl;
+  test = root.addChild("child", 0, true);
+  if (test == 0)
+    cerr << "** FAILED to append initial child node" << endl;
+  if (root.getNode("child", 0, false) != test)
+      cerr << "** FAILED to create initial child node at expected index #0" << endl;
+
+  n->getChild("child", 1, true)->setIntValue(1);
+  n->getChild("child", 2, true)->setIntValue(2);
+  n->getChild("child", 4, true)->setIntValue(4);
+  dump_node(&root);
+
+  SGPropertyNode *ch = n->addChild("child");
+  ch->setIntValue(5);
+  if (n->getChild("child", 5, false) != ch)
+      cerr << "** FAILED to create child node at expected index #5" << endl;
+  cerr << endl << "ADDED: " << ch->getPath() << endl << endl;
+
+  cout << "Testing appending child node at first empty index (Skipping 0)" << endl;
+  ch = n->addChild("child", 1, false);
+  ch->setIntValue(3);
+  if (n->getChild("child", 3, false) != ch)
+      cerr << "** FAILED to create child node at expected index #3" << endl;
+
+  cout << "Testing appending child node at first empty index" << endl;
+  ch = n->addChild("child", 0, false);
+  ch->setIntValue(0);
+  if (n->getChild("child", 0, false) != ch)
+      cerr << "** FAILED to create child node at expected index #0" << endl;
+
+  cout << "Testing appending child node" << endl;
+  ch = n->addChild("first", 0, false);
+  if (ch == 0)
+      cerr << "** Failed to add child node" << endl;
+  else
+      ch->setStringValue("append first");
+  if (n->getChild("first", 0, false) != ch)
+      cerr << "** FAILED to append child node with expected index #0" << endl;
+  cerr << "ADDED: " << ch->getPath() << endl;
+  if (root.getNode("test/foo/first", false) != ch)
+      cerr << "** FAILED to append child node at expected path 'test/foo/first'" << endl;
+
+  dump_node(&root);
+}
+
 
 int main (int ac, char ** av)
 {
@@ -342,5 +402,7 @@ int main (int ac, char ** av)
     }
   }
 
+  test_addChild();
+
   return 0;
 }