From ee7779455a9d7f2d62f6d69fa814a8414b74feab Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Wed, 9 Aug 2023 22:10:37 -0700 Subject: [PATCH] Test: Begin QuantitySpinBox QTests --- cMake/FreeCAD_Helpers/PrintFinalReport.cmake | 1 + tests/CMakeLists.txt | 31 ++++++++++ tests/src/Base/CMakeLists.txt | 2 + tests/src/{Qt => Base}/InventorBuilder.cpp | 0 tests/src/CMakeLists.txt | 1 - tests/src/Gui/CMakeLists.txt | 4 ++ tests/src/Gui/QuantitySpinBox.cpp | 62 ++++++++++++++++++++ tests/src/Qt/CMakeLists.txt | 48 --------------- 8 files changed, 100 insertions(+), 49 deletions(-) rename tests/src/{Qt => Base}/InventorBuilder.cpp (100%) create mode 100644 tests/src/Gui/QuantitySpinBox.cpp delete mode 100644 tests/src/Qt/CMakeLists.txt diff --git a/cMake/FreeCAD_Helpers/PrintFinalReport.cmake b/cMake/FreeCAD_Helpers/PrintFinalReport.cmake index 6aaa10b587..15d4cd177b 100644 --- a/cMake/FreeCAD_Helpers/PrintFinalReport.cmake +++ b/cMake/FreeCAD_Helpers/PrintFinalReport.cmake @@ -139,6 +139,7 @@ macro(PrintFinalReport) conditional(QtUiTools BUILD_GUI "not needed" ${QtUiTools_VERSION}) conditional(QtWidgets BUILD_GUI "not needed" ${QtWidgets_VERSION}) simple(QtXml ${QtXml_VERSION}) + conditional(QtTest ENABLE_DEVELOPER_TESTS "not needed" ${QtTest_VERSION}) if (BUILD_GUI) conditional(QtWebEngineWidgets BUILD_WEB "not needed (BUILD_WEB is OFF)" ${QtWebEngineWidgets_VERSION}) conditional(DesignerPlugin BUILD_DESIGNER_PLUGIN diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 50a3d3b77e..299198e3b3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -27,12 +27,43 @@ if(MSVC) endif() endif() +if(WIN32) + add_definitions(-DCOIN_DLL) +endif(WIN32) + if(NOT BUILD_DYNAMIC_LINK_PYTHON) list(APPEND Google_Tests_LIBS ${PYTHON_LIBRARIES} ) endif() +set(CMAKE_AUTOMOC ON) + +function(setup_qt_test) + foreach (_testname ${ARGN}) + add_executable(${_testname}_Tests_run ${_testname}.cpp) + add_test(NAME ${_testname}_Tests_run COMMAND ${_testname}_Tests_run) + if (NOT BUILD_DYNAMIC_LINK_PYTHON) + list(APPEND ${_testname}_LIBS + ${PYTHON_LIBRARIES} + ) + endif () + target_include_directories(${_testname}_Tests_run PUBLIC + ${Python3_INCLUDE_DIRS} + ${XercesC_INCLUDE_DIRS} + ${QtGui_INCLUDE_DIRS} + ${QtWidgets_INCLUDE_DIRS} + ${QtTest_INCLUDE_DIRS} + ${COIN3D_INCLUDE_DIRS}) + target_link_libraries(${_testname}_Tests_run + FreeCADApp + FreeCADGui + ${QtCore_LIBRARIES} + ${QtWidgets_LIBRARIES} + ${QtTest_LIBRARIES} + ${${_testname}_LIBS}) + endforeach () +endfunction() add_executable(Tests_run) add_subdirectory(lib) diff --git a/tests/src/Base/CMakeLists.txt b/tests/src/Base/CMakeLists.txt index 6871874838..324d9cf3f3 100644 --- a/tests/src/Base/CMakeLists.txt +++ b/tests/src/Base/CMakeLists.txt @@ -10,3 +10,5 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/Writer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tst_Tools.cpp ) + +setup_qt_test(InventorBuilder) diff --git a/tests/src/Qt/InventorBuilder.cpp b/tests/src/Base/InventorBuilder.cpp similarity index 100% rename from tests/src/Qt/InventorBuilder.cpp rename to tests/src/Base/InventorBuilder.cpp diff --git a/tests/src/CMakeLists.txt b/tests/src/CMakeLists.txt index 58e152818d..c95a1f3be2 100644 --- a/tests/src/CMakeLists.txt +++ b/tests/src/CMakeLists.txt @@ -2,5 +2,4 @@ add_subdirectory(Base) add_subdirectory(App) add_subdirectory(Gui) add_subdirectory(Misc) -add_subdirectory(Qt) add_subdirectory(zipios++) diff --git a/tests/src/Gui/CMakeLists.txt b/tests/src/Gui/CMakeLists.txt index 53ec78d55a..5026677829 100644 --- a/tests/src/Gui/CMakeLists.txt +++ b/tests/src/Gui/CMakeLists.txt @@ -1,5 +1,9 @@ +# Standard C++ GTest tests target_sources( Tests_run PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Assistant.cpp ) + +# Qt tests +setup_qt_test(QuantitySpinBox) diff --git a/tests/src/Gui/QuantitySpinBox.cpp b/tests/src/Gui/QuantitySpinBox.cpp new file mode 100644 index 0000000000..a332e8ecd8 --- /dev/null +++ b/tests/src/Gui/QuantitySpinBox.cpp @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include +#include + +#include + +#include "Gui/QuantitySpinBox.h" + +// NOLINTBEGIN(readability-magic-numbers) + +class testQuantitySpinBox: public QObject +{ + Q_OBJECT + +public: + testQuantitySpinBox() + { + if (App::Application::GetARGC() == 0) { + constexpr int argc = 1; + std::array argv {"FreeCAD"}; + App::Application::Config()["ExeName"] = "FreeCAD"; + App::Application::init(argc, argv.data()); + } + qsb = std::make_unique(); + } + +private Q_SLOTS: + + void init() + {} + + void cleanup() + {} + + void test_SimpleBaseUnit()// NOLINT + { + auto result = qsb->valueFromText("1mm"); + QCOMPARE(result, Base::Quantity(1, QLatin1String("mm"))); + } + + void test_UnitInNumerator()// NOLINT + { + auto result = qsb->valueFromText("1mm/10"); + QCOMPARE(result, Base::Quantity(0.1, QLatin1String("mm"))); + } + + void test_UnitInDenominator()// NOLINT + { + auto result = qsb->valueFromText("1/10mm"); + QCOMPARE(result, Base::Quantity(0.1, QLatin1String("mm"))); + } + +private: + std::unique_ptr qsb; +}; + +// NOLINTEND(readability-magic-numbers) + +QTEST_MAIN(testQuantitySpinBox) + +#include "QuantitySpinBox.moc" diff --git a/tests/src/Qt/CMakeLists.txt b/tests/src/Qt/CMakeLists.txt deleted file mode 100644 index a0d8f411bf..0000000000 --- a/tests/src/Qt/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -# 'Google_test' is the subproject name -project(Google_tests) - -if(WIN32) - add_definitions(-DCOIN_DLL) -endif(WIN32) - -# 'lib' is the folder with Google Test sources - -# 'Google_Tests_run' is the target name -#target_link_libraries(Google_Tests_run gtest gtest_main ${Google_Tests_LIBS}) - -# ------------------------------------------------------ - -enable_testing() - -function(SETUP_TESTS) - foreach(_testname ${ARGN}) - add_executable(${_testname}_Tests_run ${_testname}.cpp) - add_test(NAME ${_testname}_Tests_run COMMAND ${_testname}_Tests_run) - if(NOT BUILD_DYNAMIC_LINK_PYTHON) - list(APPEND ${_testname}_LIBS - ${PYTHON_LIBRARIES} - ) - endif() - target_link_libraries(${_testname}_Tests_run ${QtTest_LIBRARIES} ${${_testname}_LIBS}) - endforeach() -endfunction() - -set(CMAKE_AUTOMOC ON) - -# Qt Test -include_directories( - ${QtGui_INCLUDE_DIRS} - ${QtTest_INCLUDE_DIRS} - ${COIN3D_INCLUDE_DIRS} -) - -# ------------------------------------------------------ - -set (InventorBuilder_LIBS - ${COIN3D_LIBRARIES} - FreeCADBase -) - -SETUP_TESTS( - InventorBuilder -)