Commit 4048403a authored by Christian Stenger's avatar Christian Stenger
Browse files

AutoTest: Separate settings pages



Change-Id: Ib7fedbd5c3bfdc793e1ef203a3ad808c55ac1a70
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent 18dc7a5d
......@@ -31,6 +31,7 @@ SOURCES += \
gtest/gtestvisitors.cpp \
gtest/gtestframework.cpp \
gtest/gtestsettings.cpp \
gtest/gtestsettingspage.cpp \
qtest/qttesttreeitem.cpp \
qtest/qttestvisitors.cpp \
qtest/qttestconfiguration.cpp \
......@@ -39,6 +40,7 @@ SOURCES += \
qtest/qttestparser.cpp \
qtest/qttestframework.cpp \
qtest/qttestsettings.cpp \
qtest/qttestsettingspage.cpp \
quick/quicktestconfiguration.cpp \
quick/quicktestparser.cpp \
quick/quicktesttreeitem.cpp \
......@@ -80,6 +82,7 @@ HEADERS += \
gtest/gtestvisitors.h \
gtest/gtestframework.h \
gtest/gtestsettings.h \
gtest/gtestsettingspage.h \
gtest/gtestconstants.h \
qtest/qttesttreeitem.h \
qtest/qttest_utils.h \
......@@ -90,6 +93,7 @@ HEADERS += \
qtest/qttestparser.h \
qtest/qttestframework.h \
qtest/qttestsettings.h \
qtest/qttestsettingspage.h \
qtest/qttestconstants.h \
quick/quicktestconfiguration.h \
quick/quicktestparser.h \
......@@ -104,7 +108,9 @@ RESOURCES += \
autotest.qrc
FORMS += \
testsettingspage.ui
testsettingspage.ui \
qtest/qttestsettingspage.ui \
gtest/gtestsettingspage.ui
equals(TEST, 1) {
HEADERS += autotestunittests.h
......
......@@ -39,6 +39,7 @@ const char AUTOTEST_CONTEXT[] = "Auto Tests";
const char TASK_INDEX[] = "AutoTest.Task.Index";
const char TASK_PARSE[] = "AutoTest.Task.Parse";
const char AUTOTEST_SETTINGS_CATEGORY[] = "ZY.Tests";
const char AUTOTEST_SETTINGS_TR[] = QT_TRANSLATE_NOOP("AutoTest", "Test Settings");
const char FRAMEWORK_PREFIX[] = "AutoTest.Framework.";
......
......@@ -26,6 +26,7 @@
#include "gtestframework.h"
#include "gtestconstants.h"
#include "gtestsettings.h"
#include "gtestsettingspage.h"
#include "gtesttreeitem.h"
#include "gtestparser.h"
......@@ -60,6 +61,11 @@ IFrameworkSettings *GTestFramework::createFrameworkSettings() const
return new GTestSettings;
}
Core::IOptionsPage *GTestFramework::createSettingsPage(QSharedPointer<IFrameworkSettings> settings) const
{
return new GTestSettingsPage(settings);
}
bool GTestFramework::hasFrameworkSettings() const
{
return true;
......
......@@ -37,8 +37,8 @@ public:
const char *name() const override;
unsigned priority() const override;
IFrameworkSettings *createFrameworkSettings() const override;
Core::IOptionsPage *createSettingsPage(QSharedPointer<IFrameworkSettings> settings) const override;
bool hasFrameworkSettings() const override;
protected:
ITestParser *createTestParser() const override;
TestTreeItem *createRootNode() const override;
......
......@@ -41,7 +41,7 @@ QString GTestSettings::name() const
return QString("GTest");
}
void GTestSettings::fromSettings(const QSettings *s)
void GTestSettings::fromFrameworkSettings(const QSettings *s)
{
runDisabled = s->value(runDisabledKey, false).toBool();
repeat = s->value(repeatKey, false).toBool();
......@@ -52,7 +52,7 @@ void GTestSettings::fromSettings(const QSettings *s)
throwOnFailure = s->value(throwOnFailureKey, false).toBool();
}
void GTestSettings::toSettings(QSettings *s) const
void GTestSettings::toFrameworkSettings(QSettings *s) const
{
s->setValue(runDisabledKey, runDisabled);
s->setValue(repeatKey, repeat);
......
......@@ -35,8 +35,6 @@ class GTestSettings : public IFrameworkSettings
public:
GTestSettings() {}
QString name() const override;
void fromSettings(const QSettings *s) override;
void toSettings(QSettings *s) const override;
int iterations = 1;
int seed = 0;
......@@ -45,6 +43,10 @@ public:
bool repeat = false;
bool throwOnFailure = false;
bool breakOnFailure = true;
protected:
void fromFrameworkSettings(const QSettings *s) override;
void toFrameworkSettings(QSettings *s) const override;
};
} // namespace Internal
......
/****************************************************************************
**
** 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 "../autotestconstants.h"
#include "gtestconstants.h"
#include "gtestsettingspage.h"
#include "gtestsettings.h"
#include <coreplugin/icore.h>
namespace Autotest {
namespace Internal {
GTestSettingsWidget::GTestSettingsWidget(QWidget *parent)
: QWidget(parent)
{
m_ui.setupUi(this);
connect(m_ui.repeatGTestsCB, &QCheckBox::toggled, m_ui.repetitionSpin, &QSpinBox::setEnabled);
connect(m_ui.shuffleGTestsCB, &QCheckBox::toggled, m_ui.seedSpin, &QSpinBox::setEnabled);
}
void GTestSettingsWidget::setSettings(const GTestSettings &settings)
{
m_ui.runDisabledGTestsCB->setChecked(settings.runDisabled);
m_ui.repeatGTestsCB->setChecked(settings.repeat);
m_ui.shuffleGTestsCB->setChecked(settings.shuffle);
m_ui.repetitionSpin->setValue(settings.iterations);
m_ui.seedSpin->setValue(settings.seed);
m_ui.breakOnFailureCB->setChecked(settings.breakOnFailure);
m_ui.throwOnFailureCB->setChecked(settings.throwOnFailure);
}
GTestSettings GTestSettingsWidget::settings() const
{
GTestSettings result;
result.runDisabled = m_ui.runDisabledGTestsCB->isChecked();
result.repeat = m_ui.repeatGTestsCB->isChecked();
result.shuffle = m_ui.shuffleGTestsCB->isChecked();
result.iterations = m_ui.repetitionSpin->value();
result.seed = m_ui.seedSpin->value();
result.breakOnFailure = m_ui.breakOnFailureCB->isChecked();
result.throwOnFailure = m_ui.throwOnFailureCB->isChecked();
return result;
}
GTestSettingsPage::GTestSettingsPage(QSharedPointer<IFrameworkSettings> settings)
: m_settings(qSharedPointerCast<GTestSettings>(settings)), m_widget(0)
{
setId("A.AutoTest.10.GTest"); // FIXME
setDisplayName(QCoreApplication::translate("GTestFramework",
GTest::Constants::FRAMEWORK_SETTINGS_CATEGORY));
setCategory(Constants::AUTOTEST_SETTINGS_CATEGORY);
setDisplayCategory(QCoreApplication::translate("AutoTest", Constants::AUTOTEST_SETTINGS_TR));
}
GTestSettingsPage::~GTestSettingsPage()
{
}
QWidget *GTestSettingsPage::widget()
{
if (!m_widget) {
m_widget = new GTestSettingsWidget;
m_widget->setSettings(*m_settings);
}
return m_widget;
}
void GTestSettingsPage::apply()
{
if (!m_widget) // page was not shown at all
return;
*m_settings = m_widget->settings();
m_settings->toSettings(Core::ICore::settings());
}
} // namespace Internal
} // namespace Autotest
/****************************************************************************
**
** 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 "ui_gtestsettingspage.h"
#include <coreplugin/dialogs/ioptionspage.h>
#include <QPointer>
namespace Autotest {
namespace Internal {
class IFrameworkSettings;
class GTestSettings;
class GTestSettingsWidget : public QWidget
{
Q_OBJECT
public:
explicit GTestSettingsWidget(QWidget *parent = 0);
void setSettings(const GTestSettings &settings);
GTestSettings settings() const;
private:
Ui::GTestSettingsPage m_ui;
};
class GTestSettingsPage : public Core::IOptionsPage
{
Q_OBJECT
public:
explicit GTestSettingsPage(QSharedPointer<IFrameworkSettings> settings);
~GTestSettingsPage();
QWidget *widget() override;
void apply() override;
void finish() override { }
private:
QSharedPointer<GTestSettings> m_settings;
QPointer<GTestSettingsWidget> m_widget;
};
} // namespace Internal
} // namespace Autotest
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Autotest::Internal::GTestSettingsPage</class>
<widget class="QWidget" name="Autotest::Internal::GTestSettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>397</width>
<height>205</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="runDisabledGTestsCB">
<property name="toolTip">
<string>Executes disabled tests when performing a test run.</string>
</property>
<property name="text">
<string>Run disabled tests</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="breakOnFailureCB">
<property name="toolTip">
<string>Turn failures into debugger breakpoints.</string>
</property>
<property name="text">
<string>Break on failure while debugging</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="repeatGTestsCB">
<property name="toolTip">
<string>Repeats a test run (you might be required to increase the timeout to avoid canceling the tests).</string>
</property>
<property name="text">
<string>Repeat tests</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Iterations:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="repetitionSpin">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QCheckBox" name="shuffleGTestsCB">
<property name="toolTip">
<string>Shuffle tests automatically on every iteration by the given seed.</string>
</property>
<property name="text">
<string>Shuffle tests</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Seed:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="seedSpin">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>A seed of 0 generates a seed based on the current timestamp.</string>
</property>
<property name="specialValueText">
<string/>
</property>
<property name="maximum">
<number>99999</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="throwOnFailureCB">
<property name="toolTip">
<string>Turn assertion failures into C++ exceptions.</string>
</property>
<property name="text">
<string>Throw on failure</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -25,6 +25,8 @@
#pragma once
#include "autotestconstants.h"
#include <QSettings>
namespace Autotest {
......@@ -37,8 +39,28 @@ public:
virtual ~IFrameworkSettings() {}
virtual QString name() const = 0;
virtual void toSettings(QSettings *s) const = 0;
virtual void fromSettings(const QSettings *s) = 0;
void toSettings(QSettings *s) const
{
s->beginGroup(Constants::SETTINGSGROUP);
s->beginGroup(name());
toFrameworkSettings(s);
s->endGroup();
s->endGroup();
}
void fromSettings(QSettings *s)
{
s->beginGroup(Constants::SETTINGSGROUP);
s->beginGroup(name());
fromFrameworkSettings(s);
s->endGroup();
s->endGroup();
}
protected:
virtual void toFrameworkSettings(QSettings *s) const = 0;
virtual void fromFrameworkSettings(const QSettings *s) = 0;
};
} // namespace Internal
......
......@@ -28,6 +28,8 @@
#include "testtreeitem.h"
#include "itestparser.h"
namespace Core { class IOptionsPage; }
namespace Autotest {
namespace Internal {
......@@ -47,6 +49,11 @@ public:
virtual unsigned priority() const = 0; // should this be modifyable?
virtual bool hasFrameworkSettings() const { return false; }
virtual IFrameworkSettings *createFrameworkSettings() const { return 0; }
virtual Core::IOptionsPage *createSettingsPage(QSharedPointer<IFrameworkSettings> settings) const
{
Q_UNUSED(settings);
return 0;
}
TestTreeItem *rootNode()
{ if (!m_rootNode)
......
......@@ -27,6 +27,7 @@
#include "qttestconstants.h"
#include "qttestparser.h"
#include "qttestsettings.h"
#include "qttestsettingspage.h"
#include "qttesttreeitem.h"
namespace Autotest {
......@@ -50,6 +51,11 @@ IFrameworkSettings *QtTestFramework::createFrameworkSettings() const
return new QtTestSettings;
}
Core::IOptionsPage *QtTestFramework::createSettingsPage(QSharedPointer<IFrameworkSettings> settings) const
{
return new QtTestSettingsPage(settings);
}
bool QtTestFramework::hasFrameworkSettings() const
{
return true;
......
......@@ -37,6 +37,7 @@ public:
const char *name() const override;
unsigned priority() const override;
IFrameworkSettings *createFrameworkSettings() const override;
Core::IOptionsPage *createSettingsPage(QSharedPointer<IFrameworkSettings> settings) const override;
bool hasFrameworkSettings() const override;
protected:
......
......@@ -54,13 +54,13 @@ QString QtTestSettings::name() const