-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathtesterroritem.cpp
More file actions
162 lines (134 loc) · 4.89 KB
/
testerroritem.cpp
File metadata and controls
162 lines (134 loc) · 4.89 KB
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
159
160
161
162
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2026 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "testerroritem.h"
#include "erroritem.h"
#include "errortypes.h"
#include <QtTest>
QTEST_MAIN(TestErrorItem)
void TestErrorItem::guiSeverity_toString() const
{
QCOMPARE(GuiSeverity::toString(Severity::error), QString("error"));
QCOMPARE(GuiSeverity::toString(Severity::warning), QString("warning"));
QCOMPARE(GuiSeverity::toString(Severity::style), QString("style"));
QCOMPARE(GuiSeverity::toString(Severity::performance), QString("performance"));
QCOMPARE(GuiSeverity::toString(Severity::portability), QString("portability"));
QCOMPARE(GuiSeverity::toString(Severity::information), QString("information"));
QCOMPARE(GuiSeverity::toString(Severity::none), QString(""));
}
void TestErrorItem::guiSeverity_fromString() const
{
QCOMPARE(GuiSeverity::fromString("error"), Severity::error);
QCOMPARE(GuiSeverity::fromString("warning"), Severity::warning);
QCOMPARE(GuiSeverity::fromString("style"), Severity::style);
QCOMPARE(GuiSeverity::fromString("performance"), Severity::performance);
QCOMPARE(GuiSeverity::fromString("portability"), Severity::portability);
QCOMPARE(GuiSeverity::fromString("information"), Severity::information);
QCOMPARE(GuiSeverity::fromString("none"), Severity::none);
QCOMPARE(GuiSeverity::fromString("unknown"), Severity::none);
}
void TestErrorItem::errorItem_tool() const
{
ErrorItem item;
item.errorId = "nullPointer";
QCOMPARE(item.tool(), QString("cppcheck"));
item.errorId = "clang-analyzer";
QCOMPARE(item.tool(), QString("clang-analyzer"));
item.errorId = "clang-tidy-readability-braces";
QCOMPARE(item.tool(), QString("clang-tidy"));
item.errorId = "clang-diagnostic-unused";
QCOMPARE(item.tool(), QString("clang"));
}
void TestErrorItem::errorItem_toString() const
{
ErrorItem item;
item.errorId = "nullPointer";
item.severity = Severity::error;
item.summary = "Null pointer dereference";
QErrorPathItem path;
path.file = "test.cpp";
path.line = 42;
path.column = 5;
item.errorPath << path;
const QString result = item.toString();
QVERIFY(result.startsWith("test.cpp:42:5:"));
QVERIFY(result.contains("[nullPointer]"));
QVERIFY(result.contains("Null pointer dereference"));
QVERIFY(result.contains("error"));
}
void TestErrorItem::errorItem_same_byHash() const
{
ErrorItem item1;
item1.hash = 12345;
ErrorItem item2;
item2.hash = 12345;
QVERIFY(ErrorItem::same(item1, item2));
item2.hash = 99999;
QVERIFY(!ErrorItem::same(item1, item2));
}
void TestErrorItem::errorItem_same_byFields() const
{
ErrorItem item1;
item1.errorId = "nullPointer";
item1.severity = Severity::error;
item1.message = "The pointer is null";
item1.inconclusive = false;
QErrorPathItem p;
p.file = "test.cpp";
p.line = 10;
p.column = 3;
item1.errorPath << p;
ErrorItem item2 = item1;
QVERIFY(ErrorItem::same(item1, item2));
}
void TestErrorItem::errorItem_same_different() const
{
ErrorItem item1;
item1.errorId = "nullPointer";
item1.severity = Severity::error;
ErrorItem item2;
item2.errorId = "uninitVar";
item2.severity = Severity::error;
QVERIFY(!ErrorItem::same(item1, item2));
}
void TestErrorItem::errorItem_filterMatch() const
{
ErrorItem item;
item.errorId = "nullPointer";
item.summary = "Null pointer dereference";
item.message = "The pointer is null at this location";
QErrorPathItem p;
p.file = "main.cpp";
p.info = "check here";
item.errorPath << p;
// empty filter matches everything
QVERIFY(item.filterMatch(""));
// matches in errorId (case insensitive)
QVERIFY(item.filterMatch("nullPointer"));
QVERIFY(item.filterMatch("NULLpointer"));
// matches in summary
QVERIFY(item.filterMatch("Null pointer"));
QVERIFY(item.filterMatch("DEREFERENCE"));
// matches in message
QVERIFY(item.filterMatch("location"));
// matches in errorPath file
QVERIFY(item.filterMatch("main.cpp"));
// matches in errorPath info
QVERIFY(item.filterMatch("check here"));
// no match
QVERIFY(!item.filterMatch("xyz123abc"));
}