Sketcher: Add gtest unit test framework
This commit is contained in:
committed by
abdullahtahiriyo
parent
069b5859e0
commit
22d8c8f0dd
@@ -24,6 +24,7 @@
|
||||
#define PLANEGCS_CONSTRAINTS_H
|
||||
|
||||
#include "Geo.h"
|
||||
#include "../../SketcherGlobal.h"
|
||||
|
||||
//#define _GCS_EXTRACT_SOLVER_SUBSYSTEM_ // This enables debugging code intended to extract information to file bug reports against Eigen, not for production code
|
||||
|
||||
@@ -96,7 +97,7 @@ namespace GCS
|
||||
HyperbolaNegativeMinorY = 17
|
||||
};
|
||||
|
||||
class Constraint
|
||||
class SketcherExport Constraint
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <Eigen/QR>
|
||||
|
||||
#include "SubSystem.h"
|
||||
#include "../../SketcherGlobal.h"
|
||||
|
||||
|
||||
#define EIGEN_VERSION (EIGEN_WORLD_VERSION * 10000 \
|
||||
@@ -98,7 +99,7 @@ namespace GCS
|
||||
DefaultTemporaryConstraint = -1
|
||||
};
|
||||
|
||||
class System
|
||||
class SketcherExport System
|
||||
{
|
||||
// This is the main class. It holds all constraints and information
|
||||
// about partitioning into subsystems and solution strategies
|
||||
@@ -449,6 +450,18 @@ namespace GCS
|
||||
}
|
||||
|
||||
void invalidatedDiagnosis();
|
||||
|
||||
// Unit testing interface - not intended for use by production code
|
||||
protected:
|
||||
size_t _getNumberOfConstraints(int tagID = -1)
|
||||
{
|
||||
if (tagID < 0) {
|
||||
return clist.size();
|
||||
}
|
||||
return std::count_if(clist.begin(), clist.end(), [tagID](Constraint* constraint) {
|
||||
return constraint->getTag() == tagID;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -38,3 +38,8 @@ add_executable(Tests_run)
|
||||
add_subdirectory(lib)
|
||||
add_subdirectory(src)
|
||||
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_link_libraries(Sketcher_tests_run gtest_main ${Google_Tests_LIBS} Sketcher)
|
||||
|
||||
1
tests/src/Mod/Sketcher/App/CMakeLists.txt
Normal file
1
tests/src/Mod/Sketcher/App/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
add_subdirectory(planegcs)
|
||||
5
tests/src/Mod/Sketcher/App/planegcs/CMakeLists.txt
Normal file
5
tests/src/Mod/Sketcher/App/planegcs/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
target_sources(
|
||||
Sketcher_tests_run
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/GCS.cpp
|
||||
)
|
||||
50
tests/src/Mod/Sketcher/App/planegcs/GCS.cpp
Normal file
50
tests/src/Mod/Sketcher/App/planegcs/GCS.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "Mod/Sketcher/App/planegcs/GCS.h"
|
||||
|
||||
class SystemTest : public GCS::System{
|
||||
public:
|
||||
size_t getNumberOfConstraints(int tagID = -1) {
|
||||
return _getNumberOfConstraints(tagID);
|
||||
}
|
||||
};
|
||||
|
||||
class GCSTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
_system = std::make_unique<SystemTest>();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
_system.reset();
|
||||
}
|
||||
|
||||
SystemTest* System()
|
||||
{
|
||||
return _system.get();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<SystemTest> _system;
|
||||
};
|
||||
|
||||
TEST_F(GCSTest, clearConstraints) // NOLINT
|
||||
{
|
||||
// Arrange
|
||||
const size_t numConstraints {100};
|
||||
for (size_t i = 0; i < numConstraints; ++i) {
|
||||
System()->addConstraint(new GCS::Constraint());
|
||||
}
|
||||
ASSERT_EQ(numConstraints, System()->getNumberOfConstraints());
|
||||
|
||||
// Act
|
||||
System()->clear();
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(0, System()->getNumberOfConstraints());
|
||||
}
|
||||
1
tests/src/Mod/Sketcher/CMakeLists.txt
Normal file
1
tests/src/Mod/Sketcher/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
add_subdirectory(App)
|
||||
Reference in New Issue
Block a user