From b64644a809c8d763ad64265d874b48fe87e08b7e Mon Sep 17 00:00:00 2001 From: Matthias Kuehlewein Date: Sun, 28 Jul 2024 17:38:32 +0200 Subject: [PATCH 1/7] OcdFileImport: Add unit test --- test/file_format_t.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++ test/file_format_t.h | 8 ++++- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/test/file_format_t.cpp b/test/file_format_t.cpp index 3d93ddc9a..024b27ada 100644 --- a/test/file_format_t.cpp +++ b/test/file_format_t.cpp @@ -94,6 +94,8 @@ using namespace OpenOrienteering; +Q_DECLARE_METATYPE(Ocd::OcdPoint32*) +Q_DECLARE_METATYPE(int*) #ifdef QT_PRINTSUPPORT_LIB @@ -1228,6 +1230,8 @@ struct TestOcdFileImport : public OcdFileImport } using OcdFileImport::getObjectText; + using OcdFileImport::fillPathCoords; + using OcdFileImport::OcdImportedPathObject; }; void FileFormatTest::ocdTextImportTest_data() @@ -1305,7 +1309,73 @@ void FileFormatTest::ocdTextImportTest() } } +void FileFormatTest::ocdPathImportTest_data() +{ +#define C(x) ((int)((unsigned int)(x)<<8)) + // TODO: replace | 8 by Ocd::OcdPoint32::FlagGap + static Ocd::OcdPoint32 coords[] = { + { C(-1109), C(212) }, { C(-1035) | Ocd::OcdPoint32::FlagCtl1, C(302) }, { C(-1008) | Ocd::OcdPoint32::FlagCtl2, C(519) }, { C(-926), C(437) }, // area is not closed + { C(-589), C(432) }, { C(-269), C(845) | Ocd::OcdPoint32::FlagCorner }, { C(267), C(279) }, // area is not closed + { C(-972), C(-264) }, { C(-836) | Ocd::OcdPoint32::FlagLeft | 8, C(-151) | Ocd::OcdPoint32::FlagRight }, { C(-677), C(-19) }, { C(-518), C(112) }, // area is not closed + { C(100), C(-250) }, { C(150), C(-260) }, { C(100), C(-250) }, { C(200), C(-350) | Ocd::OcdPoint32::FlagHole }, { C(220), C(-400) }, { C(200), C(-350) }, // area is closed + { C(100), C(-250) }, { C(150), C(-260) }, { C(100), C(-250) }, { C(120), C(-200) | Ocd::OcdPoint32::FlagHole }, { C(200), C(-350) | Ocd::OcdPoint32::FlagHole }, { C(220), C(-400) }, { C(200), C(-350) }, + { C(100), C(-250) }, { C(150), C(-260) }, { C(100), C(-250) }, { 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) }, + { C(100), C(-250) }, { C(150), C(-260) }, { C(200), C(-350) | Ocd::OcdPoint32::FlagHole }, { C(220), C(-400) }, // areas are not closed + }; + + static int resulting_flags[] = { + MapCoord::CurveStart, 0, 0, 0, MapCoord::ClosePoint, + 0, MapCoord::DashPoint, 0, MapCoord::ClosePoint, + 0, 0, 0, 0, MapCoord::ClosePoint, + 0, 0, MapCoord::ClosePoint | MapCoord::HolePoint, 0, 0, MapCoord::ClosePoint, + // same as above + // same as above + // same as above + }; + + QTest::addColumn("first"); + QTest::addColumn("num"); + QTest::addColumn("expected_coordinates"); + QTest::addColumn("expected_flags"); + + QTest::newRow("bezier curve") << coords+0 << 4u << 5 << resulting_flags+0; + QTest::newRow("straight curve") << coords+4 << 3u << 4 << resulting_flags+5; + QTest::newRow("straight curve with virtual gap") << coords+7 << 4u << 5 << resulting_flags+9; + QTest::newRow("straight curve with hole") << coords+11 << 6u << 6 << resulting_flags+14; + QTest::newRow("straight curve with empty hole") << coords+17 << 7u << 6 << resulting_flags+14; + QTest::newRow("straight curve with two empty holes") << coords+24 << 8u << 6 << resulting_flags+14; + QTest::newRow("unclosed areas with hole") << coords+32 << 4u << 6 << resulting_flags+14; +} + +void FileFormatTest::ocdPathImportTest() +{ + QFETCH(Ocd::OcdPoint32*, first); + QFETCH(quint32, num); + QFETCH(int, expected_coordinates); + QFETCH(int*, expected_flags); + + TestOcdFileImport ocd_v12_import{12}; + + TestOcdFileImport::OcdImportedPathObject path_object; + ocd_v12_import.fillPathCoords(&path_object, true, num, first); + + QCOMPARE(path_object.getRawCoordinateVector().size(), expected_coordinates); + if (expected_flags) + { + for (int i = 0; i < expected_coordinates; ++i) + { + // QCOMPARE(path_object.getCoordinate(i).flags(), *expected_flags); + // the code below provides more details when failing + if (path_object.getCoordinate(i).flags() != static_cast(*expected_flags)) + { + QString err = QLatin1String("failing at %1: expected %2, actual %3").arg(QString::number(i)).arg(QString::number(*expected_flags)).arg(QString::number(path_object.getCoordinate(i).flags())); + QFAIL(err.toLocal8Bit().constData()); + } + ++expected_flags; + } + } +} /* * We don't need a real GUI window. diff --git a/test/file_format_t.h b/test/file_format_t.h index 1eb8cec01..3a901a442 100644 --- a/test/file_format_t.h +++ b/test/file_format_t.h @@ -24,7 +24,6 @@ #include #include - /** * @test Tests concerning the file formats, registry, import and export. * @@ -121,6 +120,13 @@ private slots: */ void ocdTextImportTest_data(); void ocdTextImportTest(); + + /** + * Test path import from OCD. + */ + void ocdPathImportTest_data(); + void ocdPathImportTest(); + }; #endif // OPENORIENTEERING_FILE_FORMAT_T_H From f8ad72713d6e241b7da373f7ab9fd4ae2b61525c Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Wed, 31 Jul 2024 05:21:29 +0200 Subject: [PATCH 2/7] Fix build --- test/file_format_t.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/file_format_t.cpp b/test/file_format_t.cpp index 024b27ada..39986fd72 100644 --- a/test/file_format_t.cpp +++ b/test/file_format_t.cpp @@ -1369,8 +1369,8 @@ void FileFormatTest::ocdPathImportTest() // the code below provides more details when failing if (path_object.getCoordinate(i).flags() != static_cast(*expected_flags)) { - QString err = QLatin1String("failing at %1: expected %2, actual %3").arg(QString::number(i)).arg(QString::number(*expected_flags)).arg(QString::number(path_object.getCoordinate(i).flags())); - QFAIL(err.toLocal8Bit().constData()); + auto err = QString::fromLatin1("failing at %1: expected %2, actual %3").arg(QString::number(i), QString::number(*expected_flags), QString::number(path_object.getCoordinate(i).flags())); + QFAIL(qPrintable(err)); } ++expected_flags; } From 9cf14f090a95abd819b0e55f4fcafa85137939ce Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Wed, 31 Jul 2024 05:27:22 +0200 Subject: [PATCH 3/7] Tune output --- test/file_format_t.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/file_format_t.cpp b/test/file_format_t.cpp index 39986fd72..8e52c8343 100644 --- a/test/file_format_t.cpp +++ b/test/file_format_t.cpp @@ -1366,10 +1366,11 @@ void FileFormatTest::ocdPathImportTest() for (int i = 0; i < expected_coordinates; ++i) { // QCOMPARE(path_object.getCoordinate(i).flags(), *expected_flags); - // the code below provides more details when failing + // Provide the current index when failing. if (path_object.getCoordinate(i).flags() != static_cast(*expected_flags)) { - auto err = QString::fromLatin1("failing at %1: expected %2, actual %3").arg(QString::number(i), QString::number(*expected_flags), QString::number(path_object.getCoordinate(i).flags())); + 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_flags)); QFAIL(qPrintable(err)); } ++expected_flags; From 2124eaaa10ca55a5b56e11dae9ffebe9ce6c63c4 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Wed, 31 Jul 2024 06:58:20 +0200 Subject: [PATCH 4/7] Nit-pick --- test/file_format_t.cpp | 94 +++++++++++++++++++++++++++++------------- 1 file changed, 66 insertions(+), 28 deletions(-) diff --git a/test/file_format_t.cpp b/test/file_format_t.cpp index 8e52c8343..bdaaf0f07 100644 --- a/test/file_format_t.cpp +++ b/test/file_format_t.cpp @@ -40,10 +40,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -1311,47 +1313,84 @@ void FileFormatTest::ocdTextImportTest() void FileFormatTest::ocdPathImportTest_data() { -#define C(x) ((int)((unsigned int)(x)<<8)) - // TODO: replace | 8 by Ocd::OcdPoint32::FlagGap + #define C(x) ((int)((unsigned int)(x)<<8)) + constexpr auto ocd_flag_gap = 8; // TODO: implement as Ocd::OcdPoint32::FlagGap static Ocd::OcdPoint32 coords[] = { - { C(-1109), C(212) }, { C(-1035) | Ocd::OcdPoint32::FlagCtl1, C(302) }, { C(-1008) | Ocd::OcdPoint32::FlagCtl2, C(519) }, { C(-926), C(437) }, // area is not closed - { C(-589), C(432) }, { C(-269), C(845) | Ocd::OcdPoint32::FlagCorner }, { C(267), C(279) }, // area is not closed - { C(-972), C(-264) }, { C(-836) | Ocd::OcdPoint32::FlagLeft | 8, C(-151) | Ocd::OcdPoint32::FlagRight }, { C(-677), C(-19) }, { C(-518), C(112) }, // area is not closed - { C(100), C(-250) }, { C(150), C(-260) }, { C(100), C(-250) }, { C(200), C(-350) | Ocd::OcdPoint32::FlagHole }, { C(220), C(-400) }, { C(200), C(-350) }, // area is closed - { C(100), C(-250) }, { C(150), C(-260) }, { C(100), C(-250) }, { C(120), C(-200) | Ocd::OcdPoint32::FlagHole }, { C(200), C(-350) | Ocd::OcdPoint32::FlagHole }, { C(220), C(-400) }, { C(200), C(-350) }, - { C(100), C(-250) }, { C(150), C(-260) }, { C(100), C(-250) }, { 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) }, - { C(100), C(-250) }, { C(150), C(-260) }, { C(200), C(-350) | Ocd::OcdPoint32::FlagHole }, { C(220), C(-400) }, // areas are not closed + // +0, bezier + { C(-1109), C(212) }, + { C(-1035) | Ocd::OcdPoint32::FlagCtl1, C(302) }, + { C(-1008) | Ocd::OcdPoint32::FlagCtl2, C(519) }, + { C(-926), C(437) }, // area is not closed + // +4, straight + { C(-589), C(432) }, + { C(-269), C(845) | Ocd::OcdPoint32::FlagCorner }, + { C(267), C(279) }, // area is not closed + // +7, straight with virtual gap + { 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) }, // area is not closed + // +11, straight with hole + { C(100), C(-250) }, + { C(150), C(-260) }, + { C(100), C(-250) }, + { C(200), C(-350) | Ocd::OcdPoint32::FlagHole }, + { C(220), C(-400) }, + { C(200), C(-350) }, // area is closed + // +17, straight with empty hole + { C(100), C(-250) }, + { C(150), C(-260) }, + { C(100), C(-250) }, + { C(120), C(-200) | Ocd::OcdPoint32::FlagHole }, + { C(200), C(-350) | Ocd::OcdPoint32::FlagHole }, + { C(220), C(-400) }, + { C(200), C(-350) }, + // +24, straight with two empty holes + { C(100), C(-250) }, + { C(150), C(-260) }, + { C(100), C(-250) }, + { 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) }, + // +32, open areas with hole + { C(100), C(-250) }, + { C(150), C(-260) }, + { C(200), C(-350) | Ocd::OcdPoint32::FlagHole }, + { C(220), C(-400) }, // areas are not closed }; static int resulting_flags[] = { - MapCoord::CurveStart, 0, 0, 0, MapCoord::ClosePoint, - 0, MapCoord::DashPoint, 0, MapCoord::ClosePoint, - 0, 0, 0, 0, MapCoord::ClosePoint, - 0, 0, MapCoord::ClosePoint | MapCoord::HolePoint, 0, 0, MapCoord::ClosePoint, - // same as above - // same as above - // same as above + // +0 + MapCoord::CurveStart, 0, 0, 0, MapCoord::ClosePoint, + // +5 + 0, MapCoord::DashPoint, 0, MapCoord::ClosePoint, + // +9 + 0, 0, 0, 0, MapCoord::ClosePoint, + // +14 + 0, 0, MapCoord::ClosePoint | MapCoord::HolePoint, 0, 0, MapCoord::ClosePoint, }; QTest::addColumn("first"); QTest::addColumn("num"); - QTest::addColumn("expected_coordinates"); + QTest::addColumn("expected_size"); QTest::addColumn("expected_flags"); - QTest::newRow("bezier curve") << coords+0 << 4u << 5 << resulting_flags+0; - QTest::newRow("straight curve") << coords+4 << 3u << 4 << resulting_flags+5; - QTest::newRow("straight curve with virtual gap") << coords+7 << 4u << 5 << resulting_flags+9; - QTest::newRow("straight curve with hole") << coords+11 << 6u << 6 << resulting_flags+14; - QTest::newRow("straight curve with empty hole") << coords+17 << 7u << 6 << resulting_flags+14; - QTest::newRow("straight curve with two empty holes") << coords+24 << 8u << 6 << resulting_flags+14; - QTest::newRow("unclosed areas with hole") << coords+32 << 4u << 6 << resulting_flags+14; + QTest::newRow("bezier") << coords+0 << 4u << 5 << resulting_flags+0; + QTest::newRow("straight") << coords+4 << 3u << 4 << resulting_flags+5; + QTest::newRow("straight with virtual gap") << coords+7 << 4u << 5 << resulting_flags+9; + QTest::newRow("straight with hole") << coords+11 << 6u << 6 << resulting_flags+14; + QTest::newRow("straight with empty hole") << coords+17 << 7u << 6 << resulting_flags+14; + QTest::newRow("straight with two empty holes") << coords+24 << 8u << 6 << resulting_flags+14; + QTest::newRow("open areas with hole") << coords+32 << 4u << 6 << resulting_flags+14; } void FileFormatTest::ocdPathImportTest() { QFETCH(Ocd::OcdPoint32*, first); QFETCH(quint32, num); - QFETCH(int, expected_coordinates); + QFETCH(int, expected_size); QFETCH(int*, expected_flags); TestOcdFileImport ocd_v12_import{12}; @@ -1359,11 +1398,11 @@ void FileFormatTest::ocdPathImportTest() TestOcdFileImport::OcdImportedPathObject path_object; ocd_v12_import.fillPathCoords(&path_object, true, num, first); - QCOMPARE(path_object.getRawCoordinateVector().size(), expected_coordinates); + QCOMPARE(path_object.getRawCoordinateVector().size(), expected_size); if (expected_flags) { - for (int i = 0; i < expected_coordinates; ++i) + for (int i = 0; i < expected_size; ++i, ++expected_flags) { // QCOMPARE(path_object.getCoordinate(i).flags(), *expected_flags); // Provide the current index when failing. @@ -1373,7 +1412,6 @@ void FileFormatTest::ocdPathImportTest() .arg(QString::number(i), QString::number(path_object.getCoordinate(i).flags()), QString::number(*expected_flags)); QFAIL(qPrintable(err)); } - ++expected_flags; } } } From 777046f56cf1613b4583178be2b58883989c0c69 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Thu, 1 Aug 2024 09:10:10 +0200 Subject: [PATCH 5/7] Refactor and fix Move expected data closer to input data. Format data more readable. Avoid redundant passing of element counts. Test path coord processing both for areas and lines. --- test/file_format_t.cpp | 298 +++++++++++++++++++++++++++++------------ 1 file changed, 211 insertions(+), 87 deletions(-) diff --git a/test/file_format_t.cpp b/test/file_format_t.cpp index bdaaf0f07..70071eefc 100644 --- a/test/file_format_t.cpp +++ b/test/file_format_t.cpp @@ -22,6 +22,7 @@ #include // IWYU pragma: no_include +#include // IWYU pragma: no_include #include #include @@ -96,8 +97,6 @@ using namespace OpenOrienteering; -Q_DECLARE_METATYPE(Ocd::OcdPoint32*) -Q_DECLARE_METATYPE(int*) #ifdef QT_PRINTSUPPORT_LIB @@ -1311,107 +1310,232 @@ void FileFormatTest::ocdTextImportTest() } } + +struct OcdPointsView { + const Ocd::OcdPoint32* data = nullptr; + int size = 0; + + OcdPointsView() = default; + + template + 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 + explicit FlagsView(T(& t)[n], int size) + : data { t } + , size { size } + {} + + template + 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)) + #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 - static Ocd::OcdPoint32 coords[] = { - // +0, bezier - { C(-1109), C(212) }, - { C(-1035) | Ocd::OcdPoint32::FlagCtl1, C(302) }, - { C(-1008) | Ocd::OcdPoint32::FlagCtl2, C(519) }, - { C(-926), C(437) }, // area is not closed - // +4, straight - { C(-589), C(432) }, - { C(-269), C(845) | Ocd::OcdPoint32::FlagCorner }, - { C(267), C(279) }, // area is not closed - // +7, straight with virtual gap - { 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) }, // area is not closed - // +11, straight with hole - { C(100), C(-250) }, - { C(150), C(-260) }, - { C(100), C(-250) }, - { C(200), C(-350) | Ocd::OcdPoint32::FlagHole }, - { C(220), C(-400) }, - { C(200), C(-350) }, // area is closed - // +17, straight with empty hole - { C(100), C(-250) }, - { C(150), C(-260) }, - { C(100), C(-250) }, - { C(120), C(-200) | Ocd::OcdPoint32::FlagHole }, - { C(200), C(-350) | Ocd::OcdPoint32::FlagHole }, - { C(220), C(-400) }, - { C(200), C(-350) }, - // +24, straight with two empty holes - { C(100), C(-250) }, - { C(150), C(-260) }, - { C(100), C(-250) }, - { 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) }, - // +32, open areas with hole - { C(100), C(-250) }, - { C(150), C(-260) }, - { C(200), C(-350) | Ocd::OcdPoint32::FlagHole }, - { C(220), C(-400) }, // areas are not closed - }; - static int resulting_flags[] = { - // +0 - MapCoord::CurveStart, 0, 0, 0, MapCoord::ClosePoint, - // +5 - 0, MapCoord::DashPoint, 0, MapCoord::ClosePoint, - // +9 - 0, 0, 0, 0, MapCoord::ClosePoint, - // +14 - 0, 0, MapCoord::ClosePoint | MapCoord::HolePoint, 0, 0, MapCoord::ClosePoint, - }; + QTest::addColumn("points"); + QTest::addColumn("personality"); + QTest::addColumn("expected"); - QTest::addColumn("first"); - QTest::addColumn("num"); - QTest::addColumn("expected_size"); - QTest::addColumn("expected_flags"); - - QTest::newRow("bezier") << coords+0 << 4u << 5 << resulting_flags+0; - QTest::newRow("straight") << coords+4 << 3u << 4 << resulting_flags+5; - QTest::newRow("straight with virtual gap") << coords+7 << 4u << 5 << resulting_flags+9; - QTest::newRow("straight with hole") << coords+11 << 6u << 6 << resulting_flags+14; - QTest::newRow("straight with empty hole") << coords+17 << 7u << 6 << resulting_flags+14; - QTest::newRow("straight with two empty holes") << coords+24 << 8u << 6 << resulting_flags+14; - QTest::newRow("open areas with hole") << coords+32 << 4u << 6 << resulting_flags+14; + { + // 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(Ocd::OcdPoint32*, first); - QFETCH(quint32, num); - QFETCH(int, expected_size); - QFETCH(int*, expected_flags); + QFETCH(OcdPointsView, points); + QFETCH(OcdPathPersonality, personality); + QFETCH(FlagsView, expected); TestOcdFileImport ocd_v12_import{12}; TestOcdFileImport::OcdImportedPathObject path_object; - ocd_v12_import.fillPathCoords(&path_object, true, num, first); + ocd_v12_import.fillPathCoords(&path_object, personality == Area, points.size, points.data); + QVERIFY(path_object.getRawCoordinateVector().size() > 0); - QCOMPARE(path_object.getRawCoordinateVector().size(), expected_size); - - if (expected_flags) +// QEXPECT_FAIL("empty hole, area", "", Abort); + QCOMPARE(path_object.getRawCoordinateVector().size(), expected.size); + + for (int i = 0; i < expected.size; ++i) { - for (int i = 0; i < expected_size; ++i, ++expected_flags) + // QCOMPARE(path_object.getCoordinate(i).flags(), *expected); + // Provide the current index when failing. + if (path_object.getCoordinate(i).flags() != static_cast(expected.data[i])) { - // QCOMPARE(path_object.getCoordinate(i).flags(), *expected_flags); - // Provide the current index when failing. - if (path_object.getCoordinate(i).flags() != static_cast(*expected_flags)) - { - 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_flags)); - QFAIL(qPrintable(err)); - } + 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)); } } } From 7f8359de8c1282b17a7076c5494710bc3c560019 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Fri, 2 Aug 2024 06:30:35 +0200 Subject: [PATCH 6/7] Fixup --- test/file_format_t.cpp | 14 ++++++++------ test/file_format_t.h | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/test/file_format_t.cpp b/test/file_format_t.cpp index 70071eefc..cbd7cca90 100644 --- a/test/file_format_t.cpp +++ b/test/file_format_t.cpp @@ -1524,17 +1524,19 @@ void FileFormatTest::ocdPathImportTest() ocd_v12_import.fillPathCoords(&path_object, personality == Area, points.size, points.data); QVERIFY(path_object.getRawCoordinateVector().size() > 0); -// QEXPECT_FAIL("empty hole, area", "", Abort); QCOMPARE(path_object.getRawCoordinateVector().size(), expected.size); - for (int i = 0; i < expected.size; ++i) { - // QCOMPARE(path_object.getCoordinate(i).flags(), *expected); // Provide the current index when failing. - if (path_object.getCoordinate(i).flags() != static_cast(expected.data[i])) + 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])); + 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)); } } diff --git a/test/file_format_t.h b/test/file_format_t.h index 3a901a442..0aad48704 100644 --- a/test/file_format_t.h +++ b/test/file_format_t.h @@ -24,6 +24,7 @@ #include #include + /** * @test Tests concerning the file formats, registry, import and export. * From 613c128a1b8c0ebda340fee470c3b3ae86ed1431 Mon Sep 17 00:00:00 2001 From: Matthias Kuehlewein Date: Fri, 2 Aug 2024 15:16:21 +0200 Subject: [PATCH 7/7] Add more complex test case The test case contains an Ocd::OcdPoint32::FlagDash property which was yet untested as well as a combination of bezier and straight line segments. The area itself contains a hole which itself contains a hole. --- test/file_format_t.cpp | 80 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/test/file_format_t.cpp b/test/file_format_t.cpp index cbd7cca90..51b469ffb 100644 --- a/test/file_format_t.cpp +++ b/test/file_format_t.cpp @@ -1491,7 +1491,7 @@ void FileFormatTest::ocdPathImportTest_data() } { - // straight segments, one hole, not actual ares + // straight segments, one hole, not actual areas static Ocd::OcdPoint32 ocd_points[] = { { C(100), C(-250) }, { C(150), C(-260) }, @@ -1510,6 +1510,84 @@ void FileFormatTest::ocdPathImportTest_data() static int expected_flags_line[4] = {}; QTest::newRow("open areas with hole, line") << OcdPointsView(ocd_points) << Line << FlagsView(expected_flags_line); } + + { + // area with hole in hole + static Ocd::OcdPoint32 ocd_points[] = { + { C(-405), C(-167) }, + { C(-348) | Ocd::OcdPoint32::FlagCtl1, C(22) }, + { C(-113) | Ocd::OcdPoint32::FlagCtl2, C(667) }, + { C(54), C(687) }, + { C(184) | Ocd::OcdPoint32::FlagCtl1, C(702) }, + { C(836) | Ocd::OcdPoint32::FlagCtl2, C(418) }, + { C(889), C(298) }, + { C(599), C(117) }, + { C(137), C(93) | Ocd::OcdPoint32::FlagDash}, // different from first point + { C(-25), C(79) | Ocd::OcdPoint32::FlagHole}, + { C(-208) | Ocd::OcdPoint32::FlagCtl1, C(259) }, + { C(90) | Ocd::OcdPoint32::FlagCtl2, C(652) }, + { C(559), C(322) }, // different from first point of hole + { C(78), C(326) | Ocd::OcdPoint32::FlagHole}, + { C(100) | Ocd::OcdPoint32::FlagCtl1, C(341) }, + { C(157) | Ocd::OcdPoint32::FlagCtl2, C(354) }, + { C(198), C(339) | Ocd::OcdPoint32::FlagCorner }, + { C(227) | Ocd::OcdPoint32::FlagCtl1, C(329) }, + { C(247) | Ocd::OcdPoint32::FlagCtl2, C(304) }, + { C(242), C(256) }, + { C(144), C(243) }, // different from first point of hole + }; + static int expected_flags_area[] = { + MapCoord::CurveStart, + 0, + 0, + MapCoord::CurveStart, + 0, + 0, + 0, + 0, + MapCoord::DashPoint, + MapCoord::ClosePoint | MapCoord::HolePoint, // injected by Mapper + MapCoord::CurveStart, + 0, + 0, + 0, + MapCoord::ClosePoint | MapCoord::HolePoint, // injected by Mapper + MapCoord::CurveStart, + 0, + 0, + MapCoord::DashPoint | MapCoord::CurveStart, + 0, + 0, + 0, + 0, + MapCoord::ClosePoint // injected by Mapper + }; + QTest::newRow("area with nested holes, area") << OcdPointsView(ocd_points) << Area << FlagsView(expected_flags_area); + static int expected_flags_line[] = { + MapCoord::CurveStart, + 0, + 0, + MapCoord::CurveStart, + 0, + 0, + 0, + 0, + MapCoord::DashPoint, + MapCoord::CurveStart, + 0, + 0, + 0, + MapCoord::CurveStart, + 0, + 0, + MapCoord::DashPoint | MapCoord::CurveStart, + 0, + 0, + 0, + 0 + }; + QTest::newRow("area with nested holes, line") << OcdPointsView(ocd_points) << Line << FlagsView(expected_flags_line); + } } void FileFormatTest::ocdPathImportTest()