paysages3d/src/tests/Layers_Test.cpp

100 lines
2.6 KiB
C++
Raw Normal View History

2013-11-10 20:14:10 +00:00
#include "BaseTestCase.h"
2013-10-31 21:53:22 +00:00
#include "Layers.h"
2013-11-10 16:03:07 +00:00
#include "PackStream.h"
2013-10-31 21:53:22 +00:00
DefinitionNode *_construc1(Layers *) {
return new DefinitionNode(NULL, "test");
2013-10-31 21:53:22 +00:00
}
DefinitionNode *_construc2(Layers *parent) {
DefinitionNode *result = new DefinitionNode(parent, "test");
2013-10-31 21:53:22 +00:00
return result;
}
TEST(Layers, Constructor) {
Layers layers1(NULL, "test", _construc1);
2013-11-10 20:14:10 +00:00
EXPECT_EQ(0, layers1.count());
2013-10-31 21:53:22 +00:00
}
TEST(Layers, NullLayer) {
Layers layers1(NULL, "test", _construc1);
2013-10-31 21:53:22 +00:00
for (int i = -2; i < 5; i++) {
DefinitionNode *layer = layers1.getLayer(0);
EXPECT_NE((DefinitionNode *)NULL, layer);
2013-10-31 21:53:22 +00:00
2013-11-10 20:14:10 +00:00
EXPECT_EQ(NULL, layer->getParent());
EXPECT_EQ(layer, layer->getRoot());
2013-10-31 21:53:22 +00:00
EXPECT_EQ("test", layer->getName());
2013-10-31 21:53:22 +00:00
}
2013-11-10 20:14:10 +00:00
EXPECT_EQ(0, layers1.count());
2013-10-31 21:53:22 +00:00
}
TEST(Layers, copy) {
Layers layers1(NULL, "test", _construc2);
2013-10-31 21:53:22 +00:00
layers1.addLayer();
2013-11-10 20:14:10 +00:00
EXPECT_EQ(1, layers1.count());
2013-10-31 21:53:22 +00:00
// Copy with the same constructor
Layers layers2(NULL, "test", _construc2);
2013-11-10 20:14:10 +00:00
EXPECT_EQ(0, layers2.count());
2013-10-31 21:53:22 +00:00
layers1.copy(&layers2);
2013-11-10 20:14:10 +00:00
EXPECT_EQ(1, layers2.count());
EXPECT_EQ("test", layers1.getLayer(0)->getName());
2013-11-10 20:14:10 +00:00
EXPECT_EQ(&layers1, layers1.getLayer(0)->getParent());
EXPECT_EQ("test", layers2.getLayer(0)->getName());
2013-11-10 20:14:10 +00:00
EXPECT_EQ(&layers2, layers2.getLayer(0)->getParent());
EXPECT_NE(layers1.getLayer(0), layers2.getLayer(0));
2013-10-31 21:53:22 +00:00
}
TEST(Layers, maxLayerCount) {
Layers layers1(NULL, "test", _construc1);
2013-10-31 21:53:22 +00:00
layers1.setMaxLayerCount(2);
2013-11-10 20:14:10 +00:00
EXPECT_EQ(0, layers1.count());
2013-10-31 21:53:22 +00:00
layers1.addLayer();
2013-11-10 20:14:10 +00:00
EXPECT_EQ(1, layers1.count());
2013-10-31 21:53:22 +00:00
layers1.addLayer();
2013-11-10 20:14:10 +00:00
EXPECT_EQ(2, layers1.count());
2013-10-31 21:53:22 +00:00
layers1.addLayer();
2013-11-10 20:14:10 +00:00
EXPECT_EQ(2, layers1.count());
2013-10-31 21:53:22 +00:00
layers1.addLayer();
2013-11-10 20:14:10 +00:00
EXPECT_EQ(2, layers1.count());
2013-10-31 21:53:22 +00:00
layers1.removeLayer(0);
2013-11-10 20:14:10 +00:00
EXPECT_EQ(1, layers1.count());
2013-10-31 21:53:22 +00:00
layers1.addLayer();
2013-11-10 20:14:10 +00:00
EXPECT_EQ(2, layers1.count());
2013-10-31 21:53:22 +00:00
layers1.addLayer();
2013-11-10 20:14:10 +00:00
EXPECT_EQ(2, layers1.count());
2013-10-31 21:53:22 +00:00
}
TEST(Layers, saveLoad) {
PackStream *stream;
Layers layers1(NULL, "test", _construc1);
layers1.addLayer();
layers1.addLayer();
ASSERT_EQ(2, layers1.count());
layers1.getLayer(0)->setName("first");
layers1.getLayer(1)->setName("second");
stream = new PackStream();
stream->bindToFile("/tmp/test_paysages_pack", true);
layers1.save(stream);
delete stream;
Layers layers2(NULL, "test", _construc1);
stream = new PackStream();
stream->bindToFile("/tmp/test_paysages_pack");
layers2.load(stream);
delete stream;
ASSERT_EQ(2, layers2.count());
EXPECT_EQ("first", layers2.getLayer(0)->getName());
EXPECT_EQ("second", layers2.getLayer(1)->getName());
}