summaryrefslogtreecommitdiff
path: root/src/plugins/autotest/gtest/gtestsettingspage.cpp
blob: f1d4d2a8271ba925cee5dcbdcbe03980bf41dcf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/****************************************************************************
**
** 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 "gtestconstants.h"
#include "gtestsettingspage.h"
#include "gtestsettings.h"
#include "gtest_utils.h"
#include "../autotestconstants.h"
#include "../testframeworkmanager.h"

#include <coreplugin/icore.h>

namespace Autotest {
namespace Internal {

static bool validateFilter(Utils::FancyLineEdit *edit, QString * /*error*/)
{
    return edit && GTestUtils::isValidGTestFilter(edit->text());
}

GTestSettingsWidget::GTestSettingsWidget()
{
    m_ui.setupUi(this);
    m_ui.filterLineEdit->setValidationFunction(&validateFilter);
    m_ui.filterLineEdit->setEnabled(m_ui.groupModeCombo->currentIndex() == 1);

    connect(m_ui.groupModeCombo, &QComboBox::currentTextChanged,
            this, [this] () {
        m_ui.filterLineEdit->setEnabled(m_ui.groupModeCombo->currentIndex() == 1);
    });
    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);
    m_ui.groupModeCombo->setCurrentIndex(settings.groupMode - 1); // there's None for internal use
    m_ui.filterLineEdit->setText(settings.gtestFilter);
    m_currentGTestFilter = settings.gtestFilter; // store it temporarily (if edit is invalid)
}

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();
    result.groupMode = static_cast<GTest::Constants::GroupMode>(
                m_ui.groupModeCombo->currentIndex() + 1);
    if (m_ui.filterLineEdit->isValid())
        result.gtestFilter = m_ui.filterLineEdit->text();
    else
        result.gtestFilter = m_currentGTestFilter;
    return result;
}

GTestSettingsPage::GTestSettingsPage(QSharedPointer<IFrameworkSettings> settings,
                                     const ITestFramework *framework)
    : ITestSettingsPage(framework),
      m_settings(qSharedPointerCast<GTestSettings>(settings))
{
    setDisplayName(QCoreApplication::translate("GTestFramework",
                                               GTest::Constants::FRAMEWORK_SETTINGS_CATEGORY));
}

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;

    GTest::Constants::GroupMode oldGroupMode = m_settings->groupMode;
    const QString oldFilter = m_settings->gtestFilter;
    *m_settings = m_widget->settings();
    m_settings->toSettings(Core::ICore::settings());
    if (m_settings->groupMode == oldGroupMode && oldFilter == m_settings->gtestFilter)
        return;

    auto id = Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix(GTest::Constants::FRAMEWORK_NAME);
    TestTreeModel::instance()->rebuild({id});
}

} // namespace Internal
} // namespace Autotest