Test: Begin QuantitySpinBox QTests
This commit is contained in:
committed by
Chris Hennes
parent
8a4e8ca60e
commit
ee7779455a
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -10,3 +10,5 @@ target_sources(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Writer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tst_Tools.cpp
|
||||
)
|
||||
|
||||
setup_qt_test(InventorBuilder)
|
||||
|
||||
@@ -2,5 +2,4 @@ add_subdirectory(Base)
|
||||
add_subdirectory(App)
|
||||
add_subdirectory(Gui)
|
||||
add_subdirectory(Misc)
|
||||
add_subdirectory(Qt)
|
||||
add_subdirectory(zipios++)
|
||||
|
||||
@@ -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)
|
||||
|
||||
62
tests/src/Gui/QuantitySpinBox.cpp
Normal file
62
tests/src/Gui/QuantitySpinBox.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <QDebug>
|
||||
#include <QTest>
|
||||
|
||||
#include <App/Application.h>
|
||||
|
||||
#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<char*, argc> argv {"FreeCAD"};
|
||||
App::Application::Config()["ExeName"] = "FreeCAD";
|
||||
App::Application::init(argc, argv.data());
|
||||
}
|
||||
qsb = std::make_unique<Gui::QuantitySpinBox>();
|
||||
}
|
||||
|
||||
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<Gui::QuantitySpinBox> qsb;
|
||||
};
|
||||
|
||||
// NOLINTEND(readability-magic-numbers)
|
||||
|
||||
QTEST_MAIN(testQuantitySpinBox)
|
||||
|
||||
#include "QuantitySpinBox.moc"
|
||||
@@ -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
|
||||
)
|
||||
Reference in New Issue
Block a user