QtTest: [skip ci] enable Qt testing framework
This commit is contained in:
@@ -93,4 +93,6 @@ CreatePackagingTargets()
|
||||
|
||||
PrintFinalReport()
|
||||
|
||||
if (BUILD_TEST)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
62
tests/src/InventorBuilder.cpp
Normal file
62
tests/src/InventorBuilder.cpp
Normal 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"
|
||||
Reference in New Issue
Block a user