Skip to content

Commit

Permalink
[Sketcher] [gtest] Add gtests for geoIdFromShapeType
Browse files Browse the repository at this point in the history
  • Loading branch information
AjinkyaDahale authored and chennes committed Jul 22, 2023
1 parent 532b391 commit 2167fb6
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions tests/src/Mod/Sketcher/App/SketchObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <App/Application.h>
#include <App/Document.h>
#include <Mod/Sketcher/App/GeoEnum.h>
#include <Mod/Sketcher/App/SketchObject.h>

class SketchObjectTest: public ::testing::Test
Expand Down Expand Up @@ -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<const char*> allowedTypes {"Vertex", "Edge", "ExternalEdge", "H_Axis", "V_Axis", "RootPoint"};
};

TEST_F(SketchObjectTest, createSketchObject) // NOLINT
Expand All @@ -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<Part::Geometry> geoline(new Part::GeomLineSegment());
static_cast<Part::GeomLineSegment*>(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);
}

0 comments on commit 2167fb6

Please sign in to comment.