File indexing completed on 2024-05-12 04:38:20
0001 /* 0002 SPDX-FileCopyrightText: 2015 Laszlo Kis-Adam <laszlo.kis-adam@kdemail.net> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include <QTest> 0008 #include <QSignalSpy> 0009 #include <shell/filteredproblemstore.h> 0010 #include <shell/problem.h> 0011 #include <shell/problemstorenode.h> 0012 #include <shell/problemconstants.h> 0013 #include <language/editor/documentrange.h> 0014 0015 #include <tests/testcore.h> 0016 #include <tests/autotestshell.h> 0017 0018 #include <KLocalizedString> 0019 0020 namespace 0021 { 0022 const int ErrorCount = 1; 0023 const int WarningCount = 2; 0024 const int HintCount = 3; 0025 const int ProblemsCount = ErrorCount + WarningCount + HintCount; 0026 0027 const int ErrorFilterProblemCount = ErrorCount; 0028 const int WarningFilterProblemCount = ErrorCount + WarningCount; 0029 const int HintFilterProblemCount = ErrorCount + WarningCount + HintCount; 0030 } 0031 0032 using namespace KDevelop; 0033 0034 class TestFilteredProblemStore : public QObject 0035 { 0036 Q_OBJECT 0037 private Q_SLOTS: 0038 void initTestCase(); 0039 void cleanupTestCase(); 0040 0041 void testSeverity(); 0042 void testSeverities(); 0043 void testGrouping(); 0044 0045 void testNoGrouping(); 0046 void testPathGrouping(); 0047 void testSeverityGrouping(); 0048 0049 private: 0050 // Severity grouping testing 0051 bool checkCounts(int error, int warning, int hint); 0052 bool checkNodeLabels(); 0053 // --------------------------- 0054 0055 void generateProblems(); 0056 0057 QScopedPointer<FilteredProblemStore> m_store; 0058 QVector<IProblem::Ptr> m_problems; 0059 IProblem::Ptr m_diagnosticTestProblem; 0060 }; 0061 0062 0063 0064 #define MYCOMPARE(actual, expected) \ 0065 if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__)) \ 0066 return false 0067 0068 #define MYVERIFY(statement) \ 0069 if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\ 0070 return false 0071 0072 void TestFilteredProblemStore::initTestCase() 0073 { 0074 AutoTestShell::init(); 0075 TestCore::initialize(Core::NoUi); 0076 0077 m_store.reset(new FilteredProblemStore()); 0078 0079 generateProblems(); 0080 } 0081 0082 void TestFilteredProblemStore::cleanupTestCase() 0083 { 0084 TestCore::shutdown(); 0085 } 0086 0087 void TestFilteredProblemStore::testSeverity() 0088 { 0089 QVERIFY(m_store->severity() == IProblem::Hint); 0090 0091 QSignalSpy changedSpy(m_store.data(), &FilteredProblemStore::changed); 0092 QSignalSpy beginRebuildSpy(m_store.data(), &FilteredProblemStore::beginRebuild); 0093 QSignalSpy endRebuildSpy(m_store.data(), &FilteredProblemStore::endRebuild); 0094 0095 m_store->setSeverity(IProblem::Error); 0096 0097 QVERIFY(m_store->severity() == IProblem::Error); 0098 0099 QCOMPARE(changedSpy.count(), 1); 0100 QCOMPARE(beginRebuildSpy.count(), 1); 0101 QCOMPARE(endRebuildSpy.count(), 1); 0102 0103 m_store->setSeverity(IProblem::Hint); 0104 } 0105 0106 void TestFilteredProblemStore::testSeverities() 0107 { 0108 QVERIFY(m_store->severities() == (IProblem::Error | IProblem::Warning | IProblem::Hint)); 0109 0110 QSignalSpy changedSpy(m_store.data(), &FilteredProblemStore::changed); 0111 QSignalSpy beginRebuildSpy(m_store.data(), &FilteredProblemStore::beginRebuild); 0112 QSignalSpy endRebuildSpy(m_store.data(), &FilteredProblemStore::endRebuild); 0113 0114 m_store->setSeverities(IProblem::Error | IProblem::Hint); 0115 0116 QVERIFY(m_store->severities() == (IProblem::Error | IProblem::Hint)); 0117 0118 QCOMPARE(changedSpy.count(), 1); 0119 QCOMPARE(beginRebuildSpy.count(), 1); 0120 QCOMPARE(endRebuildSpy.count(), 1); 0121 0122 m_store->setSeverities(IProblem::Error | IProblem::Warning | IProblem::Hint); 0123 } 0124 0125 void TestFilteredProblemStore::testGrouping() 0126 { 0127 QVERIFY(m_store->grouping() == NoGrouping); 0128 0129 QSignalSpy changedSpy(m_store.data(), &FilteredProblemStore::changed); 0130 QSignalSpy beginRebuildSpy(m_store.data(), &FilteredProblemStore::beginRebuild); 0131 QSignalSpy endRebuildSpy(m_store.data(), &FilteredProblemStore::endRebuild); 0132 0133 m_store->setGrouping(PathGrouping); 0134 QVERIFY(m_store->grouping() == PathGrouping); 0135 0136 QCOMPARE(changedSpy.count(), 1); 0137 QCOMPARE(beginRebuildSpy.count(), 1); 0138 QCOMPARE(endRebuildSpy.count(), 1); 0139 0140 m_store->setGrouping(NoGrouping); 0141 } 0142 0143 // Compares the node and it's children to a reference problem and it's diagnostics 0144 bool checkDiagnodes(const ProblemStoreNode *node, const IProblem::Ptr &reference) 0145 { 0146 const auto *problemNode = dynamic_cast<const ProblemNode*>(node); 0147 MYVERIFY(problemNode); 0148 MYCOMPARE(problemNode->problem()->description(), reference->description()); 0149 MYCOMPARE(problemNode->problem()->finalLocation().document.str(), reference->finalLocation().document.str()); 0150 MYCOMPARE(problemNode->count(), 1); 0151 0152 const IProblem::Ptr diag = reference->diagnostics().at(0); 0153 const auto *diagNode = dynamic_cast<const ProblemNode*>(problemNode->child(0)); 0154 MYVERIFY(diagNode); 0155 MYCOMPARE(diagNode->problem()->description(), diag->description()); 0156 MYCOMPARE(diagNode->count(), 1); 0157 0158 const IProblem::Ptr diagdiag = diag->diagnostics().at(0); 0159 const auto *diagdiagNode = dynamic_cast<const ProblemNode*>(diagNode->child(0)); 0160 MYVERIFY(diagdiagNode); 0161 MYCOMPARE(diagdiagNode->problem()->description(), diagdiag->description()); 0162 MYCOMPARE(diagdiagNode->count(), 0); 0163 0164 return true; 0165 } 0166 0167 void TestFilteredProblemStore::testNoGrouping() 0168 { 0169 // Add problems 0170 int c = 0; 0171 for (const IProblem::Ptr& p : qAsConst(m_problems)) { 0172 m_store->addProblem(p); 0173 0174 c++; 0175 QCOMPARE(m_store->count(), c); 0176 } 0177 for (int i = 0; i < c; i++) { 0178 const auto *node = dynamic_cast<const ProblemNode*>(m_store->findNode(i)); 0179 QVERIFY(node); 0180 0181 QCOMPARE(node->problem()->description(), m_problems[i]->description()); 0182 } 0183 0184 // Check if clear works 0185 m_store->clear(); 0186 QCOMPARE(m_store->count(), 0); 0187 0188 // Set problems 0189 m_store->setProblems(m_problems); 0190 QCOMPARE(m_problems.count(), m_store->count()); 0191 for (int i = 0; i < c; i++) { 0192 const auto *node = dynamic_cast<const ProblemNode*>(m_store->findNode(i)); 0193 QVERIFY(node); 0194 QCOMPARE(node->problem()->description(), m_problems[i]->description()); 0195 } 0196 0197 // Check old style severity filtering 0198 // old-style setSeverity 0199 // Error filter 0200 m_store->setSeverity(IProblem::Error); 0201 QCOMPARE(m_store->count(), ErrorFilterProblemCount); 0202 for (int i = 0; i < ErrorFilterProblemCount; i++) { 0203 const auto *node = dynamic_cast<const ProblemNode*>(m_store->findNode(0)); 0204 QVERIFY(node); 0205 QCOMPARE(node->problem()->description(), m_problems[i]->description()); 0206 } 0207 0208 // Warning filter 0209 m_store->setSeverity(IProblem::Warning); 0210 QCOMPARE(m_store->count(), WarningFilterProblemCount); 0211 for (int i = 0; i < WarningFilterProblemCount; i++) { 0212 const auto *node = dynamic_cast<const ProblemNode*>(m_store->findNode(i)); 0213 QVERIFY(node); 0214 0215 QCOMPARE(node->problem()->description(), m_problems[i]->description()); 0216 } 0217 0218 // Hint filter 0219 m_store->setSeverity(IProblem::Hint); 0220 QCOMPARE(m_store->count(), HintFilterProblemCount); 0221 for (int i = 0; i < HintFilterProblemCount; i++) { 0222 const auto *node = dynamic_cast<const ProblemNode*>(m_store->findNode(i)); 0223 QVERIFY(node); 0224 0225 QCOMPARE(node->problem()->description(), m_problems[i]->description()); 0226 } 0227 0228 // Check new severity filtering 0229 // Error filter 0230 m_store->setSeverities(IProblem::Error); 0231 QCOMPARE(m_store->count(), ErrorCount); 0232 for (int i = 0; i < ErrorCount; i++) { 0233 const auto *node = dynamic_cast<const ProblemNode*>(m_store->findNode(i)); 0234 QVERIFY(node); 0235 QCOMPARE(node->problem()->description(), m_problems[i]->description()); 0236 } 0237 0238 // Warning filter 0239 m_store->setSeverities(IProblem::Warning); 0240 QCOMPARE(m_store->count(), WarningCount); 0241 for (int i = 0; i < WarningCount; i++) { 0242 const auto *node = dynamic_cast<const ProblemNode*>(m_store->findNode(i)); 0243 QVERIFY(node); 0244 0245 QCOMPARE(node->problem()->description(), m_problems[i+ErrorCount]->description()); 0246 } 0247 0248 // Hint filter 0249 m_store->setSeverities(IProblem::Hint); 0250 QCOMPARE(m_store->count(), HintCount); 0251 for (int i = 0; i < HintCount; i++) { 0252 const auto *node = dynamic_cast<const ProblemNode*>(m_store->findNode(i)); 0253 QVERIFY(node); 0254 0255 QCOMPARE(node->problem()->description(), m_problems[i+ErrorCount+WarningCount]->description()); 0256 } 0257 0258 //Error + Hint filter 0259 m_store->setSeverities(IProblem::Error | IProblem::Hint); 0260 QCOMPARE(m_store->count(), HintCount + ErrorCount); 0261 for (int i = 0; i < ErrorCount; i++) { 0262 const auto *node = dynamic_cast<const ProblemNode*>(m_store->findNode(i)); 0263 QVERIFY(node); 0264 0265 QCOMPARE(node->problem()->description(), m_problems[i]->description()); 0266 } 0267 for (int i = ErrorCount; i < ErrorCount+HintCount; i++) { 0268 const auto *node = dynamic_cast<const ProblemNode*>(m_store->findNode(i)); 0269 QVERIFY(node); 0270 0271 QCOMPARE(node->problem()->description(), m_problems[i+WarningCount]->description()); 0272 } 0273 0274 m_store->setSeverities(IProblem::Error | IProblem::Warning | IProblem::Hint); 0275 m_store->clear(); 0276 0277 // Check if diagnostics are added properly 0278 m_store->addProblem(m_diagnosticTestProblem); 0279 QCOMPARE(m_store->count(), 1); 0280 QVERIFY(checkDiagnodes(m_store->findNode(0), m_diagnosticTestProblem)); 0281 } 0282 0283 0284 bool checkNodeLabel(const ProblemStoreNode *node, const QString &label) 0285 { 0286 const auto *parent = dynamic_cast<const LabelNode*>(node); 0287 0288 MYVERIFY(parent); 0289 MYCOMPARE(parent->label(), label); 0290 0291 return true; 0292 } 0293 0294 bool checkNodeDescription(const ProblemStoreNode *node, const QString &descr) 0295 { 0296 const auto *n = dynamic_cast<const ProblemNode*>(node); 0297 0298 MYVERIFY(n); 0299 MYCOMPARE(n->problem()->description(), descr); 0300 0301 return true; 0302 } 0303 0304 void TestFilteredProblemStore::testPathGrouping() 0305 { 0306 m_store->clear(); 0307 0308 // Rebuild the problem list with grouping 0309 m_store->setGrouping(PathGrouping); 0310 0311 // Add problems 0312 for (const IProblem::Ptr& p : qAsConst(m_problems)) { 0313 m_store->addProblem(p); 0314 } 0315 0316 QCOMPARE(m_store->count(), ProblemsCount); 0317 0318 for (int i = 0; i < 3; i++) { 0319 const ProblemStoreNode *node = m_store->findNode(i); 0320 checkNodeLabel(node, m_problems[i]->finalLocation().document.str()); 0321 QCOMPARE(node->count(), 1); 0322 0323 checkNodeDescription(node->child(0), m_problems[i]->description()); 0324 } 0325 0326 0327 // Now add a new problem 0328 IProblem::Ptr p(new DetectedProblem()); 0329 p->setDescription(QStringLiteral("PROBLEM4")); 0330 p->setFinalLocation(m_problems[2]->finalLocation()); 0331 m_store->addProblem(p); 0332 0333 QCOMPARE(m_store->count(), ProblemsCount); 0334 0335 // Check the first 2 top-nodes 0336 for (int i = 0; i < 2; i++) { 0337 const ProblemStoreNode *node = m_store->findNode(i); 0338 checkNodeLabel(node, m_problems[i]->finalLocation().document.str()); 0339 QCOMPARE(node->count(), 1); 0340 0341 checkNodeDescription(node->child(0), m_problems[i]->description()); 0342 } 0343 0344 // check the last one, and check the added problem is at the right place 0345 { 0346 const ProblemStoreNode *node = m_store->findNode(2); 0347 checkNodeLabel(node, m_problems[2]->finalLocation().document.str()); 0348 QCOMPARE(node->count(), 2); 0349 0350 checkNodeDescription(node->child(1), p->description()); 0351 } 0352 0353 m_store->clear(); 0354 m_store->setProblems(m_problems); 0355 0356 // Check filters 0357 // old-style setSeverity 0358 // Error filter 0359 m_store->setSeverity(IProblem::Error); 0360 QCOMPARE(m_store->count(), ErrorFilterProblemCount); 0361 { 0362 const ProblemStoreNode *node = m_store->findNode(0); 0363 checkNodeLabel(node, m_problems[0]->finalLocation().document.str()); 0364 QCOMPARE(node->count(), 1); 0365 checkNodeDescription(node->child(0), m_problems[0]->description()); 0366 } 0367 0368 // Warning filter 0369 m_store->setSeverity(IProblem::Warning); 0370 QCOMPARE(m_store->count(), WarningFilterProblemCount); 0371 for (int i = 0; i < WarningFilterProblemCount; i++) { 0372 const ProblemStoreNode *node = m_store->findNode(i); 0373 checkNodeLabel(node, m_problems[i]->finalLocation().document.str()); 0374 QCOMPARE(node->count(), 1); 0375 checkNodeDescription(node->child(0), m_problems[i]->description()); 0376 } 0377 0378 // Hint filter 0379 m_store->setSeverity(IProblem::Hint); 0380 QCOMPARE(m_store->count(), HintFilterProblemCount); 0381 for (int i = 0; i < HintFilterProblemCount; i++) { 0382 const ProblemStoreNode *node = m_store->findNode(i); 0383 checkNodeLabel(node, m_problems[i]->finalLocation().document.str()); 0384 QCOMPARE(node->count(), 1); 0385 checkNodeDescription(node->child(0), m_problems[i]->description()); 0386 } 0387 0388 // Check new severity filtering 0389 // Error filter 0390 m_store->setSeverities(IProblem::Error); 0391 for (int i = 0; i < ErrorCount; i++) { 0392 const ProblemStoreNode *node = m_store->findNode(i); 0393 checkNodeLabel(node, m_problems[i]->finalLocation().document.str()); 0394 QCOMPARE(node->count(), 1); 0395 checkNodeDescription(node->child(0), m_problems[i]->description()); 0396 } 0397 0398 // Warning filter 0399 m_store->setSeverities(IProblem::Warning); 0400 for (int i = 0; i < WarningCount; i++) { 0401 const ProblemStoreNode *node = m_store->findNode(i); 0402 checkNodeLabel(node, m_problems[i+ErrorCount]->finalLocation().document.str()); 0403 QCOMPARE(node->count(), 1); 0404 checkNodeDescription(node->child(0), m_problems[i+ErrorCount]->description()); 0405 } 0406 0407 // Hint filter 0408 m_store->setSeverities(IProblem::Hint); 0409 for (int i = 0; i < HintCount; i++) { 0410 const ProblemStoreNode *node = m_store->findNode(i); 0411 checkNodeLabel(node, m_problems[i+ErrorCount+WarningCount]->finalLocation().document.str()); 0412 QCOMPARE(node->count(), 1); 0413 checkNodeDescription(node->child(0), m_problems[i+ErrorCount+WarningCount]->description()); 0414 } 0415 0416 //Error + Hint filter 0417 m_store->setSeverities(IProblem::Error | IProblem::Hint); 0418 QCOMPARE(m_store->count(), HintCount + ErrorCount); 0419 for (int i = 0; i < ErrorCount; i++) { 0420 const ProblemStoreNode *node = m_store->findNode(i); 0421 checkNodeLabel(node, m_problems[i]->finalLocation().document.str()); 0422 QCOMPARE(node->count(), 1); 0423 checkNodeDescription(node->child(0), m_problems[i]->description()); 0424 } 0425 for (int i = ErrorCount; i < ErrorCount+HintCount; i++) { 0426 const ProblemStoreNode *node = m_store->findNode(i); 0427 checkNodeLabel(node, m_problems[i+WarningCount]->finalLocation().document.str()); 0428 QCOMPARE(node->count(), 1); 0429 checkNodeDescription(node->child(0), m_problems[i+WarningCount]->description()); 0430 } 0431 0432 m_store->setSeverities(IProblem::Error | IProblem::Warning | IProblem::Hint); 0433 0434 m_store->clear(); 0435 // Check if the diagnostics are added properly 0436 m_store->addProblem(m_diagnosticTestProblem); 0437 QCOMPARE(m_store->count(), 1); 0438 const auto *node = dynamic_cast<const LabelNode*>(m_store->findNode(0)); 0439 QVERIFY(node); 0440 QCOMPARE(node->label(), m_diagnosticTestProblem->finalLocation().document.str()); 0441 QVERIFY(checkDiagnodes(node->child(0), m_diagnosticTestProblem)); 0442 } 0443 0444 void TestFilteredProblemStore::testSeverityGrouping() 0445 { 0446 m_store->clear(); 0447 m_store->setGrouping(SeverityGrouping); 0448 QCOMPARE(m_store->count(), 3); 0449 const ProblemStoreNode *errorNode = m_store->findNode(0); 0450 const ProblemStoreNode *warningNode = m_store->findNode(1); 0451 const ProblemStoreNode *hintNode = m_store->findNode(2); 0452 0453 // Add problems 0454 for (int i=0;i<ProblemsCount;i++) 0455 { 0456 m_store->addProblem(m_problems[i]); 0457 int severityType = 0; //error 0458 int addedCountOfCurrentSeverityType = i + 1; 0459 if (i>=ErrorCount) 0460 { 0461 severityType = 1; //warning 0462 addedCountOfCurrentSeverityType = i - ErrorCount + 1; 0463 } 0464 if (i>=ErrorCount+WarningCount) 0465 { 0466 severityType = 2; //hint 0467 addedCountOfCurrentSeverityType = i - (ErrorCount + WarningCount) + 1; 0468 } 0469 QCOMPARE(m_store->findNode(severityType)->count(), addedCountOfCurrentSeverityType); 0470 } 0471 0472 QVERIFY(checkNodeLabels()); 0473 QVERIFY(checkCounts(ErrorCount, WarningCount, HintCount)); 0474 checkNodeDescription(errorNode->child(0), m_problems[0]->description()); 0475 checkNodeDescription(warningNode->child(0), m_problems[1]->description()); 0476 checkNodeDescription(hintNode->child(0), m_problems[3]->description()); 0477 0478 // Clear 0479 m_store->clear(); 0480 QCOMPARE(m_store->count(), 3); 0481 QVERIFY(checkCounts(0,0,0)); 0482 0483 // Set problems 0484 m_store->setProblems(m_problems); 0485 QCOMPARE(m_store->count(), 3); 0486 QVERIFY(checkNodeLabels()); 0487 QVERIFY(checkCounts(ErrorCount, WarningCount, HintCount)); 0488 checkNodeDescription(errorNode->child(0), m_problems[0]->description()); 0489 checkNodeDescription(warningNode->child(0), m_problems[1]->description()); 0490 checkNodeDescription(hintNode->child(0), m_problems[3]->description()); 0491 0492 // Check severity filter 0493 // old-style setSeverity 0494 // Error filter 0495 m_store->setSeverity(IProblem::Error); 0496 QCOMPARE(m_store->count(), 3); 0497 QVERIFY(checkNodeLabels()); 0498 QVERIFY(checkCounts(ErrorCount, 0, 0)); 0499 checkNodeDescription(errorNode->child(0), m_problems[0]->description()); 0500 0501 // Warning filter 0502 m_store->setSeverity(IProblem::Warning); 0503 QCOMPARE(m_store->count(), 3); 0504 checkNodeLabels(); 0505 QVERIFY(checkCounts(ErrorCount, WarningCount, 0)); 0506 checkNodeDescription(errorNode->child(0), m_problems[0]->description()); 0507 checkNodeDescription(warningNode->child(0), m_problems[1]->description()); 0508 0509 // Hint filter 0510 m_store->setSeverity(IProblem::Hint); 0511 QCOMPARE(m_store->count(), 3); 0512 QVERIFY(checkNodeLabels()); 0513 QVERIFY(checkCounts(ErrorCount, WarningCount, HintCount)); 0514 checkNodeDescription(errorNode->child(0), m_problems[0]->description()); 0515 checkNodeDescription(warningNode->child(0), m_problems[1]->description()); 0516 checkNodeDescription(hintNode->child(0), m_problems[3]->description()); 0517 0518 // Check severity filter 0519 // Error filter 0520 m_store->setSeverities(IProblem::Error); 0521 QCOMPARE(m_store->count(), 3); 0522 QVERIFY(checkNodeLabels()); 0523 QVERIFY(checkCounts(ErrorCount, 0, 0)); 0524 checkNodeDescription(errorNode->child(0), m_problems[0]->description()); 0525 0526 // Warning filter 0527 m_store->setSeverities(IProblem::Warning); 0528 QCOMPARE(m_store->count(), 3); 0529 QVERIFY(checkNodeLabels()); 0530 QVERIFY(checkCounts(0, WarningCount, 0)); 0531 checkNodeDescription(warningNode->child(0), m_problems[1]->description()); 0532 0533 // Hint filter 0534 m_store->setSeverities(IProblem::Hint); 0535 QCOMPARE(m_store->count(), 3); 0536 QVERIFY(checkNodeLabels()); 0537 QVERIFY(checkCounts(0, 0, HintCount)); 0538 checkNodeDescription(hintNode->child(0), m_problems[3]->description()); 0539 0540 // Error + Hint filter 0541 m_store->setSeverities(IProblem::Error | IProblem::Hint); 0542 QCOMPARE(m_store->count(), 3); 0543 QVERIFY(checkNodeLabels()); 0544 QVERIFY(checkCounts(ErrorCount, 0, HintCount)); 0545 checkNodeDescription(errorNode->child(0), m_problems[0]->description()); 0546 checkNodeDescription(hintNode->child(0), m_problems[3]->description()); 0547 0548 m_store->setSeverities(IProblem::Error | IProblem::Warning | IProblem::Hint); 0549 0550 m_store->clear(); 0551 // Check if diagnostics are added properly 0552 m_store->addProblem(m_diagnosticTestProblem); 0553 QVERIFY(checkNodeLabels()); 0554 QVERIFY(checkCounts(1, 0, 0)); 0555 QVERIFY(checkDiagnodes(m_store->findNode(0)->child(0), m_diagnosticTestProblem)); 0556 } 0557 0558 bool TestFilteredProblemStore::checkCounts(int error, int warning, int hint) 0559 { 0560 const ProblemStoreNode *errorNode = m_store->findNode(0); 0561 const ProblemStoreNode *warningNode = m_store->findNode(1); 0562 const ProblemStoreNode *hintNode = m_store->findNode(2); 0563 0564 MYVERIFY(errorNode); 0565 MYVERIFY(warningNode); 0566 MYVERIFY(hintNode); 0567 0568 MYCOMPARE(errorNode->count(), error); 0569 MYCOMPARE(warningNode->count(), warning); 0570 MYCOMPARE(hintNode->count(), hint); 0571 0572 return true; 0573 } 0574 0575 bool TestFilteredProblemStore::checkNodeLabels() 0576 { 0577 const ProblemStoreNode *errorNode = m_store->findNode(0); 0578 const ProblemStoreNode *warningNode = m_store->findNode(1); 0579 const ProblemStoreNode *hintNode = m_store->findNode(2); 0580 0581 MYCOMPARE(checkNodeLabel(errorNode, i18n("Error")), true); 0582 MYCOMPARE(checkNodeLabel(warningNode, i18n("Warning")), true); 0583 MYCOMPARE(checkNodeLabel(hintNode, i18n("Hint")), true); 0584 0585 return true; 0586 } 0587 0588 // Generate 3 problems, all with different paths, different severity 0589 // Also generates a problem with diagnostics 0590 void TestFilteredProblemStore::generateProblems() 0591 { 0592 IProblem::Ptr p1(new DetectedProblem()); 0593 IProblem::Ptr p2(new DetectedProblem()); 0594 IProblem::Ptr p3(new DetectedProblem()); 0595 IProblem::Ptr p4(new DetectedProblem()); 0596 IProblem::Ptr p5(new DetectedProblem()); 0597 IProblem::Ptr p6(new DetectedProblem()); 0598 0599 DocumentRange r1; 0600 r1.document = IndexedString("/just/a/random/path"); 0601 0602 p1->setDescription(QStringLiteral("PROBLEM1")); 0603 p1->setSeverity(IProblem::Error); 0604 p1->setFinalLocation(r1); 0605 0606 DocumentRange r2; 0607 r2.document = IndexedString("/just/another/path"); 0608 0609 p2->setDescription(QStringLiteral("PROBLEM2")); 0610 p2->setSeverity(IProblem::Warning); 0611 p2->setFinalLocation(r2); 0612 0613 DocumentRange r3; 0614 r3.document = IndexedString("/just/another/pathy/patha"); 0615 0616 p3->setDescription(QStringLiteral("PROBLEM3")); 0617 p3->setSeverity(IProblem::Warning); 0618 p3->setFinalLocation(r3); 0619 0620 DocumentRange r4; 0621 r4.document = IndexedString("/yet/another/test/path"); 0622 0623 p4->setDescription(QStringLiteral("PROBLEM4")); 0624 p4->setSeverity(IProblem::Hint); 0625 p4->setFinalLocation(r4); 0626 0627 DocumentRange r5; 0628 r5.document = IndexedString("/yet/another/pathy/test/path"); 0629 0630 p5->setDescription(QStringLiteral("PROBLEM5")); 0631 p5->setSeverity(IProblem::Hint); 0632 p5->setFinalLocation(r5); 0633 0634 DocumentRange r6; 0635 r6.document = IndexedString("/yet/another/test/pathy/path"); 0636 0637 p6->setDescription(QStringLiteral("PROBLEM6")); 0638 p6->setSeverity(IProblem::Hint); 0639 p6->setFinalLocation(r6); 0640 0641 0642 m_problems.push_back(p1); 0643 m_problems.push_back(p2); 0644 m_problems.push_back(p3); 0645 m_problems.push_back(p4); 0646 m_problems.push_back(p5); 0647 m_problems.push_back(p6); 0648 0649 // Problem for diagnostic testing 0650 IProblem::Ptr p(new DetectedProblem()); 0651 DocumentRange r; 0652 r.document = IndexedString("DIAGTEST"); 0653 p->setFinalLocation(r); 0654 p->setDescription(QStringLiteral("PROBLEM")); 0655 p->setSeverity(IProblem::Error); 0656 0657 IProblem::Ptr d(new DetectedProblem()); 0658 d->setDescription(QStringLiteral("DIAG")); 0659 0660 IProblem::Ptr dd(new DetectedProblem()); 0661 dd->setDescription(QStringLiteral("DIAGDIAG")); 0662 d->addDiagnostic(dd); 0663 p->addDiagnostic(d); 0664 m_diagnosticTestProblem = p; 0665 } 0666 0667 QTEST_MAIN(TestFilteredProblemStore) 0668 0669 #include "test_filteredproblemstore.moc"