| 30 | } |
| 31 | |
| 32 | void TestCppcheckParser::testParser() |
| 33 | { |
| 34 | const QString cppcheck_example_output = QStringLiteral( |
| 35 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 36 | "<results version=\"2\">\n" |
| 37 | " <cppcheck version=\"1.72\"/>" |
| 38 | " <errors>" |
| 39 | " <error id=\"memleak\" severity=\"error\" msg=\"Memory leak: ej\" verbose=\"Memory leak: ej\" cwe=\"401\">" |
| 40 | " <location file=\"/kdesrc/kdev-cppcheck/plugin.cpp\" line=\"169\"/>" |
| 41 | " </error>" |
| 42 | " <error id=\"redundantAssignment\" severity=\"performance\"" |
| 43 | " msg=\"location_test_msg\" verbose=\"location_test_verbose\">" |
| 44 | " <location file=\"location_test.cpp\" line=\"120\"/>" |
| 45 | " <location file=\"location_test.cpp\" line=\"100\"/>" |
| 46 | " </error>" |
| 47 | " <error id=\"variableScope\" severity=\"style\" inconclusive=\"true\"" |
| 48 | " msg=\"The scope of the variable...\"" |
| 49 | " verbose=\"...Here is an example...:\\012void f(int x)\\012{\\012 int i = 0;\\012}\\012...\">" |
| 50 | " <location file=\"html_pre_test.cpp\" line=\"41\"/>" |
| 51 | " </error>" |
| 52 | " </errors>" |
| 53 | "</results>"); |
| 54 | |
| 55 | cppcheck::CppcheckParser parser; |
| 56 | parser.addData(cppcheck_example_output); |
| 57 | |
| 58 | const auto problems = parser.parse(); |
| 59 | QVERIFY(!problems.empty()); |
| 60 | |
| 61 | IProblem::Ptr p = problems[0]; |
| 62 | QCOMPARE(p->description(), QStringLiteral("Memory leak: ej")); |
| 63 | QCOMPARE(p->explanation(), QStringLiteral("<html>Memory leak: ej</html>")); |
| 64 | QCOMPARE(p->finalLocation().document.str(), QStringLiteral("/kdesrc/kdev-cppcheck/plugin.cpp")); |
| 65 | QCOMPARE(p->finalLocation().start().line()+1, 169); |
| 66 | QCOMPARE(p->severity(), IProblem::Error); |
| 67 | QCOMPARE(p->source(), IProblem::Plugin); |
| 68 | |
| 69 | // test problem with 2 <location> elements |
| 70 | p = problems[1]; |
| 71 | QCOMPARE(p->description(), QStringLiteral("(performance) location_test_msg")); |
| 72 | QCOMPARE(p->explanation(), QStringLiteral("<html>location_test_verbose</html>")); |
| 73 | QCOMPARE(p->finalLocation().document.str(), QStringLiteral("location_test.cpp")); |
| 74 | QCOMPARE(p->finalLocation().start().line()+1, 120); |
| 75 | QCOMPARE(p->severity(), IProblem::Hint); |
| 76 | QCOMPARE(p->source(), IProblem::Plugin); |
| 77 | |
| 78 | // test problem with '\\012' tokens in verbose message |
| 79 | p = problems[2]; |
| 80 | QCOMPARE(p->description(), QStringLiteral("(style, inconclusive) The scope of the variable...")); |
| 81 | QCOMPARE(p->explanation(), QStringLiteral("<html>...Here is an example...:<pre>void f(int x)\n{\n int i = 0;\n}</pre><br>...</html>")); |
| 82 | QCOMPARE(p->finalLocation().document.str(), QStringLiteral("html_pre_test.cpp")); |
| 83 | QCOMPARE(p->finalLocation().start().line()+1, 41); |
| 84 | QCOMPARE(p->severity(), IProblem::Hint); |
| 85 | QCOMPARE(p->source(), IProblem::Plugin); |
| 86 | } |
| 87 | |
| 88 | QTEST_GUILESS_MAIN(TestCppcheckParser) |
| 89 |
nothing calls this directly
no test coverage detected