| | |
| |
|
| | #include <gtest/gtest.h> |
| |
|
| | #include <boost/core/ignore_unused.hpp> |
| | #include "Mod/Part/App/FeaturePartCommon.h" |
| | #include <src/App/InitApplication.h> |
| | #include <BRepBuilderAPI_MakeVertex.hxx> |
| | #include "PartTestHelpers.h" |
| | #include "App/MappedElement.h" |
| |
|
| | using namespace Part; |
| | using namespace PartTestHelpers; |
| |
|
| | class FeaturePartTest: public ::testing::Test, public PartTestHelperClass |
| | { |
| | protected: |
| | static void SetUpTestSuite() |
| | { |
| | tests::initApplication(); |
| | } |
| |
|
| |
|
| | void SetUp() override |
| | { |
| | createTestDoc(); |
| | _common = _doc->addObject<Common>(); |
| | } |
| |
|
| | void TearDown() override |
| | {} |
| |
|
| | Common* _common = nullptr; |
| | }; |
| |
|
| | TEST_F(FeaturePartTest, testGetElementName) |
| | { |
| | |
| | _common->Base.setValue(_boxes[0]); |
| | _common->Tool.setValue(_boxes[1]); |
| |
|
| | |
| | _common->execute(); |
| | const TopoShape& ts = _common->Shape.getShape(); |
| |
|
| | auto namePair = _common->getElementName("test"); |
| | auto namePairExport = _common->getElementName("test", App::GeoFeature::Export); |
| | auto namePairSelf = _common->getElementName(nullptr); |
| | |
| | EXPECT_STREQ(namePair.newName.c_str(), ""); |
| | EXPECT_STREQ(namePair.oldName.c_str(), "test"); |
| | EXPECT_STREQ(namePairExport.newName.c_str(), ""); |
| | EXPECT_STREQ(namePairExport.oldName.c_str(), "test"); |
| | EXPECT_STREQ(namePairSelf.newName.c_str(), ""); |
| | EXPECT_STREQ(namePairSelf.oldName.c_str(), ""); |
| | EXPECT_EQ(ts.getElementMap().size(), 26); |
| | |
| | } |
| |
|
| | TEST_F(FeaturePartTest, create) |
| | { |
| | |
| |
|
| | |
| | auto shape {TopoShape(BRepBuilderAPI_MakeVertex(gp_Pnt(1.0, 1.0, 1.0)).Vertex(), 1)}; |
| |
|
| | auto otherDocName {App::GetApplication().getUniqueDocumentName("otherDoc")}; |
| | |
| | auto otherDoc {App::GetApplication().newDocument(otherDocName.c_str(), "otherDocUser")}; |
| |
|
| | |
| | _doc->clearDocument(); |
| |
|
| | |
| | |
| | App::GetApplication().setActiveDocument(_doc); |
| |
|
| | |
| |
|
| | |
| | auto featureNoShape {Feature::create(TopoShape())}; |
| |
|
| | |
| | auto featureNoName {Feature::create(shape)}; |
| |
|
| | |
| | auto featureNoDoc {Feature::create(shape, "Vertex")}; |
| |
|
| | |
| | auto feature {Feature::create(shape, "Vertex", otherDoc)}; |
| |
|
| | |
| |
|
| | |
| | |
| | EXPECT_TRUE(featureNoShape->Shape.getValue().IsNull()); |
| | EXPECT_FALSE(featureNoName->Shape.getValue().IsNull()); |
| | EXPECT_FALSE(featureNoDoc->Shape.getValue().IsNull()); |
| | EXPECT_FALSE(feature->Shape.getValue().IsNull()); |
| |
|
| | |
| |
|
| | |
| | EXPECT_STREQ(_doc->getObjectName(featureNoShape), "Shape"); |
| |
|
| | |
| | |
| | EXPECT_STREQ(_doc->getObjectName(featureNoName), "Shape001"); |
| |
|
| | |
| | |
| | EXPECT_STREQ(_doc->getObjectName(featureNoDoc), "Vertex"); |
| |
|
| | |
| | |
| | EXPECT_STREQ(otherDoc->getObjectName(feature), "Vertex"); |
| |
|
| | |
| |
|
| | |
| | |
| | EXPECT_EQ(_doc->getObjects().size(), 3); |
| |
|
| | |
| | |
| | EXPECT_EQ(otherDoc->getObjects().size(), 1); |
| | } |
| |
|
| | TEST_F(FeaturePartTest, getElementHistory) |
| | { |
| | |
| | const char* name2 = "Edge2"; |
| | |
| | auto result = Feature::getElementHistory(_boxes[0], name2, true, false); |
| | Data::HistoryItem histItem = result.front(); |
| | |
| | EXPECT_EQ(result.size(), 1); |
| | EXPECT_NE(histItem.tag, 0); |
| | EXPECT_EQ(histItem.index.getIndex(), 2); |
| | EXPECT_STREQ(histItem.index.getType(), "Edge"); |
| | EXPECT_STREQ(histItem.element.toString().c_str(), name2); |
| | EXPECT_EQ(histItem.obj, _boxes[0]); |
| | } |
| |
|
| | TEST_F(FeaturePartTest, getRelatedElements) |
| | { |
| | |
| | _common->Base.setValue(_boxes[0]); |
| | _common->Tool.setValue(_boxes[1]); |
| | |
| | _common->execute(); |
| | auto label1 = _common->Label.getValue(); |
| | auto label2 = _boxes[1]->Label.getValue(); |
| | const TopoShape& ts = _common->Shape.getShape(); |
| | boost::ignore_unused(ts); |
| | auto result = Feature::getRelatedElements( |
| | _doc->getObject(label1), |
| | "Edge2", |
| | HistoryTraceType::followTypeChange, |
| | true |
| | ); |
| | auto result2 = Feature::getRelatedElements( |
| | _doc->getObject(label2), |
| | "Edge1", |
| | HistoryTraceType::followTypeChange, |
| | true |
| | ); |
| | |
| | EXPECT_EQ(result.size(), 1); |
| | EXPECT_EQ(result2.size(), 0); |
| | |
| | |
| | } |
| |
|
| | |
| | |
| | TEST_F(FeaturePartTest, getElementFromSource) |
| | { |
| | |
| | _common->Base.setValue(_boxes[0]); |
| | _common->Tool.setValue(_boxes[1]); |
| | App::DocumentObject sourceObject; |
| | |
| | |
| | _common->execute(); |
| | auto label1 = _common->Label.getValue(); |
| | auto label2 = _boxes[1]->Label.getValue(); |
| | const TopoShape& ts = _common->Shape.getShape(); |
| | boost::ignore_unused(label1); |
| | boost::ignore_unused(label2); |
| | boost::ignore_unused(ts); |
| | auto element = Feature::getElementFromSource( |
| | _common, |
| | "Part__Box001", |
| | _boxes[0], |
| | "Face1", |
| | false |
| | ); |
| | |
| | EXPECT_EQ(element.size(), 0); |
| | } |
| |
|
| | TEST_F(FeaturePartTest, getSubObject) |
| | { |
| | |
| | _common->Base.setValue(_boxes[0]); |
| | _common->Tool.setValue(_boxes[1]); |
| | App::DocumentObject sourceObject; |
| | PyObject* pyObj; |
| | |
| | _common->execute(); |
| | auto result = _boxes[1]->getSubObject("Face5", &pyObj, nullptr, false, 10); |
| | |
| | ASSERT_NE(result, nullptr); |
| | EXPECT_STREQ(result->getNameInDocument(), "Part__Box001"); |
| | } |
| |
|
| | TEST_F(FeaturePartTest, getElementTypes) |
| | { |
| | Part::Feature pf; |
| | std::vector<const char*> types = pf.getElementTypes(); |
| |
|
| | EXPECT_EQ(types.size(), 3); |
| | EXPECT_STREQ(types[0], "Face"); |
| | EXPECT_STREQ(types[1], "Edge"); |
| | EXPECT_STREQ(types[2], "Vertex"); |
| | } |
| |
|
| | TEST_F(FeaturePartTest, getComplexElementTypes) |
| | { |
| | Part::TopoShape shape; |
| | std::vector<const char*> types = shape.getElementTypes(); |
| |
|
| | EXPECT_EQ(types.size(), 3); |
| | EXPECT_STREQ(types[0], "Face"); |
| | EXPECT_STREQ(types[1], "Edge"); |
| | EXPECT_STREQ(types[2], "Vertex"); |
| | } |
| |
|