Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
test_viewmanager.cpp
1 #include "test_viewmanager.h"
2 #include "viewmanager.h"
3 #include "object.h"
4 
5 TestViewManager::TestViewManager()
6 {
7 
8 }
9 
10 void TestViewManager::initTestCase()
11 {
12  Object* object = new Object();
13  object->init();
14 
15  mEditor = new Editor();
16  mEditor->setObject(object);
17 }
18 
19 void TestViewManager::cleanupTestCase()
20 {
21  delete mEditor;
22 }
23 
24 void TestViewManager::testTranslation10()
25 {
26  ViewManager v(mEditor);
27  v.setEditor(mEditor);
28  v.init();
29 
30  v.translate(10, 10);
31 
32  QCOMPARE( QPointF(10 ,10), v.mapCanvasToScreen(QPointF(0,0)) );
33 }
34 
35 void TestViewManager::testTranslation2Times()
36 {
37  ViewManager v(mEditor);
38  v.setEditor(mEditor);
39  v.init();
40 
41  v.translate(0, 15);
42  QCOMPARE( v.mapCanvasToScreen(QPointF(0, 0)), QPointF(0, 15));
43 
44  v.translate(0, 30);
45  QCOMPARE( v.mapCanvasToScreen(QPointF(0, 0)), QPointF(0, 30));
46 }
47 
48 void TestViewManager::testTranslationQPointF()
49 {
50  ViewManager v(mEditor);
51  v.setEditor(mEditor);
52  v.init();
53 
54  v.translate(QPointF(10, 10));
55  QCOMPARE(QPointF(10, 10), v.mapCanvasToScreen(QPointF(0, 0)));
56 }
57 
58 void TestViewManager::testRotation90()
59 {
60  ViewManager v(mEditor);
61  v.setEditor(mEditor);
62  v.init();
63 
64  v.rotate(90); // counter-clockwise rotation
65  QCOMPARE( v.mapCanvasToScreen(QPointF(1, 0)), QPointF(0, 1));
66  QCOMPARE(v.mapCanvasToScreen(QPointF(23.6, 0)), QPointF(0, 23.6));
67 }
68 
69 void TestViewManager::testRotation180()
70 {
71  ViewManager v(mEditor);
72  v.setEditor(mEditor);
73  v.init();
74 
75  v.rotate(180); // counter-clockwise rotation
76  QCOMPARE(v.rotation(), 180.f);
77  QCOMPARE(v.mapCanvasToScreen(QPointF(1, 0)), QPointF(-1, 0));
78  QCOMPARE(v.mapCanvasToScreen(QPointF(92.1, 0)), QPointF(-92.1, 0));
79 }
80 
81 void TestViewManager::testRotationTwice()
82 {
83  ViewManager v(mEditor);
84  v.setEditor(mEditor);
85  v.init();
86 
87  v.rotate(45); // counter-clockwise rotation
88  QCOMPARE(v.rotation(), 45.f);
89  QCOMPARE(v.mapCanvasToScreen(QPointF(1, 0)), QPointF(cos(M_PI/4), sin(M_PI /4)));
90 
91  v.rotate(90);
92  QCOMPARE(v.rotation(), 90.f);
93  QCOMPARE(v.mapCanvasToScreen(QPointF(1, 0)), QPointF(0, 1));
94 }
95 
96 void TestViewManager::testScaling2()
97 {
98  ViewManager v(mEditor);
99  v.setEditor(mEditor);
100  v.init();
101 
102  v.scale(2);
103  QCOMPARE(v.mapCanvasToScreen(QPointF(1, 1)), QPointF(2, 2));
104  QCOMPARE(v.scaling(), 2.0f);
105 }
106 
107 void TestViewManager::testScaling2Times()
108 {
109  ViewManager v(mEditor);
110  v.setEditor(mEditor);
111  v.init();
112 
113  v.scale(2);
114  QCOMPARE(v.scaling(), 2.0f);
115  QCOMPARE(v.mapCanvasToScreen(QPointF(1, 1)), QPointF(2, 2));
116 
117  v.scale(6);
118  QCOMPARE(v.scaling(), 6.0f);
119  QCOMPARE(v.mapCanvasToScreen(QPointF(1, 1)), QPointF(6, 6));
120  QCOMPARE(v.mapCanvasToScreen(QPointF(-1, 2)), QPointF(-6, 12));
121 }
122 
123 void TestViewManager::testMaxScalingValue()
124 {
125  ViewManager v(mEditor);
126  v.setEditor(mEditor);
127  v.init();
128 
129  // set a ridiculously large number
130  // should be clamp to 100.f, the maximum scaling value we set
131  v.scale(10000);
132  QCOMPARE(v.mapCanvasToScreen(QPointF(1, 1)), QPointF(100, 100));
133 }
134 
135 void TestViewManager::testMinScalingValue()
136 {
137  ViewManager v(mEditor);
138  v.setEditor(mEditor);
139  v.init();
140 
141  v.scale(0.0005f);
142 
143  QPointF p1 = v.mapCanvasToScreen(QPointF(1, 1));
144  QPointF p2 = QPointF(0.01, 0.01);
145 
146  QVERIFY(std::abs(p1.x() - p2.x()) < 0.000001);
147  QVERIFY(std::abs(p1.y() - p2.y()) < 0.000001);
148 }
149 
150 void TestViewManager::testTranslateAndRotate()
151 {
152  ViewManager v(mEditor);
153  v.setEditor(mEditor);
154  v.init();
155 
156  v.translate(10, 0);
157  v.rotate(90);
158  // translation is always applied first
159  // (1, 1) => translate 10 units on x => (11, 1)
160  // (11, 1) => rotate 90 deg => (-1, 11)
161  QCOMPARE(v.mapCanvasToScreen(QPointF(1, 1)), QPointF(-1, 11));
162 }
Definition: object.h:71
Definition: editor.h:45