paysages3d/src/tests/Layers_Test.cpp

81 lines
1.9 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
BaseDefinition* _construc1(Layers*)
{
return new BaseDefinition(NULL);
}
BaseDefinition* _construc2(Layers* parent)
{
BaseDefinition* result = new BaseDefinition(parent);
result->setName("test");
return result;
}
2013-11-10 20:14:10 +00:00
TEST(Layers, Constructor)
2013-10-31 21:53:22 +00:00
{
Layers layers1(NULL, _construc1);
2013-11-10 20:14:10 +00:00
EXPECT_EQ(0, layers1.count());
2013-10-31 21:53:22 +00:00
}
2013-11-10 20:14:10 +00:00
TEST(Layers, NullLayer)
2013-10-31 21:53:22 +00:00
{
Layers layers1(NULL, _construc1);
for (int i = -2; i < 5; i++)
{
BaseDefinition* layer = layers1.getLayer(0);
2013-11-10 20:14:10 +00:00
EXPECT_NE((BaseDefinition*)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
2013-11-10 20:14:10 +00:00
EXPECT_EQ(QString(), 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
}
2013-11-10 20:14:10 +00:00
TEST(Layers, copy)
2013-10-31 21:53:22 +00:00
{
Layers layers1(NULL, _construc2);
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, _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(QString("test"), layers1.getLayer(0)->getName());
EXPECT_EQ(&layers1, layers1.getLayer(0)->getParent());
EXPECT_EQ(QString("test"), layers2.getLayer(0)->getName());
EXPECT_EQ(&layers2, layers2.getLayer(0)->getParent());
EXPECT_NE(layers1.getLayer(0), layers2.getLayer(0));
2013-10-31 21:53:22 +00:00
}
2013-11-10 20:14:10 +00:00
TEST(Layers, maxLayerCount)
2013-10-31 21:53:22 +00:00
{
Layers layers1(NULL, _construc1);
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
}