[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/libs/flake/tests
From:       Jan Hambrecht <jaham () gmx ! net>
Date:       2009-09-23 20:48:21
Message-ID: 1253738901.653791.10672.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1027327 by jaham:

add some unit tests which shows some deficiencies in the KoShapeReorderCommand



 M  +174 -1    TestShapeReorderCommand.cpp  
 M  +3 -0      TestShapeReorderCommand.h  


--- trunk/koffice/libs/flake/tests/TestShapeReorderCommand.cpp #1027326:1027327
@@ -1,5 +1,5 @@
 /* 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 @@
     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"
--- trunk/koffice/libs/flake/tests/TestShapeReorderCommand.h #1027326:1027327
@@ -33,6 +33,9 @@
     void testSendToBack();
     void testMoveUp();
     void testMoveDown();
+    void testMoveUpOverlapping();
+    void testMoveDownOverlapping();
+    void testSendToBackChildren();
 };
 
 #endif // TESTSHAPEREORDERCOMMAND_H


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic