Commit ed336054 authored by Thomas Zander's avatar Thomas Zander
Browse files

Add a test (which fails) for KoShapesManager::shapeAt().

Anyone up to fixing the tested code to make this test pass?

svn path=/trunk/koffice/; revision=603288
parent 8b40dcc1
......@@ -29,4 +29,16 @@ add_test(flake-TestSelection ${EXECUTABLE_OUTPUT_PATH}/TestSelection)
########### next target ###############
set(TestSelection_test_SRCS TestShapeAt.cpp )
kde4_automoc(${TestSelection_test_SRCS})
kde4_add_executable(TestShapeAt RUN_UNINSTALLED ${TestSelection_test_SRCS})
target_link_libraries(TestShapeAt ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
add_test(flake-TestShapeAt ${EXECUTABLE_OUTPUT_PATH}/TestShapeAt)
########### next target ###############
endif(KDE4_BUILD_TESTS)
#include <KoShapeGroup.h>
#include <KoCanvasBase.h>
class MockShape : public KoShape {
void paint(QPainter &painter, const KoViewConverter &converter) {
......@@ -20,3 +21,22 @@ class MockGroup : public KoShapeGroup {
Q_UNUSED(converter);
}
};
class KCommand;
class KoToolProxy;
class MockCanvas : public KoCanvasBase {
public:
MockCanvas() {}
~MockCanvas() {}
void gridSize(double *, double *) const {}
bool snapToGrid() const { return false; }
void addCommand(KCommand *, bool = true) { }
KoShapeManager *shapeManager() const { return 0; }
void updateCanvas(const QRectF& ) {};
KoToolProxy * toolProxy() { return 0; }
KoViewConverter *viewConverter() { return 0; }
QWidget* canvasWidget() { return 0; }
KoUnit::Unit unit() { return KoUnit::U_MM; }
};
#include "TestShapeAt.h"
#include "MockShapes.h"
#include <kdebug.h>
#include <KoShapeManager.h>
#include <KoSelection.h>
void TestShapeAt::test() {
MockCanvas canvas;
KoShapeManager manager(&canvas);
MockShape shape1;
shape1.setPosition(QPointF(100, 100));
shape1.resize(QSizeF(50, 50));
shape1.setZIndex(0);
manager.add(&shape1);
QVERIFY(manager.shapeAt(QPointF(90, 90)) == 0);
QVERIFY(manager.shapeAt(QPointF(110, 140)) != 0);
QVERIFY(manager.shapeAt(QPointF(100, 100)) != 0);
QVERIFY(manager.shapeAt(QPointF(100, 100), KoFlake::Selected) == 0);
QVERIFY(manager.shapeAt(QPointF(100, 100), KoFlake::Unselected) != 0 );
QVERIFY(manager.shapeAt(QPointF(100, 100), KoFlake::NextUnselected) != 0 );
//QCOMPARE
//QVERIFY
MockShape shape2;
shape2.setPosition(QPointF(80, 80));
shape2.resize(QSizeF(50, 50));
shape2.setZIndex(1);
manager.add(&shape2);
QVERIFY(manager.shapeAt(QPointF(200, 200)) == 0);
QCOMPARE(manager.shapeAt(QPointF(90, 90)), &shape2);
QCOMPARE(manager.shapeAt(QPointF(105, 105)), &shape2); // the one on top
KoShape *dummy = 0;
QCOMPARE(manager.shapeAt(QPointF(105, 105), KoFlake::Selected), dummy);
QCOMPARE(manager.shapeAt(QPointF(105, 105), KoFlake::Unselected), &shape2); // the one on top
QCOMPARE(manager.shapeAt(QPointF(105, 105), KoFlake::NextUnselected), &shape2);
manager.selection()->select(&shape2);
QVERIFY(manager.shapeAt(QPointF(200, 200)) == 0);
QCOMPARE(manager.shapeAt(QPointF(90, 90)), &shape2);
QCOMPARE(manager.shapeAt(QPointF(105, 105)), &shape2); // the one on top
QCOMPARE(manager.shapeAt(QPointF(105, 105), KoFlake::Selected), &shape2);
QCOMPARE(manager.shapeAt(QPointF(105, 105), KoFlake::Unselected), &shape1);
QCOMPARE(manager.shapeAt(QPointF(105, 105), KoFlake::NextUnselected), &shape1);
MockShape shape3;
shape3.setPosition(QPointF(120, 80));
shape3.resize(QSizeF(50, 50));
shape3.setZIndex(2);
manager.add(&shape3);
QVERIFY(manager.shapeAt(QPointF(200, 200)) == 0);
QCOMPARE(manager.shapeAt(QPointF(90, 90)), &shape2);
QVERIFY(manager.shapeAt(QPointF(200, 200)) == 0);
QCOMPARE(manager.shapeAt(QPointF(90, 90)), &shape2);
QCOMPARE(manager.shapeAt(QPointF(105, 145)), &shape1);
QCOMPARE(manager.shapeAt(QPointF(165, 90)), &shape3);
QCOMPARE(manager.shapeAt(QPointF(125, 105)), &shape3); // the one on top
QCOMPARE(manager.shapeAt(QPointF(105, 105), KoFlake::Selected), &shape2);
QCOMPARE(manager.shapeAt(QPointF(105, 105), KoFlake::Unselected), &shape1);
QCOMPARE(manager.shapeAt(QPointF(105, 105), KoFlake::NextUnselected), &shape1);
QCOMPARE(manager.shapeAt(QPointF(125, 105), KoFlake::Selected), &shape2);
QCOMPARE(manager.shapeAt(QPointF(125, 105), KoFlake::Unselected), &shape3);
QCOMPARE(manager.shapeAt(QPointF(125, 105), KoFlake::NextUnselected), &shape1);
}
QTEST_MAIN(TestShapeAt)
#include "TestShapeAt.moc"
#ifndef TestShapeAt_H
#define TestShapeAt_H
#include <QtTest/QtTest>
class TestShapeAt : public QObject
{
Q_OBJECT
private slots:
// tests
void test();
};
#endif
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