2
* Copyright 2015 Laszlo Kis-Adam <laszlo.kis-adam@kdemail.net>
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.
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.
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.
24
#include "../problemsview.h"
26
#include <tests/testcore.h>
27
#include <tests/autotestshell.h>
29
#include <interfaces/ilanguagecontroller.h>
30
#include <shell/problemmodelset.h>
31
#include <shell/problemmodel.h>
32
#include <shell/problem.h>
34
using namespace KDevelop;
36
class TestProblemsView : public QObject
41
void cleanupTestCase();
46
void testRemoveModel();
47
void testAddRemoveProblems();
48
void testSetProblems();
51
QTabWidget* tabWidget();
53
QScopedPointer<ProblemsView> m_view;
56
void TestProblemsView::initTestCase()
58
AutoTestShell::init();
59
TestCore::initialize(Core::NoUi);
61
ProblemModelSet* pms = ICore::self()->languageController()->problemModelSet();
62
ProblemModel* model = new ProblemModel(pms);
63
IProblem::Ptr p(new DetectedProblem());
65
pms->addModel(QStringLiteral("MODEL1_ID"), QStringLiteral("MODEL1"), model);
67
m_view.reset(new ProblemsView());
70
void TestProblemsView::cleanupTestCase()
75
void TestProblemsView::testLoad()
79
// Check that the initial model's tab shows up
80
QTabWidget* tab = tabWidget();
82
QCOMPARE(tab->count(), 1);
83
QCOMPARE(tab->tabText(0), QStringLiteral("MODEL1 (1)"));
86
void TestProblemsView::testAddModel()
88
ProblemModelSet* pms = ICore::self()->languageController()->problemModelSet();
89
pms->addModel(QStringLiteral("MODEL2_ID"), QStringLiteral("MODEL2"), new ProblemModel(pms));
91
QTabWidget* tab = tabWidget();
93
QCOMPARE(tab->count(), 2);
94
QCOMPARE(tab->tabText(0), QStringLiteral("MODEL1 (1)"));
95
QCOMPARE(tab->tabText(1), QStringLiteral("MODEL2 (0)"));
98
QVector<bool> visibilites(const QList<QAction*> actions)
100
QVector<bool> visibilites;
101
foreach (auto action, actions) {
102
visibilites << action->isVisible();
107
void TestProblemsView::testSwitchTab()
109
QTabWidget* tab = tabWidget();
112
// Check that the current widget's actions are in the toolbar
113
QWidget* oldWidget = tab->currentWidget();
115
const auto oldVisibilites = visibilites(m_view->actions());
117
tab->setCurrentIndex(1);
119
// Check that the new widget's actions are in the toolbar
120
QWidget* newWidget = tab->currentWidget();
122
QVERIFY(newWidget != oldWidget);
123
const auto newVisibilites = visibilites(m_view->actions());
124
QCOMPARE(oldVisibilites, newVisibilites);
127
void TestProblemsView::testRemoveModel()
130
ProblemModelSet* pms = ICore::self()->languageController()->problemModelSet();
131
ProblemModel* model = pms->findModel(QStringLiteral("MODEL1_ID"));
133
pms->removeModel(QStringLiteral("MODEL1_ID"));
137
// Now let's see if the view has been updated!
138
QTabWidget* tab = tabWidget();
140
QCOMPARE(tab->count(), 1);
141
QCOMPARE(tab->tabText(0), QStringLiteral("MODEL2 (0)"));
144
void TestProblemsView::testAddRemoveProblems()
146
ProblemModelSet* pms = ICore::self()->languageController()->problemModelSet();
147
ProblemModel* model = pms->findModel(QStringLiteral("MODEL2_ID"));
150
QTabWidget* tab = tabWidget();
153
// Make sure there are no problems right now
154
model->clearProblems();
155
QCOMPARE(tab->tabText(0), QStringLiteral("MODEL2 (0)"));
157
// Let's add some problems
159
for (int i = 0; i < 3; i++) {
160
IProblem::Ptr p(new DetectedProblem());
161
model->addProblem(p);
164
// Check if the view has noticed the addition
165
QString label = QStringLiteral("MODEL2 (%1)").arg(c);
166
QCOMPARE(tab->tabText(0), label);
169
// Clear the problems
170
model->clearProblems();
172
// Check if the view has noticed the clear
173
QCOMPARE(tab->tabText(0), QStringLiteral("MODEL2 (0)"));
176
void TestProblemsView::testSetProblems()
178
ProblemModelSet* pms = ICore::self()->languageController()->problemModelSet();
179
ProblemModel* model = pms->findModel(QStringLiteral("MODEL2_ID"));
182
QTabWidget* tab = tabWidget();
185
// Make sure there are no problems right now
186
model->clearProblems();
187
QCOMPARE(tab->tabText(0), QStringLiteral("MODEL2 (0)"));
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);
195
model->setProblems(problems);
197
// Check if the view has noticed
198
QCOMPARE(tab->tabText(0), QStringLiteral("MODEL2 (3)"));
201
//////////////////////////////////////////////////////////////////////////////////////////////////////////
203
QTabWidget* TestProblemsView::tabWidget()
205
QTabWidget* tab = m_view->findChild<QTabWidget*>();
209
QTEST_MAIN(TestProblemsView)
211
#include "test_problemsview.moc"