1 #include "DocumentModelCoords.h"
2 #include "DocumentModelGridDisplay.h"
3 #include "GridLineLimiter.h"
4 #include "Logger.h"
5 #include "MainWindow.h"
6 #include "MainWindowModel.h"
7 #include <qmath.h>
8 #include <QtTest/QtTest>
9 #include "Test/TestGridLineLimiter.h"
10 #include "Transformation.h"
11
12 QTEST_MAIN (TestGridLineLimiter)
13
14 using namespace std;
15
TestGridLineLimiter(QObject * parent)16 TestGridLineLimiter::TestGridLineLimiter(QObject *parent) :
17 QObject(parent)
18 {
19 }
20
cleanupTestCase()21 void TestGridLineLimiter::cleanupTestCase ()
22 {
23 }
24
initTestCase()25 void TestGridLineLimiter::initTestCase ()
26 {
27 const bool NO_DROP_REGRESSION = false;
28 const QString NO_ERROR_REPORT_LOG_FILE;
29 const QString NO_REGRESSION_OPEN_FILE;
30 const bool NO_GNUPLOT_LOG_FILES = false;
31 const bool NO_REGRESSION_IMPORT = false;
32 const bool NO_RESET = false;
33 const bool NO_EXPORT_ONLY = false;
34 const bool NO_EXTRACT_IMAGE_ONLY = false;
35 const QString NO_EXTRACT_IMAGE_EXTENSION;
36 const bool DEBUG_FLAG = false;
37 const QStringList NO_LOAD_STARTUP_FILES;
38 const QStringList NO_COMMAND_LINE;
39
40 initializeLogging ("engauge_test",
41 "engauge_test.log",
42 DEBUG_FLAG);
43
44 MainWindow w (NO_ERROR_REPORT_LOG_FILE,
45 NO_REGRESSION_OPEN_FILE,
46 NO_DROP_REGRESSION,
47 NO_REGRESSION_IMPORT,
48 NO_GNUPLOT_LOG_FILES,
49 NO_RESET,
50 NO_EXPORT_ONLY,
51 NO_EXTRACT_IMAGE_ONLY,
52 NO_EXTRACT_IMAGE_EXTENSION,
53 NO_LOAD_STARTUP_FILES,
54 NO_COMMAND_LINE);
55 w.show ();
56 }
57
testBadStepLinearX()58 void TestGridLineLimiter::testBadStepLinearX ()
59 {
60 bool success = testLinearX (0,
61 0, // Bad
62 100,
63 0.001, 0.001,
64 1000, 0.001,
65 0.001, 1000);
66
67 QVERIFY (success);
68 }
69
testBadStepLinearY()70 void TestGridLineLimiter::testBadStepLinearY ()
71 {
72 bool success = testLinearY (0,
73 0, // Bad
74 100,
75 0.001, 0.001,
76 1000, 0.001,
77 0.001, 1000);
78
79 QVERIFY (success);
80 }
81
testBadStepLogX()82 void TestGridLineLimiter::testBadStepLogX ()
83 {
84 bool success = testLogX (0, // Bad
85 1, // Bad
86 100,
87 0.001, 0.001,
88 1000, 0.001,
89 0.001, 1000);
90
91 QVERIFY (success);
92 }
93
testBadStepLogY()94 void TestGridLineLimiter::testBadStepLogY ()
95 {
96 bool success = testLogY (0, // Bad
97 1, // Bad
98 100,
99 0.001, 0.001,
100 1000, 0.001,
101 0.001, 1000);
102
103 QVERIFY (success);
104 }
105
testLinearX(double start,double step,double stop,double x1,double y1,double x2,double y2,double x3,double y3)106 bool TestGridLineLimiter::testLinearX (double start,
107 double step,
108 double stop,
109 double x1, double y1,
110 double x2, double y2,
111 double x3, double y3)
112 {
113 GridLineLimiter limiter;
114 QImage image;
115 Document document (image);
116 DocumentModelCoords modelCoords;
117 MainWindowModel modelMainWindow;
118 DocumentModelGridDisplay modelGrid;
119 Transformation transformation;
120 double startX, stepX, stopX; // Outputs from GridLineLimiter
121
122 modelCoords.setCoordScaleXTheta (COORD_SCALE_LINEAR);
123 modelGrid.setStartX (start);
124 modelGrid.setStepX (step);
125 modelGrid.setStopX (stop);
126 modelMainWindow.setMaximumGridLines (5);
127 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
128 document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
129 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
130
131 limiter.limitForXTheta (document,
132 transformation,
133 modelCoords,
134 modelMainWindow,
135 modelGrid,
136 startX,
137 stepX,
138 stopX);
139
140 bool success = true;
141
142 if (stepX > 0) {
143
144 int gridLineCount = 1 + (stopX - startX) / stepX;
145 success = (gridLineCount <= 20);
146
147 } else {
148
149 success = (startX == stopX);
150
151 }
152
153 return success;
154 }
155
testLinearY(double start,double step,double stop,double x1,double y1,double x2,double y2,double x3,double y3)156 bool TestGridLineLimiter::testLinearY (double start,
157 double step,
158 double stop,
159 double x1, double y1,
160 double x2, double y2,
161 double x3, double y3)
162 {
163 GridLineLimiter limiter;
164 QImage image;
165 Document document (image);
166 DocumentModelCoords modelCoords;
167 MainWindowModel modelMainWindow;
168 DocumentModelGridDisplay modelGrid;
169 Transformation transformation;
170 double startY, stepY, stopY; // Outputs from GridLineLimiter
171
172 modelCoords.setCoordScaleXTheta (COORD_SCALE_LINEAR);
173 modelGrid.setStartY (start);
174 modelGrid.setStepY (step);
175 modelGrid.setStopY (stop);
176 modelMainWindow.setMaximumGridLines (5);
177 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
178 document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
179 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
180
181 limiter.limitForYRadius (document,
182 transformation,
183 modelCoords,
184 modelMainWindow,
185 modelGrid,
186 startY,
187 stepY,
188 stopY);
189
190 bool success = true;
191
192 if (stepY > 0) {
193
194 int gridLineCount = 1 + (stopY - startY) / stepY;
195 success = (gridLineCount <= 20);
196
197 } else {
198
199 success = (startY == stopY);
200
201 }
202
203 return success;
204 }
205
testLogX(double start,double step,double stop,double x1,double y1,double x2,double y2,double x3,double y3)206 bool TestGridLineLimiter::testLogX (double start,
207 double step,
208 double stop,
209 double x1, double y1,
210 double x2, double y2,
211 double x3, double y3)
212 {
213 GridLineLimiter limiter;
214 QImage image;
215 Document document (image);
216 DocumentModelCoords modelCoords;
217 MainWindowModel modelMainWindow;
218 DocumentModelGridDisplay modelGrid;
219 Transformation transformation;
220 double startX, stepX, stopX; // Outputs from GridLineLimiter
221
222 modelCoords.setCoordScaleXTheta (COORD_SCALE_LOG);
223 modelGrid.setStartX (start);
224 modelGrid.setStepX (step);
225 modelGrid.setStopX (stop);
226 modelMainWindow.setMaximumGridLines (5);
227 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
228 document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
229 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
230
231 limiter.limitForXTheta (document,
232 transformation,
233 modelCoords,
234 modelMainWindow,
235 modelGrid,
236 startX,
237 stepX,
238 stopX);
239
240 bool success = (startX > 0) && (stepX > 0);
241
242 if (success) {
243
244 int gridLineCount = 1 + (qLn (stopX) - qLn (startX)) / qLn (stepX);
245 success = (gridLineCount <= 20);
246
247 }
248
249 return success;
250 }
251
testLogY(double start,double step,double stop,double x1,double y1,double x2,double y2,double x3,double y3)252 bool TestGridLineLimiter::testLogY (double start,
253 double step,
254 double stop,
255 double x1, double y1,
256 double x2, double y2,
257 double x3, double y3)
258 {
259 GridLineLimiter limiter;
260 QImage image;
261 Document document (image);
262 DocumentModelCoords modelCoords;
263 MainWindowModel modelMainWindow;
264 DocumentModelGridDisplay modelGrid;
265 Transformation transformation;
266 double startY, stepY, stopY; // Outputs from GridLineLimiter
267
268 modelCoords.setCoordScaleYRadius (COORD_SCALE_LOG);
269 modelGrid.setStartY (start);
270 modelGrid.setStepY (step);
271 modelGrid.setStopY (stop);
272 modelMainWindow.setMaximumGridLines (5);
273 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
274 document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
275 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
276
277 limiter.limitForYRadius (document,
278 transformation,
279 modelCoords,
280 modelMainWindow,
281 modelGrid,
282 startY,
283 stepY,
284 stopY);
285
286 bool success = (startY > 0) && (stepY > 0);
287
288 if (success) {
289
290 int gridLineCount = 1 + (qLn (stopY) - qLn (startY)) / qLn (stepY);
291 success = (gridLineCount <= 20);
292
293 }
294
295 return success;
296 }
297
testTransitionLinearToLogX()298 void TestGridLineLimiter::testTransitionLinearToLogX ()
299 {
300 bool success = testLogX (0,
301 250,
302 1000,
303 0.001, 0.001,
304 1000, 0.001,
305 0.001, 1000);
306
307 QVERIFY (success);
308 }
309
testTransitionLinearToLogY()310 void TestGridLineLimiter::testTransitionLinearToLogY ()
311 {
312 bool success = testLogY (0,
313 250,
314 1000,
315 0.001, 0.001,
316 1000, 0.001,
317 0.001, 1000);
318
319 QVERIFY (success);
320 }
321