Commit 63e158b4 authored by Christian Stenger's avatar Christian Stenger
Browse files

AutoTest: Enhance wizard to support GTest



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

Change-Id: I2121cd24493a8d65c5acd0be5c9dd5858702645d
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 8ea16789
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
%{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 <iostream>
int main(int , char **)
{
std::cout << "Hello World!\\n";
return 0;
}
@endif
@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}
@if "%{TestFrameWork}" == "QtTest"
QT += testlib
@if "%{RequireGUI}" == "false"
QT -= gui
......@@ -12,3 +13,22 @@ CONFIG += qt warn_on depend_includepath testcase
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
%{Cpp:LicenseTemplate}\
#include "%{TestCaseFileWithHeaderSuffix}"
#include <gtest/gtest.h>
int main(int argc, char *argv[])
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
%{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));
}
{
"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
},
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment