Engauge Digitizer 2
Loading...
Searching...
No Matches
TestGridLineLimiter.cpp
Go to the documentation of this file.
3#include "GridLineLimiter.h"
4#include "Logger.h"
5#include "MainWindow.h"
6#include "MainWindowModel.h"
7#include <qmath.h>
8#include <QtTest/QtTest>
10#include "Transformation.h"
11
13
14using namespace std;
15
20
21void TestGridLineLimiter::cleanupTestCase ()
22{
23}
24
25void TestGridLineLimiter::initTestCase ()
26{
27 const bool NO_DROP_REGRESSION = false;
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;
36 const bool DEBUG_FLAG = false;
39
40 initializeLogging ("engauge_test",
41 "engauge_test.log",
43
55 w.show ();
56}
57
58void 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
70void 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
82void 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
94void 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
106bool 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{
114 QImage image;
115 Document document (image);
116 DocumentModelCoords modelCoords;
117 MainWindowModel modelMainWindow;
119 Transformation transformation;
120 double startX, stepX, stopX; // Outputs from GridLineLimiter
121
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
156bool 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{
164 QImage image;
165 Document document (image);
166 DocumentModelCoords modelCoords;
167 MainWindowModel modelMainWindow;
169 Transformation transformation;
170 double startY, stepY, stopY; // Outputs from GridLineLimiter
171
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
206bool 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{
214 QImage image;
215 Document document (image);
216 DocumentModelCoords modelCoords;
217 MainWindowModel modelMainWindow;
219 Transformation transformation;
220 double startX, stepX, stopX; // Outputs from GridLineLimiter
221
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
252bool 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{
260 QImage image;
261 Document document (image);
262 DocumentModelCoords modelCoords;
263 MainWindowModel modelMainWindow;
265 Transformation transformation;
266 double startY, stepY, stopY; // Outputs from GridLineLimiter
267
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
298void 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
310void 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}
@ COORD_SCALE_LINEAR
Definition CoordScale.h:13
@ COORD_SCALE_LOG
Definition CoordScale.h:14
const int INNER_RADIUS_MIN
void initializeLogging(const QString &name, const QString &filename, bool isDebug)
Definition Logger.cpp:21
const bool NO_EXPORT_ONLY
const QStringList NO_COMMAND_LINE
const QString NO_EXTRACT_IMAGE_EXTENSION
const QString NO_ERROR_REPORT_LOG_FILE
const bool NO_GNUPLOT_LOG_FILES
const QString NO_REGRESSION_OPEN_FILE
const QStringList NO_LOAD_STARTUP_FILES
const bool NO_REGRESSION_IMPORT
const bool NO_EXTRACT_IMAGE_ONLY
const bool NO_DROP_REGRESSION
const bool DEBUG_FLAG
Model for DlgSettingsCoords and CmdSettingsCoords.
void setCoordScaleXTheta(CoordScale coordScale)
Set method for linear/log scale on x/theta.
void setCoordScaleYRadius(CoordScale coordScale)
Set method for linear/log scale on y/radius.
Model for DlgSettingsGridDisplay and CmdSettingsGridDisplay.
Storage of one imported image and the data attached to that image.
Definition Document.h:42
Limit the number of grid lines so a bad combination of start/step/stop value will not lead to extreme...
Model for DlgSettingsMainWindow.
void setMaximumGridLines(int maximumGridLines)
Set method for maximum number of grid lines.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition MainWindow.h:92
Unit test of GridLineLimiter class.
TestGridLineLimiter(QObject *parent=0)
Single constructor.
Affine transformation between screen and graph coordinates, based on digitized axis points.