Skip to content

Commit

Permalink
Test: Begin QuantitySpinBox QTests
Browse files Browse the repository at this point in the history
  • Loading branch information
chennes committed Aug 12, 2023
1 parent 79a31d7 commit bc64b1f
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 49 deletions.
31 changes: 31 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Qt::Test
Qt::Core
Qt::Widgets
${${_testname}_LIBS})
endforeach()
endfunction()

add_executable(Tests_run)
add_subdirectory(lib)
Expand Down
2 changes: 2 additions & 0 deletions tests/src/Base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/Writer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tst_Tools.cpp
)

SETUP_QT_TEST(InventorBuilder)
File renamed without changes.
1 change: 0 additions & 1 deletion tests/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ add_subdirectory(Base)
add_subdirectory(App)
add_subdirectory(Gui)
add_subdirectory(Misc)
add_subdirectory(Qt)
add_subdirectory(zipios++)
4 changes: 4 additions & 0 deletions tests/src/Gui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 changes: 62 additions & 0 deletions tests/src/Gui/QuantitySpinBox.cpp
Original file line number Diff line number Diff line change
@@ -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()
{}

[[maybe_unused]] void test_SimpleBaseUnit()
{
auto result = qsb->valueFromText("1mm");
QCOMPARE(result, Base::Quantity(1, QLatin1String("mm")));
}

[[maybe_unused]] void test_UnitInNumerator()
{
auto result = qsb->valueFromText("1mm/10");
QCOMPARE(result, Base::Quantity(0.1, QLatin1String("mm")));
}

[[maybe_unused]] void test_UnitInDenominator()
{
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"

Check failure on line 62 in tests/src/Gui/QuantitySpinBox.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

'QuantitySpinBox.moc' file not found [clang-diagnostic-error]
48 changes: 0 additions & 48 deletions tests/src/Qt/CMakeLists.txt

This file was deleted.

0 comments on commit bc64b1f

Please sign in to comment.