FreeCAD WebAssembly development snapshot
Some checks failed
FreeCAD master CI / Prepare (push) Has been cancelled
FreeCAD master CI / Pixi (push) Has been cancelled
FreeCAD master CI / Ubuntu (push) Has been cancelled
FreeCAD master CI / Windows (push) Has been cancelled
FreeCAD master CI / Lint (push) Has been cancelled
FreeCAD master CI / WrapUp (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Stale Issues / stale (push) Has been cancelled
Some checks failed
FreeCAD master CI / Prepare (push) Has been cancelled
FreeCAD master CI / Pixi (push) Has been cancelled
FreeCAD master CI / Ubuntu (push) Has been cancelled
FreeCAD master CI / Windows (push) Has been cancelled
FreeCAD master CI / Lint (push) Has been cancelled
FreeCAD master CI / WrapUp (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Stale Issues / stale (push) Has been cancelled
This commit is contained in:
129
tests/src/Mod/PartDesign/App/BackwardCompatibility.cpp
Normal file
129
tests/src/Mod/PartDesign/App/BackwardCompatibility.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include "src/App/InitApplication.h"
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <Mod/PartDesign/App/FeatureChamfer.h>
|
||||
|
||||
// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
|
||||
class BackwardCompatibilityTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
_testPath = App::Application::getHomePath() + "tests/TestModels/";
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(_doc->getName());
|
||||
}
|
||||
|
||||
const App::Document* getDocument() const
|
||||
{
|
||||
return _doc;
|
||||
}
|
||||
|
||||
void setDocument(App::Document* doc)
|
||||
{
|
||||
_doc = doc;
|
||||
}
|
||||
|
||||
std::string getTestPath() const
|
||||
{
|
||||
return _testPath;
|
||||
}
|
||||
|
||||
private:
|
||||
App::Document* _doc = nullptr;
|
||||
std::string _testPath;
|
||||
};
|
||||
|
||||
TEST_F(BackwardCompatibilityTest, TestOpenV021Model)
|
||||
{
|
||||
|
||||
// arrange
|
||||
|
||||
auto doc = App::GetApplication().openDocument(
|
||||
std::string(getTestPath() + "ModelFromV021.FCStd").c_str()
|
||||
);
|
||||
setDocument(doc);
|
||||
|
||||
auto chamfer = dynamic_cast<PartDesign::Chamfer*>(doc->getObject("Chamfer"));
|
||||
auto chamferEdgesNames = chamfer->Base.getSubValues();
|
||||
|
||||
std::vector<TopoDS_Shape> chamferOriginalEdges {};
|
||||
for (const auto& chamferEdgesName : chamferEdgesNames) {
|
||||
chamferOriginalEdges.push_back(
|
||||
chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesName.c_str()).getShape()
|
||||
);
|
||||
}
|
||||
|
||||
// act
|
||||
|
||||
doc->recompute();
|
||||
chamfer = dynamic_cast<PartDesign::Chamfer*>(doc->getObject("Chamfer"));
|
||||
chamferEdgesNames = chamfer->Base.getSubValues();
|
||||
|
||||
// assert
|
||||
|
||||
auto checkSameVertexes = [](const TopoDS_Shape& e1, const TopoDS_Shape& e2) {
|
||||
TopExp_Explorer e1Vertexes(e1, TopAbs_VERTEX);
|
||||
TopExp_Explorer e2Vertexes(e2, TopAbs_VERTEX);
|
||||
|
||||
bool sameCoords {true};
|
||||
bool moreToCheck {e1Vertexes.More() && e2Vertexes.More()};
|
||||
|
||||
// If one of the vertexes doesn't have the same coordinates of the other one then it'll be
|
||||
// useless to continue
|
||||
while (moreToCheck && sameCoords) {
|
||||
auto p1 = BRep_Tool::Pnt(TopoDS::Vertex(e1Vertexes.Current()));
|
||||
auto p2 = BRep_Tool::Pnt(TopoDS::Vertex(e2Vertexes.Current()));
|
||||
|
||||
sameCoords &= (p1.X() == p2.X() && p1.Y() == p2.Y() && p1.Z() == p2.Z());
|
||||
e1Vertexes.Next();
|
||||
e2Vertexes.Next();
|
||||
|
||||
moreToCheck = (e1Vertexes.More() && e2Vertexes.More());
|
||||
|
||||
// Extra check: both edges should have the same number of vertexes (e*Vertexes.More()
|
||||
// should be true or false at the same time for both the edges).
|
||||
// If this doesn't happen then one of the edges won't have enough vertexes to perform a
|
||||
// full coordinates comparison.
|
||||
// This shouldn't happen, so it's here just in case
|
||||
sameCoords &= (e1Vertexes.More() == e2Vertexes.More());
|
||||
}
|
||||
|
||||
return sameCoords;
|
||||
};
|
||||
|
||||
EXPECT_TRUE(checkSameVertexes(
|
||||
chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesNames[0].c_str()).getShape(),
|
||||
chamferOriginalEdges[0]
|
||||
));
|
||||
EXPECT_TRUE(checkSameVertexes(
|
||||
chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesNames[1].c_str()).getShape(),
|
||||
chamferOriginalEdges[1]
|
||||
));
|
||||
EXPECT_TRUE(checkSameVertexes(
|
||||
chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesNames[2].c_str()).getShape(),
|
||||
chamferOriginalEdges[2]
|
||||
));
|
||||
EXPECT_TRUE(checkSameVertexes(
|
||||
chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesNames[3].c_str()).getShape(),
|
||||
chamferOriginalEdges[3]
|
||||
));
|
||||
}
|
||||
|
||||
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
22
tests/src/Mod/PartDesign/App/CMakeLists.txt
Normal file
22
tests/src/Mod/PartDesign/App/CMakeLists.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_executable(PartDesign_tests_run
|
||||
BackwardCompatibility.cpp
|
||||
DatumPlane.cpp
|
||||
ShapeBinder.cpp
|
||||
Pad.cpp
|
||||
)
|
||||
|
||||
set(PartDesignTestData_Files
|
||||
TestModels/ModelFromV021.FCStd
|
||||
)
|
||||
|
||||
ADD_CUSTOM_TARGET(PartDesignTestData ALL
|
||||
SOURCES ${PartDesignTestData_Files}
|
||||
)
|
||||
|
||||
fc_target_copy_resource(PartDesignTestData
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_BINARY_DIR}/tests
|
||||
${PartDesignTestData_Files}
|
||||
)
|
||||
68
tests/src/Mod/PartDesign/App/DatumPlane.cpp
Normal file
68
tests/src/Mod/PartDesign/App/DatumPlane.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
// 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 <App/Origin.h>
|
||||
#include "Mod/Part/App/Attacher.h"
|
||||
#include "Mod/PartDesign/App/Body.h"
|
||||
#include "Mod/PartDesign/App/DatumPlane.h"
|
||||
|
||||
class DatumPlaneTest: 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 = _doc->addObject<PartDesign::Body>();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(_docName.c_str());
|
||||
}
|
||||
|
||||
App::Document* getDocument() const
|
||||
{
|
||||
return _doc;
|
||||
}
|
||||
|
||||
PartDesign::Body* getBody() const
|
||||
{
|
||||
return _body;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _docName;
|
||||
App::Document* _doc = nullptr;
|
||||
PartDesign::Body* _body = nullptr;
|
||||
};
|
||||
|
||||
TEST_F(DatumPlaneTest, attachDatumPlane)
|
||||
{
|
||||
auto datumPlane = getDocument()->addObject<PartDesign::Plane>("Plane");
|
||||
ASSERT_TRUE(datumPlane);
|
||||
getBody()->addObject(datumPlane);
|
||||
auto origin = getBody()->getOrigin();
|
||||
|
||||
App::PropertyLinkSubList support;
|
||||
std::vector<App::DocumentObject*> objs;
|
||||
std::vector<std::string> subs;
|
||||
objs.push_back(origin->getXY());
|
||||
subs.emplace_back();
|
||||
support.setValues(objs, subs);
|
||||
|
||||
auto attach = datumPlane->getExtensionByType<Part::AttachExtension>();
|
||||
attach->attacher().setReferences(support);
|
||||
Attacher::SuggestResult sugr;
|
||||
attach->attacher().suggestMapModes(sugr);
|
||||
EXPECT_EQ(sugr.message, Attacher::SuggestResult::srOK);
|
||||
}
|
||||
93
tests/src/Mod/PartDesign/App/Pad.cpp
Normal file
93
tests/src/Mod/PartDesign/App/Pad.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
// 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/Geometry.h>
|
||||
#include <Mod/PartDesign/App/Body.h>
|
||||
#include <Mod/PartDesign/App/FeaturePad.h>
|
||||
#include <Mod/Sketcher/App/SketchObject.h>
|
||||
|
||||
// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
|
||||
class PadTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
tests::initApplication();
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
_doc = App::GetApplication().newDocument("Pad_test", "testUser");
|
||||
_body = _doc->addObject<PartDesign::Body>();
|
||||
_sketch = _doc->addObject<Sketcher::SketchObject>("Sketch");
|
||||
_body->addObject(_sketch);
|
||||
|
||||
_sketch->AttachmentSupport.setValue(_doc->getObject("XY_Plane"), "");
|
||||
_sketch->MapMode.setValue("FlatFace");
|
||||
Part::GeomCircle circle;
|
||||
circle.setRadius(10.0);
|
||||
_sketch->addGeometry(&circle, false);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(_doc->getName());
|
||||
}
|
||||
|
||||
App::Document* getDocument() const
|
||||
{
|
||||
return _doc;
|
||||
}
|
||||
|
||||
PartDesign::Body* getBody() const
|
||||
{
|
||||
return _body;
|
||||
}
|
||||
|
||||
Sketcher::SketchObject* getSketch() const
|
||||
{
|
||||
return _sketch;
|
||||
}
|
||||
|
||||
private:
|
||||
App::Document* _doc = nullptr;
|
||||
PartDesign::Body* _body = nullptr;
|
||||
Sketcher::SketchObject* _sketch = nullptr;
|
||||
};
|
||||
|
||||
TEST_F(PadTest, TestMidPlaneTwoLength)
|
||||
{
|
||||
auto doc = getDocument();
|
||||
auto body = getBody();
|
||||
auto sketch = getSketch();
|
||||
|
||||
doc->recompute();
|
||||
|
||||
auto pad = doc->addObject<PartDesign::Pad>("Pad");
|
||||
body->addObject(pad);
|
||||
pad->Profile.setValue(sketch, {""});
|
||||
pad->Direction.setValue(0.0, 0.0, 1.0);
|
||||
pad->Midplane.setValue(true);
|
||||
pad->Length.setValue(10.0);
|
||||
pad->Length2.setValue(20.0);
|
||||
|
||||
pad->SideType.setValue("Two sides");
|
||||
|
||||
doc->recompute();
|
||||
|
||||
auto bbox = pad->Shape.getBoundingBox();
|
||||
|
||||
EXPECT_DOUBLE_EQ(bbox.MaxX, 10.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MinX, -10.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MaxY, 10.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MinY, -10.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MaxZ, 10.0);
|
||||
EXPECT_DOUBLE_EQ(bbox.MinZ, -20.0);
|
||||
}
|
||||
|
||||
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
81
tests/src/Mod/PartDesign/App/ShapeBinder.cpp
Normal file
81
tests/src/Mod/PartDesign/App/ShapeBinder.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
// 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 = _doc->addObject<PartDesign::Body>();
|
||||
_box = _doc->addObject<Part::Box>();
|
||||
_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 = _doc->addObject<PartDesign::ShapeBinder>("ShapeBinderFoo");
|
||||
_subbinder = _doc->addObject<PartDesign::SubShapeBinder>("SubShapeBinderBar");
|
||||
_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)
|
||||
BIN
tests/src/Mod/PartDesign/App/TestModels/ModelFromV021.FCStd
Normal file
BIN
tests/src/Mod/PartDesign/App/TestModels/ModelFromV021.FCStd
Normal file
Binary file not shown.
10
tests/src/Mod/PartDesign/CMakeLists.txt
Normal file
10
tests/src/Mod/PartDesign/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
add_subdirectory(App)
|
||||
|
||||
target_link_libraries(PartDesign_tests_run
|
||||
gtest_main
|
||||
${Google_Tests_LIBS}
|
||||
PartDesign
|
||||
Sketcher
|
||||
)
|
||||
Reference in New Issue
Block a user