Tests/Toponaming: Add test framework for makeShapeWithElementMap

This commit is contained in:
Chris Hennes
2024-01-19 14:55:45 -07:00
parent d43fe277a7
commit f91d39bac3
5 changed files with 104 additions and 21 deletions

View File

@@ -15,5 +15,7 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/TopoShape.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeCache.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeExpansion.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeExpansionHelpers.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeMakeShapeWithElementMap.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeMapper.cpp
)

View File

@@ -2,6 +2,7 @@
#include "gtest/gtest.h"
#include "src/App/InitApplication.h"
#include "TopoShapeExpansionHelpers.h"
#include <Mod/Part/App/TopoShape.h>
#include <Mod/Part/App/TopoShapeOpCode.h>
@@ -125,30 +126,10 @@ TEST_F(TopoShapeExpansionTest, makeElementCompoundTwoShapesGeneratesMap)
EXPECT_EQ(4, topoShape.getMappedChildElements().size()); // two vertices and two edges
}
namespace
{
std::pair<TopoDS_Shape, TopoDS_Shape> CreateTwoCubes()
{
auto boxMaker1 = BRepPrimAPI_MakeBox(1.0, 1.0, 1.0);
boxMaker1.Build();
auto box1 = boxMaker1.Shape();
auto boxMaker2 = BRepPrimAPI_MakeBox(1.0, 1.0, 1.0);
boxMaker2.Build();
auto box2 = boxMaker2.Shape();
auto transform = gp_Trsf();
transform.SetTranslation(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0));
box2.Location(TopLoc_Location(transform));
return {box1, box2};
}
} // namespace
TEST_F(TopoShapeExpansionTest, makeElementCompoundTwoCubes)
{
// Arrange
auto [cube1, cube2] = CreateTwoCubes();
auto [cube1, cube2] = TopoShapeExpansionHelpers::CreateTwoCubes();
Part::TopoShape cube1TS {cube1};
cube1TS.Tag = 1;
Part::TopoShape cube2TS {cube2};

View File

@@ -0,0 +1,26 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "TopoShapeExpansionHelpers.h"
#include <BRepPrimAPI_MakeBox.hxx>
namespace TopoShapeExpansionHelpers
{
std::pair<TopoDS_Shape, TopoDS_Shape> CreateTwoCubes()
{
auto boxMaker1 = BRepPrimAPI_MakeBox(1.0, 1.0, 1.0);
boxMaker1.Build();
auto box1 = boxMaker1.Shape();
auto boxMaker2 = BRepPrimAPI_MakeBox(1.0, 1.0, 1.0);
boxMaker2.Build();
auto box2 = boxMaker2.Shape();
auto transform = gp_Trsf();
transform.SetTranslation(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0));
box2.Location(TopLoc_Location(transform));
return {box1, box2};
}
} // namespace TopoShapeExpansionHelpers

View File

@@ -0,0 +1,13 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef FREECAD_TOPOSHAPEEXPANSIONHELPERS_H
#define FREECAD_TOPOSHAPEEXPANSIONHELPERS_H
#include <TopoDS_Shape.hxx>
namespace TopoShapeExpansionHelpers
{
std::pair<TopoDS_Shape, TopoDS_Shape> CreateTwoCubes();
}
#endif // FREECAD_TOPOSHAPEEXPANSIONHELPERS_H

View File

@@ -0,0 +1,61 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Tests for the makeShapeWithElementMap method, extracted from the main set of tests for TopoShape
// due to length and complexity.
#include "gtest/gtest.h"
#include "src/App/InitApplication.h"
#include "TopoShapeExpansionHelpers.h"
#include <Mod/Part/App/TopoShape.h>
#include <TopoDS_Vertex.hxx>
class TopoShapeMakeShapeWithElementMapTests: 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;
}
void TearDown() override
{
App::GetApplication().closeDocument(_docName.c_str());
}
Part::TopoShape* Shape()
{
return &_shape;
}
Part::TopoShape::Mapper* Mapper()
{
return &_mapper;
}
private:
std::string _docName;
Data::ElementIDRefs _sid;
QVector<App::StringIDRef>* _sids = nullptr;
Part::TopoShape _shape;
Part::TopoShape::Mapper _mapper;
};
TEST_F(TopoShapeMakeShapeWithElementMapTests, nullShapeThrows)
{
// Arrange
auto [cube1, cube2] = TopoShapeExpansionHelpers::CreateTwoCubes();
std::vector<Part::TopoShape> sources {cube1, cube2};
TopoDS_Vertex nullShape;
// Act and assert
EXPECT_THROW(Shape()->makeShapeWithElementMap(nullShape, *Mapper(), sources),
Part::NullShapeException);
}