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;
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
00129 bool success = (stepX > 0);
00130
00131 if (success) {
00132
00133 bool stopX = modelGrid.stopX ();
00134 int gridLineCount = 1 + (stopX - startX) / stepX;
00135 success = (gridLineCount <= 20);
00136
00137 }
00138
00139 return success;
00140 }
00141
00142 bool TestGridLineLimiter::testLinearY (double start,
00143 double step,
00144 double stop,
00145 double x1, double y1,
00146 double x2, double y2,
00147 double x3, double y3)
00148 {
00149 GridLineLimiter limiter;
00150 QImage image;
00151 Document document (image);
00152 DocumentModelCoords modelCoords;
00153 MainWindowModel modelMainWindow;
00154 DocumentModelGridDisplay modelGrid;
00155 Transformation transformation;
00156 double startY, stepY;
00157
00158 modelCoords.setCoordScaleXTheta (COORD_SCALE_LINEAR);
00159 modelGrid.setStartY (start);
00160 modelGrid.setStepY (step);
00161 modelGrid.setStopY (stop);
00162 modelMainWindow.setMaximumGridLines (5);
00163 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
00164 document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
00165 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
00166
00167 limiter.limitForYRadius (document,
00168 transformation,
00169 modelCoords,
00170 modelMainWindow,
00171 modelGrid,
00172 startY,
00173 stepY);
00174
00175 bool success = (stepY > 0);
00176
00177 if (success) {
00178
00179 bool stopY = modelGrid.stopY ();
00180 int gridLineCount = 1 + (stopY - startY) / stepY;
00181 success = (gridLineCount <= 20);
00182
00183 }
00184
00185 return success;
00186 }
00187
00188 bool TestGridLineLimiter::testLogX (double start,
00189 double step,
00190 double stop,
00191 double x1, double y1,
00192 double x2, double y2,
00193 double x3, double y3)
00194 {
00195 GridLineLimiter limiter;
00196 QImage image;
00197 Document document (image);
00198 DocumentModelCoords modelCoords;
00199 MainWindowModel modelMainWindow;
00200 DocumentModelGridDisplay modelGrid;
00201 Transformation transformation;
00202 double startX, stepX;
00203
00204 modelCoords.setCoordScaleXTheta (COORD_SCALE_LOG);
00205 modelGrid.setStartX (start);
00206 modelGrid.setStepX (step);
00207 modelGrid.setStopX (stop);
00208 modelMainWindow.setMaximumGridLines (5);
00209 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
00210 document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
00211 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
00212
00213 limiter.limitForXTheta (document,
00214 transformation,
00215 modelCoords,
00216 modelMainWindow,
00217 modelGrid,
00218 startX,
00219 stepX);
00220
00221 bool success = (startX > 0) && (stepX > 0);
00222
00223 if (success) {
00224
00225 bool stopX = modelGrid.stopX ();
00226 int gridLineCount = 1 + (qLn (stopX) - qLn (startX)) / qLn (stepX);
00227 success = (gridLineCount <= 20);
00228
00229 }
00230
00231 return success;
00232 }
00233
00234 bool TestGridLineLimiter::testLogY (double start,
00235 double step,
00236 double stop,
00237 double x1, double y1,
00238 double x2, double y2,
00239 double x3, double y3)
00240 {
00241 GridLineLimiter limiter;
00242 QImage image;
00243 Document document (image);
00244 DocumentModelCoords modelCoords;
00245 MainWindowModel modelMainWindow;
00246 DocumentModelGridDisplay modelGrid;
00247 Transformation transformation;
00248 double startY, stepY;
00249
00250 modelCoords.setCoordScaleYRadius (COORD_SCALE_LOG);
00251 modelGrid.setStartY (start);
00252 modelGrid.setStepY (step);
00253 modelGrid.setStopY (stop);
00254 modelMainWindow.setMaximumGridLines (5);
00255 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 0), QPointF (x1, y1), QString ("axis1"), 0.0, false);
00256 document.addPointAxisWithSpecifiedIdentifier (QPointF (100, 0), QPointF (x2, y2), QString ("axis2"), 0.0, false);
00257 document.addPointAxisWithSpecifiedIdentifier (QPointF (0 , 100), QPointF (x3, y3), QString ("axis3"), 0.0, false);
00258
00259 limiter.limitForYRadius (document,
00260 transformation,
00261 modelCoords,
00262 modelMainWindow,
00263 modelGrid,
00264 startY,
00265 stepY);
00266
00267 bool success = (startY > 0) && (stepY > 0);
00268
00269 if (success) {
00270
00271 bool stopY = modelGrid.stopY ();
00272 int gridLineCount = 1 + (qLn (stopY) - qLn (startY)) / qLn (stepY);
00273 success = (gridLineCount <= 20);
00274
00275 }
00276
00277 return success;
00278 }
00279
00280 void TestGridLineLimiter::testTransitionLinearToLogX ()
00281 {
00282 bool success = testLogX (0,
00283 250,
00284 1000,
00285 0.001, 0.001,
00286 1000, 0.001,
00287 0.001, 1000);
00288
00289 QVERIFY (success);
00290 }
00291
00292 void TestGridLineLimiter::testTransitionLinearToLogY ()
00293 {
00294 bool success = testLogY (0,
00295 250,
00296 1000,
00297 0.001, 0.001,
00298 1000, 0.001,
00299 0.001, 1000);
00300
00301 QVERIFY (success);
00302 }