diff --git a/share/qtcreator/templates/wizards/autotest/files/tst.pro b/share/qtcreator/templates/wizards/autotest/files/tst.pro index 49ab1c90d83..766b0c14ae1 100644 --- a/share/qtcreator/templates/wizards/autotest/files/tst.pro +++ b/share/qtcreator/templates/wizards/autotest/files/tst.pro @@ -70,6 +70,35 @@ isEmpty(BOOST_INCLUDE_DIR): { SOURCES += \\ %{MainCppName} @endif +@if "%{TestFrameWork}" == "BoostTest_dyn" +TEMPLATE = app +CONFIG -= qt +CONFIG -= app_bundle +CONFIG += console + +isEmpty(BOOST_INSTALL_DIR): BOOST_INSTALL_DIR=$$(BOOST_INSTALL_DIR) +@if "%{BoostInstallDir}" != "" +# set by Qt Creator wizard +isEmpty(BOOST_INSTALL_DIR): BOOST_INSTALL_DIR="%{BoostInstallDir}" +@endif +!isEmpty(BOOST_INSTALL_DIR) { + win32: INCLUDEPATH *= $${BOOST_INSTALL_DIR} + else: INCLUDEPATH *= $${BOOST_INSTALL_DIR}/include +} +# Windows: adapt to name scheme, e.g. lib64-msvc-14.2 +!isEmpty(BOOST_INSTALL_DIR): LIBS *= -L$${BOOST_INSTALL_DIR}/lib +# Windows: adapt to name scheme, e.g. boost_unit_test_framework-vc142-mt-gd-x64-1_80 +LIBS *= -lboost_unit_test_framework +DEFINES *= BOOST_UNIT_TEST_FRAMEWORK_DYN_LINK + +isEmpty(BOOST_INSTALL_DIR): { + message("BOOST_INSTALL_DIR is not set, assuming Boost can be found automatically in your system") +} + +SOURCES += \\ + %{MainCppName} \\ + %{TestCaseFileWithCppSuffix} +@endif @if "%{TestFrameWork}" == "Catch2" TEMPLATE = app @if "%{Catch2NeedsQt}" == "true" diff --git a/share/qtcreator/templates/wizards/autotest/files/tst.qbs b/share/qtcreator/templates/wizards/autotest/files/tst.qbs index 99a218090ed..dda4df02cc9 100644 --- a/share/qtcreator/templates/wizards/autotest/files/tst.qbs +++ b/share/qtcreator/templates/wizards/autotest/files/tst.qbs @@ -7,6 +7,11 @@ import "googlecommon.js" as googleCommon import qbs.Environment import qbs.File @endif +@if "%{TestFrameWork}" == "BoostTest_dyn" +import qbs.Environment +import qbs.File +import qbs.FileInfo +@endif @if "%{TestFrameWork}" == "Catch2" import qbs.Environment import qbs.File @@ -116,6 +121,40 @@ CppApplication { files: [ "%{MainCppName}" ] +@endif +@if "%{TestFrameWork}" == "BoostTest_dyn" + type: "application" + + property string boostInstallDir: { + if (typeof Environment.getEnv("BOOST_INSTALL_DIR") !== 'undefined') + return Environment.getEnv("BOOST_INSTALL_DIR"); + return "%{BoostInstallDir}"; // set by Qt Creator wizard + } + + Properties { + condition: boostInstallDir && File.exists(boostInstallDir) + cpp.includePaths: base.concat([qbs.hostOS.contains("windows") + ? boostInstallDir + : FileInfo.joinPaths(boostInstallDir, "include")]) + // Windows: adapt to different directory layout, e.g. "lib64-msvc-14.2" + cpp.libraryPaths: base.concat([FileInfo.joinPaths(boostInstallDir, "lib")]) + } + cpp.defines: base.concat("BOOST_UNIT_TEST_FRAMEWORK_DYN_LINK") + // Windows: adapt to name scheme, e.g. "boost_unit_test_framework-vc142-mt-gd-x64-1_80" + cpp.dynamicLibraries: ["boost_unit_test_framework"] + + condition: { + if (!boostInstallDir) + console.log("BOOST_INSTALL_DIR is not set, assuming Boost can be " + + "found automatically in your system"); + return true; + } + + files: [ + "%{MainCppName}", + "%{TestCaseFileWithCppSuffix}", + ] + @endif @if "%{TestFrameWork}" == "Catch2" type: "application" diff --git a/share/qtcreator/templates/wizards/autotest/files/tst.txt b/share/qtcreator/templates/wizards/autotest/files/tst.txt index 7e1bd4c46ee..739ec2c26a8 100644 --- a/share/qtcreator/templates/wizards/autotest/files/tst.txt +++ b/share/qtcreator/templates/wizards/autotest/files/tst.txt @@ -133,6 +133,33 @@ elseif (EXISTS ${BOOST_INCLUDE_DIR}) include_directories(${BOOST_INCLUDE_DIR}) endif () @endif +@if "%{TestFrameWork}" == "BoostTest_dyn" +set(Boost_USE_STATIC_LIBS OFF) +set(Boost_USE_MULTITHREADED ON) +set(Boost_USE_STATIC_RUNTIME OFF) + +if (DEFINED ENV{BOOST_INSTALL_DIR}) + set(BOOST_INSTALL_DIR $ENV{BOOST_INSTALL_DIR}) +else () + set(BOOST_INSTALL_DIR "%{BoostInstallDir}") # set by Qt Creator wizard +endif () +if (BOOST_INSTALL_DIR STREQUAL "") + message("BOOST_INSTALL_DIR not set, assuming Boost can be found automatically in your system") +elseif (EXISTS ${BOOST_INSTALL_DIR}) + set(BOOST_ROOT ${BOOST_INSTALL_DIR}) +endif () +find_package(Boost COMPONENTS unit_test_framework REQUIRED) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +add_executable(%{TestCaseName} %{MainCppName} %{TestCaseFileGTestWithCppSuffix}) +add_test(NAME %{TestCaseName} COMMAND %{TestCaseName}) +if (Boost_FOUND) + include_directories(${Boost_INCLUDE_DIRS}) + target_link_libraries(%{TestCaseName} PUBLIC ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) +endif () +@endif @if "%{TestFrameWork}" == "Catch2" SET(CMAKE_CXX_STANDARD 11) diff --git a/share/qtcreator/templates/wizards/autotest/files/tst_main.cpp b/share/qtcreator/templates/wizards/autotest/files/tst_main.cpp index ac88e1b0f1d..1c915089d6f 100644 --- a/share/qtcreator/templates/wizards/autotest/files/tst_main.cpp +++ b/share/qtcreator/templates/wizards/autotest/files/tst_main.cpp @@ -21,13 +21,22 @@ int main(int argc, char *argv[]) } @endif @if "%{TestFrameWork}" == "BoostTest" -#define BOOST_TEST_MODULE %{TestSuiteName} +#define BOOST_TEST_MODULE My test module #include +BOOST_AUTO_TEST_SUITE( %{TestSuiteName} ) + BOOST_AUTO_TEST_CASE( %{TestCaseName} ) { BOOST_TEST( true /* test assertion */ ); } + +BOOST_AUTO_TEST_SUITE_END() +@endif +@if "%{TestFrameWork}" == "BoostTest_dyn" +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE My test module +#include @endif @if "%{TestFrameWork}" == "Catch2" @if "%{Catch2NeedsQt}" == "true" diff --git a/share/qtcreator/templates/wizards/autotest/files/tst_src_boost.cpp b/share/qtcreator/templates/wizards/autotest/files/tst_src_boost.cpp new file mode 100644 index 00000000000..d523db48b99 --- /dev/null +++ b/share/qtcreator/templates/wizards/autotest/files/tst_src_boost.cpp @@ -0,0 +1,13 @@ +%{Cpp:LicenseTemplate}\ +@if "%{TestFrameWork}" == "BoostTest_dyn" +#define BOOST_TEST_DYN_LINK +#include + +BOOST_AUTO_TEST_SUITE( %{TestSuiteName} ) + +BOOST_AUTO_TEST_CASE( %{TestCaseName} ) +{ + BOOST_TEST( true /* test assertion */ ); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/share/qtcreator/templates/wizards/autotest/wizard.json b/share/qtcreator/templates/wizards/autotest/wizard.json index ae8fdb9d121..6f19d679eac 100644 --- a/share/qtcreator/templates/wizards/autotest/wizard.json +++ b/share/qtcreator/templates/wizards/autotest/wizard.json @@ -90,9 +90,13 @@ "value": "QtQuickTest" }, { - "trKey": "Boost Test", + "trKey": "Boost Test (header only)", "value": "BoostTest" }, + { + "trKey": "Boost Test (shared libraries)", + "value": "BoostTest_dyn" + }, { "trKey": "Catch2", "value": "Catch2" @@ -113,7 +117,7 @@ { "name": "TestSuiteName", "trDisplayName": "Test suite name:", - "visible": "%{JS: ['BoostTest', 'GTest'].indexOf(value('TestFrameWork')) >= 0}", + "visible": "%{JS: ['BoostTest', 'BoostTest_dyn', 'GTest'].indexOf(value('TestFrameWork')) >= 0}", "mandatory": true, "type": "LineEdit", "data": { "validator": "^[a-zA-Z_0-9]+$" } @@ -181,6 +185,16 @@ "kind": "existingDirectory" } }, + { + "name": "BoostInstallDir", + "trDisplayName": "Boost install directory (optional):", + "visible": "%{JS: value('TestFrameWork') == 'BoostTest_dyn'}", + "mandatory": false, + "type": "PathChooser", + "data": { + "kind": "existingDirectory" + } + }, { "name": "CatchIncDir", "trDisplayName": "Catch2 include directory (optional):", @@ -300,9 +314,14 @@ { "source": "files/tst_main.cpp", "target": "%{MainCppName}", - "condition": "%{JS: ['GTest', 'QtQuickTest', 'BoostTest', 'Catch2'].indexOf(value('TestFrameWork')) >= 0}", + "condition": "%{JS: ['GTest', 'QtQuickTest', 'BoostTest', 'BoostTest_dyn', 'Catch2'].indexOf(value('TestFrameWork')) >= 0}", "openInEditor": true }, + { + "source": "files/tst_src_boost.cpp", + "target": "%{TestCaseFileWithCppSuffix}", + "condition": "%{JS: value('TestFrameWork') === 'BoostTest_dyn'}" + }, { "source": "files/tst_qml.tmpl", "target": "%{TestCaseFileWithQmlSuffix}",