00001 #include "DocumentModelCoords.h"
00002 #include "DocumentModelGridDisplay.h"
00003 #include "GridLineLimiter.h"
00004 #include "Logger.h"
00005 #include "MainWindow.h"
00006 #include "MainWindowModel.h"
00007 #include <qmath.h>
00008 #include <QtTest/QtTest>
00009 #include "Test/TestGridLineLimiter.h"
00010 #include "Transformation.h"
00011
00012 QTEST_MAIN (TestGridLineLimiter)
00013
00014 using namespace std;
00015
00016 TestGridLineLimiter::TestGridLineLimiter(QObject *parent) :
00017 QObject(parent)
00018 {
00019 }
00020
00021 void TestGridLineLimiter::cleanupTestCase ()
00022 {
00023 }
00024
00025 void TestGridLineLimiter::initTestCase ()
00026 {
00027 const QString NO_ERROR_REPORT_LOG_FILE;
00028 const QString NO_REGRESSION_OPEN_FILE;
00029 const bool NO_GNUPLOT_LOG_FILES = false;
00030 const bool NO_REGRESSION_IMPORT = false;
00031 const bool NO_RESET = false;
00032 const bool DEBUG_FLAG = false;
00033 const QStringList NO_LOAD_STARTUP_FILES;
00034
00035 initializeLogging ("engauge_test",
00036 "engauge_test.log",
00037 DEBUG_FLAG);
00038
00039 MainWindow w (NO_ERROR_REPORT_LOG_FILE,
00040 NO_REGRESSION_OPEN_FILE,
00041 NO_GNUPLOT_LOG_FILES,
00042 NO_REGRESSION_IMPORT,
00043 NO_RESET,
00044 NO_LOAD_STARTUP_FILES);
00045 w.show ();
00046 }
00047
00048 void TestGridLineLimiter::testBadStepLinearX ()
00049 {
00050 bool success = testLinearX (0,
00051 0,
00052 100,
00053 0.001, 0.001,
00054 1000, 0.001,
00055 0.001, 1000);
00056
00057 QVERIFY (success);
00058 }
00059
00060 void TestGridLineLimiter::testBadStepLinearY ()
00061 {
00062 bool success = testLinearY (0,
00063 0,
00064 100,
00065 0.001, 0.001,
00066 1000, 0.001,
00067 0.001, 1000);
00068
00069 QVERIFY (success);
00070 }
00071
00072 void TestGridLineLimiter::testBadStepLogX ()
00073 {
00074 bool success = testLogX (0,
00075 1,
00076 100,
00077 0.001, 0.001,
00078 1000, 0.001,
00079 0.001, 1000);
00080
00081 QVERIFY (success);
00082 }
00083
00084 void TestGridLineLimiter::testBadStepLogY ()
00085 {
00086 bool success = testLogY (0,
00087 1,
00088 100,
00089 0.001, 0.001,
00090 1000, 0.001,
00091 0.001, 1000);
00092
00093 QVERIFY (success);
00094 }
00095
00096 bool TestGridLineLimiter::testLinearX (double start,
00097 double step,
00098 double stop,
00099 double x1, double y1,
00100 double x2, double y2,
00101 double x3, double y3)
00102 {
00103 GridLineLimiter limiter;
00104 QImage image;
00105 Document document (image);
00106 DocumentModelCoords modelCoords;
00107 MainWindowModel modelMainWindow;
00108 DocumentModelGridDisplay modelGrid;
00109 Transformation transformation;
00110 double startX, stepX, stopX;
00111
00112 modelCoords.setCoordScaleXTheta (COORD_SCALE_LINEAR);
00113 modelGrid.setStartX (start);
00114 modelGrid.setStepX (step);
00115 modelGrid.setStopX (stop);
00116 modelMainWindow.setMaximumGridLines (5);
00117 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
00118 document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
00119 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
00120
00121 limiter.limitForXTheta (document,
00122 transformation,
00123 modelCoords,
00124 modelMainWindow,
00125 modelGrid,
00126 startX,
00127 stepX,
00128 stopX);
00129
00130 bool success = true;
00131
00132 if (stepX > 0) {
00133
00134 int gridLineCount = 1 + (stopX - startX) / stepX;
00135 success = (gridLineCount <= 20);
00136
00137 } else {
00138
00139 success = (startX == stopX);
00140
00141 }
00142
00143 return success;
00144 }
00145
00146 bool TestGridLineLimiter::testLinearY (double start,
00147 double step,
00148 double stop,
00149 double x1, double y1,
00150 double x2, double y2,
00151 double x3, double y3)
00152 {
00153 GridLineLimiter limiter;
00154 QImage image;
00155 Document document (image);
00156 DocumentModelCoords modelCoords;
00157 MainWindowModel modelMainWindow;
00158 DocumentModelGridDisplay modelGrid;
00159 Transformation transformation;
00160 double startY, stepY, stopY;
00161
00162 modelCoords.setCoordScaleXTheta (COORD_SCALE_LINEAR);
00163 modelGrid.setStartY (start);
00164 modelGrid.setStepY (step);
00165 modelGrid.setStopY (stop);
00166 modelMainWindow.setMaximumGridLines (5);
00167 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
00168 document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
00169 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
00170
00171 limiter.limitForYRadius (document,
00172 transformation,
00173 modelCoords,
00174 modelMainWindow,
00175 modelGrid,
00176 startY,
00177 stepY,
00178 stopY);
00179
00180 bool success = true;
00181
00182 if (stepY > 0) {
00183
00184 int gridLineCount = 1 + (stopY - startY) / stepY;
00185 success = (gridLineCount <= 20);
00186
00187 } else {
00188
00189 success = (startY == stopY);
00190
00191 }
00192
00193 return success;
00194 }
00195
00196 bool TestGridLineLimiter::testLogX (double start,
00197 double step,
00198 double stop,
00199 double x1, double y1,
00200 double x2, double y2,
00201 double x3, double y3)
00202 {
00203 GridLineLimiter limiter;
00204 QImage image;
00205 Document document (image);
00206 DocumentModelCoords modelCoords;
00207 MainWindowModel modelMainWindow;
00208 DocumentModelGridDisplay modelGrid;
00209 Transformation transformation;
00210 double startX, stepX, stopX;
00211
00212 modelCoords.setCoordScaleXTheta (COORD_SCALE_LOG);
00213 modelGrid.setStartX (start);
00214 modelGrid.setStepX (step);
00215 modelGrid.setStopX (stop);
00216 modelMainWindow.setMaximumGridLines (5);
00217 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
00218 document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
00219 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
00220
00221 limiter.limitForXTheta (document,
00222 transformation,
00223 modelCoords,
00224 modelMainWindow,
00225 modelGrid,
00226 startX,
00227 stepX,
00228 stopX);
00229
00230 bool success = (startX > 0) && (stepX > 0);
00231
00232 if (success) {
00233
00234 int gridLineCount = 1 + (qLn (stopX) - qLn (startX)) / qLn (stepX);
00235 success = (gridLineCount <= 20);
00236
00237 }
00238
00239 return success;
00240 }
00241
00242 bool TestGridLineLimiter::testLogY (double start,
00243 double step,
00244 double stop,
00245 double x1, double y1,
00246 double x2, double y2,
00247 double x3, double y3)
00248 {
00249 GridLineLimiter limiter;
00250 QImage image;
00251 Document document (image);
00252 DocumentModelCoords modelCoords;
00253 MainWindowModel modelMainWindow;
00254 DocumentModelGridDisplay modelGrid;
00255 Transformation transformation;
00256 double startY, stepY, stopY;
00257
00258 modelCoords.setCoordScaleYRadius (COORD_SCALE_LOG);
00259 modelGrid.setStartY (start);
00260 modelGrid.setStepY (step);
00261 modelGrid.setStopY (stop);
00262 modelMainWindow.setMaximumGridLines (5);
00263 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
00264 document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
00265 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
00266
00267 limiter.limitForYRadius (document,
00268 transformation,
00269 modelCoords,
00270 modelMainWindow,
00271 modelGrid,
00272 startY,
00273 stepY,
00274 stopY);
00275
00276 bool success = (startY > 0) && (stepY > 0);
00277
00278 if (success) {
00279
00280 int gridLineCount = 1 + (qLn (stopY) - qLn (startY)) / qLn (stepY);
00281 success = (gridLineCount <= 20);
00282
00283 }
00284
00285 return success;
00286 }
00287
00288 void TestGridLineLimiter::testTransitionLinearToLogX ()
00289 {
00290 bool success = testLogX (0,
00291 250,
00292 1000,
00293 0.001, 0.001,
00294 1000, 0.001,
00295 0.001, 1000);
00296
00297 QVERIFY (success);
00298 }
00299
00300 void TestGridLineLimiter::testTransitionLinearToLogY ()
00301 {
00302 bool success = testLogY (0,
00303 250,
00304 1000,
00305 0.001, 0.001,
00306 1000, 0.001,
00307 0.001, 1000);
00308
00309 QVERIFY (success);
00310 }