Add c++ testing framework for PartDesign, ShapeBinder
This commit is contained in:
@@ -90,6 +90,9 @@ endif(BUILD_MESH)
|
||||
if(BUILD_PART)
|
||||
list (APPEND TestExecutables Part_tests_run)
|
||||
endif(BUILD_PART)
|
||||
if(BUILD_PART_DESIGN)
|
||||
list (APPEND TestExecutables PartDesign_tests_run)
|
||||
endif(BUILD_PART_DESIGN)
|
||||
if(BUILD_POINTS)
|
||||
list (APPEND TestExecutables Points_tests_run)
|
||||
endif(BUILD_POINTS)
|
||||
|
||||
@@ -10,6 +10,9 @@ endif(BUILD_MESH)
|
||||
if(BUILD_PART)
|
||||
add_subdirectory(Part)
|
||||
endif(BUILD_PART)
|
||||
if(BUILD_PART_DESIGN)
|
||||
add_subdirectory(PartDesign)
|
||||
endif(BUILD_PART_DESIGN)
|
||||
if(BUILD_POINTS)
|
||||
add_subdirectory(Points)
|
||||
endif(BUILD_POINTS)
|
||||
|
||||
6
tests/src/Mod/PartDesign/App/CMakeLists.txt
Normal file
6
tests/src/Mod/PartDesign/App/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
target_sources(
|
||||
PartDesign_tests_run
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ShapeBinder.cpp
|
||||
)
|
||||
82
tests/src/Mod/PartDesign/App/ShapeBinder.cpp
Normal file
82
tests/src/Mod/PartDesign/App/ShapeBinder.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/App/InitApplication.h"
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include "Mod/Part/App/FeaturePartBox.h"
|
||||
#include "Mod/PartDesign/App/Body.h"
|
||||
#include "Mod/PartDesign/App/ShapeBinder.h"
|
||||
|
||||
// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
|
||||
class ShapeBinderTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
_docName = App::GetApplication().getUniqueDocumentName("test");
|
||||
_doc = App::GetApplication().newDocument(_docName.c_str(), "testUser");
|
||||
_body = dynamic_cast<PartDesign::Body*>(_doc->addObject("PartDesign::Body")); // NOLINT
|
||||
_box = dynamic_cast<Part::Box*>(_doc->addObject("Part::Box")); // NOLINT
|
||||
_box->Length.setValue(1);
|
||||
_box->Width.setValue(2);
|
||||
_box->Height.setValue(3);
|
||||
_box->Placement.setValue(
|
||||
Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())); // NOLINT
|
||||
// _body->addObject(_box); // Invalid, Part::Features can't go in a PartDesign::Body,
|
||||
// but we can bind them.
|
||||
_binder = dynamic_cast<PartDesign::ShapeBinder*>(
|
||||
_doc->addObject("PartDesign::ShapeBinder", "ShapeBinderFoo")); // NOLINT
|
||||
_subbinder = dynamic_cast<PartDesign::SubShapeBinder*>(
|
||||
_doc->addObject("PartDesign::SubShapeBinder", "SubShapeBinderBar")); // NOLINT
|
||||
_binder->Shape.setValue(_box->Shape.getShape());
|
||||
_subbinder->setLinks({{_box, {"Face1", "Face2"}}}, false);
|
||||
_body->addObject(_binder);
|
||||
_body->addObject(_subbinder);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(_docName.c_str());
|
||||
}
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-non-private-member-variables-in-classes)
|
||||
|
||||
App::Document* _doc = nullptr;
|
||||
std::string _docName = "";
|
||||
Part::Box* _box = nullptr;
|
||||
PartDesign::Body* _body = nullptr;
|
||||
PartDesign::ShapeBinder* _binder = nullptr;
|
||||
PartDesign::SubShapeBinder* _subbinder = nullptr;
|
||||
|
||||
// NOLINTEND(cppcoreguidelines-non-private-member-variables-in-classes)
|
||||
};
|
||||
|
||||
TEST_F(ShapeBinderTest, shapeBinderExists)
|
||||
{
|
||||
// Arrange
|
||||
// Act
|
||||
auto binder = _doc->getObject("ShapeBinderFoo");
|
||||
// Assert the object is correct
|
||||
EXPECT_NE(binder, nullptr);
|
||||
// Assert the elementMap is correct
|
||||
}
|
||||
|
||||
TEST_F(ShapeBinderTest, subShapeBinderExists)
|
||||
{
|
||||
// Arrange
|
||||
// Act
|
||||
auto subbinder = _doc->getObject("SubShapeBinderBar");
|
||||
// Assert the object is correct
|
||||
EXPECT_NE(subbinder, nullptr);
|
||||
// Assert the elementMap is correct
|
||||
}
|
||||
|
||||
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
15
tests/src/Mod/PartDesign/CMakeLists.txt
Normal file
15
tests/src/Mod/PartDesign/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
target_include_directories(PartDesign_tests_run PUBLIC
|
||||
${EIGEN3_INCLUDE_DIR}
|
||||
${OCC_INCLUDE_DIR}
|
||||
${Python3_INCLUDE_DIRS}
|
||||
${XercesC_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(PartDesign_tests_run
|
||||
gtest_main
|
||||
${Google_Tests_LIBS}
|
||||
PartDesign
|
||||
)
|
||||
|
||||
add_subdirectory(App)
|
||||
Reference in New Issue
Block a user