| | |
| |
|
| | #include <gtest/gtest.h> |
| |
|
| | #include "Mod/Part/App/FeaturePartCommon.h" |
| | #include <src/App/InitApplication.h> |
| |
|
| | #include "PartTestHelpers.h" |
| |
|
| | class FeaturePartCommonTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass |
| | { |
| | protected: |
| | static void SetUpTestSuite() |
| | { |
| | tests::initApplication(); |
| | } |
| |
|
| |
|
| | void SetUp() override |
| | { |
| | createTestDoc(); |
| | _common = _doc->addObject<Part::Common>(); |
| | } |
| |
|
| | void TearDown() override |
| | {} |
| |
|
| | Part::Common* _common = nullptr; |
| | }; |
| |
|
| | TEST_F(FeaturePartCommonTest, testIntersecting) |
| | { |
| | |
| | _common->Base.setValue(_boxes[0]); |
| | _common->Tool.setValue(_boxes[1]); |
| |
|
| | |
| | _common->execute(); |
| | Part::TopoShape ts = _common->Shape.getValue(); |
| | double volume = PartTestHelpers::getVolume(ts.getShape()); |
| | Base::BoundBox3d bb = ts.getBoundBox(); |
| |
|
| | |
| | EXPECT_DOUBLE_EQ(volume, 3.0); |
| | |
| | EXPECT_DOUBLE_EQ(bb.MinX, 0.0); |
| | EXPECT_DOUBLE_EQ(bb.MinY, 1.0); |
| | EXPECT_DOUBLE_EQ(bb.MinZ, 0.0); |
| | EXPECT_DOUBLE_EQ(bb.MaxX, 1.0); |
| | EXPECT_DOUBLE_EQ(bb.MaxY, 2.0); |
| | EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0); |
| | } |
| |
|
| | TEST_F(FeaturePartCommonTest, testNonIntersecting) |
| | { |
| | |
| | _common->Base.setValue(_boxes[0]); |
| | _common->Tool.setValue(_boxes[2]); |
| |
|
| | |
| | _common->execute(); |
| | Part::TopoShape ts = _common->Shape.getValue(); |
| | double volume = PartTestHelpers::getVolume(ts.getShape()); |
| | Base::BoundBox3d bb = ts.getBoundBox(); |
| |
|
| | |
| | EXPECT_FALSE(bb.IsValid()); |
| | EXPECT_DOUBLE_EQ(volume, 0.0); |
| | } |
| |
|
| | TEST_F(FeaturePartCommonTest, testTouching) |
| | { |
| | |
| | _common->Base.setValue(_boxes[0]); |
| | _common->Tool.setValue(_boxes[3]); |
| |
|
| | |
| | _common->execute(); |
| | Part::TopoShape ts = _common->Shape.getValue(); |
| | double volume = PartTestHelpers::getVolume(ts.getShape()); |
| | Base::BoundBox3d bb = ts.getBoundBox(); |
| |
|
| | |
| | EXPECT_FALSE(bb.IsValid()); |
| | EXPECT_DOUBLE_EQ(volume, 0.0); |
| | } |
| |
|
| | TEST_F(FeaturePartCommonTest, testAlmostTouching) |
| | { |
| | |
| | _common->Base.setValue(_boxes[0]); |
| | _common->Tool.setValue(_boxes[4]); |
| |
|
| | |
| | _common->execute(); |
| | Part::TopoShape ts = _common->Shape.getValue(); |
| | double volume = PartTestHelpers::getVolume(ts.getShape()); |
| | Base::BoundBox3d bb = ts.getBoundBox(); |
| |
|
| | |
| | EXPECT_FALSE(bb.IsValid()); |
| | EXPECT_DOUBLE_EQ(volume, 0.0); |
| | } |
| |
|
| | TEST_F(FeaturePartCommonTest, testBarelyIntersecting) |
| | { |
| | |
| | _common->Base.setValue(_boxes[0]); |
| | _common->Tool.setValue(_boxes[5]); |
| |
|
| | |
| | _common->execute(); |
| | Part::TopoShape ts = _common->Shape.getValue(); |
| | double volume = PartTestHelpers::getVolume(ts.getShape()); |
| | double target = PartTestHelpers::minimalDistance * 3; |
| | Base::BoundBox3d bb = ts.getBoundBox(); |
| |
|
| | |
| | |
| | |
| | |
| | EXPECT_FLOAT_EQ(volume, target); |
| | |
| | EXPECT_DOUBLE_EQ(bb.MinX, 0.0); |
| | EXPECT_DOUBLE_EQ(bb.MinY, 2.0 - PartTestHelpers::minimalDistance); |
| | EXPECT_DOUBLE_EQ(bb.MinZ, 0.0); |
| | EXPECT_DOUBLE_EQ(bb.MaxX, 1.0); |
| | EXPECT_DOUBLE_EQ(bb.MaxY, 2.0); |
| | EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0); |
| | } |
| |
|
| | TEST_F(FeaturePartCommonTest, testMustExecute) |
| | { |
| | |
| | EXPECT_FALSE(_common->mustExecute()); |
| | |
| | _common->Base.setValue(_boxes[0]); |
| | |
| | EXPECT_FALSE(_common->mustExecute()); |
| | |
| | _common->Tool.setValue(_boxes[1]); |
| | |
| | EXPECT_TRUE(_common->mustExecute()); |
| | |
| | _doc->recompute(); |
| | |
| | EXPECT_FALSE(_common->mustExecute()); |
| | } |
| |
|
| | TEST_F(FeaturePartCommonTest, testGetProviderName) |
| | { |
| | |
| | _common->execute(); |
| | const char* name = _common->getViewProviderName(); |
| | |
| | EXPECT_STREQ(name, "PartGui::ViewProviderBoolean"); |
| | } |
| |
|
| | TEST_F(FeaturePartCommonTest, testHistory) |
| | { |
| | |
| | _common->Base.setValue(_boxes[0]); |
| | _common->Tool.setValue(_boxes[1]); |
| | |
| | using MapList = std::map<int, std::vector<int>>; |
| | using List = std::vector<int>; |
| | MapList compare1 = { |
| | {0, List {0}}, |
| | {1, List {5}}, |
| | {2, List()}, |
| | {3, List {2}}, |
| | {4, List {3}}, |
| | {5, List {1}} |
| | }; |
| | MapList compare2 = { |
| | {0, List {0}}, |
| | {1, List {5}}, |
| | {2, List {4}}, |
| | {3, List()}, |
| | {4, List {3}}, |
| | {5, List {1}} |
| | }; |
| |
|
| | |
| | std::vector<Part::ShapeHistory> hist = _common->History.getValues(); |
| | EXPECT_EQ(hist.size(), 0); |
| |
|
| | |
| | _common->execute(); |
| | hist = _common->History.getValues(); |
| | |
| | ASSERT_EQ( |
| | hist.size(), |
| | 0 |
| | ); |
| | } |
| |
|
| | TEST_F(FeaturePartCommonTest, testMapping) |
| | { |
| |
|
| | |
| | _common->Base.setValue(_boxes[0]); |
| | _common->Tool.setValue(_boxes[1]); |
| | |
| | _common->execute(); |
| | const Part::TopoShape& ts1 = _common->Shape.getShape(); |
| | |
| | EXPECT_EQ(ts1.getElementMap().size(), 26); |
| | } |
| |
|