2015-08-12 20:21:10 +00:00
|
|
|
#include "BaseTestCase.h"
|
|
|
|
|
|
|
|
#include "DefinitionNode.h"
|
2015-08-13 21:46:50 +00:00
|
|
|
#include "FloatNode.h"
|
|
|
|
#include "PackStream.h"
|
2015-08-12 20:21:10 +00:00
|
|
|
|
|
|
|
TEST(DefinitionNode, toString)
|
|
|
|
{
|
|
|
|
DefinitionNode root(NULL, "root");
|
|
|
|
DefinitionNode branch(&root, "branch");
|
|
|
|
DefinitionNode leaf1(&branch, "leaf1");
|
|
|
|
DefinitionNode leaf2(&branch, "leaf2");
|
|
|
|
|
|
|
|
EXPECT_EQ("root\n branch\n leaf1\n leaf2", root.toString());
|
|
|
|
EXPECT_EQ("branch\n leaf1\n leaf2", branch.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DefinitionNode, attachDetach)
|
|
|
|
{
|
|
|
|
DefinitionNode* root = new DefinitionNode(NULL, "root");
|
|
|
|
DefinitionNode* child1 = new DefinitionNode(root, "child1");
|
|
|
|
DefinitionNode* child2 = new DefinitionNode(root, "child2");
|
|
|
|
|
|
|
|
EXPECT_EQ(root, child1->getParent());
|
|
|
|
EXPECT_EQ(root, child2->getParent());
|
|
|
|
EXPECT_EQ(2, root->getChildrenCount());
|
|
|
|
|
|
|
|
delete child1;
|
|
|
|
|
|
|
|
EXPECT_EQ(1, root->getChildrenCount());
|
|
|
|
|
|
|
|
delete child2;
|
|
|
|
|
|
|
|
EXPECT_EQ(0, root->getChildrenCount());
|
|
|
|
|
|
|
|
delete root;
|
|
|
|
}
|
2015-08-13 21:46:50 +00:00
|
|
|
|
|
|
|
TEST(DefinitionNode, saveLoad)
|
|
|
|
{
|
|
|
|
PackStream *stream;
|
2015-08-13 22:22:20 +00:00
|
|
|
int check_in = 42, check_out = 0;
|
2015-08-13 21:46:50 +00:00
|
|
|
|
|
|
|
DefinitionNode* before = new DefinitionNode(NULL, "root");
|
|
|
|
DefinitionNode* before1 = new DefinitionNode(before, "before1");
|
2015-08-13 21:59:27 +00:00
|
|
|
new FloatNode(before1, "before11", 2.1);
|
|
|
|
new FloatNode(before1, "before12", -4.3);
|
2015-08-13 21:46:50 +00:00
|
|
|
DefinitionNode* before2 = new DefinitionNode(before, "before2");
|
2015-08-13 21:59:27 +00:00
|
|
|
new DefinitionNode(before2, "before21");
|
|
|
|
new FloatNode(before2, "before22");
|
|
|
|
new FloatNode(before, "before3", 6.7);
|
2015-08-13 21:46:50 +00:00
|
|
|
|
|
|
|
stream = new PackStream();
|
|
|
|
stream->bindToFile("/tmp/test_paysages_pack", true);
|
|
|
|
before->save(stream);
|
2015-08-13 22:22:20 +00:00
|
|
|
stream->write(&check_in);
|
2015-08-13 21:46:50 +00:00
|
|
|
delete stream;
|
|
|
|
|
|
|
|
// Same definition tree, but with missing nodes, and added ones
|
|
|
|
DefinitionNode* after = new DefinitionNode(NULL, "root");
|
|
|
|
DefinitionNode* after1 = new DefinitionNode(after, "before1");
|
|
|
|
FloatNode* after12 = new FloatNode(after1, "before12");
|
|
|
|
FloatNode* after13 = new FloatNode(after1, "before13");
|
|
|
|
FloatNode* after3 = new FloatNode(after, "before3");
|
|
|
|
FloatNode* after4 = new FloatNode(after, "before4");
|
|
|
|
|
|
|
|
stream = new PackStream();
|
|
|
|
stream->bindToFile("/tmp/test_paysages_pack");
|
|
|
|
after->load(stream);
|
2015-08-13 22:22:20 +00:00
|
|
|
stream->read(&check_out);
|
2015-08-13 21:46:50 +00:00
|
|
|
delete stream;
|
|
|
|
|
|
|
|
EXPECT_DOUBLE_EQ(-4.3, after12->getValue());
|
|
|
|
EXPECT_DOUBLE_EQ(0.0, after13->getValue());
|
|
|
|
EXPECT_DOUBLE_EQ(6.7, after3->getValue());
|
|
|
|
EXPECT_DOUBLE_EQ(0.0, after4->getValue());
|
2015-08-13 22:22:20 +00:00
|
|
|
EXPECT_EQ(42, check_out);
|
2015-08-13 21:59:27 +00:00
|
|
|
|
|
|
|
delete before;
|
|
|
|
delete after;
|
2015-08-13 21:46:50 +00:00
|
|
|
}
|