[Sketcher] [gtest] Add SketchObject test

Create a document and then add a `SketchObject` to it. Does not work without
creating document.

Also `FCConfig.h` is needed for `FC_OS_WIN32`.
This commit is contained in:
Ajinkya Dahale
2023-07-06 14:52:02 +05:30
committed by Chris Hennes
parent b2840e7a5e
commit 532b391b69
3 changed files with 57 additions and 1 deletions

View File

@@ -42,5 +42,5 @@ target_link_libraries(Tests_run gtest_main ${Google_Tests_LIBS} FreeCADApp)
add_executable(Sketcher_tests_run)
add_subdirectory(src/Mod/Sketcher)
target_include_directories(Sketcher_tests_run PUBLIC ${EIGEN3_INCLUDE_DIR})
target_include_directories(Sketcher_tests_run PUBLIC ${EIGEN3_INCLUDE_DIR} ${OCC_INCLUDE_DIR} ${Python3_INCLUDE_DIRS})
target_link_libraries(Sketcher_tests_run gtest_main ${Google_Tests_LIBS} Sketcher)

View File

@@ -1 +1,7 @@
target_sources(
Sketcher_tests_run
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/SketchObject.cpp
)
add_subdirectory(planegcs)

View File

@@ -0,0 +1,50 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "gtest/gtest.h"
#include <FCConfig.h>
#include <App/Application.h>
#include <App/Document.h>
#include <Mod/Sketcher/App/SketchObject.h>
class SketchObjectTest: public ::testing::Test
{
protected:
static void SetUpTestSuite()
{
if (App::Application::GetARGC() == 0) {
int argc = 1;
char* argv[] = {"FreeCAD"};
App::Application::Config()["ExeName"] = "FreeCAD";
App::Application::init(argc, argv);
}
}
void SetUp() override
{
_docName = App::GetApplication().getUniqueDocumentName("test");
auto _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser");
// TODO: Do we add a body first, or is just adding sketch sufficient for this test?
_sketchobj = static_cast<Sketcher::SketchObject*>(_doc->addObject("Sketcher::SketchObject"));
}
void TearDown() override
{
App::GetApplication().closeDocument(_docName.c_str());
}
private:
// TODO: use shared_ptr or something else here?
Sketcher::SketchObject* _sketchobj;
std::string _docName;
};
TEST_F(SketchObjectTest, createSketchObject) // NOLINT
{
// Arrange
// Act
// Assert
}