diff --git a/tests/src/Mod/PartDesign/App/BackwardCompatibility.cpp b/tests/src/Mod/PartDesign/App/BackwardCompatibility.cpp new file mode 100644 index 0000000000..42689b5fa9 --- /dev/null +++ b/tests/src/Mod/PartDesign/App/BackwardCompatibility.cpp @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include +#include +#include +#include +#include "src/App/InitApplication.h" + +#include +#include +#include + +// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers) + +class BackwardCompatibilityTest: public ::testing::Test +{ +protected: + static void SetUpTestSuite() + { + tests::initApplication(); + } + + void SetUp() override + { + _testPath = App::Application::getHomePath() + "tests/TestModels/"; + } + + void TearDown() override + { + App::GetApplication().closeDocument(_doc->getName()); + } + + const App::Document* getDocument() const + { + return _doc; + } + + void setDocument(App::Document* doc) + { + _doc = doc; + } + + std::string getTestPath() const + { + return _testPath; + } + +private: + App::Document* _doc = nullptr; // NOLINT Can't be private in a test framework + std::string _testPath; // NOLINT Can't be private in a test framework +}; + +TEST_F(BackwardCompatibilityTest, TestOpenV021Model) +{ + + // arrange + + auto doc = App::GetApplication().openDocument( + std::string(getTestPath() + "ModelFromV021.FCStd").c_str()); + setDocument(doc); + + auto chamfer = dynamic_cast(doc->getObject("Chamfer")); + auto chamferEdgesNames = chamfer->Base.getSubValues(); + + std::vector chamferOriginalEdges {}; + for (const auto& chamferEdgesName : chamferEdgesNames) { + chamferOriginalEdges.push_back( + chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesName.c_str()).getShape()); + } + + // act + + doc->recompute(); + chamfer = dynamic_cast(doc->getObject("Chamfer")); + chamferEdgesNames = chamfer->Base.getSubValues(); + + // assert + + auto checkSameVertexes = [](const TopoDS_Shape& e1, const TopoDS_Shape& e2) { + TopExp_Explorer e1Vertexes(e1, TopAbs_VERTEX); + TopExp_Explorer e2Vertexes(e2, TopAbs_VERTEX); + + bool sameCoords {true}; + bool moreToCheck {e1Vertexes.More() && e2Vertexes.More()}; + + // If one of the vertexes doesn't have the same coordinates of the other one then it'll be + // useless to continue + while (moreToCheck && sameCoords) { + auto p1 = BRep_Tool::Pnt(TopoDS::Vertex(e1Vertexes.Current())); + auto p2 = BRep_Tool::Pnt(TopoDS::Vertex(e2Vertexes.Current())); + + sameCoords &= (p1.X() == p2.X() && p1.Y() == p2.Y() && p1.Z() == p2.Z()); + e1Vertexes.Next(); + e2Vertexes.Next(); + + moreToCheck = (e1Vertexes.More() && e2Vertexes.More()); + + // Extra check: both edges should have the same number of vertexes (e*Vertexes.More() + // should be true or false at the same time for both the edges). + // If this doesn't happen then one of the edges won't have enough vertexes to perform a + // full coordinates comparison. + // This shouldn't happen, so it's here just in case + sameCoords &= (e1Vertexes.More() == e2Vertexes.More()); + } + + return sameCoords; + }; + + EXPECT_TRUE(checkSameVertexes( + chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesNames[0].c_str()).getShape(), + chamferOriginalEdges[0])); + EXPECT_TRUE(checkSameVertexes( + chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesNames[1].c_str()).getShape(), + chamferOriginalEdges[1])); + EXPECT_TRUE(checkSameVertexes( + chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesNames[2].c_str()).getShape(), + chamferOriginalEdges[2])); + EXPECT_TRUE(checkSameVertexes( + chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesNames[3].c_str()).getShape(), + chamferOriginalEdges[3])); +} + +// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers) diff --git a/tests/src/Mod/PartDesign/App/CMakeLists.txt b/tests/src/Mod/PartDesign/App/CMakeLists.txt index 007fd820de..48583700bc 100644 --- a/tests/src/Mod/PartDesign/App/CMakeLists.txt +++ b/tests/src/Mod/PartDesign/App/CMakeLists.txt @@ -2,7 +2,22 @@ target_sources( PartDesign_tests_run PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/BackwardCompatibility.cpp ${CMAKE_CURRENT_SOURCE_DIR}/DatumPlane.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ShapeBinder.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Pad.cpp ) + +set(PartDesignTestData_Files + TestModels/ModelFromV021.FCStd +) + +ADD_CUSTOM_TARGET(PartDesignTestData ALL + SOURCES ${PartDesignTestData_Files} +) + +fc_target_copy_resource(PartDesignTestData + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_BINARY_DIR}/tests + ${PartDesignTestData_Files} +) diff --git a/tests/src/Mod/PartDesign/App/TestModels/ModelFromV021.FCStd b/tests/src/Mod/PartDesign/App/TestModels/ModelFromV021.FCStd new file mode 100644 index 0000000000..2a062d8361 Binary files /dev/null and b/tests/src/Mod/PartDesign/App/TestModels/ModelFromV021.FCStd differ