From 2167fb6f7ec6ac5c2f6365d4c3035d2db6879b1e Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Thu, 20 Jul 2023 23:40:09 +0530 Subject: [PATCH] [Sketcher] [gtest] Add gtests for `geoIdFromShapeType` --- tests/src/Mod/Sketcher/App/SketchObject.cpp | 108 ++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/tests/src/Mod/Sketcher/App/SketchObject.cpp b/tests/src/Mod/Sketcher/App/SketchObject.cpp index df6d511b704d..56e6144382ac 100644 --- a/tests/src/Mod/Sketcher/App/SketchObject.cpp +++ b/tests/src/Mod/Sketcher/App/SketchObject.cpp @@ -6,6 +6,7 @@ #include #include +#include #include class SketchObjectTest: public ::testing::Test @@ -34,10 +35,16 @@ class SketchObjectTest: public ::testing::Test App::GetApplication().closeDocument(_docName.c_str()); } + Sketcher::SketchObject* getObject() + { + return _sketchobj; + } + private: // TODO: use shared_ptr or something else here? Sketcher::SketchObject* _sketchobj; std::string _docName; + std::vector allowedTypes {"Vertex", "Edge", "ExternalEdge", "H_Axis", "V_Axis", "RootPoint"}; }; TEST_F(SketchObjectTest, createSketchObject) // NOLINT @@ -48,3 +55,104 @@ TEST_F(SketchObjectTest, createSketchObject) // NOLINT // Assert } + +TEST_F(SketchObjectTest, testGeoIdFromShapeTypeEdge) +{ + // Arrange + // TODO: Do we need to separate existing vs non-existing? + // It would need to be implemented in code as well. + Data::IndexedName name("Edge", 1); + int geoId; + Sketcher::PointPos posId; + + // Act + getObject()->geoIdFromShapeType(name, geoId, posId); + + // Assert + EXPECT_EQ(geoId, 0); + EXPECT_EQ(posId, Sketcher::PointPos::none); +} + +TEST_F(SketchObjectTest, testGeoIdFromShapeTypeVertex) +{ + // Arrange + // For operating on vertices, there is first a check if the vertex exists. + Base::Vector3d p1(0.0, 0.0, 0.0), p2(1.0, 0.0, 0.0); + std::unique_ptr geoline(new Part::GeomLineSegment()); + static_cast(geoline.get())->setPoints(p1, p2); + getObject()->addGeometry(geoline.get()); + // TODO: Do we need to separate existing vs non-existing? + // It would need to be implemented in code as well. + Data::IndexedName name("Vertex", 1); + int geoId; + Sketcher::PointPos posId; + + // Act + getObject()->geoIdFromShapeType(name, geoId, posId); + + // Assert + EXPECT_EQ(geoId, 0); + EXPECT_EQ(posId, Sketcher::PointPos::start); +} + +TEST_F(SketchObjectTest, testGeoIdFromShapeTypeExternalEdge) +{ + // Arrange + // TODO: Do we need to separate existing vs non-existing? + // It would need to be implemented in code as well. + Data::IndexedName name("ExternalEdge", 1); + int geoId; + Sketcher::PointPos posId; + + // Act + getObject()->geoIdFromShapeType(name, geoId, posId); + + // Assert + EXPECT_EQ(geoId, Sketcher::GeoEnum::RefExt); + EXPECT_EQ(posId, Sketcher::PointPos::none); +} + +TEST_F(SketchObjectTest, testGeoIdFromShapeTypeHAxis) +{ + // Arrange + Data::IndexedName name("H_Axis"); + int geoId; + Sketcher::PointPos posId; + + // Act + getObject()->geoIdFromShapeType(name, geoId, posId); + + // Assert + EXPECT_EQ(geoId, Sketcher::GeoEnum::HAxis); + EXPECT_EQ(posId, Sketcher::PointPos::none); +} + +TEST_F(SketchObjectTest, testGeoIdFromShapeTypeVAxis) +{ + // Arrange + Data::IndexedName name("V_Axis"); + int geoId; + Sketcher::PointPos posId; + + // Act + getObject()->geoIdFromShapeType(name, geoId, posId); + + // Assert + EXPECT_EQ(geoId, Sketcher::GeoEnum::VAxis); + EXPECT_EQ(posId, Sketcher::PointPos::none); +} + +TEST_F(SketchObjectTest, testGeoIdFromShapeTypeRootPoint) +{ + // Arrange + Data::IndexedName name("RootPoint"); + int geoId; + Sketcher::PointPos posId; + + // Act + getObject()->geoIdFromShapeType(name, geoId, posId); + + // Assert + EXPECT_EQ(geoId, Sketcher::GeoEnum::RtPnt); + EXPECT_EQ(posId, Sketcher::PointPos::start); +}