Engauge Digitizer  2
TestGridLineLimiter.cpp
Go to the documentation of this file.
1 #include "DocumentModelCoords.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>
10 #include "Transformation.h"
11 
12 QTEST_MAIN (TestGridLineLimiter)
13 
14 using namespace std;
15 
17  QObject(parent)
18 {
19 }
20 
21 void TestGridLineLimiter::cleanupTestCase ()
22 {
23 }
24 
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 
49  NO_RESET,
55  w.show ();
56 }
57 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 
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 }
@ COORD_SCALE_LINEAR
Definition: CoordScale.h:13
@ COORD_SCALE_LOG
Definition: CoordScale.h:14
void initializeLogging(const QString &name, const QString &filename, bool isDebug)
Definition: Logger.cpp:21
const bool NO_EXPORT_ONLY
Definition: TestExport.cpp:32
const QStringList NO_COMMAND_LINE
Definition: TestExport.cpp:37
const QString NO_EXTRACT_IMAGE_EXTENSION
Definition: TestExport.cpp:34
const QString NO_ERROR_REPORT_LOG_FILE
Definition: TestExport.cpp:27
const bool NO_GNUPLOT_LOG_FILES
Definition: TestExport.cpp:29
const QString NO_REGRESSION_OPEN_FILE
Definition: TestExport.cpp:28
const QStringList NO_LOAD_STARTUP_FILES
Definition: TestExport.cpp:36
const bool NO_REGRESSION_IMPORT
Definition: TestExport.cpp:30
const bool NO_EXTRACT_IMAGE_ONLY
Definition: TestExport.cpp:33
const bool NO_DROP_REGRESSION
Definition: TestExport.cpp:24
const bool DEBUG_FLAG
Definition: TestExport.cpp:35
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.
void setStepX(double stepX)
Set method for x grid line increment.
void setStepY(double yStep)
Set method for y grid line increment.
void setStopX(double stopX)
Set method for x grid line upper bound (inclusive).
void setStopY(double yStop)
Set method for y grid line upper bound (inclusive).
void setStartX(double startX)
Set method for x grid line lower bound (inclusive).
void setStartY(double yStart)
Set method for y grid line lower bound (inclusive).
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...
void limitForYRadius(const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, const DocumentModelGridDisplay &modelGrid, double &startY, double &stepY, double &stopY) const
Limit step value for y/range coordinate. This is a noop if the maximum grid line limit in MainWindowM...
void limitForXTheta(const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, const DocumentModelGridDisplay &modelGrid, double &startX, double &stepX, double &stopX) const
Limit step value for x/theta coordinate. This is a noop if the maximum grid line limit in MainWindowM...
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.