From 51ee04ca34047f37fcda30f9936dd461ee42ca30 Mon Sep 17 00:00:00 2001 From: bgbsww Date: Tue, 16 Jan 2024 19:13:29 -0500 Subject: [PATCH] Tests for transferred TopoShapeMapper objects --- tests/src/Mod/Part/App/CMakeLists.txt | 1 + tests/src/Mod/Part/App/TopoShapeMapper.cpp | 121 +++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 tests/src/Mod/Part/App/TopoShapeMapper.cpp diff --git a/tests/src/Mod/Part/App/CMakeLists.txt b/tests/src/Mod/Part/App/CMakeLists.txt index f2467f3b12..9c642e65e2 100644 --- a/tests/src/Mod/Part/App/CMakeLists.txt +++ b/tests/src/Mod/Part/App/CMakeLists.txt @@ -15,4 +15,5 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/TopoShape.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeCache.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeExpansion.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeMapper.cpp ) diff --git a/tests/src/Mod/Part/App/TopoShapeMapper.cpp b/tests/src/Mod/Part/App/TopoShapeMapper.cpp new file mode 100644 index 0000000000..047dd1c3a9 --- /dev/null +++ b/tests/src/Mod/Part/App/TopoShapeMapper.cpp @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include "gtest/gtest.h" +#include "src/App/InitApplication.h" +#include +#include "Mod/Part/App/TopoShapeMapper.h" + +#include +#include +#include +#include +#include +#include +#include + +// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers) + +class TopoShapeMapperTest: public ::testing::Test +{ +protected: + static void SetUpTestSuite() + { + tests::initApplication(); + } + + void SetUp() override + { + _docName = App::GetApplication().getUniqueDocumentName("test"); + App::GetApplication().newDocument(_docName.c_str(), "testUser"); + } + + void TearDown() override + { + App::GetApplication().closeDocument(_docName.c_str()); + } + +private: + std::string _docName; +}; + +TEST_F(TopoShapeMapperTest, shapeHasherTests) +{ + // 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}; + auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(1.0, 1.0, 0.0)).Edge(); + Part::TopoShape topoShape2 {edge2}; + std::pair pair1(topoShape, topoShape2); + std::pair pair2(topoShape, topoShape); + std::pair pair3(edge, edge2); + std::pair pair4(edge, edge); + struct Part::ShapeHasher hasher; + + // Act + size_t hash1 = hasher(topoShape); + size_t hash2 = hasher(topoShape2); + size_t hash3 = hasher(edge); + size_t hash4 = hasher(edge2); + size_t hash5 = hasher(topoShape, topoShape); + size_t hash6 = hasher(topoShape, topoShape2); + size_t hash7 = hasher(edge, edge); + size_t hash8 = hasher(edge, edge2); + size_t hash9 = hasher(pair1); + size_t hash10 = hasher(pair2); + size_t hash11 = hasher(pair3); + size_t hash12 = hasher(pair4); + size_t hash13 = hasher(pair1, pair1); + size_t hash14 = hasher(pair1, pair2); + size_t hash15 = hasher(pair3, pair3); + size_t hash16 = hasher(pair3, pair4); + + // Assert + EXPECT_EQ(hash1, hash3); + EXPECT_EQ(hash2, hash4); + EXPECT_NE(hash1, hash2); + EXPECT_TRUE(hash5); + EXPECT_FALSE(hash6); + EXPECT_TRUE(hash7); + EXPECT_FALSE(hash8); + EXPECT_EQ(hash9, hash11); + EXPECT_EQ(hash10, hash12); + EXPECT_NE(hash9, hash10); + EXPECT_TRUE(hash13); + EXPECT_FALSE(hash14); + EXPECT_TRUE(hash15); + EXPECT_FALSE(hash16); +} + +TEST_F(TopoShapeMapperTest, mapperMakerTests) +{ + // How can this be tested? +} + +TEST_F(TopoShapeMapperTest, mapperHistoryTests) +{ + // How can this be tested? +} + +TEST_F(TopoShapeMapperTest, shapeMapperTests) +{ + // Arrange + auto mapper = Part::ShapeMapper(); + auto boxMaker1 = BRepPrimAPI_MakeBox(1.0, 1.0, 1.0); + boxMaker1.Build(); + auto box1 = boxMaker1.Shape(); + Part::TopoShape topoShape1 {box1}; + + // Act + auto e = topoShape1.getSubTopoShapes(TopAbs_EDGE); + mapper.populate(false, box1, {e[0], e[1], e[2], e[3]}); + mapper.populate(true, box1, {e[4], e[5], e[6]}); + std::vector vec1 = mapper.modified(box1); + std::vector vec2 = mapper.generated(box1); + + // Assert + EXPECT_EQ(vec1.size(), 4); + EXPECT_EQ(vec2.size(), 3); +} + + +// // NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)