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 DEBUG_FLAG = false;
00038 const QStringList NO_LOAD_STARTUP_FILES;
00039
00040 initializeLogging ("engauge_test",
00041 "engauge_test.log",
00042 DEBUG_FLAG);
00043
00044 MainWindow m (NO_ERROR_REPORT_LOG_FILE,
00045 NO_REGRESSION_OPEN_FILE,
00046 NO_GNUPLOT_LOG_FILES,
00047 NO_REGRESSION_IMPORT,
00048 NO_LOAD_STARTUP_FILES);
00049 m.show ();
00050 }
00051
00052 void TestSegmentFill::testFindSegments()
00053 {
00054 const bool NO_GNUPLOT = false;
00055 const bool NO_DLG = false;
00056 const QString OUT_FILE_ACTUAL ("../test/test_segment_fill.gnuplot_actual");
00057 const QString OUT_FILE_EXPECTED ("../test/test_segment_fill.gnuplot_expected");
00058
00059 QList<Segment*> segments;
00060
00061
00062 QDir::setCurrent (QApplication::applicationDirPath());
00063
00064 QImage img ("../samples/corners.png");
00065
00066 QGraphicsScene *scene = new QGraphicsScene;
00067 SegmentFactory segmentFactory (*scene,
00068 NO_GNUPLOT);
00069
00070 DocumentModelSegments modelSegments;
00071
00072 segmentFactory.clearSegments (segments);
00073
00074
00075 segmentFactory.makeSegments (img,
00076 modelSegments,
00077 segments,
00078 NO_DLG);
00079
00080
00081 QFile out (OUT_FILE_ACTUAL);
00082 QTextStream outStr (&out);
00083
00084 out.open(QIODevice::WriteOnly | QIODevice::Text);
00085
00086
00087 for (int indexS = 0; indexS < segments.count(); indexS++) {
00088 Segment* segment = segments [indexS];
00089
00090 QList<QPoint> points = segment->fillPoints (modelSegments);
00091
00092
00093 if (points.count() > 1) {
00094
00095 for (int indexP = 0; indexP < points.count(); indexP++) {
00096 QPoint point = points [indexP];
00097
00098
00099
00100 outStr << point.x() << " " << point.y() << endl;
00101 }
00102
00103
00104 outStr << endl;
00105 }
00106 }
00107
00108 out.close();
00109
00110
00111 QCryptographicHash hashActual (QCryptographicHash::Sha1);
00112 QCryptographicHash hashExpected (QCryptographicHash::Sha1);
00113 QFile fileActual (OUT_FILE_ACTUAL);
00114 QFile fileExpected (OUT_FILE_EXPECTED);
00115
00116 bool success = false;
00117 if (fileActual.open(QIODevice::ReadOnly) && fileExpected.open(QIODevice::ReadOnly)) {
00118 hashActual.addData (fileActual.readAll());
00119 hashExpected.addData (fileExpected.readAll());
00120 QByteArray signatureActual = hashActual.result();
00121 QByteArray signatureExpected = hashExpected.result();
00122
00123
00124 success = (signatureActual == signatureExpected);
00125 }
00126
00127 QVERIFY (success);
00128 }