AutoTest: Enhance wizard to support GTest

Initially this adds basic gtest testing - to be improved later on.

Change-Id: I2121cd24493a8d65c5acd0be5c9dd5858702645d
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Christian Stenger
2016-06-22 16:01:34 +02:00
parent 8ea167892f
commit 63e158b4d4
12 changed files with 186 additions and 26 deletions

View File

@@ -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

View File

@@ -1,4 +1,5 @@
%{Cpp:LicenseTemplate}\ %{Cpp:LicenseTemplate}\
@if "%{TestFrameWork}" == "QtTest"
@if "%{RequireGUI}" == "true" @if "%{RequireGUI}" == "true"
%{JS: QtSupport.qtIncludes([ 'QtGui/QApplication' ], %{JS: QtSupport.qtIncludes([ 'QtGui/QApplication' ],
[ 'QtWidgets/QApplication' ]) }\ [ 'QtWidgets/QApplication' ]) }\
@@ -6,7 +7,6 @@
%{JS: QtSupport.qtIncludes([ 'QtCore/QCoreApplication' ], %{JS: QtSupport.qtIncludes([ 'QtCore/QCoreApplication' ],
[ 'QtCore/QCoreApplication' ]) }\ [ 'QtCore/QCoreApplication' ]) }\
@endif @endif
// add necessary includes here // add necessary includes here
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@@ -19,3 +19,13 @@ int main(int argc, char *argv[])
return a.exec(); return a.exec();
} }
@else
#include <iostream>
int main(int , char **)
{
std::cout << "Hello World!\\n";
return 0;
}
@endif

View File

@@ -1,13 +1,18 @@
@if "%{TestFrameWork}" == "QtTest"
@if "%{RequireGUI}" == "true" @if "%{RequireGUI}" == "true"
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
@else @else
QT -= gui QT -= gui
@endif
@else
CONFIG -= qt
@endif
CONFIG += console CONFIG += console
CONFIG -= app_bundle CONFIG -= app_bundle
@endif
TEMPLATE = app TEMPLATE = app
TARGET = %{ProjectName} TARGET = %{ProjectName}
SOURCES += %{MainCppName} SOURCES += %{MainCppName}

View File

@@ -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

View File

@@ -0,0 +1,10 @@
%{Cpp:LicenseTemplate}\
#include "%{TestCaseFileWithHeaderSuffix}"
#include <gtest/gtest.h>
int main(int argc, char *argv[])
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@@ -0,0 +1,11 @@
%{Cpp:LicenseTemplate}\
#include <gtest/gtest.h>
#include <gmock/gmock-matchers.h>
using namespace testing;
TEST(%{TestCaseName}, %{TestSetName})
{
EXPECT_EQ(1, 1);
ASSERT_THAT(0, Eq(0));
}

View File

@@ -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}

View File

@@ -1,10 +1,10 @@
{ {
"version": 1, "version": 1,
"supportedProjectTypes": [ "Qt4ProjectManager.Qt4Project" ], "supportedProjectTypes": [ "Qt4ProjectManager.Qt4Project" ],
"id": "R.AutoTest2", "id": "R.AutoTest",
"category": "H.Project", "category": "H.Project",
"trDescription": "Creates a new project including auto test skeleton.", "trDescription": "Creates a new project including auto test skeleton.",
"trDisplayName": "Qt Test project", "trDisplayName": "Auto Test Project",
"trDisplayCategory": "Other Project", "trDisplayCategory": "Other Project",
"icon": "autotest_24.png", "icon": "autotest_24.png",
"featuresRequired": [ "QtSupport.Wizards.FeatureQt", "QtSupport.Wizards.FeatureDesktop" ], "featuresRequired": [ "QtSupport.Wizards.FeatureQt", "QtSupport.Wizards.FeatureDesktop" ],
@@ -21,6 +21,10 @@
{ "key": "MainCppName", { "key": "MainCppName",
"value": "%{JS: 'main.' + Util.preferredSuffix('text/x-c++src') }" "value": "%{JS: 'main.' + Util.preferredSuffix('text/x-c++src') }"
}, },
{
"key": "TestCaseFileWithHeaderSuffix",
"value": "%{JS: 'tst_%{TestCaseName}.'.toLowerCase() + Util.preferredSuffix('text/x-c++hdr') }"
},
{ {
"key": "TestCaseFileWithCppSuffix", "key": "TestCaseFileWithCppSuffix",
"value": "%{JS: 'tst_%{TestCaseName}.'.toLowerCase() + Util.preferredSuffix('text/x-c++src') }" "value": "%{JS: 'tst_%{TestCaseName}.'.toLowerCase() + Util.preferredSuffix('text/x-c++src') }"
@@ -35,7 +39,7 @@
"typeId": "Project", "typeId": "Project",
"data": "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", "typeId": "Fields",
"data": "data":
[ [
{
"name": "TestFrameWork",
"trDisplayName": "Test Framework:",
"type": "ComboBox",
"data":
{
"index": 0,
"items":
[
{
"trKey": "Qt Test",
"value": "QtTest"
},
{
"trKey": "Googletest",
"value": "GTest"
}
]
}
},
{ {
"name": "RequireGUI", "name": "RequireGUI",
"trDisplayName": "GUI Application", "trDisplayName": "GUI Application",
"visible": "%{JS: '%{TestFrameWork}' === 'QtTest'}",
"type": "CheckBox", "type": "CheckBox",
"data": { "data": {
"checked": false, "checked": false,
@@ -64,6 +89,7 @@
{ {
"name": "RequireApplication", "name": "RequireApplication",
"trDisplayName": "Requires QApplication", "trDisplayName": "Requires QApplication",
"visible": "%{JS: '%{TestFrameWork}' === 'QtTest'}",
"type": "CheckBox", "type": "CheckBox",
"data": { "data": {
"checked": false, "checked": false,
@@ -74,6 +100,25 @@
{ {
"name": "GenerateInitAndCleanup", "name": "GenerateInitAndCleanup",
"trDisplayName": "Generate initialization and cleanup code", "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", "type": "CheckBox",
"data": { "data": {
"checked": false, "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": "data":
[ [
{ {
"source": "tmp.pro", "source": "files/tmp.pro",
"target": "%{ProFileName}", "target": "%{ProFileName}",
"openAsProject": true "openAsProject": true
}, },
{ {
"source": "src.pro", "source": "files/src.pro",
"target": "src/src.pro", "target": "src/src.pro",
"openInEditor": false "openInEditor": false
}, },
{ {
"source": "main.cpp", "source": "files/main.cpp",
"target": "src/%{MainCppName}", "target": "src/%{MainCppName}",
"openInEditor": true "openInEditor": true
}, },
{ {
"source": "tests.pro", "source": "files/tests.pro",
"target": "tests/tests.pro", "target": "tests/tests.pro",
"openInEditor": false "openInEditor": false
}, },
{ {
"source": "auto.pro", "source": "files/auto.pro",
"target": "tests/auto/auto.pro", "target": "tests/auto/auto.pro",
"openInEditor": false "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' }", "target": "%{JS: 'tests/auto/' + '%{TestCaseName}/%{TestCaseName}'.toLowerCase() + '.pro' }",
"openInEditor": false "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}' }", "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 "openInEditor": true
}, },
{ {