diff --git a/tests/src/Mod/Part/App/Attacher.cpp b/tests/src/Mod/Part/App/Attacher.cpp index f279e185a2..4ce0429739 100644 --- a/tests/src/Mod/Part/App/Attacher.cpp +++ b/tests/src/Mod/Part/App/Attacher.cpp @@ -12,9 +12,11 @@ using namespace Attacher; using namespace PartTestHelpers; /* - * Testing note: It looks like there are about 45 different attachment modes, and these tests all - * only look at one of them - to prove that adding elementMap code doesn't break anything. A - * comprehensive test of the Attacher would definitely want to try many more code paths. + * Testing note: It looks like there are about 45 different attachment modes, and these tests + * mostly only look at some of them - to prove that adding elementMap code doesn't break anything. + * While a trivial bounding box test is used to ensure no hard crashes in any of the modes, any + * mode that requires additional shapes beyond a couple of boxes would need a more comprehensive + * test. */ class AttacherTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass @@ -105,3 +107,247 @@ TEST_F(AttacherTest, TestCalculateAttachedPlacement) EXPECT_EQ(placement.getPosition().y, 0); EXPECT_EQ(placement.getPosition().z, 0); } + +TEST_F(AttacherTest, TestAllStringModesValid) +{ + // Arrange + const char* modes[] = { + "Deactivated", + "Translate", + "ObjectXY", + "ObjectXZ", + "ObjectYZ", + "FlatFace", + "TangentPlane", + "NormalToEdge", + "FrenetNB", + "FrenetTN", + "FrenetTB", + "Concentric", + "SectionOfRevolution", + "ThreePointsPlane", + "ThreePointsNormal", + "Folding", + + "ObjectX", + "ObjectY", + "ObjectZ", + "AxisOfCurvature", + "Directrix1", + "Directrix2", + "Asymptote1", + "Asymptote2", + "Tangent", + "Normal", + "Binormal", + "TangentU", + "TangentV", + "TwoPointLine", + "IntersectionLine", + "ProximityLine", + + "ObjectOrigin", + "Focus1", + "Focus2", + "OnEdge", + "CenterOfCurvature", + "CenterOfMass", + "IntersectionPoint", + "Vertex", + "ProximityPoint1", + "ProximityPoint2", + + "AxisOfInertia1", + "AxisOfInertia2", + "AxisOfInertia3", + + "InertialCS", + + "FaceNormal", + + "OZX", + "OZY", + "OXY", + "OXZ", + "OYZ", + "OYX", + }; + int index = 0; + for (auto mode : modes) { + _boxes[1]->MapMode.setValue(mode); // There are lots of attachment modes! + _boxes[1]->recomputeFeature(); + EXPECT_STREQ(_boxes[1]->MapMode.getValueAsString(), mode); + EXPECT_EQ(_boxes[1]->MapMode.getValue(), index); + index++; + } +} + +TEST_F(AttacherTest, TestAllModesBoundaries) +{ + _boxes[1]->MapMode.setValue(mmTranslate); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 1, 2, 3))); + _boxes[1]->MapMode.setValue(mmObjectXY); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 1, 2, 3))); + _boxes[1]->MapMode.setValue(mmObjectXZ); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, -3, 0, 1, 0, 2))); + _boxes[1]->MapMode.setValue(mmObjectYZ); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + + _boxes[1]->MapMode.setValue(mmFlatFace); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mmTangentPlane); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm1Normal); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + + _boxes[1]->MapMode.setValue(mmFrenetNB); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mmFrenetTN); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mmFrenetTB); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mmConcentric); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mmRevolutionSection); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mmThreePointsNormal); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mmThreePointsPlane); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mmFolding); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + + _boxes[1]->MapMode.setValue(mm1AxisX); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm1AxisY); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm1AxisZ); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm1AxisCurv); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm1Directrix1); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm1Directrix2); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm1Asymptote1); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm1Asymptote2); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm1Tangent); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm1TangentU); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm1TangentV); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm1TwoPoints); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm1Intersection); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm1Proximity); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + + _boxes[1]->MapMode.setValue(mm0Origin); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm0Focus1); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm0Focus2); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm0OnEdge); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm0CenterOfCurvature); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm0CenterOfMass); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm1Intersection); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm0Vertex); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm0ProximityPoint1); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm0ProximityPoint2); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + + _boxes[1]->MapMode.setValue(mm1AxisInertia1); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm1AxisInertia2); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + _boxes[1]->MapMode.setValue(mm1AxisInertia3); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE(boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0, 0, 0, 3, 1, 2))); + + _boxes[1]->MapMode.setValue(mmInertialCS); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE( + boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))); + + _boxes[1]->MapMode.setValue(mm1FaceNormal); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE( + boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))); + + _boxes[1]->MapMode.setValue(mmOZX); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE( + boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))); + _boxes[1]->MapMode.setValue(mmOZY); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE( + boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))); + _boxes[1]->MapMode.setValue(mmOXY); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE( + boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))); + _boxes[1]->MapMode.setValue(mmOXZ); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE( + boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))); + _boxes[1]->MapMode.setValue(mmOYZ); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE( + boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))); + _boxes[1]->MapMode.setValue(mmOYX); + _boxes[1]->recomputeFeature(); + EXPECT_TRUE( + boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))); +}