Tests/Toponaming: Add tests for makeElementCompound

This commit is contained in:
Chris Hennes
2024-01-12 10:06:14 -06:00
committed by Yorik van Havre
parent 928c4ce813
commit 60a7f45ece
2 changed files with 120 additions and 9 deletions

View File

@@ -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
)

View File

@@ -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 <Mod/Part/App/TopoShape.h>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <TopoDS_Edge.hxx>
#include <BRep_Builder.hxx>
// 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<App::StringHasher>(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<App::StringIDRef>* _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<Part::TopoShape> 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<Part::TopoShape> 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<Part::TopoShape> 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<Part::TopoShape> 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<Part::TopoShape> 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)