Fix property find_last_child/addChild.

Initial "addChild" should have index #0 (not #1).
Also extend test cases.
(Test case shows addChild(append=false) isn't working as expected!?)
This commit is contained in:
ThorstenB
2012-11-07 00:53:32 +01:00
parent 81bee2bbc6
commit 3fe513f9e0
2 changed files with 33 additions and 6 deletions

View File

@@ -186,7 +186,7 @@ find_child (Itr begin, Itr end, int index, const PropertyList& nodes)
for (int i = 0; i < nNodes; i++) {
SGPropertyNode * node = nodes[i];
// searching for a mathing index is a lot less time consuming than
// searching for a matching index is a lot less time consuming than
// comparing two strings so do that first.
if (node->getIndex() == index && boost::equals(node->getName(), name))
return i;
@@ -201,7 +201,7 @@ static int
find_last_child (const char * name, const PropertyList& nodes)
{
int nNodes = nodes.size();
int index = 0;
int index = -1;
for (int i = 0; i < nNodes; i++) {
SGPropertyNode * node = nodes[i];
@@ -230,7 +230,7 @@ first_unused_index( const char * name,
return index;
}
SG_LOG(SG_GENERAL, SG_ALERT, "Too much nodes: " << name);
SG_LOG(SG_GENERAL, SG_ALERT, "Too many nodes: " << name);
return -1;
}

View File

@@ -324,7 +324,7 @@ 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;
}
@@ -338,14 +338,41 @@ void test_addChild()
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(2);
n->getChild("child", 4, true)->setIntValue(4);
dump_node(&root);
SGPropertyNode *ch = n->addChild("child");
ch->setIntValue(3);
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" << endl;
ch = n->addChild("child", 0, 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" << endl;
ch = n->addChild("first", 0, false);
if (ch == 0)
cerr << "** Failed to add child node" << endl;
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.getChild("test/foo/first", false) != ch)
cerr << "** FAILED to append child node at expected path 'test/foo/first'" << endl;
dump_node(&root);
}