00001 #include <iostream>
00002 #include "Logger.h"
00003 #include "MainWindow.h"
00004 #include <QCryptographicHash>
00005 #include <QGraphicsScene>
00006 #include <QGraphicsView>
00007 #include <QList>
00008 #include <qmath.h>
00009 #include <QTextStream>
00010 #include <QtTest/QtTest>
00011 #include "Segment.h"
00012 #include "SegmentFactory.h"
00013 #include "Spline.h"
00014 #include "SplinePair.h"
00015 #include "Test/TestSegmentFill.h"
00016
00017 QTEST_MAIN (TestSegmentFill)
00018
00019 using namespace std;
00020
00021 TestSegmentFill::TestSegmentFill(QObject *parent) :
00022 QObject(parent)
00023 {
00024 }
00025
00026 void TestSegmentFill::cleanupTestCase ()
00027 {
00028
00029 }
00030
00031 void TestSegmentFill::initTestCase ()
00032 {
00033 const QString NO_ERROR_REPORT_LOG_FILE;
00034 const QString NO_REGRESSION_OPEN_FILE;
00035 const bool NO_GNUPLOT_LOG_FILES = false;
00036 const bool NO_REGRESSION_IMPORT = false;
00037 const bool NO_RESET = false;
00038 const bool DEBUG_FLAG = false;
00039 const QStringList NO_LOAD_STARTUP_FILES;
00040
00041 initializeLogging ("engauge_test",
00042 "engauge_test.log",
00043 DEBUG_FLAG);
00044
00045 MainWindow m (NO_ERROR_REPORT_LOG_FILE,
00046 NO_REGRESSION_OPEN_FILE,
00047 NO_GNUPLOT_LOG_FILES,
00048 NO_REGRESSION_IMPORT,
00049 NO_RESET,
00050 NO_LOAD_STARTUP_FILES);
00051 m.show ();
00052 }
00053
00054 void TestSegmentFill::testFindSegments()
00055 {
00056 const bool NO_GNUPLOT = false;
00057 const bool NO_DLG = false;
00058 const QString OUT_FILE_ACTUAL ("../test/test_segment_fill.gnuplot_actual");
00059 const QString OUT_FILE_EXPECTED ("../test/test_segment_fill.gnuplot_expected");
00060
00061 QList<Segment*> segments;
00062
00063
00064 QDir::setCurrent (QApplication::applicationDirPath());
00065
00066 QImage img ("../samples/corners.png");
00067
00068 QGraphicsScene *scene = new QGraphicsScene;
00069 SegmentFactory segmentFactory (*scene,
00070 NO_GNUPLOT);
00071
00072 DocumentModelSegments modelSegments;
00073
00074 segmentFactory.clearSegments (segments);
00075
00076
00077 segmentFactory.makeSegments (img,
00078 modelSegments,
00079 segments,
00080 NO_DLG);
00081
00082
00083 QFile out (OUT_FILE_ACTUAL);
00084 QTextStream outStr (&out);
00085
00086 out.open(QIODevice::WriteOnly | QIODevice::Text);
00087
00088
00089 for (int indexS = 0; indexS < segments.count(); indexS++) {
00090 Segment* segment = segments [indexS];
00091
00092 QList<QPoint> points = segment->fillPoints (modelSegments);
00093
00094
00095 if (points.count() > 1) {
00096
00097 for (int indexP = 0; indexP < points.count(); indexP++) {
00098 QPoint point = points [indexP];
00099
00100
00101
00102 outStr << point.x() << " " << point.y() << endl;
00103 }
00104
00105
00106 outStr << endl;
00107 }
00108 }
00109
00110 out.close();
00111
00112
00113 QCryptographicHash hashActual (QCryptographicHash::Sha1);
00114 QCryptographicHash hashExpected (QCryptographicHash::Sha1);
00115 QFile fileActual (OUT_FILE_ACTUAL);
00116 QFile fileExpected (OUT_FILE_EXPECTED);
00117
00118 bool success = false;
00119 if (fileActual.open(QIODevice::ReadOnly) && fileExpected.open(QIODevice::ReadOnly)) {
00120 hashActual.addData (fileActual.readAll());
00121 hashExpected.addData (fileExpected.readAll());
00122 QByteArray signatureActual = hashActual.result();
00123 QByteArray signatureExpected = hashExpected.result();
00124
00125
00126 success = (signatureActual == signatureExpected);
00127 }
00128
00129 QVERIFY (success);
00130 }