QtTest: [skip ci] enable Qt testing framework

This commit is contained in:
wmayer
2022-12-01 13:57:00 +01:00
parent 92e77ce1df
commit 1d7369e321
4 changed files with 98 additions and 1 deletions

View File

@@ -93,4 +93,6 @@ CreatePackagingTargets()
PrintFinalReport()
if (BUILD_TEST)
add_subdirectory(tests)
endif()

View File

@@ -19,6 +19,9 @@ if(BUILD_GUI)
list (APPEND FREECAD_QT_COMPONENTS Designer)
endif()
endif()
if (BUILD_TEST)
list (APPEND FREECAD_QT_COMPONENTS Test)
endif ()
foreach(COMPONENT IN LISTS FREECAD_QT_COMPONENTS)
find_package(Qt${FREECAD_QT_MAJOR_VERSION} REQUIRED COMPONENTS ${COMPONENT})

View File

@@ -15,3 +15,33 @@ add_executable(
)
target_link_libraries(Google_Tests_run gtest gtest_main)
# ------------------------------------------------------
enable_testing()
function(SETUP_TESTS)
foreach(_testname ${ARGN})
add_executable(${_testname}_Tests_run src/${_testname}.cpp)
add_test(NAME ${_testname}_Tests_run COMMAND ${_testname}_Tests_run)
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}
)
# ------------------------------------------------------
set (InventorBuilder_LIBS
FreeCADBase
)
SETUP_TESTS(
InventorBuilder
)

View File

@@ -0,0 +1,62 @@
#include <QTest>
#include <sstream>
#include <Base/Builder3D.h>
class testInventorBuilder : public QObject
{
Q_OBJECT
public:
testInventorBuilder()
: builder(output)
{
}
~testInventorBuilder()
{
}
private Q_SLOTS:
void initTestCase()
{
}
void initTestCase_data()
{
}
void cleanupTestCase()
{
}
void init()
{
}
void cleanup()
{
// clear the buffer
output.str(std::string());
}
void test_Output()
{
QCOMPARE(output.str().c_str(), "#Inventor V2.1 ascii \n\n");
}
void test_MaterialBinding()
{
Base::MaterialBindingItem item{Base::MaterialBinding{}};
builder.addNode(item);
QCOMPARE(output.str().c_str(), "MaterialBinding { value OVERALL } \n");
}
private:
std::stringstream output;
Base::InventorBuilder builder;
};
QTEST_GUILESS_MAIN(testInventorBuilder)
#include "InventorBuilder.moc"