diff options
author | Christian Stenger <christian.stenger@qt.io> | 2018-01-12 14:10:27 +0100 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2018-02-01 09:23:07 +0000 |
commit | e43668f603f25e372dfdf3e9070bbc2d7db147f3 (patch) | |
tree | fe5a4cb619d7d8e58620eef5e3e839ee4dff79cc /share | |
parent | 97631cfdb83654d0aced65d84583303dc4bc245b (diff) |
AutoTest: Provide missing QtQuick test template
The Auto Test Project wizard had minimal templates for
QtTest and GoogleTest. Provide the QtQuick minimum
template as well.
Task-number: QTCREATORBUG-19579
Change-Id: I0efc1915c3bd0c251d8b94c50ed7ed6341812242
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'share')
6 files changed, 98 insertions, 6 deletions
diff --git a/share/qtcreator/templates/wizards/autotest/files/tst.pro b/share/qtcreator/templates/wizards/autotest/files/tst.pro index 4731fb8cc6..a973d1a9cb 100644 --- a/share/qtcreator/templates/wizards/autotest/files/tst.pro +++ b/share/qtcreator/templates/wizards/autotest/files/tst.pro @@ -13,7 +13,19 @@ CONFIG += qt warn_on depend_includepath testcase TEMPLATE = app SOURCES += %{TestCaseFileWithCppSuffix} -@else +@endif +@if "%{TestFrameWork}" == "QtQuickTest" +CONFIG += warn_on qmltestcase + +TEMPLATE = app + +DISTFILES += \\ + %{TestCaseFileWithQmlSuffix} + +SOURCES += \\ + %{MainCppName} +@endif +@if "%{TestFrameWork}" == "GTest" include(gtest_dependency.pri) TEMPLATE = app diff --git a/share/qtcreator/templates/wizards/autotest/files/tst.qbs b/share/qtcreator/templates/wizards/autotest/files/tst.qbs index 33f15226af..cb7076a0ac 100644 --- a/share/qtcreator/templates/wizards/autotest/files/tst.qbs +++ b/share/qtcreator/templates/wizards/autotest/files/tst.qbs @@ -17,6 +17,7 @@ CppApplication { ] @else consoleApplication: true +@endif @if "%{TestFrameWork}" == "GTest" property string googletestDir: { @@ -28,7 +29,6 @@ CppApplication { return Environment.getEnv("GOOGLETEST_DIR") } } -@endif @if "%{GTestCXX11}" == "true" cpp.cxxLanguageVersion: "c++11" @@ -52,4 +52,24 @@ CppApplication { ].concat(googleCommon.getGTestAll(googletestDir)) .concat(googleCommon.getGMockAll(googletestDir)) @endif +@if "%{TestFrameWork}" == "QtQuickTest" + Depends { name: "cpp" } + Depends { name: "Qt.core" } + Depends { + condition: Qt.core.versionMajor > 4 + name: "Qt.qmltest" + } + + Group { + name: "main application" + files: [ "%{MainCppName}" ] + } + + Group { + name: "qml test files" + files: "%{TestCaseFileWithQmlSuffix}" + } + + cpp.defines: base.concat("QUICK_TEST_SOURCE_DIR=\\"" + path + "\\"") +@endif } diff --git a/share/qtcreator/templates/wizards/autotest/files/tst.txt b/share/qtcreator/templates/wizards/autotest/files/tst.txt index 8c13344d41..239e7087f8 100644 --- a/share/qtcreator/templates/wizards/autotest/files/tst.txt +++ b/share/qtcreator/templates/wizards/autotest/files/tst.txt @@ -13,6 +13,7 @@ find_package(Qt5Gui REQUIRED) SET(CMAKE_AUTOMOC ON) SET(CMAKE_INCLUDE_CURRENT_DIR ON) SET(CMAKE_CXX_STANDARD 11) +SET(CMAKE_CXX_STANDARD_REQUIRED ON) ENABLE_TESTING() add_executable(${PROJECT_NAME} %{TestCaseFileWithCppSuffix}) @@ -24,7 +25,26 @@ target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Gui Qt5::Test) target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Test) @endif -@else +@endif +@if "%{TestFrameWork}" == "QtQuickTest" +find_package(Qt5QuickTest REQUIRED) + +SET(CMAKE_AUTOMOC ON) +SET(CMAKE_INCLUDE_CURRENT_DIR ON) +SET(CMAKE_CXX_STANDARD 11) +SET(CMAKE_CXX_STANDARD_REQUIRED ON) +ENABLE_TESTING() + +# no need to copy around qml test files for shadow builds - just set the respective define +add_definitions(-DQUICK_TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") + +add_executable(${PROJECT_NAME} %{MainCppName}) +add_test(${PROJECT_NAME} COMMAND ${PROJECT_NAME}) + +target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::QuickTest) + +@endif +@if "%{TestFrameWork}" == "GTest" @if "%{GTestCXX11}" == "true" add_definitions(-DGTEST_LANGUAGE_CXX11) diff --git a/share/qtcreator/templates/wizards/autotest/files/tst_main.cpp b/share/qtcreator/templates/wizards/autotest/files/tst_main.cpp index 2e25da44ea..d918350551 100644 --- a/share/qtcreator/templates/wizards/autotest/files/tst_main.cpp +++ b/share/qtcreator/templates/wizards/autotest/files/tst_main.cpp @@ -1,3 +1,8 @@ +@if "%{TestFrameWork}" == "QtQuickTest" +#include <QtQuickTest/quicktest.h> + +QUICK_TEST_MAIN(example) +@else %{Cpp:LicenseTemplate}\ #include "%{TestCaseFileWithHeaderSuffix}" @@ -8,3 +13,4 @@ int main(int argc, char *argv[]) ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } +@endif diff --git a/share/qtcreator/templates/wizards/autotest/files/tst_qml.tmpl b/share/qtcreator/templates/wizards/autotest/files/tst_qml.tmpl new file mode 100644 index 0000000000..5d3da10b70 --- /dev/null +++ b/share/qtcreator/templates/wizards/autotest/files/tst_qml.tmpl @@ -0,0 +1,19 @@ +import QtQuick 2.0 +import QtTest 1.0 + +TestCase { + name: "%{TestCaseName}" + +@if "%{GenerateInitAndCleanup}" == "true" + function initTestCase() { + } + + function cleanupTestCase() { + } + +@endif + function test_case1() { + compare(1 + 1, 2, "sanity check"); + verify(true); + } +} diff --git a/share/qtcreator/templates/wizards/autotest/wizard.json b/share/qtcreator/templates/wizards/autotest/wizard.json index 8b2c548977..0df18f33f4 100644 --- a/share/qtcreator/templates/wizards/autotest/wizard.json +++ b/share/qtcreator/templates/wizards/autotest/wizard.json @@ -39,6 +39,10 @@ { "key": "TestCaseFileWithCppSuffix", "value": "%{JS: 'tst_%{TestCaseName}.'.toLowerCase() + Util.preferredSuffix('text/x-c++src') }" + }, + { + "key": "TestCaseFileWithQmlSuffix", + "value": "%{JS: 'tst_%{TestCaseName}.qml'.toLowerCase() }" } ], @@ -75,7 +79,12 @@ { "trKey": "Googletest", "value": "GTest" + }, + { + "trKey": "QtQuick Test", + "value": "QtQuickTest" } + ] } }, @@ -107,7 +116,7 @@ { "name": "GenerateInitAndCleanup", "trDisplayName": "Generate initialization and cleanup code", - "visible": "%{JS: '%{TestFrameWork}' === 'QtTest'}", + "visible": "%{JS: [ 'QtTest', 'QtQuickTest' ].indexOf('%{TestFrameWork}') >= 0 }", "type": "CheckBox", "data": { "checked": false @@ -174,7 +183,7 @@ "enabled": "%{IsTopLevelProject}", "data": { "projectFilePath": "%{ProjectFilePath}", - "requiredFeatures": [ "%{JS: ('%{BuildSystem}' == 'cmake' && '%{TestFrameWork}' == 'QtTest') ? 'QtSupport.Wizards.FeatureQt.5' : 'QtSupport.Wizards.FeatureQt' }" ] + "requiredFeatures": [ "%{JS: (('%{BuildSystem}' === 'cmake' && '%{TestFrameWork}' === 'QtTest') || '%{TestFrameWork}' === 'QtQuickTest') ? 'QtSupport.Wizards.FeatureQt.5' : 'QtSupport.Wizards.FeatureQt' }" ] } }, { @@ -237,7 +246,13 @@ { "source": "files/tst_main.cpp", "target": "%{MainCppName}", - "condition": "%{JS: '%{TestFrameWork}' == 'GTest'}", + "condition": "%{JS: ['GTest', 'QtQuickTest'].indexOf('%{TestFrameWork}') >= 0}", + "openInEditor": true + }, + { + "source": "files/tst_qml.tmpl", + "target": "%{TestCaseFileWithQmlSuffix}", + "condition": "%{JS: '%{TestFrameWork}' === 'QtQuickTest'}", "openInEditor": true }, { |