File: test_problemstore.cpp

package info (click to toggle)
kdevelop 4%3A5.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 57,892 kB
  • sloc: cpp: 278,773; javascript: 3,558; python: 3,385; sh: 1,317; ansic: 689; xml: 273; php: 95; makefile: 40; lisp: 13; sed: 12
file content (158 lines) | stat: -rw-r--r-- 3,905 bytes parent folder | download
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 * Copyright 2015 Laszlo Kis-Adam <laszlo.kis-adam@kdemail.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Library General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <QTest>
#include <QSignalSpy>
#include <shell/problemstore.h>
#include <shell/problem.h>
#include <shell/problemstorenode.h>
#include <shell/problemconstants.h>

#include <tests/testcore.h>
#include <tests/autotestshell.h>

using namespace KDevelop;

class TestProblemStore : public QObject
{
    Q_OBJECT

private Q_SLOTS:
    void initTestCase();
    void cleanupTestCase();

    void testAddProblems();
    void testClearProblems();
    void testSetProblems();
    void testFindNode();
    void testSeverity();
    void testSeverities();
    void testScope();

private:
    void generateProblems();

    QScopedPointer<ProblemStore> m_store;
    QVector<IProblem::Ptr> m_problems;
};


void TestProblemStore::initTestCase()
{
    AutoTestShell::init();
    TestCore::initialize(Core::NoUi);

    m_store.reset(new ProblemStore());
    m_store->setScope(CurrentDocument);
    QVERIFY(m_store->scope() == CurrentDocument);

    generateProblems();
}

void TestProblemStore::cleanupTestCase()
{
    TestCore::shutdown();
}

void TestProblemStore::testAddProblems()
{
    QCOMPARE(m_store->count(), 0);

    int c = 0;
    for (const IProblem::Ptr& problem : qAsConst(m_problems)) {
        m_store->addProblem(problem);
        c++;

        QCOMPARE(m_store->count(), c);
    }
}

void TestProblemStore::testClearProblems()
{
    m_store->clear();
    QCOMPARE(m_store->count(), 0);
}

void TestProblemStore::testSetProblems()
{
    m_store->setProblems(m_problems);

    QCOMPARE(m_store->count(), m_problems.count());
}

void TestProblemStore::testFindNode()
{
    for (int i = 0; i < m_problems.count(); i++) {
        const auto *node = dynamic_cast<const ProblemNode*>(m_store->findNode(i));

        QVERIFY(node);
        QVERIFY(node->problem().data());
        QCOMPARE(node->problem().data()->description(), m_problems[i]->description());
    }
}

void TestProblemStore::testSeverity()
{
    IProblem::Severity severity = IProblem::Error;

    QVERIFY(severity != m_store->severity());

    QSignalSpy spy(m_store.data(), &ProblemStore::changed);
    m_store->setSeverity(severity);

    QVERIFY(m_store->severity() == severity);
    QCOMPARE(spy.count(), 1);
}

void TestProblemStore::testSeverities()
{
    IProblem::Severities severities = IProblem::Error | IProblem::Hint;

    QVERIFY(severities != m_store->severities());

    QSignalSpy spy(m_store.data(), &ProblemStore::changed);
    m_store->setSeverities(severities);

    QVERIFY(m_store->severities() == severities);
    QCOMPARE(spy.count(), 1);
}

void TestProblemStore::testScope()
{
    QSignalSpy spy(m_store.data(), &ProblemStore::changed);
    ProblemScope scope = AllProjects;

    m_store->setScope(scope);
    QVERIFY(m_store->scope() == scope);
    QCOMPARE(spy.count(), 1);
}

void TestProblemStore::generateProblems()
{
    for (int i = 0; i < 5; i++) {
        IProblem::Ptr problem(new DetectedProblem());

        problem->setDescription(QStringLiteral("PROBLEM") + QString::number(i + 1));
        m_problems.push_back(problem);
    }
}

QTEST_MAIN(TestProblemStore)

#include "test_problemstore.moc"