// Test harness.
////////////////////////////////////////////////////////////////////////
+#ifdef HAVE_CONFIG_H
+# include <simgear_config.h>
+#endif
+
#include <simgear/compiler.h>
-#include STL_IOSTREAM
+#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.
////////////////////////////////////////////////////////////////////////
};
-\f
+
////////////////////////////////////////////////////////////////////////
// Sample function.
////////////////////////////////////////////////////////////////////////
static double getNum (int index) { return 1.0 / index; }
-\f
+
////////////////////////////////////////////////////////////////////////
// Show a value.
////////////////////////////////////////////////////////////////////////
}
-\f
+
////////////////////////////////////////////////////////////////////////
// Test individual values.
////////////////////////////////////////////////////////////////////////
}
-\f
+
////////////////////////////////////////////////////////////////////////
// Check property nodes.
////////////////////////////////////////////////////////////////////////
cout << endl;
cout << "Looking for all /hack[0]/bar children" << endl;
- vector<SGPropertyNode_ptr> bar = child->getChildren("bar");
+ std::vector<SGPropertyNode_ptr> bar = child->getChildren("bar");
cout << "There are " << bar.size() << " matches" << endl;
for (int i = 0; i < (int)bar.size(); i++)
cout << bar[i]->getName() << '[' << bar[i]->getIndex() << ']' << endl;
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)
{
readProperties(av[i], &root);
writeProperties(cout, &root, true);
cout << endl;
- } catch (string &message) {
+ } catch (std::string &message) {
cout << "Aborted with " << message << endl;
}
}
+ test_addChild();
+
return 0;
}