00001 #include "CurveConnectAs.h"
00002 #include "Document.h"
00003 #include "DocumentModelExportFormat.h"
00004 #include "ExportFileFunctions.h"
00005 #include "ExportFileRelations.h"
00006 #include "ExportValuesXOrY.h"
00007 #include "LineStyle.h"
00008 #include "Logger.h"
00009 #include "MainWindow.h"
00010 #include "MainWindowModel.h"
00011 #include "PointStyle.h"
00012 #include <QImage>
00013 #include <qmath.h>
00014 #include <QtTest/QtTest>
00015 #include "Spline.h"
00016 #include "SplinePair.h"
00017 #include "Test/TestExport.h"
00018 #include "Transformation.h"
00019
00020 QTEST_MAIN (TestExport)
00021
00022 using namespace std;
00023
00024 const bool NOT_USING_GNUPLOT = false;
00025
00026 TestExport::TestExport(QObject *parent) :
00027 QObject(parent),
00028 m_document (0)
00029 {
00030 }
00031
00032 bool TestExport::checkCommasInFunctionsForDelimiter (ExportDelimiter delimiter,
00033 QLocale::Country country,
00034 QString &output)
00035 {
00036 initData (false,
00037 delimiter,
00038 country);
00039
00040 QTextStream str (&output);
00041 bool success = true;
00042 QString dummy;
00043
00044 try {
00045 bool isLogXTheta = (m_modelCoords.coordScaleXTheta() == COORD_SCALE_LOG);
00046 bool isLogYRadius = (m_modelCoords.coordScaleYRadius() == COORD_SCALE_LOG);
00047 unsigned int numWritesSoFar = 0;
00048
00049 ExportFileFunctions exportFile;
00050 exportFile.exportAllPerLineXThetaValuesMerged (m_modelExportOverride,
00051 *m_document,
00052 m_modelMainWindow,
00053 m_curvesIncluded,
00054 m_xThetaValues,
00055 exportDelimiterToText (delimiter, NOT_USING_GNUPLOT),
00056 m_transformation,
00057 isLogXTheta,
00058 isLogYRadius,
00059 str,
00060 numWritesSoFar);
00061 }
00062 catch (...)
00063 {
00064 success = false;
00065 }
00066
00067 return (success);
00068 }
00069
00070 bool TestExport::checkCommasInRelationsForDelimiter (ExportDelimiter delimiter,
00071 QLocale::Country country,
00072 QString &output)
00073 {
00074 initData (false,
00075 delimiter,
00076 country);
00077
00078 QTextStream str (&output);
00079 bool success = true;
00080 QString dummy;
00081
00082 try {
00083 bool isLogXTheta = (m_modelCoords.coordScaleXTheta() == COORD_SCALE_LOG);
00084 bool isLogYRadius = (m_modelCoords.coordScaleYRadius() == COORD_SCALE_LOG);
00085 unsigned int numWritesSoFar = 0;
00086
00087 ExportFileRelations exportFile;
00088 exportFile.exportAllPerLineXThetaValuesMerged (m_modelExportOverride,
00089 *m_document,
00090 m_modelMainWindow,
00091 m_curvesIncluded,
00092 exportDelimiterToText (delimiter, NOT_USING_GNUPLOT),
00093 m_transformation,
00094 isLogXTheta,
00095 isLogYRadius,
00096 str,
00097 numWritesSoFar);
00098 }
00099 catch (...)
00100 {
00101 success = false;
00102 }
00103
00104 return (success);
00105 }
00106
00107 void TestExport::cleanupTestCase ()
00108 {
00109 }
00110
00111 void TestExport::initData (bool isLog,
00112 ExportDelimiter delimiter,
00113 QLocale::Country country)
00114 {
00115 const QString CURVE_NAME ("Curve1");
00116 const int LINE_WIDTH = 2, POINT_LINE_WIDTH = 1;
00117 const ColorPalette LINE_COLOR = COLOR_PALETTE_BLACK, POINT_COLOR = COLOR_PALETTE_BLACK;
00118 const int RADIUS = 5;
00119
00120 QImage nullImage;
00121 m_document = new Document (nullImage);
00122
00123 m_curvesIncluded.clear ();
00124 m_curvesIncluded << CURVE_NAME;
00125
00126 CurveStyles curveStyles (m_document->coordSystem ());
00127 CurveStyle curveStyle (LineStyle (LINE_WIDTH,
00128 LINE_COLOR,
00129 CONNECT_AS_FUNCTION_SMOOTH),
00130 PointStyle (POINT_SHAPE_CIRCLE,
00131 RADIUS,
00132 POINT_LINE_WIDTH,
00133 POINT_COLOR));
00134 curveStyles.setCurveStyle (CURVE_NAME, curveStyle);
00135 if (isLog) {
00136 m_modelCoords.setCoordScaleXTheta (COORD_SCALE_LOG);
00137 m_modelCoords.setCoordScaleYRadius (COORD_SCALE_LOG);
00138 } else {
00139 m_modelCoords.setCoordScaleXTheta (COORD_SCALE_LINEAR);
00140 m_modelCoords.setCoordScaleYRadius (COORD_SCALE_LINEAR);
00141 }
00142 m_modelCoords.setCoordsType (COORDS_TYPE_CARTESIAN);
00143 m_modelGeneral.setCursorSize (3);
00144 m_modelGeneral.setExtraPrecision (1);
00145
00146 m_modelExportOverride.setPointsSelectionFunctions (EXPORT_POINTS_SELECTION_FUNCTIONS_INTERPOLATE_FIRST_CURVE);
00147 m_modelExportOverride.setDelimiter (delimiter);
00148
00149 m_document->setModelExport (m_modelExportOverride);
00150 m_document->setModelCurveStyles (curveStyles);
00151 m_document->setModelCoords (m_modelCoords);
00152 m_document->setModelGeneral (m_modelGeneral);
00153
00154 m_modelMainWindow.setLocale (QLocale::English,
00155 country);
00156
00157 m_document->addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (845, 305), "Curve1\t0", 0);
00158 m_document->addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (850, 294), "Curve1\t1", 1);
00159 m_document->addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (862, 272), "Curve1\t2", 2);
00160 m_document->addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (876, 244), "Curve1\t3", 3);
00161 m_document->addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (887, 222), "Curve1\t4", 4);
00162 m_document->addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (899, 200), "Curve1\t5", 5);
00163 m_document->addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (910, 177), "Curve1\t6", 6);
00164 m_document->addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (922, 155), "Curve1\t7", 7);
00165 m_document->addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (933, 133), "Curve1\t8", 8);
00166 m_document->addPointGraphWithSpecifiedIdentifier (CURVE_NAME, QPointF (945, 110), "Curve1\t9", 9);
00167
00168 m_xThetaValues.clear ();
00169 m_xThetaValues << 0.0009999;
00170 m_xThetaValues << 0.001;
00171 m_xThetaValues << 0.01;
00172 m_xThetaValues << 0.1;
00173 m_xThetaValues << 1;
00174 m_xThetaValues << 10;
00175 m_xThetaValues << 100;
00176 m_xThetaValues << 1000;
00177 QTransform matrixScreen ( 51, 52, 1123,
00178 548, 10, 548,
00179 1, 1, 1);
00180 QTransform matrixGraph (qLn (0.001), qLn (0.001), qLn (1000),
00181 qLn ( 1), qLn ( 100), qLn ( 1),
00182 1, 1, 1);
00183 m_transformation.updateTransformFromMatrices (matrixScreen,
00184 matrixGraph);
00185 m_transformation.setModelCoords (m_modelCoords,
00186 m_modelGeneral,
00187 m_modelMainWindow);
00188 }
00189
00190 void TestExport::initTestCase ()
00191 {
00192 const QString NO_ERROR_REPORT_LOG_FILE;
00193 const QString NO_REGRESSION_OPEN_FILE;
00194 const bool NO_GNUPLOT_LOG_FILES = false;
00195 const bool NO_REGRESSION_IMPORT = false;
00196 const bool NO_RESET = false;
00197 const bool DEBUG_FLAG = false;
00198 const QStringList NO_LOAD_STARTUP_FILES;
00199
00200 initializeLogging ("engauge_test",
00201 "engauge_test.log",
00202 DEBUG_FLAG);
00203
00204 MainWindow w (NO_ERROR_REPORT_LOG_FILE,
00205 NO_REGRESSION_OPEN_FILE,
00206 NO_GNUPLOT_LOG_FILES,
00207 NO_REGRESSION_IMPORT,
00208 NO_RESET,
00209 NO_LOAD_STARTUP_FILES);
00210
00211 w.show ();
00212 }
00213
00214 void TestExport::testCommasInFunctionsForCommasSwitzerland ()
00215 {
00216 QString outputExpectedIfCommaSeparator =
00217 "x,Curve1\n"
00218 "\"0,001\",\"-1,27563\"\n"
00219 "\"0,001\",\"-1,27563\"\n"
00220 "\"0,01\",\"-1,26683\"\n"
00221 "\"0,1\",\"-1,17881\"\n"
00222 "1,\"-0,29658\"\n"
00223 "10,\"-706,15184\"\n"
00224 "100,\"-3997814,14355\"\n"
00225 "1000,\"-4541901224,06376\"\n";
00226 QString outputExpectedIfPeriodSeparator =
00227 "x,Curve1\n"
00228 "0.001,-1.27563\n"
00229 "0.001,-1.27563\n"
00230 "0.01,-1.26683\n"
00231 "0.1,-1.17881\n"
00232 "1,-0.29658\n"
00233 "10,-706.15184\n"
00234 "100,-3997814.14355\n"
00235 "1000,-4541901224.06376\n";
00236
00237 QString outputGot;
00238 bool success = checkCommasInFunctionsForDelimiter (EXPORT_DELIMITER_COMMA,
00239 QLocale::Switzerland,
00240 outputGot);
00241 if (!success) {
00242 outputGot = "";
00243 }
00244
00245 QVERIFY (outputGot == outputExpectedIfCommaSeparator ||
00246 outputGot == outputExpectedIfPeriodSeparator);
00247 }
00248
00249 void TestExport::testCommasInFunctionsForCommasUnitedStates ()
00250 {
00251 QString outputExpected =
00252 "x,Curve1\n"
00253 "0.001,-1.27563\n"
00254 "0.001,-1.27563\n"
00255 "0.01,-1.26683\n"
00256 "0.1,-1.17881\n"
00257 "1,-0.29658\n"
00258 "10,-706.15184\n"
00259 "100,-3997814.14355\n"
00260 "1000,-4541901224.06376\n";
00261
00262 QString outputGot;
00263 bool success = checkCommasInFunctionsForDelimiter (EXPORT_DELIMITER_COMMA,
00264 QLocale::UnitedStates,
00265 outputGot);
00266 if (!success) {
00267 outputGot = "";
00268 }
00269
00270 QVERIFY (outputGot == outputExpected);
00271 }
00272
00273 void TestExport::testCommasInFunctionsForTabsSwitzerland ()
00274 {
00275 QString outputExpectedIfCommaSeparator =
00276 "x\tCurve1\n"
00277 "0,001\t-1,27563\n"
00278 "0,001\t-1,27563\n"
00279 "0,01\t-1,26683\n"
00280 "0,1\t-1,17881\n"
00281 "1\t-0,29658\n"
00282 "10\t-706,15184\n"
00283 "100\t-3997814,14355\n"
00284 "1000\t-4541901224,06376\n";
00285 QString outputExpectedIfPeriodSeparator =
00286 "x\tCurve1\n"
00287 "0.001\t-1.27563\n"
00288 "0.001\t-1.27563\n"
00289 "0.01\t-1.26683\n"
00290 "0.1\t-1.17881\n"
00291 "1\t-0.29658\n"
00292 "10\t-706.15184\n"
00293 "100\t-3997814.14355\n"
00294 "1000\t-4541901224.06376\n";
00295
00296 QString outputGot;
00297 bool success = checkCommasInFunctionsForDelimiter (EXPORT_DELIMITER_TAB,
00298 QLocale::Switzerland,
00299 outputGot);
00300 if (!success) {
00301 outputGot = "";
00302 }
00303
00304 QVERIFY (outputGot == outputExpectedIfCommaSeparator ||
00305 outputGot == outputExpectedIfPeriodSeparator);
00306 }
00307
00308 void TestExport::testCommasInFunctionsForTabsUnitedStates ()
00309 {
00310 QString outputExpected =
00311 "x\tCurve1\n"
00312 "0.001\t-1.27563\n"
00313 "0.001\t-1.27563\n"
00314 "0.01\t-1.26683\n"
00315 "0.1\t-1.17881\n"
00316 "1\t-0.29658\n"
00317 "10\t-706.15184\n"
00318 "100\t-3997814.14355\n"
00319 "1000\t-4541901224.06376\n";
00320
00321 QString outputGot;
00322 bool success = checkCommasInFunctionsForDelimiter (EXPORT_DELIMITER_TAB,
00323 QLocale::UnitedStates,
00324 outputGot);
00325 if (!success) {
00326 outputGot = "";
00327 }
00328
00329 QVERIFY (outputGot == outputExpected);
00330 }
00331
00332 void TestExport::testCommasInRelationsForCommasSwitzerland ()
00333 {
00334 QString outputExpectedIfCommaSeparator =
00335 "x,Curve1\n"
00336 "\"3,3192\",\"2,08003\"\n"
00337 "\"3,3723\",\"2,15796\"\n"
00338 "\"3,432\",\"2,23368\"\n"
00339 "\"3,4935\",\"2,30883\"\n"
00340 "\"3,5539\",\"2,38438\"\n"
00341 "\"3,6113\",\"2,46094\"\n"
00342 "\"3,6687\",\"2,5375\"\n"
00343 "\"3,7261\",\"2,61406\"\n"
00344 "\"3,7836\",\"2,69062\"\n"
00345 "\"3,841\",\"2,76718\"\n"
00346 "\"3,9012\",\"2,84276\"\n"
00347 "\"3,9628\",\"2,91791\"\n"
00348 "\"4,0231\",\"2,99345\"\n"
00349 "\"4,0785\",\"3,07067\"\n"
00350 "\"4,1339\",\"3,14789\"\n"
00351 "\"4,1932\",\"3,22378\"\n"
00352 "\"4,2547\",\"3,29893\"\n"
00353 "\"4,3156\",\"3,37426\"\n"
00354 "\"4,3731\",\"3,45082\"\n"
00355 "\"4,4305\",\"3,52738\"\n"
00356 "\"4,4892\",\"3,60349\"\n"
00357 "\"4,5486\",\"3,67938\"\n";
00358 QString outputExpectedIfPeriodSeparator =
00359 "x,Curve1\n"
00360 "3.3192,2.08003\n"
00361 "3.3723,2.15796\n"
00362 "3.432,2.23368\n"
00363 "3.4935,2.30883\n"
00364 "3.5539,2.38438\n"
00365 "3.6113,2.46094\n"
00366 "3.6687,2.5375\n"
00367 "3.7261,2.61406\n"
00368 "3.7836,2.69062\n"
00369 "3.841,2.76718\n"
00370 "3.9012,2.84276\n"
00371 "3.9628,2.91791\n"
00372 "4.0231,2.99345\n"
00373 "4.0785,3.07067\n"
00374 "4.1339,3.14789\n"
00375 "4.1932,3.22378\n"
00376 "4.2547,3.29893\n"
00377 "4.3156,3.37426\n"
00378 "4.3731,3.45082\n"
00379 "4.4305,3.52738\n"
00380 "4.4892,3.60349\n"
00381 "4.5486,3.67938\n";
00382
00383 QString outputGot;
00384 bool success = checkCommasInRelationsForDelimiter (EXPORT_DELIMITER_COMMA,
00385 QLocale::Switzerland,
00386 outputGot);
00387 if (!success) {
00388 outputGot = "";
00389 }
00390
00391 QVERIFY (outputGot == outputExpectedIfCommaSeparator ||
00392 outputGot == outputExpectedIfPeriodSeparator);
00393 }
00394
00395 void TestExport::testCommasInRelationsForCommasUnitedStates ()
00396 {
00397 QString outputExpected =
00398 "x,Curve1\n"
00399 "3.3192,2.08003\n"
00400 "3.3723,2.15796\n"
00401 "3.432,2.23368\n"
00402 "3.4935,2.30883\n"
00403 "3.5539,2.38438\n"
00404 "3.6113,2.46094\n"
00405 "3.6687,2.5375\n"
00406 "3.7261,2.61406\n"
00407 "3.7836,2.69062\n"
00408 "3.841,2.76718\n"
00409 "3.9012,2.84276\n"
00410 "3.9628,2.91791\n"
00411 "4.0231,2.99345\n"
00412 "4.0785,3.07067\n"
00413 "4.1339,3.14789\n"
00414 "4.1932,3.22378\n"
00415 "4.2547,3.29893\n"
00416 "4.3156,3.37426\n"
00417 "4.3731,3.45082\n"
00418 "4.4305,3.52738\n"
00419 "4.4892,3.60349\n"
00420 "4.5486,3.67938\n";
00421
00422 QString outputGot;
00423 bool success = checkCommasInRelationsForDelimiter (EXPORT_DELIMITER_COMMA,
00424 QLocale::UnitedStates,
00425 outputGot);
00426 if (!success) {
00427 outputGot = "";
00428 }
00429
00430 QVERIFY (outputGot == outputExpected);
00431 }
00432
00433 void TestExport::testCommasInRelationsForTabsSwitzerland ()
00434 {
00435 QString outputExpectedIfCommaSeparator =
00436 "x\tCurve1\n"
00437 "3,3192\t2,08003\n"
00438 "3,3723\t2,15796\n"
00439 "3,432\t2,23368\n"
00440 "3,4935\t2,30883\n"
00441 "3,5539\t2,38438\n"
00442 "3,6113\t2,46094\n"
00443 "3,6687\t2,5375\n"
00444 "3,7261\t2,61406\n"
00445 "3,7836\t2,69062\n"
00446 "3,841\t2,76718\n"
00447 "3,9012\t2,84276\n"
00448 "3,9628\t2,91791\n"
00449 "4,0231\t2,99345\n"
00450 "4,0785\t3,07067\n"
00451 "4,1339\t3,14789\n"
00452 "4,1932\t3,22378\n"
00453 "4,2547\t3,29893\n"
00454 "4,3156\t3,37426\n"
00455 "4,3731\t3,45082\n"
00456 "4,4305\t3,52738\n"
00457 "4,4892\t3,60349\n"
00458 "4,5486\t3,67938\n";
00459 QString outputExpectedIfPeriodSeparator =
00460 "x\tCurve1\n"
00461 "3.3192\t2.08003\n"
00462 "3.3723\t2.15796\n"
00463 "3.432\t2.23368\n"
00464 "3.4935\t2.30883\n"
00465 "3.5539\t2.38438\n"
00466 "3.6113\t2.46094\n"
00467 "3.6687\t2.5375\n"
00468 "3.7261\t2.61406\n"
00469 "3.7836\t2.69062\n"
00470 "3.841\t2.76718\n"
00471 "3.9012\t2.84276\n"
00472 "3.9628\t2.91791\n"
00473 "4.0231\t2.99345\n"
00474 "4.0785\t3.07067\n"
00475 "4.1339\t3.14789\n"
00476 "4.1932\t3.22378\n"
00477 "4.2547\t3.29893\n"
00478 "4.3156\t3.37426\n"
00479 "4.3731\t3.45082\n"
00480 "4.4305\t3.52738\n"
00481 "4.4892\t3.60349\n"
00482 "4.5486\t3.67938\n";
00483
00484 QString outputGot;
00485 bool success = checkCommasInRelationsForDelimiter (EXPORT_DELIMITER_TAB,
00486 QLocale::Switzerland,
00487 outputGot);
00488 if (!success) {
00489 outputGot = "";
00490 }
00491
00492 QVERIFY (outputGot == outputExpectedIfCommaSeparator ||
00493 outputGot == outputExpectedIfPeriodSeparator);
00494 }
00495
00496 void TestExport::testCommasInRelationsForTabsUnitedStates ()
00497 {
00498 QString outputExpected =
00499 "x\tCurve1\n"
00500 "3.3192\t2.08003\n"
00501 "3.3723\t2.15796\n"
00502 "3.432\t2.23368\n"
00503 "3.4935\t2.30883\n"
00504 "3.5539\t2.38438\n"
00505 "3.6113\t2.46094\n"
00506 "3.6687\t2.5375\n"
00507 "3.7261\t2.61406\n"
00508 "3.7836\t2.69062\n"
00509 "3.841\t2.76718\n"
00510 "3.9012\t2.84276\n"
00511 "3.9628\t2.91791\n"
00512 "4.0231\t2.99345\n"
00513 "4.0785\t3.07067\n"
00514 "4.1339\t3.14789\n"
00515 "4.1932\t3.22378\n"
00516 "4.2547\t3.29893\n"
00517 "4.3156\t3.37426\n"
00518 "4.3731\t3.45082\n"
00519 "4.4305\t3.52738\n"
00520 "4.4892\t3.60349\n"
00521 "4.5486\t3.67938\n";
00522
00523 QString outputGot;
00524 bool success = checkCommasInRelationsForDelimiter (EXPORT_DELIMITER_TAB,
00525 QLocale::UnitedStates,
00526 outputGot);
00527 if (!success) {
00528 outputGot = "";
00529 }
00530
00531 QVERIFY (outputGot == outputExpected);
00532 }
00533
00534 void TestExport::testLogExtrapolationFunctionsAll ()
00535 {
00536 initData (true,
00537 EXPORT_DELIMITER_COMMA,
00538 QLocale::UnitedStates);
00539
00540 bool success = true;
00541 QString dummy;
00542 QTextStream str (&dummy);
00543
00544 try {
00545 bool isLogXTheta = (m_modelCoords.coordScaleXTheta() == COORD_SCALE_LOG);
00546 bool isLogYRadius = (m_modelCoords.coordScaleYRadius() == COORD_SCALE_LOG);
00547 unsigned int numWritesSoFar = 0;
00548
00549 ExportFileFunctions exportFile;
00550 exportFile.exportAllPerLineXThetaValuesMerged (m_modelExportOverride,
00551 *m_document,
00552 m_modelMainWindow,
00553 m_curvesIncluded,
00554 m_xThetaValues,
00555 " ",
00556 m_transformation,
00557 isLogXTheta,
00558 isLogYRadius,
00559 str,
00560 numWritesSoFar);
00561 }
00562 catch (...)
00563 {
00564 success = false;
00565 }
00566
00567 QVERIFY (success);
00568 }