Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 0f7d8913 authored by Thomas Zander's avatar Thomas Zander

Add a test to test the shape-container (well, the model mostly for now)

svn path=/trunk/koffice/; revision=690194
parent 2205ad22
......@@ -3,108 +3,80 @@ include_directories( ${FLAKE_INCLUDES} )
########### next target ###############
set(TestPosition_test_SRCS TestPosition.cpp )
kde4_add_unit_test(TestPosition TESTNAME libs-flake-TestPosition ${TestPosition_test_SRCS})
target_link_libraries(TestPosition ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
########### next target ###############
set(TestSelection_test_SRCS TestSelection.cpp )
kde4_add_unit_test(TestSelection TESTNAME libs-flake-TestSelection ${TestSelection_test_SRCS})
target_link_libraries(TestSelection ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
########### next target ###############
set(TestPathShape_test_SRCS TestPathShape.cpp )
kde4_add_unit_test(TestPathShape TESTNAME libs-flake-TestPathShape ${TestPathShape_test_SRCS})
target_link_libraries(TestPathShape ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
########### next target ###############
set(TestPathTool_test_SRCS TestPathTool.cpp )
kde4_add_unit_test(TestPathTool TESTNAME libs-flake-TestPathTool ${TestPathTool_test_SRCS})
target_link_libraries(TestPathTool ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
########### next target ###############
set(TestControlPointMoveCommand_test_SRCS TestControlPointMoveCommand.cpp )
kde4_add_unit_test(TestControlPointMoveCommand TESTNAME libs-flake-TestControlPointMoveCommand ${TestControlPointMoveCommand_test_SRCS})
target_link_libraries(TestControlPointMoveCommand ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
########### next target ###############
set(TestPointTypeCommand_test_SRCS TestPointTypeCommand.cpp )
kde4_add_unit_test(TestPointTypeCommand TESTNAME libs-flake-TestPointTypeCommand ${TestPointTypeCommand_test_SRCS})
target_link_libraries(TestPointTypeCommand ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
########### next target ###############
set(TestPointRemoveCommand_test_SRCS TestPointRemoveCommand.cpp )
kde4_add_unit_test(TestPointRemoveCommand TESTNAME libs-flake-TestPointRemoveCommand ${TestPointRemoveCommand_test_SRCS})
target_link_libraries(TestPointRemoveCommand ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
########### next target ###############
set(TestRemoveSubpathCommand_test_SRCS TestRemoveSubpathCommand.cpp )
kde4_add_unit_test(TestRemoveSubpathCommand TESTNAME libs-flake-TestRemoveSubpathCommand ${TestRemoveSubpathCommand_test_SRCS})
target_link_libraries(TestRemoveSubpathCommand ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
########### next target ###############
set(TestShapeAt_test_SRCS TestShapeAt.cpp )
kde4_add_unit_test(TestShapeAt TESTNAME libs-flake-TestShapeAt ${TestShapeAt_test_SRCS})
target_link_libraries(TestShapeAt ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
########### next target ###############
set(TestShapePaint_test_SRCS TestShapePainting.cpp )
kde4_add_unit_test(TestShapePainting TESTNAME libs-flake-TestShapePainting ${TestShapePaint_test_SRCS})
target_link_libraries(TestShapePainting ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
########### next target ###############
set(TestKoShapeFactory_test_SRCS TestKoShapeFactory.cpp )
kde4_add_unit_test(TestKoShapeFactory TESTNAME libs-flake-TestKoShapeFactory ${TestKoShapeFactory_test_SRCS})
target_link_libraries(TestKoShapeFactory ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
########### next target ###############
set(TestKoShapeRegistry_test_SRCS TestKoShapeRegistry.cpp )
kde4_add_unit_test(TestKoShapeRegistry TESTNAME libs-flake-TestKoShapeRegistry ${TestKoShapeRegistry_test_SRCS})
target_link_libraries(TestKoShapeRegistry ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
########### end ###############
kde4_add_unit_test(TestKoShapeRegistry TESTNAME libs-flake-TestKoShapeRegistry ${TestKoShapeRegistry_test_SRCS})
set(TestShapeContainer_test_SRCS TestShapeContainer.cpp )
kde4_add_unit_test(TestShapeContainer TESTNAME libs-flake-TestShapeContainer ${TestShapeContainer_test_SRCS})
target_link_libraries(TestShapeContainer ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
target_link_libraries(TestKoShapeRegistry ${KDE4_KDECORE_LIBS} flake ${QT_QTTEST_LIBRARY})
########### end ###############
########### next target ###############
#ifndef MOCKSHAPES_H
#define MOCKSHAPES_H
#include <KoShapeGroup.h>
#include <KoCanvasBase.h>
#include <KoShapeControllerBase.h>
#include <KoShapeContainerModel.h>
#include <QPainter>
#include "kdebug.h"
#ifndef MOCKSHAPES_H
#define MOCKSHAPES_H
class MockShape : public KoShape {
public:
......@@ -24,6 +26,7 @@ public:
class MockContainer : public KoShapeContainer {
public:
MockContainer(KoShapeContainerModel *model) : KoShapeContainer(model), paintedCount(0) {}
MockContainer() : paintedCount(0) {}
void paintComponent(QPainter &painter, const KoViewConverter &converter) {
Q_UNUSED(painter);
......@@ -98,4 +101,52 @@ private:
QSet<KoShape * > m_shapes;
};
class MockContainerModel : public KoShapeContainerModel {
public:
MockContainerModel()
{
resetCounts();
}
/// reimplemented
void add(KoShape *child) {
m_children.append(child); // note that we explicitly do not check for duplicates here!
}
/// reimplemented
void remove(KoShape *child) {
m_children.removeAll(child);
}
/// reimplemented
void setClipping(const KoShape *, bool ) { } // ignored
/// reimplemented
bool childClipped(const KoShape *) const { return false; }// ignored
/// reimplemented
bool isChildLocked(const KoShape *child) const { return child->isLocked(); }
/// reimplemented
int count() const { return m_children.count(); }
/// reimplemented
QList<KoShape*> iterator() const { return m_children; }
/// reimplemented
void containerChanged(KoShapeContainer *) { m_containerChangedCalled++; }
/// reimplemented
void proposeMove(KoShape *, QPointF &) { m_proposeMoveCalled++; }
/// reimplemented
void childChanged(KoShape *, KoShape::ChangeType ) { m_childChangedCalled++; }
int containerChangedCalled() const { return m_containerChangedCalled; }
int childChangedCalled() const { return m_childChangedCalled; }
int proposeMoveCalled() const { return m_proposeMoveCalled; }
void resetCounts() {
m_containerChangedCalled = 0;
m_childChangedCalled = 0;
m_proposeMoveCalled = 0;
}
private:
QList<KoShape*> m_children;
int m_containerChangedCalled, m_childChangedCalled, m_proposeMoveCalled;
};
#endif
#include "TestShapeContainer.h"
#include "MockShapes.h"
void TestShapeContainer::testModel() {
MockContainerModel *model = new MockContainerModel();
MockContainer container(model);
MockShape *shape1 = new MockShape();
container.addChild(shape1);
QCOMPARE(model->containerChangedCalled(), 0);
QCOMPARE(model->childChangedCalled(), 1);
QCOMPARE(model->proposeMoveCalled(), 0);
shape1->setPosition(QPointF(300, 300));
QCOMPARE(model->containerChangedCalled(), 0);
QCOMPARE(model->childChangedCalled(), 2);
QCOMPARE(model->proposeMoveCalled(), 0);
shape1->rotate(10);
QCOMPARE(model->containerChangedCalled(), 0);
QCOMPARE(model->childChangedCalled(), 3);
QCOMPARE(model->proposeMoveCalled(), 0);
shape1->moveBy(10., 40.);
QCOMPARE(model->containerChangedCalled(), 0);
QCOMPARE(model->childChangedCalled(), 4);
QCOMPARE(model->proposeMoveCalled(), 0);
shape1->setTransformation(QMatrix());
QCOMPARE(model->containerChangedCalled(), 0);
QEXPECT_FAIL("", "faulty", Continue); // TODO fix KoShape
QCOMPARE(model->childChangedCalled(), 5);
QCOMPARE(model->proposeMoveCalled(), 0);
model->resetCounts();
container.setPosition(QPointF(30, 30));
QCOMPARE(model->containerChangedCalled(), 1);
QCOMPARE(model->childChangedCalled(), 0);
QCOMPARE(model->proposeMoveCalled(), 0);
}
QTEST_MAIN(TestShapeContainer)
#include "TestShapeContainer.moc"
#ifndef TestShapeContainer_H
#define TestShapeContainer_H
#include <QtTest/QtTest>
class TestShapeContainer : public QObject
{
Q_OBJECT
private slots:
// tests
void testModel();
};
#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