-
Notifications
You must be signed in to change notification settings - Fork 120
Test OcdFileImport::fillPathCoords #2270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
|
|
||
| #include <algorithm> | ||
| // IWYU pragma: no_include <array> | ||
| #include <cstddef> | ||
| // IWYU pragma: no_include <initializer_list> | ||
| #include <limits> | ||
| #include <memory> | ||
|
|
@@ -40,10 +41,12 @@ | |
| #include <QDir> | ||
| #include <QFile> | ||
| #include <QFileInfo> | ||
| #include <QFlags> | ||
| #include <QIODevice> | ||
| #include <QLatin1Char> | ||
| #include <QLatin1String> | ||
| #include <QMetaObject> | ||
| #include <QMetaType> | ||
| #include <QPageSize> | ||
| #include <QPoint> | ||
| #include <QPointF> | ||
|
|
@@ -1228,6 +1231,8 @@ struct TestOcdFileImport : public OcdFileImport | |
| } | ||
|
|
||
| using OcdFileImport::getObjectText; | ||
| using OcdFileImport::fillPathCoords; | ||
| using OcdFileImport::OcdImportedPathObject; | ||
| }; | ||
|
|
||
| void FileFormatTest::ocdTextImportTest_data() | ||
|
|
@@ -1306,6 +1311,236 @@ void FileFormatTest::ocdTextImportTest() | |
| } | ||
|
|
||
|
|
||
| struct OcdPointsView { | ||
| const Ocd::OcdPoint32* data = nullptr; | ||
| int size = 0; | ||
|
|
||
| OcdPointsView() = default; | ||
|
|
||
| template <class T, std::size_t n> | ||
| explicit OcdPointsView(T(& t)[n]) | ||
| : data { t } | ||
| , size { int(n) } | ||
| {} | ||
| }; | ||
| Q_DECLARE_METATYPE(OcdPointsView) | ||
|
|
||
| struct FlagsView { | ||
| const int* data = nullptr; | ||
| int size = 0; | ||
|
|
||
| FlagsView() = default; | ||
|
|
||
| template <class T, std::size_t n> | ||
| explicit FlagsView(T(& t)[n], int size) | ||
| : data { t } | ||
| , size { size } | ||
| {} | ||
|
|
||
| template <class T, std::size_t n> | ||
| explicit FlagsView(T(& t)[n]) | ||
| : data { t } | ||
| , size { int(n) } | ||
| {} | ||
| }; | ||
| Q_DECLARE_METATYPE(FlagsView) | ||
|
|
||
| enum OcdPathPersonality { | ||
| Line = 0, | ||
| Area = 1 | ||
| }; | ||
| Q_DECLARE_METATYPE(OcdPathPersonality) | ||
|
|
||
| void FileFormatTest::ocdPathImportTest_data() | ||
| { | ||
| #define C(x) ((int)((unsigned int)(x)<<8)) // FIXME: Not the same as in export | ||
| constexpr auto ocd_flag_gap = 8; // TODO: implement as Ocd::OcdPoint32::FlagGap | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| QTest::addColumn<OcdPointsView>("points"); | ||
| QTest::addColumn<OcdPathPersonality>("personality"); | ||
| QTest::addColumn<FlagsView>("expected"); | ||
|
|
||
| { | ||
| // bezier curve | ||
| static Ocd::OcdPoint32 ocd_points[] = { | ||
| { C(-1109), C(212) }, | ||
| { C(-1035) | Ocd::OcdPoint32::FlagCtl1, C(302) }, | ||
| { C(-1008) | Ocd::OcdPoint32::FlagCtl2, C(519) }, | ||
| { C(-926), C(437) } // different from first point | ||
| }; | ||
| static int expected_flags[] = { | ||
| MapCoord::CurveStart, | ||
| 0, | ||
| 0, | ||
| 0, | ||
| MapCoord::ClosePoint // injected by Mapper | ||
| }; | ||
| QTest::newRow("bezier, area") << OcdPointsView(ocd_points) << Area << FlagsView(expected_flags); | ||
| QTest::newRow("bezier, line") << OcdPointsView(ocd_points) << Line << FlagsView(expected_flags, 4); | ||
| } | ||
|
|
||
| { | ||
| // straight segments, corner flag | ||
| static Ocd::OcdPoint32 ocd_points[] = { | ||
| { C(-589), C(432) }, | ||
| { C(-269), C(845) | Ocd::OcdPoint32::FlagCorner }, | ||
| { C(267), C(279) }, // different from first point | ||
| }; | ||
| static int expected_flags[] = { | ||
| 0, | ||
| MapCoord::DashPoint, | ||
| 0, | ||
| MapCoord::ClosePoint // injected by Mapper | ||
| }; | ||
| QTest::newRow("straight, area") << OcdPointsView(ocd_points) << Area << FlagsView(expected_flags); | ||
| QTest::newRow("straight, line") << OcdPointsView(ocd_points) << Line << FlagsView(expected_flags, 3); | ||
| } | ||
|
|
||
| { | ||
| // straight segments, virtual gap | ||
| static Ocd::OcdPoint32 ocd_points[] = { | ||
| { C(-972), C(-264) }, | ||
| { C(-836) | Ocd::OcdPoint32::FlagLeft | ocd_flag_gap, C(-151) | Ocd::OcdPoint32::FlagRight }, | ||
| { C(-677), C(-19) }, | ||
| { C(-518), C(112) } // different from first point | ||
| }; | ||
| static int expected_flags[] = { | ||
| 0, | ||
| 0, | ||
| 0, | ||
| 0, | ||
| MapCoord::ClosePoint // injected by Mapper | ||
| }; | ||
| QTest::newRow("virtual gap, area") << OcdPointsView(ocd_points) << Area << FlagsView(expected_flags); | ||
| QTest::newRow("virtual gap, line") << OcdPointsView(ocd_points) << Line << FlagsView(expected_flags, 4); | ||
| } | ||
|
|
||
| { | ||
| // straight segments, one hole | ||
| static Ocd::OcdPoint32 ocd_points[] = { | ||
| { C(100), C(-250) }, | ||
| { C(150), C(-260) }, | ||
| { C(100), C(-250) }, // same as first point | ||
| { C(200), C(-350) | Ocd::OcdPoint32::FlagHole }, | ||
| { C(220), C(-400) }, | ||
| { C(200), C(-350) } // same as first point of hole | ||
| }; | ||
| static int expected_flags_area[] = { | ||
| 0, | ||
| 0, | ||
| MapCoord::ClosePoint | MapCoord::HolePoint, | ||
| 0, | ||
| 0, | ||
| MapCoord::ClosePoint | ||
| }; | ||
| QTest::newRow("hole, area") << OcdPointsView(ocd_points) << Area << FlagsView(expected_flags_area); | ||
| static int expected_flags_line[6] = {}; | ||
| QTest::newRow("hole, line") << OcdPointsView(ocd_points) << Line << FlagsView(expected_flags_line); | ||
| } | ||
|
|
||
| { | ||
| // straight segments, with an "empty" hole | ||
| static Ocd::OcdPoint32 ocd_points[] = { | ||
| { C(100), C(-250) }, | ||
| { C(150), C(-260) }, | ||
| { C(100), C(-250) }, // same as first point | ||
| { C(120), C(-200) | Ocd::OcdPoint32::FlagHole }, | ||
| { C(200), C(-350) | Ocd::OcdPoint32::FlagHole }, | ||
| { C(220), C(-400) }, | ||
| { C(200), C(-350) } // same as second FlagHole point | ||
| }; | ||
| static int expected_flags_area[] = { | ||
| 0, | ||
| 0, | ||
| MapCoord::ClosePoint | MapCoord::HolePoint, | ||
| MapCoord::ClosePoint | MapCoord::HolePoint, | ||
| 0, | ||
| 0, | ||
| MapCoord::ClosePoint | ||
| }; | ||
| QTest::newRow("empty hole, area") << OcdPointsView(ocd_points) << Area << FlagsView(expected_flags_area); | ||
| static int expected_flags_line[7] = {}; | ||
| QTest::newRow("empty hole, line") << OcdPointsView(ocd_points) << Line << FlagsView(expected_flags_line); | ||
| } | ||
|
|
||
| { | ||
| // straight segments, with two "empty" holes | ||
| static Ocd::OcdPoint32 ocd_points[] = { | ||
| { C(100), C(-250) }, | ||
| { C(150), C(-260) }, | ||
| { C(100), C(-250) }, // same as first point | ||
| { C(120), C(-200) | Ocd::OcdPoint32::FlagHole }, | ||
| { C(140), C(-300) | Ocd::OcdPoint32::FlagHole }, | ||
| { C(200), C(-350) | Ocd::OcdPoint32::FlagHole }, | ||
| { C(220), C(-400) }, | ||
| { C(200), C(-350) }, // same as third FlagHole point | ||
| }; | ||
| static int expected_flags_area[] = { | ||
| 0, | ||
| 0, | ||
| MapCoord::ClosePoint | MapCoord::HolePoint, | ||
| MapCoord::ClosePoint | MapCoord::HolePoint, | ||
| MapCoord::ClosePoint | MapCoord::HolePoint, | ||
| 0, | ||
| 0, | ||
| MapCoord::ClosePoint | ||
| }; | ||
| QTest::newRow("two empty holes, area") << OcdPointsView(ocd_points) << Area << FlagsView(expected_flags_area); | ||
| static int expected_flags_line[8] = {}; | ||
| QTest::newRow("two empty holes, line") << OcdPointsView(ocd_points) << Line << FlagsView(expected_flags_line); | ||
| } | ||
|
|
||
| { | ||
| // straight segments, one hole, not actual ares | ||
| static Ocd::OcdPoint32 ocd_points[] = { | ||
| { C(100), C(-250) }, | ||
| { C(150), C(-260) }, | ||
| { C(200), C(-350) | Ocd::OcdPoint32::FlagHole }, | ||
| { C(220), C(-400) } | ||
| }; | ||
| static int expected_flags_area[] = { | ||
| 0, | ||
| 0, | ||
| MapCoord::ClosePoint | MapCoord::HolePoint, // injected by Mapper | ||
| 0, | ||
| 0, | ||
| MapCoord::ClosePoint // injected by Mapper | ||
| }; | ||
| QTest::newRow("open areas with hole, area") << OcdPointsView(ocd_points) << Area << FlagsView(expected_flags_area); | ||
| static int expected_flags_line[4] = {}; | ||
| QTest::newRow("open areas with hole, line") << OcdPointsView(ocd_points) << Line << FlagsView(expected_flags_line); | ||
| } | ||
| } | ||
|
|
||
| void FileFormatTest::ocdPathImportTest() | ||
| { | ||
| QFETCH(OcdPointsView, points); | ||
| QFETCH(OcdPathPersonality, personality); | ||
| QFETCH(FlagsView, expected); | ||
|
|
||
| TestOcdFileImport ocd_v12_import{12}; | ||
|
|
||
| TestOcdFileImport::OcdImportedPathObject path_object; | ||
| ocd_v12_import.fillPathCoords(&path_object, personality == Area, points.size, points.data); | ||
| QVERIFY(path_object.getRawCoordinateVector().size() > 0); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a time when |
||
|
|
||
| QCOMPARE(path_object.getRawCoordinateVector().size(), expected.size); | ||
| for (int i = 0; i < expected.size; ++i) | ||
| { | ||
| // Provide the current index when failing. | ||
| if (path_object.getCoordinate(i).flags() != MapCoord::Flags(expected.data[i])) | ||
| { | ||
| auto err = QString::fromLatin1("Compared flags are not the same at index %1\n" | ||
| " Actual : %2\n" | ||
| " Expected: %3" | ||
| ).arg(QString::number(i), | ||
| QString::number(path_object.getCoordinate(i).flags()), | ||
| QString::number(expected.data[i]) | ||
| ); | ||
| QFAIL(qPrintable(err)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| * We don't need a real GUI window. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as we don't check the actual x/y values, it doesn't need action.