Commit ed93c90c authored by Jan Hambrecht's avatar Jan Hambrecht

add some unit tests which shows some deficiencies in the KoShapeReorderCommand


svn path=/trunk/koffice/; revision=1027327
parent 8dc1a524
/* This file is part of the KDE project
* Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net>
* Copyright (C) 2007,2009 Jan Hambrecht <jaham@gmx.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -181,5 +181,178 @@ void TestShapeReorderCommand::testMoveDown()
delete cmd;
}
void TestShapeReorderCommand::testMoveUpOverlapping()
{
MockShape shape1, shape2, shape3, shape4, shape5;
shape1.setSize(QSizeF(100, 100));
shape1.setZIndex(1);
shape2.setSize(QSizeF(100, 100));
shape2.setZIndex(2);
shape3.setSize(QSizeF(300, 300));
shape3.setZIndex(3);
shape4.setSize(QSizeF(100, 100));
shape4.setPosition(QPointF(200,200));
shape4.setZIndex(4);
shape5.setSize(QSizeF(100, 100));
shape5.setPosition(QPointF(200,200));
shape5.setZIndex(5);
QList<KoShape*> shapes;
shapes.append(&shape1);
shapes.append(&shape2);
shapes.append(&shape3);
shapes.append(&shape4);
shapes.append(&shape5);
MockCanvas canvas;
KoShapeManager manager(&canvas, shapes);
QVERIFY(shape1.zIndex() < shape2.zIndex());
QVERIFY(shape2.zIndex() < shape3.zIndex());
QVERIFY(shape3.zIndex() < shape4.zIndex());
QVERIFY(shape4.zIndex() < shape5.zIndex());
QList<KoShape*> selectedShapes;
selectedShapes.append(&shape1);
QUndoCommand * cmd = KoShapeReorderCommand::createCommand(selectedShapes, &manager, KoShapeReorderCommand::RaiseShape);
cmd->redo();
delete cmd;
QVERIFY(shape1.zIndex() > shape2.zIndex());
QVERIFY(shape2.zIndex() < shape3.zIndex());
QVERIFY(shape1.zIndex() < shape3.zIndex());
QVERIFY(shape3.zIndex() < shape4.zIndex());
QVERIFY(shape4.zIndex() < shape5.zIndex());
}
void TestShapeReorderCommand::testMoveDownOverlapping()
{
MockShape shape1, shape2, shape3, shape4, shape5;
shape1.setSize(QSizeF(100, 100));
shape1.setZIndex(1);
shape2.setSize(QSizeF(100, 100));
shape2.setZIndex(2);
shape3.setSize(QSizeF(300, 300));
shape3.setZIndex(3);
shape4.setSize(QSizeF(100, 100));
shape4.setPosition(QPointF(200,200));
shape4.setZIndex(4);
shape5.setSize(QSizeF(100, 100));
shape5.setPosition(QPointF(200,200));
shape5.setZIndex(5);
QList<KoShape*> shapes;
shapes.append(&shape1);
shapes.append(&shape2);
shapes.append(&shape3);
shapes.append(&shape4);
shapes.append(&shape5);
MockCanvas canvas;
KoShapeManager manager(&canvas, shapes);
QVERIFY(shape1.zIndex() < shape2.zIndex());
QVERIFY(shape2.zIndex() < shape3.zIndex());
QVERIFY(shape3.zIndex() < shape4.zIndex());
QVERIFY(shape4.zIndex() < shape5.zIndex());
QList<KoShape*> selectedShapes;
selectedShapes.append(&shape5);
QUndoCommand * cmd = KoShapeReorderCommand::createCommand(selectedShapes, &manager, KoShapeReorderCommand::LowerShape);
cmd->redo();
delete cmd;
QVERIFY(shape1.zIndex() < shape2.zIndex());
QVERIFY(shape2.zIndex() < shape3.zIndex());
QVERIFY(shape3.zIndex() < shape4.zIndex());
QVERIFY(shape4.zIndex() > shape5.zIndex());
QVERIFY(shape3.zIndex() > shape5.zIndex());
}
void TestShapeReorderCommand::testSendToBackChildren()
{
MockShape shape1, shape2, shape3;
shape1.setSize(QSizeF(100, 100));
shape1.setZIndex(1);
shape2.setSize(QSizeF(100, 100));
shape2.setZIndex(2);
shape3.setSize(QSizeF(100, 100));
shape3.setZIndex(3);
MockContainer container;
container.addChild(&shape1);
container.addChild(&shape2);
container.addChild(&shape3);
QList<KoShape*> shapes;
shapes.append(&shape1);
shapes.append(&shape2);
shapes.append(&shape3);
shapes.append(&container);
MockCanvas canvas;
KoShapeManager manager(&canvas, shapes);
qSort(shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
QCOMPARE(shapes.indexOf(&container), 0); // atm the parent is always lower than its children
QCOMPARE(shapes.indexOf(&shape1), 1);
QCOMPARE(shapes.indexOf(&shape2), 2);
QCOMPARE(shapes.indexOf(&shape3), 3);
QList<KoShape*> selectedShapes;
selectedShapes.append(&shape3);
QUndoCommand * cmd = KoShapeReorderCommand::createCommand(selectedShapes, &manager, KoShapeReorderCommand::SendToBack);
cmd->redo();
delete cmd;
qSort(shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
QCOMPARE(shapes.indexOf(&container), 0); // atm the parent is always lower than its children
QCOMPARE(shapes.indexOf(&shape3), 1);
QVERIFY(shape3.zIndex() < shape1.zIndex());
QCOMPARE(shapes.indexOf(&shape1), 2);
QVERIFY(shape1.zIndex() < shape2.zIndex());
QCOMPARE(shapes.indexOf(&shape2), 3);
selectedShapes.clear();
selectedShapes.append(&shape2);
cmd = KoShapeReorderCommand::createCommand(selectedShapes, &manager, KoShapeReorderCommand::SendToBack);
cmd->redo();
delete cmd;
qSort(shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
QCOMPARE(shapes.indexOf(&container), 0); // atm the parent is always lower than its children
QCOMPARE(shapes.indexOf(&shape2), 1);
QVERIFY(shape2.zIndex() < shape3.zIndex());
QCOMPARE(shapes.indexOf(&shape3), 2);
QVERIFY(shape3.zIndex() < shape1.zIndex());
QCOMPARE(shapes.indexOf(&shape1), 3);
selectedShapes.clear();
selectedShapes.append(&shape1);
cmd = KoShapeReorderCommand::createCommand(selectedShapes, &manager, KoShapeReorderCommand::SendToBack);
cmd->redo();
delete cmd;
qSort(shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
QCOMPARE(shapes.indexOf(&container), 0); // atm the parent is always lower than its children
QCOMPARE(shapes.indexOf(&shape1), 1);
QVERIFY(shape1.zIndex() < shape2.zIndex());
QCOMPARE(shapes.indexOf(&shape2), 2);
QVERIFY(shape2.zIndex() < shape3.zIndex());
QCOMPARE(shapes.indexOf(&shape3), 3);
}
QTEST_MAIN(TestShapeReorderCommand)
#include "TestShapeReorderCommand.moc"
......@@ -33,6 +33,9 @@ private slots:
void testSendToBack();
void testMoveUp();
void testMoveDown();
void testMoveUpOverlapping();
void testMoveDownOverlapping();
void testSendToBackChildren();
};
#endif // TESTSHAPEREORDERCOMMAND_H
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