[Sketcher] [gtest] Add gtests for geoIdFromShapeType
This commit is contained in:
committed by
Chris Hennes
parent
532b391b69
commit
2167fb6f7e
@@ -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
|
||||
@@ -34,10 +35,16 @@ protected:
|
||||
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
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user