diff --git a/share/qtcreator/templates/wizards/autotest/auto.pro b/share/qtcreator/templates/wizards/autotest/files/auto.pro similarity index 100% rename from share/qtcreator/templates/wizards/autotest/auto.pro rename to share/qtcreator/templates/wizards/autotest/files/auto.pro diff --git a/share/qtcreator/templates/wizards/autotest/files/gtest_dependency.pri b/share/qtcreator/templates/wizards/autotest/files/gtest_dependency.pri new file mode 100644 index 00000000000..c01bab677c1 --- /dev/null +++ b/share/qtcreator/templates/wizards/autotest/files/gtest_dependency.pri @@ -0,0 +1,31 @@ +isEmpty(GOOGLETEST_DIR):GOOGLETEST_DIR=$$(GOOGLETEST_DIR) + +isEmpty(GOOGLETEST_DIR) { + warning("Using googletest src dir specified at Qt Creator wizard") + message("set GOOGLETEST_DIR as environment variable or qmake variable to get rid of this message") + GOOGLETEST_DIR = %{GTestRepository} +} + +!isEmpty(GOOGLETEST_DIR): { + GTEST_SRCDIR = $$GOOGLETEST_DIR/googletest + GMOCK_SRCDIR = $$GOOGLETEST_DIR/googlemock +} + +requires(exists($$GTEST_SRCDIR):exists($$GMOCK_SRCDIR)) + +!exists($$GOOGLETEST_DIR):message("No googletest src dir found - set GOOGLETEST_DIR to enable.") + +@if "%{GTestCXX11}" == "true" +DEFINES += \\ + GTEST_LANG_CXX11 +@endif + +INCLUDEPATH *= \\ + $$GTEST_SRCDIR \\ + $$GTEST_SRCDIR/include \\ + $$GMOCK_SRCDIR \\ + $$GMOCK_SRCDIR/include + +SOURCES += \\ + $$GTEST_SRCDIR/src/gtest-all.cc \\ + $$GMOCK_SRCDIR/src/gmock-all.cc diff --git a/share/qtcreator/templates/wizards/autotest/main.cpp b/share/qtcreator/templates/wizards/autotest/files/main.cpp similarity index 77% rename from share/qtcreator/templates/wizards/autotest/main.cpp rename to share/qtcreator/templates/wizards/autotest/files/main.cpp index 2eb09afb0dc..8a4a5671fc3 100644 --- a/share/qtcreator/templates/wizards/autotest/main.cpp +++ b/share/qtcreator/templates/wizards/autotest/files/main.cpp @@ -1,4 +1,5 @@ %{Cpp:LicenseTemplate}\ +@if "%{TestFrameWork}" == "QtTest" @if "%{RequireGUI}" == "true" %{JS: QtSupport.qtIncludes([ 'QtGui/QApplication' ], [ 'QtWidgets/QApplication' ]) }\ @@ -6,7 +7,6 @@ %{JS: QtSupport.qtIncludes([ 'QtCore/QCoreApplication' ], [ 'QtCore/QCoreApplication' ]) }\ @endif - // add necessary includes here int main(int argc, char *argv[]) @@ -19,3 +19,13 @@ int main(int argc, char *argv[]) return a.exec(); } +@else +#include + +int main(int , char **) +{ + std::cout << "Hello World!\\n"; + + return 0; +} +@endif diff --git a/share/qtcreator/templates/wizards/autotest/src.pro b/share/qtcreator/templates/wizards/autotest/files/src.pro similarity index 78% rename from share/qtcreator/templates/wizards/autotest/src.pro rename to share/qtcreator/templates/wizards/autotest/files/src.pro index 3cbad0593f8..8d49098b6be 100644 --- a/share/qtcreator/templates/wizards/autotest/src.pro +++ b/share/qtcreator/templates/wizards/autotest/files/src.pro @@ -1,13 +1,18 @@ +@if "%{TestFrameWork}" == "QtTest" @if "%{RequireGUI}" == "true" QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets @else QT -= gui +@endif +@else +CONFIG -= qt +@endif CONFIG += console CONFIG -= app_bundle -@endif TEMPLATE = app + TARGET = %{ProjectName} SOURCES += %{MainCppName} diff --git a/share/qtcreator/templates/wizards/autotest/tests.pro b/share/qtcreator/templates/wizards/autotest/files/tests.pro similarity index 100% rename from share/qtcreator/templates/wizards/autotest/tests.pro rename to share/qtcreator/templates/wizards/autotest/files/tests.pro diff --git a/share/qtcreator/templates/wizards/autotest/tmp.pro b/share/qtcreator/templates/wizards/autotest/files/tmp.pro similarity index 100% rename from share/qtcreator/templates/wizards/autotest/tmp.pro rename to share/qtcreator/templates/wizards/autotest/files/tmp.pro diff --git a/share/qtcreator/templates/wizards/autotest/files/tst.pro b/share/qtcreator/templates/wizards/autotest/files/tst.pro new file mode 100644 index 00000000000..5f0f7455f47 --- /dev/null +++ b/share/qtcreator/templates/wizards/autotest/files/tst.pro @@ -0,0 +1,34 @@ +@if "%{TestFrameWork}" == "QtTest" +QT += testlib +@if "%{RequireGUI}" == "false" +QT -= gui + +CONFIG += qt console warn_on depend_includepath testcase +CONFIG -= app_bundle +@else +QT += gui +CONFIG += qt warn_on depend_includepath testcase +@endif + +TEMPLATE = app + +SOURCES += %{TestCaseFileWithCppSuffix} +@else +include(../gtest_dependency.pri) + +TEMPLATE = app +@if "%{GTestCXX11}" == "true" +CONFIG += console c++11 +@else +CONFIG += console +@endif +CONFIG -= app_bundle +CONFIG += thread +CONFIG -= qt + +HEADERS += \ + %{TestCaseFileWithHeaderSuffix} + +SOURCES += \ + %{MainCppName} +@endif diff --git a/share/qtcreator/templates/wizards/autotest/files/tst_main.cpp b/share/qtcreator/templates/wizards/autotest/files/tst_main.cpp new file mode 100644 index 00000000000..2e25da44ead --- /dev/null +++ b/share/qtcreator/templates/wizards/autotest/files/tst_main.cpp @@ -0,0 +1,10 @@ +%{Cpp:LicenseTemplate}\ +#include "%{TestCaseFileWithHeaderSuffix}" + +#include + +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/share/qtcreator/templates/wizards/autotest/tst_src.cpp b/share/qtcreator/templates/wizards/autotest/files/tst_src.cpp similarity index 100% rename from share/qtcreator/templates/wizards/autotest/tst_src.cpp rename to share/qtcreator/templates/wizards/autotest/files/tst_src.cpp diff --git a/share/qtcreator/templates/wizards/autotest/files/tst_src.h b/share/qtcreator/templates/wizards/autotest/files/tst_src.h new file mode 100644 index 00000000000..9731d06cf58 --- /dev/null +++ b/share/qtcreator/templates/wizards/autotest/files/tst_src.h @@ -0,0 +1,11 @@ +%{Cpp:LicenseTemplate}\ +#include +#include + +using namespace testing; + +TEST(%{TestCaseName}, %{TestSetName}) +{ + EXPECT_EQ(1, 1); + ASSERT_THAT(0, Eq(0)); +} diff --git a/share/qtcreator/templates/wizards/autotest/tst.pro b/share/qtcreator/templates/wizards/autotest/tst.pro deleted file mode 100644 index f58c30fd8ea..00000000000 --- a/share/qtcreator/templates/wizards/autotest/tst.pro +++ /dev/null @@ -1,14 +0,0 @@ -QT += testlib -@if "%{RequireGUI}" == "false" -QT -= gui - -CONFIG += qt console warn_on depend_includepath testcase -CONFIG -= app_bundle -@else -QT += gui -CONFIG += qt warn_on depend_includepath testcase -@endif - -TEMPLATE = app - -SOURCES += %{TestCaseFileWithCppSuffix} diff --git a/share/qtcreator/templates/wizards/autotest/wizard.json b/share/qtcreator/templates/wizards/autotest/wizard.json index 16f318aa574..0a7b6e29aee 100644 --- a/share/qtcreator/templates/wizards/autotest/wizard.json +++ b/share/qtcreator/templates/wizards/autotest/wizard.json @@ -1,10 +1,10 @@ { "version": 1, "supportedProjectTypes": [ "Qt4ProjectManager.Qt4Project" ], - "id": "R.AutoTest2", + "id": "R.AutoTest", "category": "H.Project", "trDescription": "Creates a new project including auto test skeleton.", - "trDisplayName": "Qt Test project", + "trDisplayName": "Auto Test Project", "trDisplayCategory": "Other Project", "icon": "autotest_24.png", "featuresRequired": [ "QtSupport.Wizards.FeatureQt", "QtSupport.Wizards.FeatureDesktop" ], @@ -21,6 +21,10 @@ { "key": "MainCppName", "value": "%{JS: 'main.' + Util.preferredSuffix('text/x-c++src') }" }, + { + "key": "TestCaseFileWithHeaderSuffix", + "value": "%{JS: 'tst_%{TestCaseName}.'.toLowerCase() + Util.preferredSuffix('text/x-c++hdr') }" + }, { "key": "TestCaseFileWithCppSuffix", "value": "%{JS: 'tst_%{TestCaseName}.'.toLowerCase() + Util.preferredSuffix('text/x-c++src') }" @@ -35,7 +39,7 @@ "typeId": "Project", "data": { - "trDescription": "This wizard creates a simple Qmake based Qt project with additional auto test skeleton." + "trDescription": "This wizard creates a simple Qmake based project with additional auto test skeleton." } }, { @@ -44,9 +48,30 @@ "typeId": "Fields", "data": [ + { + "name": "TestFrameWork", + "trDisplayName": "Test Framework:", + "type": "ComboBox", + "data": + { + "index": 0, + "items": + [ + { + "trKey": "Qt Test", + "value": "QtTest" + }, + { + "trKey": "Googletest", + "value": "GTest" + } + ] + } + }, { "name": "RequireGUI", "trDisplayName": "GUI Application", + "visible": "%{JS: '%{TestFrameWork}' === 'QtTest'}", "type": "CheckBox", "data": { "checked": false, @@ -64,6 +89,7 @@ { "name": "RequireApplication", "trDisplayName": "Requires QApplication", + "visible": "%{JS: '%{TestFrameWork}' === 'QtTest'}", "type": "CheckBox", "data": { "checked": false, @@ -74,6 +100,25 @@ { "name": "GenerateInitAndCleanup", "trDisplayName": "Generate initialization and cleanup code", + "visible": "%{JS: '%{TestFrameWork}' === 'QtTest'}", + "type": "CheckBox", + "data": { + "checked": false, + "checkedValue": "true", + "uncheckedValue": "false" + } + }, + { + "name": "TestSetName", + "trDisplayName": "Test Set Name:", + "visible": "%{JS: '%{TestFrameWork}' === 'GTest'}", + "type": "LineEdit", + "data": { "validator": "^[a-zA-Z0-9]+$" } + }, + { + "name": "GTestCXX11", + "trDisplayName": "Enable C++11", + "visible": "%{JS: '%{TestFrameWork}' === 'GTest'}", "type": "CheckBox", "data": { "checked": false, @@ -100,6 +145,15 @@ } ] } + }, + { + "name": "GTestRepository", + "trDisplayName": "Googletest repository:", + "visible": "%{JS: '%{TestFrameWork}' === 'GTest'}", + "type": "PathChooser", + "data": { + "kind": "existingDirectory" + } } ] }, @@ -123,38 +177,57 @@ "data": [ { - "source": "tmp.pro", + "source": "files/tmp.pro", "target": "%{ProFileName}", "openAsProject": true }, { - "source": "src.pro", + "source": "files/src.pro", "target": "src/src.pro", "openInEditor": false }, { - "source": "main.cpp", + "source": "files/main.cpp", "target": "src/%{MainCppName}", "openInEditor": true }, { - "source": "tests.pro", + "source": "files/tests.pro", "target": "tests/tests.pro", "openInEditor": false }, { - "source": "auto.pro", + "source": "files/auto.pro", "target": "tests/auto/auto.pro", "openInEditor": false }, { - "source": "tst.pro", + "source": "files/gtest_dependency.pri", + "target": "tests/auto/gtest_dependency.pri", + "condition": "%{JS: '%{TestFrameWork}' == 'GTest'}", + "openInEditor": false + }, + { + "source": "files/tst.pro", "target": "%{JS: 'tests/auto/' + '%{TestCaseName}/%{TestCaseName}'.toLowerCase() + '.pro' }", "openInEditor": false }, { - "source": "tst_src.cpp", + "source": "files/tst_src.h", + "target": "%{JS: 'tests/auto/' + '%{TestCaseName}/'.toLowerCase() + '%{TestCaseFileWithHeaderSuffix}' }", + "condition": "%{JS: '%{TestFrameWork}' == 'GTest'}", + "openInEditor": true + }, + { + "source": "files/tst_src.cpp", "target": "%{JS: 'tests/auto/' + '%{TestCaseName}/'.toLowerCase() + '%{TestCaseFileWithCppSuffix}' }", + "condition": "%{JS: '%{TestFrameWork}' == 'QtTest'}", + "openInEditor": true + }, + { + "source": "files/tst_main.cpp", + "target": "%{JS: 'tests/auto/' + '%{TestCaseName}'.toLowerCase() + '/%{MainCppName}' }", + "condition": "%{JS: '%{TestFrameWork}' == 'GTest'}", "openInEditor": true }, {