00001 #include "TestPosition.h"
00002
00003 #include "MockShapes.h"
00004 #include <QPointF>
00005
00006
00007 void TestPosition::initTestCase() {
00008 shape1 = new MockShape();
00009 shape1->setPosition(QPointF(50, 50));
00010 shape1->resize(QSize(50, 50));
00011 shape2 = new MockShape();
00012 shape2->setPosition(QPointF(20, 20));
00013 shape2->resize(QSize(50, 50));
00014
00015 childShape1 = new MockShape();
00016 childShape1->setPosition(QPointF(20, 20));
00017 childShape1->resize(QSize(50, 50));
00018 container = new MockContainer();
00019 container->setPosition(QPointF(100, 100));
00020 container->addChild(childShape1);
00021 container->setClipping(childShape1, false);
00022
00023 childShape2 = new MockShape();
00024 childShape2->setPosition(QPointF(25, 25));
00025 childShape2->resize(QSizeF(10, 15));
00026 container2 = new MockContainer();
00027 container2->setPosition(QPointF(100, 200));
00028 container2->resize(QSizeF(100, 100));
00029 container2->rotate(90);
00030 container2->addChild(childShape2);
00031 }
00032
00033 void TestPosition::cleanupTestCase() {
00034 delete shape1;
00035 delete shape2;
00036 delete childShape1;
00037 delete childShape2;
00038 delete container;
00039 delete container2;
00040 }
00041
00042 void TestPosition::testBasePosition() {
00043
00044 QCOMPARE(shape1->position(), QPointF(50,50) );
00045 QCOMPARE(shape2->position(), QPointF(20,20) );
00046 QCOMPARE(childShape1->position(), QPointF(20,20) );
00047 QCOMPARE(container->position(), QPointF(100,100) );
00048 }
00049
00050 void TestPosition::testAbsolutePosition() {
00051 QCOMPARE(shape1->absolutePosition(), QPointF(75,75) );
00052 QCOMPARE(shape2->absolutePosition(), QPointF(45,45) );
00053
00054
00055 QCOMPARE(childShape1->absolutePosition(), QPointF(100 + 20 + 25, 100 + 20 + 25) );
00056
00057
00058 container2->setClipping(childShape2, false);
00059 QCOMPARE(container2->absolutePosition(), QPointF(150, 250) );
00060 QCOMPARE(childShape2->absolutePosition(), QPointF(130, 232.5) );
00061 container2->setClipping(childShape2, true);
00062 QCOMPARE(childShape2->absolutePosition(), QPointF(167.5, 230) );
00063 }
00064
00065 void TestPosition::testSetAbsolutePosition() {
00066 shape1->rotate(0);
00067 shape1->setPosition(QPointF(10, 10));
00068 QCOMPARE(shape1->absolutePosition(), QPointF(10 + 25, 10 + 25) );
00069 shape1->setAbsolutePosition(QPointF(10, 10));
00070 QCOMPARE(shape1->absolutePosition(), QPointF(10, 10) );
00071 shape1->rotate(45);
00072 QCOMPARE(shape1->absolutePosition(), QPointF(10, 10) );
00073
00074 childShape1->setAbsolutePosition(QPointF(0, 0));
00075 QCOMPARE(childShape1->position(), QPointF(-125, -125) );
00076 QCOMPARE(childShape1->absolutePosition(), QPointF(0, 0) );
00077
00078 QCOMPARE(container2->position(), QPointF(100, 200) );
00079 container2->setClipping(childShape2, false);
00080 childShape2->setAbsolutePosition(QPointF(0, 0));
00081 QCOMPARE(childShape2->position(), QPointF(-100 - 5, -200 - 7.5) );
00082 QCOMPARE(childShape2->absolutePosition(), QPointF(0, 0) );
00083
00084 container2->setClipping(childShape2, true);
00085 childShape2->setAbsolutePosition(QPointF(0, 0));
00086 QCOMPARE(childShape2->absolutePosition(), QPointF(0, 0) );
00087 QCOMPARE(childShape2->position(), QPointF(-200 - 5, 200 - 7.5) );
00088 }
00089
00090 QTEST_MAIN(TestPosition)
00091 #include "TestPosition.moc"