Engauge Digitizer 2
Loading...
Searching...
No Matches
TestSegmentFill.cpp
1#include <iostream>
2#include "Logger.h"
3#include "MainWindow.h"
4#include <QCryptographicHash>
5#include <QGraphicsScene>
6#include <QGraphicsView>
7#include <QList>
8#include <qmath.h>
9#include <QTextStream>
10#include <QtTest/QtTest>
11#include "Segment.h"
12#include "SegmentFactory.h"
13#include "Spline.h"
14#include "SplinePair.h"
15#include "Test/TestSegmentFill.h"
16
17QTEST_MAIN (TestSegmentFill)
18
19using namespace std;
20
22 QObject(parent)
23{
24}
25
26void TestSegmentFill::cleanupTestCase ()
27{
28
29}
30
31void TestSegmentFill::initTestCase ()
32{
33 const QString NO_ERROR_REPORT_LOG_FILE;
34 const QString NO_REGRESSION_OPEN_FILE;
35 const bool NO_GNUPLOT_LOG_FILES = false;
36 const bool NO_REGRESSION_IMPORT = false;
37 const bool DEBUG_FLAG = false;
38 const QStringList NO_LOAD_STARTUP_FILES;
39
40 initializeLogging ("engauge_test",
41 "engauge_test.log",
42 DEBUG_FLAG);
43
44 MainWindow m (NO_ERROR_REPORT_LOG_FILE,
45 NO_REGRESSION_OPEN_FILE,
46 NO_GNUPLOT_LOG_FILES,
47 NO_REGRESSION_IMPORT,
48 NO_LOAD_STARTUP_FILES);
49 m.show ();
50}
51
52void TestSegmentFill::testFindSegments()
53{
54 const bool NO_GNUPLOT = false;
55 const bool NO_DLG = false;
56 const QString OUT_FILE_ACTUAL ("../test/test_segment_fill.gnuplot_actual");
57 const QString OUT_FILE_EXPECTED ("../test/test_segment_fill.gnuplot_expected");
58
59 QList<Segment*> segments;
60
61 QImage img ("../samples/corners.png");
62
63 QGraphicsScene *scene = new QGraphicsScene;
64 SegmentFactory segmentFactory (*scene,
65 NO_GNUPLOT);
66
67 DocumentModelSegments modelSegments;
68
69 segmentFactory.clearSegments (segments);
70
71 // This will crash if dialog box appears since QApplication is not executing and therefore cannot process events
72 segmentFactory.makeSegments (img,
73 modelSegments,
74 segments,
75 NO_DLG);
76
77 // Open output file
78 QFile out (OUT_FILE_ACTUAL);
79 QTextStream outStr (&out);
80
81 out.open(QIODevice::WriteOnly | QIODevice::Text);
82
83 // Output to file
84 for (int indexS = 0; indexS < segments.count(); indexS++) {
85 Segment* segment = segments [indexS];
86
87 QList<QPoint> points = segment->fillPoints (modelSegments);
88
89 // Skip segments with only one point since they are apparently random
90 if (points.count() > 1) {
91
92 for (int indexP = 0; indexP < points.count(); indexP++) {
93 QPoint point = points [indexP];
94
95 // Output in gnuplot format for plotting. A space precedes each field. This can be plotted with
96 // plot "../test/test_segment_fill.gnuplot_actual" w lp
97 outStr << point.x() << " " << point.y() << endl;
98 }
99
100 // Blank line between curves
101 outStr << endl;
102 }
103 }
104
105 out.close();
106
107 // Hash values
108 QCryptographicHash hashActual (QCryptographicHash::Sha1);
109 QCryptographicHash hashExpected (QCryptographicHash::Sha1);
110 QFile fileActual (OUT_FILE_ACTUAL);
111 QFile fileExpected (OUT_FILE_EXPECTED);
112
113 bool success = false;
114 if (fileActual.open(QIODevice::ReadOnly) && fileExpected.open(QIODevice::ReadOnly)) {
115 hashActual.addData (fileActual.readAll());
116 hashExpected.addData (fileExpected.readAll());
117 QByteArray signatureActual = hashActual.result();
118 QByteArray signatureExpected = hashExpected.result();
119
120 // Compare
121 success = (signatureActual == signatureExpected);
122 }
123
124 QVERIFY (success);
125}
Model for DlgSettingsSegments and CmdSettingsSegments.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition MainWindow.h:78
Factory class for Segment objects.
Selectable piecewise-defined line that follows a filtered line in the image.
Definition Segment.h:22
QList< QPoint > fillPoints(const DocumentModelSegments &modelSegments)
Create evenly spaced points along the segment.
Definition Segment.cpp:208
Unit test of segment fill feature.
TestSegmentFill(QObject *parent=0)
Single constructor.