Commit d51721cf authored by Sebastian Sauer's avatar Sebastian Sauer

Added unittests for z-index and run-through sorting.

parent ee4efeca
......@@ -49,8 +49,7 @@ public:
class MockContainer : public KoShapeContainer
{
public:
MockContainer(KoShapeContainerModel *model) : KoShapeContainer(model), paintedCount(0) {}
MockContainer() : paintedCount(0) {}
MockContainer(KoShapeContainerModel *model = 0) : KoShapeContainer(model), paintedCount(0) {}
void paintComponent(QPainter &painter, const KoViewConverter &converter) {
Q_UNUSED(painter);
Q_UNUSED(converter);
......
......@@ -33,6 +33,130 @@ TestShapeReorderCommand::~TestShapeReorderCommand()
{
}
void TestShapeReorderCommand::testZIndexSorting()
{
MockShape shape1;
MockShape shape2;
MockShape shape3;
MockShape shape4;
MockShape shape5;
shape1.setZIndex(-2);
shape2.setZIndex(5);
shape3.setZIndex(0);
shape4.setZIndex(9999);
shape5.setZIndex(-9999);
QList<KoShape*> shapes;
shapes.append(&shape1);
shapes.append(&shape2);
shapes.append(&shape3);
shapes.append(&shape4);
shapes.append(&shape5);
qSort(shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
QCOMPARE(shapes.indexOf(&shape1), 1);
QCOMPARE(shapes.indexOf(&shape2), 3);
QCOMPARE(shapes.indexOf(&shape3), 2);
QCOMPARE(shapes.indexOf(&shape4), 4);
QCOMPARE(shapes.indexOf(&shape5), 0);
}
void TestShapeReorderCommand::testRunThroughSorting()
{
MockShape shape1;
MockShape shape2;
MockShape shape3;
MockShape shape4;
MockShape shape5;
shape1.setZIndex(-2);
shape2.setZIndex(5);
shape3.setZIndex(0);
shape4.setZIndex(9999);
shape5.setZIndex(-9999);
shape2.setTextRunAroundSide(KoShape::RunThrough, KoShape::Background);
shape3.setTextRunAroundSide(KoShape::RunThrough, KoShape::Foreground);
QList<KoShape*> shapes;
shapes.append(&shape1);
shapes.append(&shape2);
shapes.append(&shape3);
shapes.append(&shape4);
shapes.append(&shape5);
qSort(shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
QCOMPARE(shapes.indexOf(&shape1), 2);
QCOMPARE(shapes.indexOf(&shape2), 0);
QCOMPARE(shapes.indexOf(&shape3), 4);
QCOMPARE(shapes.indexOf(&shape4), 3);
QCOMPARE(shapes.indexOf(&shape5), 1);
}
void TestShapeReorderCommand::testParentChildSorting()
{
MockShape shape1;
MockShape shape2;
MockShape shape3;
MockShape shape4;
MockShape shape5;
MockShape shape6;
MockShape shape7;
MockContainer container1;
MockContainer container2;
MockContainer container3;
shape1.setZIndex(-2);
shape2.setZIndex(5);
shape3.setZIndex(0);
shape4.setZIndex(9999);
shape5.setZIndex(-9999);
shape6.setZIndex(3);
shape7.setZIndex(7);
container1.setZIndex(-55);
container2.setZIndex(57);
shape2.setTextRunAroundSide(KoShape::RunThrough, KoShape::Background);
shape3.setTextRunAroundSide(KoShape::RunThrough, KoShape::Foreground);
container1.setTextRunAroundSide(KoShape::RunThrough, KoShape::Foreground);
container1.addShape(&shape1);
container1.addShape(&shape2);
container2.addShape(&shape4);
container2.addShape(&shape5);
container1.addShape(&container2);
container1.addShape(&container3);
QList<KoShape*> shapes;
shapes.append(&shape1);
shapes.append(&shape2);
shapes.append(&shape3);
shapes.append(&shape4);
shapes.append(&shape5);
shapes.append(&shape6);
shapes.append(&shape7);
shapes.append(&container1);
shapes.append(&container2);
shapes.append(&container3);
qSort(shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
QCOMPARE(shapes.indexOf(&shape1), 3);
QCOMPARE(shapes.indexOf(&shape2), 2);
QCOMPARE(shapes.indexOf(&shape3), 9);
QCOMPARE(shapes.indexOf(&shape4), 7);
QCOMPARE(shapes.indexOf(&shape5), 6);
QCOMPARE(shapes.indexOf(&shape6), 0);
QCOMPARE(shapes.indexOf(&shape7), 1);
QCOMPARE(shapes.indexOf(&container1), 8);
QCOMPARE(shapes.indexOf(&container2), 5);
QCOMPARE(shapes.indexOf(&container3), 4);
}
void TestShapeReorderCommand::testBringToFront()
{
MockShape shape1, shape2, shape3;
......
......@@ -29,6 +29,10 @@ public:
TestShapeReorderCommand();
~TestShapeReorderCommand();
private slots:
void testZIndexSorting();
void testRunThroughSorting();
void testParentChildSorting();
void testBringToFront();
void testSendToBack();
void testMoveUp();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment