diff --git a/tests/src/Mod/Part/App/CMakeLists.txt b/tests/src/Mod/Part/App/CMakeLists.txt index 1acd3509aa..f2467f3b12 100644 --- a/tests/src/Mod/Part/App/CMakeLists.txt +++ b/tests/src/Mod/Part/App/CMakeLists.txt @@ -2,7 +2,6 @@ target_sources( Part_tests_run PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/TopoShape.cpp ${CMAKE_CURRENT_SOURCE_DIR}/FeatureChamfer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/FeatureCompound.cpp ${CMAKE_CURRENT_SOURCE_DIR}/FeatureExtrusion.cpp @@ -13,10 +12,7 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/FeaturePartFuse.cpp ${CMAKE_CURRENT_SOURCE_DIR}/FeatureRevolution.cpp ${CMAKE_CURRENT_SOURCE_DIR}/PartTestHelpers.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TopoShape.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeCache.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/FeaturePartCommon.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/FeaturePartCut.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/FeaturePartFuse.cpp - # ${CMAKE_CURRENT_SOURCE_DIR}/FeatureFillet.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/PartTestHelpers.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeExpansion.cpp ) diff --git a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp index 702f97331d..50d487d342 100644 --- a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -1,3 +1,118 @@ -// -// Created by Chris Hennes on 1/11/24. -// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include "gtest/gtest.h" +#include "src/App/InitApplication.h" +#include + +#include +#include +#include + +// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers) + +class TopoShapeExpansionTest: public ::testing::Test +{ +protected: + static void SetUpTestSuite() + { + tests::initApplication(); + } + + void SetUp() override + { + _docName = App::GetApplication().getUniqueDocumentName("test"); + App::GetApplication().newDocument(_docName.c_str(), "testUser"); + _sids = &_sid; + _hasher = Base::Reference(new App::StringHasher); + ASSERT_EQ(_hasher.getRefCount(), 1); + } + + void TearDown() override + { + App::GetApplication().closeDocument(_docName.c_str()); + } + +private: + std::string _docName; + Data::ElementIDRefs _sid; + QVector* _sids = nullptr; + App::StringHasherRef _hasher; +}; + +TEST_F(TopoShapeExpansionTest, makeElementCompoundOneShapeReturnsShape) +{ + // Arrange + auto edge = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge(); + Part::TopoShape topoShape {edge}; + std::vector shapes {topoShape}; + + // Act + topoShape.makeElementCompound(shapes, "C", false /*Don't force the creation*/); + + // Assert + EXPECT_EQ(edge.ShapeType(), topoShape.getShape().ShapeType()); // NOT a Compound +} + +TEST_F(TopoShapeExpansionTest, makeElementCompoundOneShapeForceReturnsCompound) +{ + // Arrange + auto edge = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge(); + Part::TopoShape topoShape {edge}; + std::vector shapes {topoShape}; + + // Act + topoShape.makeElementCompound(shapes, "C", true /*Force the creation*/); + + // Assert + EXPECT_NE(edge.ShapeType(), topoShape.getShape().ShapeType()); // No longer the same thing +} + +TEST_F(TopoShapeExpansionTest, makeElementCompoundTwoShapesReturnsCompound) +{ + // Arrange + auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge(); + auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(2.0, 0.0, 0.0)).Edge(); + Part::TopoShape topoShape {edge1}; + std::vector shapes {edge1, edge2}; + + // Act + topoShape.makeElementCompound(shapes); + + // Assert + EXPECT_EQ(TopAbs_ShapeEnum::TopAbs_COMPOUND, topoShape.getShape().ShapeType()); +} + +TEST_F(TopoShapeExpansionTest, makeElementCompoundEmptyShapesReturnsEmptyCompound) +{ + // Arrange + auto edge = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge(); + Part::TopoShape topoShape {edge}; + std::vector shapes; + + // Act + topoShape.makeElementCompound(shapes); + + // Assert + EXPECT_EQ(TopAbs_ShapeEnum::TopAbs_COMPOUND, topoShape.getShape().ShapeType()); + EXPECT_TRUE(topoShape.getMappedChildElements().empty()); +#if OCC_VERSION_HEX >= 0x070400 + EXPECT_EQ(0, topoShape.getShape().TShape()->NbChildren()); +#endif +} + +TEST_F(TopoShapeExpansionTest, makeElementCompoundTwoShapesGeneratesMap) +{ + // Arrange + auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0)).Edge(); + auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(2.0, 0.0, 0.0)).Edge(); + Part::TopoShape topoShape {edge1}; + std::vector shapes {edge1, edge2}; + + // Act + topoShape.makeElementCompound(shapes); + + // Assert + EXPECT_EQ(4, topoShape.getMappedChildElements().size()); // two vertices and two edges +} + +// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)