forked from qt-creator/qt-creator
Remove duplicated "Qt Unit Test" wizard
There are currently two types of wizards for creating auto tests: - Qt Unit Test - Auto Test Project Both produce almost identical code in the case of a Qt GUI-based test, and the descriptions are very similar. This is really confusing. The Auto Test Project wizard has support for Qt Test, Google Test and Qt Quick Test. In addition, the documentation only mentions Auto Test Projects when it discusses the creation of auto tests: http://doc.qt.io/qtcreator/creator-autotest.html#creating-tests So let's just use that and make everything simpler. Change-Id: Ia16c88c462744baa8df3f9e8082cbcad6ad9eb15 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -157,10 +157,6 @@
|
|||||||
|
|
||||||
\list
|
\list
|
||||||
|
|
||||||
\li Qt Unit Test
|
|
||||||
|
|
||||||
Qt unit tests for features or classes
|
|
||||||
|
|
||||||
\li Auto Test Project
|
\li Auto Test Project
|
||||||
|
|
||||||
Projects with boilerplate code for a Qt or Google test. For more
|
Projects with boilerplate code for a Qt or Google test. For more
|
||||||
|
@@ -25,9 +25,6 @@ HEADERS += \
|
|||||||
wizards/librarywizard.h \
|
wizards/librarywizard.h \
|
||||||
wizards/librarywizarddialog.h \
|
wizards/librarywizarddialog.h \
|
||||||
wizards/guiappwizarddialog.h \
|
wizards/guiappwizarddialog.h \
|
||||||
wizards/testwizard.h \
|
|
||||||
wizards/testwizarddialog.h \
|
|
||||||
wizards/testwizardpage.h \
|
|
||||||
wizards/modulespage.h \
|
wizards/modulespage.h \
|
||||||
wizards/filespage.h \
|
wizards/filespage.h \
|
||||||
wizards/qtwizard.h \
|
wizards/qtwizard.h \
|
||||||
@@ -69,9 +66,6 @@ SOURCES += \
|
|||||||
wizards/librarywizard.cpp \
|
wizards/librarywizard.cpp \
|
||||||
wizards/librarywizarddialog.cpp \
|
wizards/librarywizarddialog.cpp \
|
||||||
wizards/guiappwizarddialog.cpp \
|
wizards/guiappwizarddialog.cpp \
|
||||||
wizards/testwizard.cpp \
|
|
||||||
wizards/testwizarddialog.cpp \
|
|
||||||
wizards/testwizardpage.cpp \
|
|
||||||
wizards/modulespage.cpp \
|
wizards/modulespage.cpp \
|
||||||
wizards/filespage.cpp \
|
wizards/filespage.cpp \
|
||||||
wizards/qtwizard.cpp \
|
wizards/qtwizard.cpp \
|
||||||
@@ -94,8 +88,7 @@ SOURCES += \
|
|||||||
FORMS += makestep.ui \
|
FORMS += makestep.ui \
|
||||||
qmakestep.ui \
|
qmakestep.ui \
|
||||||
qmakeprojectconfigwidget.ui \
|
qmakeprojectconfigwidget.ui \
|
||||||
librarydetailswidget.ui \
|
librarydetailswidget.ui
|
||||||
wizards/testwizardpage.ui
|
|
||||||
|
|
||||||
RESOURCES += qmakeprojectmanager.qrc \
|
RESOURCES += qmakeprojectmanager.qrc \
|
||||||
wizards/wizards.qrc
|
wizards/wizards.qrc
|
||||||
|
@@ -90,10 +90,6 @@ Project {
|
|||||||
"subdirsprojectwizard.cpp", "subdirsprojectwizard.h",
|
"subdirsprojectwizard.cpp", "subdirsprojectwizard.h",
|
||||||
"subdirsprojectwizarddialog.cpp", "subdirsprojectwizarddialog.h",
|
"subdirsprojectwizarddialog.cpp", "subdirsprojectwizarddialog.h",
|
||||||
"simpleprojectwizard.cpp", "simpleprojectwizard.h",
|
"simpleprojectwizard.cpp", "simpleprojectwizard.h",
|
||||||
"testwizard.cpp", "testwizard.h",
|
|
||||||
"testwizarddialog.cpp", "testwizarddialog.h",
|
|
||||||
"testwizardpage.cpp", "testwizardpage.h",
|
|
||||||
"testwizardpage.ui",
|
|
||||||
"wizards.qrc"
|
"wizards.qrc"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -34,7 +34,6 @@
|
|||||||
#include "desktopqmakerunconfiguration.h"
|
#include "desktopqmakerunconfiguration.h"
|
||||||
#include "wizards/guiappwizard.h"
|
#include "wizards/guiappwizard.h"
|
||||||
#include "wizards/librarywizard.h"
|
#include "wizards/librarywizard.h"
|
||||||
#include "wizards/testwizard.h"
|
|
||||||
#include "wizards/simpleprojectwizard.h"
|
#include "wizards/simpleprojectwizard.h"
|
||||||
#include "wizards/subdirsprojectwizard.h"
|
#include "wizards/subdirsprojectwizard.h"
|
||||||
#include "customwidgetwizard/customwidgetwizard.h"
|
#include "customwidgetwizard/customwidgetwizard.h"
|
||||||
@@ -148,7 +147,6 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
|
|||||||
new SubdirsProjectWizard,
|
new SubdirsProjectWizard,
|
||||||
new GuiAppWizard,
|
new GuiAppWizard,
|
||||||
new LibraryWizard,
|
new LibraryWizard,
|
||||||
new TestWizard,
|
|
||||||
new CustomWidgetWizard,
|
new CustomWidgetWizard,
|
||||||
new SimpleProjectWizard
|
new SimpleProjectWizard
|
||||||
};
|
};
|
||||||
|
@@ -1,183 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "testwizard.h"
|
|
||||||
#include "testwizarddialog.h"
|
|
||||||
|
|
||||||
#include <cpptools/abstracteditorsupport.h>
|
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
|
||||||
#include <qtsupport/qtsupportconstants.h>
|
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
|
||||||
#include <utils/qtcassert.h>
|
|
||||||
|
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QTextStream>
|
|
||||||
#include <QFileInfo>
|
|
||||||
|
|
||||||
namespace QmakeProjectManager {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
TestWizard::TestWizard()
|
|
||||||
{
|
|
||||||
setId("L.Qt4Test");
|
|
||||||
setCategory(QLatin1String(ProjectExplorer::Constants::QT_PROJECT_WIZARD_CATEGORY));
|
|
||||||
setDisplayCategory(QCoreApplication::translate("ProjectExplorer",
|
|
||||||
ProjectExplorer::Constants::QT_PROJECT_WIZARD_CATEGORY_DISPLAY));
|
|
||||||
setDisplayName(tr("Qt Unit Test"));
|
|
||||||
setDescription(tr("Creates a QTestLib-based unit test for a feature or a class. "
|
|
||||||
"Unit tests allow you to verify that the code is fit for use "
|
|
||||||
"and that there are no regressions."));
|
|
||||||
setIcon(QIcon(QLatin1String(":/wizards/images/console.png")));
|
|
||||||
setRequiredFeatures({QtSupport::Constants::FEATURE_QT_CONSOLE, QtSupport::Constants::FEATURE_QT_PREFIX});
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::BaseFileWizard *TestWizard::create(QWidget *parent, const Core::WizardDialogParameters ¶meters) const
|
|
||||||
{
|
|
||||||
TestWizardDialog *dialog = new TestWizardDialog(this, displayName(), icon(), parent, parameters);
|
|
||||||
dialog->setProjectName(TestWizardDialog::uniqueProjectName(parameters.defaultPath()));
|
|
||||||
return dialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------- code generation helpers
|
|
||||||
static const char initTestCaseC[] = "initTestCase";
|
|
||||||
static const char cleanupTestCaseC[] = "cleanupTestCase";
|
|
||||||
static const char closeFunctionC[] = "}\n\n";
|
|
||||||
static const char testDataTypeC[] = "QString";
|
|
||||||
|
|
||||||
static inline void writeVoidMemberDeclaration(QTextStream &str,
|
|
||||||
const QString &indent,
|
|
||||||
const QString &methodName)
|
|
||||||
{
|
|
||||||
str << indent << "void " << methodName << "();\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void writeVoidMemberBody(QTextStream &str,
|
|
||||||
const QString &className,
|
|
||||||
const QString &methodName,
|
|
||||||
bool close = true)
|
|
||||||
{
|
|
||||||
str << "void " << className << "::" << methodName << "()\n{\n";
|
|
||||||
if (close)
|
|
||||||
str << closeFunctionC;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString generateTestCode(const TestWizardParameters &testParams,
|
|
||||||
const QString &sourceBaseName)
|
|
||||||
{
|
|
||||||
QString rc;
|
|
||||||
const QString indent = QString(4, QLatin1Char(' '));
|
|
||||||
QTextStream str(&rc);
|
|
||||||
// Includes
|
|
||||||
str << CppTools::AbstractEditorSupport::licenseTemplate(testParams.fileName, testParams.className)
|
|
||||||
<< "#include <QString>\n#include <QtTest>\n";
|
|
||||||
if (testParams.requiresQApplication)
|
|
||||||
str << "#include <QCoreApplication>\n";
|
|
||||||
// Class declaration
|
|
||||||
str << "\nclass " << testParams.className << " : public QObject\n"
|
|
||||||
"{\n" << indent << "Q_OBJECT\n\npublic:\n"
|
|
||||||
<< indent << testParams.className << "();\n\nprivate Q_SLOTS:\n";
|
|
||||||
if (testParams.initializationCode) {
|
|
||||||
writeVoidMemberDeclaration(str, indent, QLatin1String(initTestCaseC));
|
|
||||||
writeVoidMemberDeclaration(str, indent, QLatin1String(cleanupTestCaseC));
|
|
||||||
}
|
|
||||||
const QString dataSlot = testParams.testSlot + QLatin1String("_data");
|
|
||||||
if (testParams.useDataSet)
|
|
||||||
writeVoidMemberDeclaration(str, indent, dataSlot);
|
|
||||||
writeVoidMemberDeclaration(str, indent, testParams.testSlot);
|
|
||||||
str << "};\n\n";
|
|
||||||
// Code: Constructor
|
|
||||||
str << testParams.className << "::" << testParams.className << "()\n{\n}\n\n";
|
|
||||||
// Code: Initialization slots
|
|
||||||
if (testParams.initializationCode) {
|
|
||||||
writeVoidMemberBody(str, testParams.className, QLatin1String(initTestCaseC));
|
|
||||||
writeVoidMemberBody(str, testParams.className, QLatin1String(cleanupTestCaseC));
|
|
||||||
}
|
|
||||||
// test data generation slot
|
|
||||||
if (testParams.useDataSet) {
|
|
||||||
writeVoidMemberBody(str, testParams.className, dataSlot, false);
|
|
||||||
str << indent << "QTest::addColumn<" << testDataTypeC << ">(\"data\");\n"
|
|
||||||
<< indent << "QTest::newRow(\"0\") << " << testDataTypeC << "();\n"
|
|
||||||
<< closeFunctionC;
|
|
||||||
}
|
|
||||||
// Test slot with data or dummy
|
|
||||||
writeVoidMemberBody(str, testParams.className, testParams.testSlot, false);
|
|
||||||
if (testParams.useDataSet)
|
|
||||||
str << indent << "QFETCH(" << testDataTypeC << ", data);\n";
|
|
||||||
switch (testParams.type) {
|
|
||||||
case TestWizardParameters::Test:
|
|
||||||
str << indent << "QVERIFY2(true, \"Failure\");\n";
|
|
||||||
break;
|
|
||||||
case TestWizardParameters::Benchmark:
|
|
||||||
str << indent << "QBENCHMARK {\n" << indent << "}\n";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
str << closeFunctionC;
|
|
||||||
// Main & moc include
|
|
||||||
str << (testParams.requiresQApplication ? "QTEST_MAIN" : "QTEST_APPLESS_MAIN")
|
|
||||||
<< '(' << testParams.className << ")\n\n"
|
|
||||||
<< "#include \"" << sourceBaseName << ".moc\"\n";
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::GeneratedFiles TestWizard::generateFiles(const QWizard *w, QString *errorMessage) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(errorMessage)
|
|
||||||
|
|
||||||
const TestWizardDialog *wizardDialog = qobject_cast<const TestWizardDialog *>(w);
|
|
||||||
QTC_ASSERT(wizardDialog, return Core::GeneratedFiles());
|
|
||||||
|
|
||||||
const QtProjectParameters projectParams = wizardDialog->projectParameters();
|
|
||||||
const TestWizardParameters testParams = wizardDialog->testParameters();
|
|
||||||
const QString projectPath = projectParams.projectPath();
|
|
||||||
|
|
||||||
// Create files: Source
|
|
||||||
const QString sourceFilePath = Core::BaseFileWizardFactory::buildFileName(projectPath, testParams.fileName, sourceSuffix());
|
|
||||||
const QFileInfo sourceFileInfo(sourceFilePath);
|
|
||||||
|
|
||||||
Core::GeneratedFile source(sourceFilePath);
|
|
||||||
source.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
|
|
||||||
source.setContents(generateTestCode(testParams, sourceFileInfo.baseName()));
|
|
||||||
|
|
||||||
// Create profile with define for base dir to find test data
|
|
||||||
const QString profileName = Core::BaseFileWizardFactory::buildFileName(projectPath, projectParams.fileName, profileSuffix());
|
|
||||||
Core::GeneratedFile profile(profileName);
|
|
||||||
profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
|
|
||||||
QString contents;
|
|
||||||
{
|
|
||||||
QTextStream proStr(&contents);
|
|
||||||
QtProjectParameters::writeProFileHeader(proStr);
|
|
||||||
projectParams.writeProFile(proStr);
|
|
||||||
proStr << "\n\nSOURCES +="
|
|
||||||
<< " \\\n " << Utils::FileName::fromString(sourceFilePath).fileName()
|
|
||||||
<< " \n\nDEFINES += SRCDIR=\\\\\\\"$$PWD/\\\\\\\"\n";
|
|
||||||
}
|
|
||||||
profile.setContents(contents);
|
|
||||||
|
|
||||||
return Core::GeneratedFiles() << source << profile;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace QmakeProjectManager
|
|
@@ -1,47 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "qtwizard.h"
|
|
||||||
|
|
||||||
namespace QmakeProjectManager {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class TestWizard : public QtWizard
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
TestWizard();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Core::BaseFileWizard *create(QWidget *parent, const Core::WizardDialogParameters ¶meters) const;
|
|
||||||
|
|
||||||
Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace QmakeProjectManager
|
|
@@ -1,93 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "testwizarddialog.h"
|
|
||||||
#include "testwizardpage.h"
|
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
|
||||||
|
|
||||||
#include <QFileInfo>
|
|
||||||
|
|
||||||
enum PageIds { StartPageId = 0 };
|
|
||||||
|
|
||||||
namespace QmakeProjectManager {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
const char *TestWizardParameters::filePrefix = "tst_";
|
|
||||||
|
|
||||||
TestWizardParameters::TestWizardParameters() :
|
|
||||||
type(Test),
|
|
||||||
initializationCode(false),
|
|
||||||
useDataSet(false),
|
|
||||||
requiresQApplication(requiresQApplicationDefault)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
TestWizardDialog::TestWizardDialog(const Core::BaseFileWizardFactory *factory,
|
|
||||||
const QString &templateName,
|
|
||||||
const QIcon &icon,
|
|
||||||
QWidget *parent,
|
|
||||||
const Core::WizardDialogParameters ¶meters) :
|
|
||||||
BaseQmakeProjectWizardDialog(factory, true, parent, parameters),
|
|
||||||
m_testPage(new TestWizardPage)
|
|
||||||
{
|
|
||||||
setIntroDescription(tr("This wizard generates a Qt Unit Test "
|
|
||||||
"consisting of a single source file with a test class."));
|
|
||||||
setWindowIcon(icon);
|
|
||||||
setWindowTitle(templateName);
|
|
||||||
setSelectedModules(QLatin1String("core testlib"), true);
|
|
||||||
if (!parameters.extraValues().contains(QLatin1String(ProjectExplorer::Constants::PROJECT_KIT_IDS)))
|
|
||||||
addTargetSetupPage();
|
|
||||||
addModulesPage();
|
|
||||||
m_testPageId = addPage(m_testPage);
|
|
||||||
addExtensionPages(extensionPages());
|
|
||||||
connect(this, &QWizard::currentIdChanged, this, &TestWizardDialog::slotCurrentIdChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestWizardDialog::slotCurrentIdChanged(int id)
|
|
||||||
{
|
|
||||||
if (id == m_testPageId)
|
|
||||||
m_testPage->setProjectName(projectName());
|
|
||||||
}
|
|
||||||
|
|
||||||
TestWizardParameters TestWizardDialog::testParameters() const
|
|
||||||
{
|
|
||||||
return m_testPage->parameters();
|
|
||||||
}
|
|
||||||
|
|
||||||
QtProjectParameters TestWizardDialog::projectParameters() const
|
|
||||||
{
|
|
||||||
QtProjectParameters rc;
|
|
||||||
rc.type = QtProjectParameters::ConsoleApp;
|
|
||||||
rc.fileName = projectName();
|
|
||||||
rc.path = path();
|
|
||||||
// Name binary "tst_xx" after the main source
|
|
||||||
rc.target = QFileInfo(m_testPage->sourcefileName()).baseName();
|
|
||||||
rc.selectedModules = selectedModulesList();
|
|
||||||
rc.deselectedModules = deselectedModulesList();
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace QmakeProjectManager
|
|
@@ -1,75 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "qtwizard.h"
|
|
||||||
|
|
||||||
namespace QmakeProjectManager {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class TestWizardPage;
|
|
||||||
|
|
||||||
// Parameters of the test wizard.
|
|
||||||
struct TestWizardParameters {
|
|
||||||
enum { requiresQApplicationDefault = 0 };
|
|
||||||
|
|
||||||
static const char *filePrefix;
|
|
||||||
|
|
||||||
TestWizardParameters();
|
|
||||||
|
|
||||||
|
|
||||||
enum Type { Test, Benchmark };
|
|
||||||
|
|
||||||
Type type;
|
|
||||||
bool initializationCode;
|
|
||||||
bool useDataSet;
|
|
||||||
bool requiresQApplication;
|
|
||||||
|
|
||||||
QString className;
|
|
||||||
QString testSlot;
|
|
||||||
QString fileName;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TestWizardDialog : public BaseQmakeProjectWizardDialog
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit TestWizardDialog(const Core::BaseFileWizardFactory *factory, const QString &templateName,
|
|
||||||
const QIcon &icon,
|
|
||||||
QWidget *parent,
|
|
||||||
const Core::WizardDialogParameters ¶meters);
|
|
||||||
|
|
||||||
TestWizardParameters testParameters() const;
|
|
||||||
QtProjectParameters projectParameters() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void slotCurrentIdChanged(int id);
|
|
||||||
TestWizardPage *m_testPage;
|
|
||||||
int m_testPageId;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace QmakeProjectManager
|
|
@@ -1,137 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#include "testwizardpage.h"
|
|
||||||
#include "testwizarddialog.h"
|
|
||||||
#include "qtwizard.h"
|
|
||||||
#include "ui_testwizardpage.h"
|
|
||||||
|
|
||||||
#include <utils/wizard.h>
|
|
||||||
|
|
||||||
namespace QmakeProjectManager {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
TestWizardPage::TestWizardPage(QWidget *parent) :
|
|
||||||
QWizardPage(parent),
|
|
||||||
m_sourceSuffix(QtWizard::sourceSuffix()),
|
|
||||||
m_lowerCaseFileNames(QtWizard::lowerCaseFiles()),
|
|
||||||
ui(new Ui::TestWizardPage),
|
|
||||||
m_fileNameEdited(false),
|
|
||||||
m_valid(false)
|
|
||||||
{
|
|
||||||
setTitle(tr("Test Class Information"));
|
|
||||||
ui->setupUi(this);
|
|
||||||
ui->testSlotLineEdit->setText(QLatin1String("testCase1"));
|
|
||||||
ui->testClassLineEdit->setLowerCaseFileName(m_lowerCaseFileNames);
|
|
||||||
ui->qApplicationCheckBox->setChecked(TestWizardParameters::requiresQApplicationDefault);
|
|
||||||
connect(ui->testClassLineEdit, &Utils::ClassNameValidatingLineEdit::updateFileName,
|
|
||||||
this, &TestWizardPage::slotClassNameEdited);
|
|
||||||
connect(ui->fileLineEdit, &QLineEdit::textEdited, \
|
|
||||||
this, &TestWizardPage::slotFileNameEdited);
|
|
||||||
connect(ui->testClassLineEdit, &Utils::FancyLineEdit::validChanged,
|
|
||||||
this, &TestWizardPage::slotUpdateValid);
|
|
||||||
connect(ui->testSlotLineEdit, &Utils::FancyLineEdit::validChanged,
|
|
||||||
this, &TestWizardPage::slotUpdateValid);
|
|
||||||
connect(ui->fileLineEdit, &Utils::FancyLineEdit::validChanged,
|
|
||||||
this, &TestWizardPage::slotUpdateValid);
|
|
||||||
|
|
||||||
setProperty(Utils::SHORT_TITLE_PROPERTY, tr("Details"));
|
|
||||||
}
|
|
||||||
|
|
||||||
TestWizardPage::~TestWizardPage()
|
|
||||||
{
|
|
||||||
delete ui;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TestWizardPage::isComplete() const
|
|
||||||
{
|
|
||||||
return m_valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString TestWizardPage::sourcefileName() const
|
|
||||||
{
|
|
||||||
return ui->fileLineEdit->text();
|
|
||||||
}
|
|
||||||
|
|
||||||
TestWizardParameters TestWizardPage::parameters() const
|
|
||||||
{
|
|
||||||
TestWizardParameters rc;
|
|
||||||
rc.type = static_cast<TestWizardParameters::Type>(ui->typeComboBox->currentIndex());
|
|
||||||
rc.initializationCode = ui->initCheckBox->isChecked();
|
|
||||||
rc.useDataSet = ui->dataCheckBox->isChecked();
|
|
||||||
rc.requiresQApplication = ui->qApplicationCheckBox->isChecked();
|
|
||||||
rc.className = ui->testClassLineEdit->text();
|
|
||||||
rc.testSlot = ui->testSlotLineEdit->text();
|
|
||||||
rc.fileName = sourcefileName();
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString fileNameFromClass(const QString &className,
|
|
||||||
bool lowerCase,
|
|
||||||
const QString &suffix)
|
|
||||||
{
|
|
||||||
QString rc = QLatin1String(TestWizardParameters::filePrefix);
|
|
||||||
rc += lowerCase ? className.toLower() : className;
|
|
||||||
rc += QLatin1Char('.');
|
|
||||||
rc += suffix;
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestWizardPage::setProjectName(const QString &t)
|
|
||||||
{
|
|
||||||
if (t.isEmpty())
|
|
||||||
return;
|
|
||||||
// initially populate
|
|
||||||
QString className = t;
|
|
||||||
className[0] = className.at(0).toUpper();
|
|
||||||
className += QLatin1String("Test");
|
|
||||||
ui->testClassLineEdit->setText(className);
|
|
||||||
ui->fileLineEdit->setText(fileNameFromClass(className, m_lowerCaseFileNames, m_sourceSuffix));
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestWizardPage::slotClassNameEdited(const QString &className)
|
|
||||||
{
|
|
||||||
if (!m_fileNameEdited)
|
|
||||||
ui->fileLineEdit->setText(fileNameFromClass(className, m_lowerCaseFileNames, m_sourceSuffix));
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestWizardPage::slotFileNameEdited()
|
|
||||||
{
|
|
||||||
m_fileNameEdited = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestWizardPage::slotUpdateValid()
|
|
||||||
{
|
|
||||||
const bool newValid = ui->fileLineEdit->isValid()
|
|
||||||
&& ui->testClassLineEdit->isValid()
|
|
||||||
&& ui->testSlotLineEdit->isValid();
|
|
||||||
if (newValid != m_valid) {
|
|
||||||
m_valid = newValid;
|
|
||||||
emit completeChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace QmakeProjectManager
|
|
@@ -1,67 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
** Contact: https://www.qt.io/licensing/
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator.
|
|
||||||
**
|
|
||||||
** Commercial License Usage
|
|
||||||
** Licensees holding valid commercial Qt licenses may use this file in
|
|
||||||
** accordance with the commercial license agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and The Qt Company. For licensing terms
|
|
||||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
||||||
** information use the contact form at https://www.qt.io/contact-us.
|
|
||||||
**
|
|
||||||
** GNU General Public License Usage
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU
|
|
||||||
** General Public License version 3 as published by the Free Software
|
|
||||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
||||||
** included in the packaging of this file. Please review the following
|
|
||||||
** information to ensure the GNU General Public License requirements will
|
|
||||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QWizardPage>
|
|
||||||
|
|
||||||
namespace QmakeProjectManager {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
namespace Ui { class TestWizardPage; }
|
|
||||||
|
|
||||||
struct TestWizardParameters;
|
|
||||||
|
|
||||||
/* TestWizardPage: Let's the user input test class name, slot
|
|
||||||
* (for which a CLassNameValidatingLineEdit is abused) and file name. */
|
|
||||||
|
|
||||||
class TestWizardPage : public QWizardPage
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit TestWizardPage(QWidget *parent = 0);
|
|
||||||
~TestWizardPage();
|
|
||||||
virtual bool isComplete() const;
|
|
||||||
|
|
||||||
TestWizardParameters parameters() const;
|
|
||||||
QString sourcefileName() const;
|
|
||||||
|
|
||||||
void setProjectName(const QString &);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void slotClassNameEdited(const QString&);
|
|
||||||
void slotFileNameEdited();
|
|
||||||
void slotUpdateValid();
|
|
||||||
|
|
||||||
const QString m_sourceSuffix;
|
|
||||||
const bool m_lowerCaseFileNames;
|
|
||||||
Ui::TestWizardPage *ui;
|
|
||||||
bool m_fileNameEdited;
|
|
||||||
bool m_valid;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace QmakeProjectManager
|
|
@@ -1,141 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>QmakeProjectManager::Internal::TestWizardPage</class>
|
|
||||||
<widget class="QWizardPage" name="QmakeProjectManager::Internal::TestWizardPage">
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string>WizardPage</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="descriptionLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Specify basic information about the test class for which you want to generate skeleton source code file.</string>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="verticalSpacer_2">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeType">
|
|
||||||
<enum>QSizePolicy::Fixed</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>0</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<layout class="QFormLayout" name="formLayout">
|
|
||||||
<property name="fieldGrowthPolicy">
|
|
||||||
<enum>QFormLayout::ExpandingFieldsGrow</enum>
|
|
||||||
</property>
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="testClassLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Class name:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="Utils::ClassNameValidatingLineEdit" name="testClassLineEdit"/>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="label">
|
|
||||||
<property name="text">
|
|
||||||
<string>Test slot:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="Utils::ClassNameValidatingLineEdit" name="testSlotLineEdit"/>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLabel" name="typeLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Type:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QComboBox" name="typeComboBox">
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Test</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Benchmark</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0" colspan="2">
|
|
||||||
<widget class="QCheckBox" name="dataCheckBox">
|
|
||||||
<property name="text">
|
|
||||||
<string>Use a test data set</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="0" colspan="2">
|
|
||||||
<widget class="QCheckBox" name="qApplicationCheckBox">
|
|
||||||
<property name="text">
|
|
||||||
<string>Requires QApplication</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="0" colspan="2">
|
|
||||||
<widget class="QCheckBox" name="initCheckBox">
|
|
||||||
<property name="text">
|
|
||||||
<string>Generate initialization and cleanup code</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="6" column="0">
|
|
||||||
<widget class="QLabel" name="fileLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>File:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="6" column="1">
|
|
||||||
<widget class="Utils::FileNameValidatingLineEdit" name="fileLineEdit">
|
|
||||||
<property name="allowDirectories">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="verticalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>Utils::ClassNameValidatingLineEdit</class>
|
|
||||||
<extends>QLineEdit</extends>
|
|
||||||
<header location="global">utils/classnamevalidatinglineedit.h</header>
|
|
||||||
</customwidget>
|
|
||||||
<customwidget>
|
|
||||||
<class>Utils::FileNameValidatingLineEdit</class>
|
|
||||||
<extends>QLineEdit</extends>
|
|
||||||
<header location="global">utils/filenamevalidatinglineedit.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<resources/>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
Reference in New Issue
Block a user