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
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
DefinitionNode *_construc1(Layers *) {
|
2015-08-12 20:21:10 +00:00
|
|
|
return new DefinitionNode(NULL, "test");
|
2013-10-31 21:53:22 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
DefinitionNode *_construc2(Layers *parent) {
|
|
|
|
DefinitionNode *result = new DefinitionNode(parent, "test");
|
2013-10-31 21:53:22 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
TEST(Layers, Constructor) {
|
2015-08-12 15:02:27 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
TEST(Layers, NullLayer) {
|
2015-08-12 15:02:27 +00:00
|
|
|
Layers layers1(NULL, "test", _construc1);
|
2013-10-31 21:53:22 +00:00
|
|
|
|
2015-11-09 21:30:46 +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
|
|
|
|
2015-08-12 15:02:27 +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
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
TEST(Layers, copy) {
|
2015-08-12 15:02:27 +00:00
|
|
|
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
|
2015-08-12 15:02:27 +00:00
|
|
|
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());
|
2013-12-10 21:32:58 +00:00
|
|
|
EXPECT_EQ("test", layers1.getLayer(0)->getName());
|
2013-11-10 20:14:10 +00:00
|
|
|
EXPECT_EQ(&layers1, layers1.getLayer(0)->getParent());
|
2013-12-10 21:32:58 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
TEST(Layers, maxLayerCount) {
|
2015-08-12 15:02:27 +00:00
|
|
|
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
|
|
|
}
|
2015-08-13 21:46:50 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
TEST(Layers, saveLoad) {
|
2015-08-13 21:46:50 +00:00
|
|
|
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());
|
|
|
|
}
|