~kdevelop/kdevplatform/master

« back to all changes in this revision

Viewing changes to plugins/problemreporter/tests/test_problemsview.cpp

  • Committer: Friedrich W. H. Kossebau
  • Date: 2017-08-13 21:54:31 UTC
  • Revision ID: git-v1:8ce76bea4df0831deb2fb243af33cc90d3cc8043
Wipe master branch and point in README to new location

Summary: also add util script for moving over existing personal branches

Reviewers: #kdevelop, apol, kfunk

Reviewed By: #kdevelop, apol, kfunk

Subscribers: kfunk, kdevelop-devel

Differential Revision: https://phabricator.kde.org/D7244

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2015 Laszlo Kis-Adam <laszlo.kis-adam@kdemail.net>
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify
5
 
 * it under the terms of the GNU Library General Public License as
6
 
 * published by the Free Software Foundation; either version 2 of the
7
 
 * License, or (at your option) any later version.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public
15
 
 * License along with this program; if not, write to the
16
 
 * Free Software Foundation, Inc.,
17
 
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
 
 */
19
 
 
20
 
#include <QTest>
21
 
#include <QAction>
22
 
#include <QTabWidget>
23
 
 
24
 
#include "../problemsview.h"
25
 
 
26
 
#include <tests/testcore.h>
27
 
#include <tests/autotestshell.h>
28
 
 
29
 
#include <interfaces/ilanguagecontroller.h>
30
 
#include <shell/problemmodelset.h>
31
 
#include <shell/problemmodel.h>
32
 
#include <shell/problem.h>
33
 
 
34
 
using namespace KDevelop;
35
 
 
36
 
class TestProblemsView : public QObject
37
 
{
38
 
    Q_OBJECT
39
 
private Q_SLOTS:
40
 
    void initTestCase();
41
 
    void cleanupTestCase();
42
 
 
43
 
    void testLoad();
44
 
    void testAddModel();
45
 
    void testSwitchTab();
46
 
    void testRemoveModel();
47
 
    void testAddRemoveProblems();
48
 
    void testSetProblems();
49
 
 
50
 
private:
51
 
    QTabWidget* tabWidget();
52
 
 
53
 
    QScopedPointer<ProblemsView> m_view;
54
 
};
55
 
 
56
 
void TestProblemsView::initTestCase()
57
 
{
58
 
    AutoTestShell::init();
59
 
    TestCore::initialize(Core::NoUi);
60
 
 
61
 
    ProblemModelSet* pms = ICore::self()->languageController()->problemModelSet();
62
 
    ProblemModel* model = new ProblemModel(pms);
63
 
    IProblem::Ptr p(new DetectedProblem());
64
 
    model->addProblem(p);
65
 
    pms->addModel(QStringLiteral("MODEL1_ID"), QStringLiteral("MODEL1"), model);
66
 
 
67
 
    m_view.reset(new ProblemsView());
68
 
}
69
 
 
70
 
void TestProblemsView::cleanupTestCase()
71
 
{
72
 
    TestCore::shutdown();
73
 
}
74
 
 
75
 
void TestProblemsView::testLoad()
76
 
{
77
 
    m_view->load();
78
 
 
79
 
    // Check that the initial model's tab shows up
80
 
    QTabWidget* tab = tabWidget();
81
 
    QVERIFY(tab);
82
 
    QCOMPARE(tab->count(), 1);
83
 
    QCOMPARE(tab->tabText(0), QStringLiteral("MODEL1 (1)"));
84
 
}
85
 
 
86
 
void TestProblemsView::testAddModel()
87
 
{
88
 
    ProblemModelSet* pms = ICore::self()->languageController()->problemModelSet();
89
 
    pms->addModel(QStringLiteral("MODEL2_ID"), QStringLiteral("MODEL2"), new ProblemModel(pms));
90
 
 
91
 
    QTabWidget* tab = tabWidget();
92
 
    QVERIFY(tab);
93
 
    QCOMPARE(tab->count(), 2);
94
 
    QCOMPARE(tab->tabText(0), QStringLiteral("MODEL1 (1)"));
95
 
    QCOMPARE(tab->tabText(1), QStringLiteral("MODEL2 (0)"));
96
 
}
97
 
 
98
 
QVector<bool> visibilites(const QList<QAction*> actions)
99
 
{
100
 
    QVector<bool> visibilites;
101
 
    foreach (auto action, actions) {
102
 
        visibilites << action->isVisible();
103
 
    }
104
 
    return visibilites;
105
 
}
106
 
 
107
 
void TestProblemsView::testSwitchTab()
108
 
{
109
 
    QTabWidget* tab = tabWidget();
110
 
    QVERIFY(tab);
111
 
 
112
 
    // Check that the current widget's actions are in the toolbar
113
 
    QWidget* oldWidget = tab->currentWidget();
114
 
    QVERIFY(oldWidget);
115
 
    const auto oldVisibilites = visibilites(m_view->actions());
116
 
 
117
 
    tab->setCurrentIndex(1);
118
 
 
119
 
    // Check that the new widget's actions are in the toolbar
120
 
    QWidget* newWidget = tab->currentWidget();
121
 
    QVERIFY(newWidget);
122
 
    QVERIFY(newWidget != oldWidget);
123
 
    const auto newVisibilites = visibilites(m_view->actions());
124
 
    QCOMPARE(oldVisibilites, newVisibilites);
125
 
}
126
 
 
127
 
void TestProblemsView::testRemoveModel()
128
 
{
129
 
    // Remove the model
130
 
    ProblemModelSet* pms = ICore::self()->languageController()->problemModelSet();
131
 
    ProblemModel* model = pms->findModel(QStringLiteral("MODEL1_ID"));
132
 
    QVERIFY(model);
133
 
    pms->removeModel(QStringLiteral("MODEL1_ID"));
134
 
    delete model;
135
 
    model = nullptr;
136
 
 
137
 
    // Now let's see if the view has been updated!
138
 
    QTabWidget* tab = tabWidget();
139
 
    QVERIFY(tab);
140
 
    QCOMPARE(tab->count(), 1);
141
 
    QCOMPARE(tab->tabText(0), QStringLiteral("MODEL2 (0)"));
142
 
}
143
 
 
144
 
void TestProblemsView::testAddRemoveProblems()
145
 
{
146
 
    ProblemModelSet* pms = ICore::self()->languageController()->problemModelSet();
147
 
    ProblemModel* model = pms->findModel(QStringLiteral("MODEL2_ID"));
148
 
    QVERIFY(model);
149
 
 
150
 
    QTabWidget* tab = tabWidget();
151
 
    QVERIFY(tab);
152
 
 
153
 
    // Make sure there are no problems right now
154
 
    model->clearProblems();
155
 
    QCOMPARE(tab->tabText(0), QStringLiteral("MODEL2 (0)"));
156
 
 
157
 
    // Let's add some problems
158
 
    int c = 0;
159
 
    for (int i = 0; i < 3; i++) {
160
 
        IProblem::Ptr p(new DetectedProblem());
161
 
        model->addProblem(p);
162
 
        c++;
163
 
 
164
 
        // Check if the view has noticed the addition
165
 
        QString label = QStringLiteral("MODEL2 (%1)").arg(c);
166
 
        QCOMPARE(tab->tabText(0), label);
167
 
    }
168
 
 
169
 
    // Clear the problems
170
 
    model->clearProblems();
171
 
 
172
 
    // Check if the view has noticed the clear
173
 
    QCOMPARE(tab->tabText(0), QStringLiteral("MODEL2 (0)"));
174
 
}
175
 
 
176
 
void TestProblemsView::testSetProblems()
177
 
{
178
 
    ProblemModelSet* pms = ICore::self()->languageController()->problemModelSet();
179
 
    ProblemModel* model = pms->findModel(QStringLiteral("MODEL2_ID"));
180
 
    QVERIFY(model);
181
 
 
182
 
    QTabWidget* tab = tabWidget();
183
 
    QVERIFY(tab);
184
 
 
185
 
    // Make sure there are no problems right now
186
 
    model->clearProblems();
187
 
    QCOMPARE(tab->tabText(0), QStringLiteral("MODEL2 (0)"));
188
 
 
189
 
    // Build a problem vector and set the problems
190
 
    QVector<IProblem::Ptr> problems;
191
 
    for (int i = 0; i < 3; i++) {
192
 
        IProblem::Ptr p(new DetectedProblem());
193
 
        problems.push_back(p);
194
 
    }
195
 
    model->setProblems(problems);
196
 
 
197
 
    // Check if the view has noticed
198
 
    QCOMPARE(tab->tabText(0), QStringLiteral("MODEL2 (3)"));
199
 
}
200
 
 
201
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////
202
 
 
203
 
QTabWidget* TestProblemsView::tabWidget()
204
 
{
205
 
    QTabWidget* tab = m_view->findChild<QTabWidget*>();
206
 
    return tab;
207
 
}
208
 
 
209
 
QTEST_MAIN(TestProblemsView)
210
 
 
211
 
#include "test_problemsview.moc"