|
| 1 | +/* |
| 2 | + * Cppcheck - A tool for static C/C++ code analysis |
| 3 | + * Copyright (C) 2007-2021 Cppcheck team. |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | + |
| 19 | +#include "testresultstree.h" |
| 20 | +#include "resultstree.h" |
| 21 | + |
| 22 | +// headers that declare mocked functions/variables |
| 23 | +#include "applicationlist.h" |
| 24 | +#include "common.h" |
| 25 | +#include "threadhandler.h" |
| 26 | +#include "projectfile.h" |
| 27 | +#include "xmlreportv2.h" |
| 28 | + |
| 29 | +#include "cppcheck.h" |
| 30 | +#include "errorlogger.h" |
| 31 | +#include "path.h" |
| 32 | +#include "settings.h" |
| 33 | + |
| 34 | +#include <QtTest> |
| 35 | + |
| 36 | +// Mock GUI... |
| 37 | +ProjectFile *ProjectFile::mActiveProject; |
| 38 | +void ProjectFile::addSuppression(const SuppressionList::Suppression & /*unused*/) {} |
| 39 | +QString ProjectFile::getWarningTags(std::size_t /*unused*/) const { |
| 40 | + return QString(); |
| 41 | +} |
| 42 | +void ProjectFile::setWarningTags(std::size_t /*unused*/, const QString& /*unused*/) {} |
| 43 | +bool ProjectFile::write(const QString & /*unused*/) { |
| 44 | + return true; |
| 45 | +} |
| 46 | +std::string severityToString(Severity severity) { |
| 47 | + return std::to_string((int)severity); |
| 48 | +} |
| 49 | +int ApplicationList::getApplicationCount() const { |
| 50 | + return 0; |
| 51 | +} |
| 52 | +bool ThreadHandler::isChecking() const { |
| 53 | + return false; |
| 54 | +} |
| 55 | +Application& ApplicationList::getApplication(const int /*unused*/) { |
| 56 | + throw 1; |
| 57 | +} |
| 58 | +const Application& ApplicationList::getApplication(const int index) const { |
| 59 | + return mApplications.at(index); |
| 60 | +} |
| 61 | +QString getPath(const QString &type) { |
| 62 | + return "/" + type; |
| 63 | +} |
| 64 | +void setPath(const QString & /*unused*/, const QString & /*unused*/) {} |
| 65 | +QString XmlReport::quoteMessage(const QString &message) { |
| 66 | + return message; |
| 67 | +} |
| 68 | +QString XmlReport::unquoteMessage(const QString &message) { |
| 69 | + return message; |
| 70 | +} |
| 71 | +XmlReport::XmlReport(const QString& filename) : Report(filename) {} |
| 72 | + |
| 73 | +// Mock LIB... |
| 74 | +bool Path::isHeader(std::string const& /*unused*/) { |
| 75 | + return false; |
| 76 | +} |
| 77 | +const std::set<std::string> ErrorLogger::mCriticalErrorIds; |
| 78 | +std::string ErrorMessage::FileLocation::getfile(bool /*unused*/) const { |
| 79 | + return std::string(); |
| 80 | +} |
| 81 | +const char* CppCheck::version() { |
| 82 | + return "1.0"; |
| 83 | +} |
| 84 | +std::pair<std::string, std::string> Settings::getNameAndVersion(const std::string& /*unused*/) { |
| 85 | + throw 1; |
| 86 | +} |
| 87 | +Severity severityFromString(const std::string& severity) { |
| 88 | + return (Severity)std::stoi(severity); |
| 89 | +} |
| 90 | + |
| 91 | +// Test... |
| 92 | + |
| 93 | +void TestResultsTree::test1() const |
| 94 | +{ |
| 95 | + // #12772 : GUI: information messages are shown even though information tool button is deselected |
| 96 | + ResultsTree tree(nullptr); |
| 97 | + tree.showResults(ShowTypes::ShowType::ShowInformation, false); |
| 98 | + ErrorItem errorItem; |
| 99 | + errorItem.errorPath << QErrorPathItem(); |
| 100 | + errorItem.severity = Severity::information; |
| 101 | + tree.addErrorItem(errorItem); |
| 102 | + QCOMPARE(tree.isRowHidden(0,QModelIndex()), true); // Added item is hidden |
| 103 | + tree.showResults(ShowTypes::ShowType::ShowInformation, true); |
| 104 | + QCOMPARE(tree.isRowHidden(0,QModelIndex()), false); // Show item |
| 105 | +} |
| 106 | + |
| 107 | +QTEST_MAIN(TestResultsTree) |
| 108 | + |
0 commit comments