diff --git a/CMakeLists.txt b/CMakeLists.txt index 26b13d78d6..f7659ffa21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,4 +93,6 @@ CreatePackagingTargets() PrintFinalReport() -add_subdirectory(tests) +if (BUILD_TEST) + add_subdirectory(tests) +endif() diff --git a/cMake/FreeCAD_Helpers/SetupQt.cmake b/cMake/FreeCAD_Helpers/SetupQt.cmake index 2d72a7826f..2f3d71b223 100644 --- a/cMake/FreeCAD_Helpers/SetupQt.cmake +++ b/cMake/FreeCAD_Helpers/SetupQt.cmake @@ -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}) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a23379c969..e2596bd904 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 +) diff --git a/tests/src/InventorBuilder.cpp b/tests/src/InventorBuilder.cpp new file mode 100644 index 0000000000..27cd47c5ac --- /dev/null +++ b/tests/src/InventorBuilder.cpp @@ -0,0 +1,62 @@ +#include +#include +#include + +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"