1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/*
* Copyright (C) 2018 Damir Porobic <damir.porobic@gmx.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "LineResizeHandlesTest.h"
void LineResizeHandlesTest::TestInitHandles_Should_PositionTwoHandles()
{
auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2));
QPointF p1(10, 10);
QPointF p2(20, 20);
AnnotationLine lineItem(p1, properties);
lineItem.addPoint(p2, false);
LineResizeHandles lineResizeHandles(&lineItem, 1.0);
QCOMPARE(lineResizeHandles.handles().count(), 2);
QCOMPARE(lineResizeHandles.handles()[0].anchor(), p1);
QCOMPARE(lineResizeHandles.handles()[1].anchor(), p2);
}
void LineResizeHandlesTest::TestIndexOfHandleAt_Should_ReturnIndexOfHandle_When_HandleIsAtProvidedPosition()
{
auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2));
QPointF p1(10, 10);
QPointF p2(20, 20);
AnnotationLine lineItem(p1, properties);
lineItem.addPoint(p2, false);
LineResizeHandles lineResizeHandles(&lineItem, 1.0);
auto resultP1 = lineResizeHandles.indexOfHandleAt(p1 + QPointF(2, 2));
auto resultP2 = lineResizeHandles.indexOfHandleAt(p2 + QPointF(-2, -2));
QCOMPARE(lineResizeHandles.handles().count(), 2);
QCOMPARE(resultP1, 0);
QCOMPARE(resultP2, 1);
}
void LineResizeHandlesTest::TestIndexOfHandleAt_Should_NotReturnAnyIndex_When_HandleIsNotAtProvidedPosition()
{
auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2));
QPointF p1(10, 10);
QPointF p2(20, 20);
AnnotationLine lineItem(p1, properties);
lineItem.addPoint(p2, false);
LineResizeHandles lineResizeHandles(&lineItem, 1.0);
auto resultP1 = lineResizeHandles.indexOfHandleAt(QPointF(50, 50));
QCOMPARE(lineResizeHandles.handles().count(), 2);
QCOMPARE(resultP1, -1);
}
void LineResizeHandlesTest::TestHandle_Should_ReturnRectAtIndex_When_HandleAtIndexExists()
{
auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2));
QPointF p1(10, 10);
QPointF p2(20, 20);
AnnotationLine lineItem(p1, properties);
lineItem.addPoint(p2, false);
LineResizeHandles lineResizeHandles(&lineItem, 1.0);
auto result = lineResizeHandles.handle(1);
QVERIFY(result != QRectF());
QCOMPARE(result.anchor(), p2);
}
void LineResizeHandlesTest::TestHandle_Should_NotReturnRect_When_HandleAtIndexDoesntExists()
{
auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 2));
QPointF p1(10, 10);
QPointF p2(20, 20);
AnnotationLine lineItem(p1, properties);
lineItem.addPoint(p2, false);
LineResizeHandles lineResizeHandles(&lineItem, 1.0);
auto result = lineResizeHandles.handle(3);
QCOMPARE(result, ResizeHandle());
}
void LineResizeHandlesTest::TestGetCursorForHandle_Should_NotReturnDefaultCursor_When_ProvidedPositionOnHandle()
{
auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1));
QPointF p1(10, 10);
QPointF p2(20, 20);
AnnotationLine lineItem(p1, properties);
lineItem.addPoint(p2, false);
LineResizeHandles lineResizeHandles(&lineItem, 1.0);
auto result = lineResizeHandles.cursorForPos(p1);
QVERIFY(result != CursorHelper::defaultCursor());
}
void LineResizeHandlesTest::TestGetCursorForHandle_Should_ReturnDefaultCursor_When_ProvidedPositionNotOnHandle()
{
auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1));
QPointF p1(10, 10);
QPointF p2(20, 20);
QPointF p3(50, 50);
AnnotationLine lineItem(p1, properties);
lineItem.addPoint(p2, false);
LineResizeHandles lineResizeHandles(&lineItem, 1.0);
auto result = lineResizeHandles.cursorForPos(p3);
QCOMPARE(result, CursorHelper::defaultCursor());
}
void LineResizeHandlesTest::TestUpdate_Should_SetMoveHandlesToNewPositions()
{
auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1));
QPointF p1(10, 10);
QPointF p2(20, 20);
QPointF p3(50, 50);
QPointF p4(60, 60);
AnnotationLine lineItem(p1, properties);
lineItem.addPoint(p2, false);
LineResizeHandles lineResizeHandles(&lineItem, 1.0);
QCOMPARE(lineResizeHandles.handles()[0].center(), p1);
QCOMPARE(lineResizeHandles.handles()[1].center(), p2);
lineItem.setPointAt(p3, 0, false);
lineItem.setPointAt(p4, 1, false);
lineResizeHandles.update();
QCOMPARE(lineResizeHandles.handles()[0].center(), p3);
QCOMPARE(lineResizeHandles.handles()[1].center(), p4);
}
TEST_MAIN(LineResizeHandlesTest);
|