File: AnnotationItemModifierTest.cpp

package info (click to toggle)
kimageannotator 0.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,904 kB
  • sloc: cpp: 21,502; makefile: 16; ansic: 13
file content (168 lines) | stat: -rw-r--r-- 5,978 bytes parent folder | download | duplicates (3)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * 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 "AnnotationItemModifierTest.h"

#include "tests/mocks/MockZoomValueProvider.h"

void AnnotationItemModifierTest::HandleMousePressMoveRelease_Should_MoveResizerHandle_When_ClickedOnResizerHandle()
{
	auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1));
	QPointF p1(10, 10);
	QPointF p2(10, 20);
	QPointF p3(30, 30);
	AnnotationLine line(p1, properties);
	line.addPoint(p2, false);
	QList<AbstractAnnotationItem *> items;
	items.append(&line);
	MockZoomValueProvider zoomValueProvider;
	AnnotationItemModifier modifer(&zoomValueProvider);
	QUndoStack undoStack;
	connect(&modifer, &AnnotationItemModifier::newCommand, &undoStack, &QUndoStack::push);
	modifer.handleMousePress(p1, &items, false);
	modifer.handleMouseRelease(&items);

	modifer.handleMousePress(p1, &items, false);
	modifer.handleMouseMove(p3, false);

	QCOMPARE(line.line().p1(), p3);
	QCOMPARE(line.line().p2(), p2);
}

void AnnotationItemModifierTest::HandleMousePressMove_Should_NotMoveResizerHandle_When_NotClickedOnResizerHandle()
{
	auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1));
	QPointF p1(10, 10);
	QPointF p2(10, 20);
	QPointF p3(30, 30);
	QPointF p4(40, 40);
	AnnotationLine line(p1, properties);
	line.addPoint(p2, false);
	QList<AbstractAnnotationItem *> items;
	items.append(&line);
	MockZoomValueProvider zoomValueProvider;
	AnnotationItemModifier modifer(&zoomValueProvider);
	modifer.handleMousePress(p1, &items, false);
	modifer.handleMouseRelease(&items);

	modifer.handleMousePress(p3, &items, false);
	modifer.handleMouseMove(p4, false);

	QCOMPARE(line.line().p1(), p1);
	QCOMPARE(line.line().p2(), p2);
}

void AnnotationItemModifierTest::HandleMousePressMoveRelease_Should_SelectMultipleItems_When_ClickedNotOnItem()
{
	auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 1));
	auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 1));
	QPointF p1(10, 10);
	QPointF p2(10, 20);
	QPointF p3(15, 15);
	QPointF p4(20, 20);
	AnnotationLine line1(p1, properties1);
	AnnotationLine line2(p3, properties2);
	line1.addPoint(p2, false);
	line2.addPoint(p4, false);
	QList<AbstractAnnotationItem *> items;
	items.append(&line1);
	items.append(&line2);
	MockZoomValueProvider zoomValueProvider;
	AnnotationItemModifier modifer(&zoomValueProvider);

	modifer.handleMousePress(p1 + QPointF(-5, -5), &items, false);
	modifer.handleMouseMove(p4 + QPointF(5, 5), false);
	modifer.handleMouseRelease(&items);

	auto results = modifer.selectedItems();
	QCOMPARE(results.count(), 2);
	QCOMPARE(results.contains(&line1), true);
	QCOMPARE(results.contains(&line2), true);
}

void AnnotationItemModifierTest::HandleMousePressMove_Should_MoveClickedItem_When_ClickedOnItemAndMoved()
{
	auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1));
	QPointF p1(10, 10);
	QPointF p2(20, 20);
	QPointF clickPos(15, 15);
	QPointF movePos(30, 30);
	AnnotationLine line(p1, properties);
	line.addPoint(p2, false);
	QList<AbstractAnnotationItem *> items;
	items.append(&line);
	MockZoomValueProvider zoomValueProvider;
	AnnotationItemModifier modifer(&zoomValueProvider);
	QUndoStack undoStack;
	connect(&modifer, &AnnotationItemModifier::newCommand, &undoStack, &QUndoStack::push);

	modifer.handleMousePress(clickPos, &items, false);
	modifer.handleMouseMove(movePos, false);

	QCOMPARE(line.boundingRect().topLeft(), movePos - (clickPos - p1));
}

void AnnotationItemModifierTest::HandleMousePressMove_Should_MoveSelectedItems_When_ClickedOnOfSelectedItemsAndMoved()
{
	auto properties1 = PropertiesPtr(new AnnotationProperties(Qt::red, 1));
	auto properties2 = PropertiesPtr(new AnnotationProperties(Qt::red, 1));
	QPointF p1(10, 10);
	QPointF p2(30, 30);
	QPointF p3(45, 45);
	QPointF p4(60, 60);
	QPointF clickPos(20, 20);
	QPointF movePos(80, 80);
	AnnotationLine line1(p1, properties1);
	AnnotationLine line2(p3, properties2);
	line1.addPoint(p2, false);
	line2.addPoint(p4, false);
	QList<AbstractAnnotationItem *> items;
	items.append(&line1);
	items.append(&line2);
	MockZoomValueProvider zoomValueProvider;
	AnnotationItemModifier modifer(&zoomValueProvider);
	QUndoStack undoStack;
	connect(&modifer, &AnnotationItemModifier::newCommand, &undoStack, &QUndoStack::push);
	modifer.handleMousePress(p1 + QPointF(-5, -5), &items, false);
	modifer.handleMouseMove(p4 + QPointF(5, 5), false);
	modifer.handleMouseRelease(&items);
	QCOMPARE(modifer.selectedItems().count(), 2);

	modifer.handleMousePress(clickPos, &items, false);
	modifer.handleMouseMove(movePos, false);

	QCOMPARE(line1.boundingRect().topLeft(), movePos - (clickPos - p1));
	QCOMPARE(line2.boundingRect().topLeft(), movePos - (clickPos - p3));
}

void AnnotationItemModifierTest::SelectItem_Should_SelectProvidedItem()
{
	auto properties = PropertiesPtr(new AnnotationProperties(Qt::red, 1));
	AnnotationLine line(QPointF(10, 10), properties);
	line.addPoint(QPointF(20, 20), false);
	MockZoomValueProvider zoomValueProvider;
	AnnotationItemModifier modifer(&zoomValueProvider);

	modifer.selectItem(&line);

	QCOMPARE(modifer.selectedItems().count(), 1);
	QCOMPARE(modifer.selectedItems().first(), &line);
}

TEST_MAIN(AnnotationItemModifierTest);