1 /*
2 * Cppcheck - A tool for static C/C++ code analysis
3 * Copyright (C) 2007-2019 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 <QObject>
20 #include "testprojectfile.h"
21 #include "projectfile.h"
22 #include "settings.h"
23
24 // Mock...
25 const char Settings::SafeChecks::XmlRootName[] = "safe-checks";
26 const char Settings::SafeChecks::XmlClasses[] = "class-public";
27 const char Settings::SafeChecks::XmlExternalFunctions[] = "external-functions";
28 const char Settings::SafeChecks::XmlInternalFunctions[] = "internal-functions";
29 const char Settings::SafeChecks::XmlExternalVariables[] = "external-variables";
Settings()30 Settings::Settings() : maxCtuDepth(10), maxTemplateRecursion(100) {}
Platform()31 cppcheck::Platform::Platform() {}
Library()32 Library::Library() {}
ImportProject()33 ImportProject::ImportProject() {}
34
loadInexisting()35 void TestProjectFile::loadInexisting()
36 {
37 const QString filepath(QString(SRCDIR) + "/../data/projectfiles/foo.cppcheck");
38 ProjectFile pfile(filepath);
39 QCOMPARE(pfile.read(), false);
40 }
41
loadSimple()42 void TestProjectFile::loadSimple()
43 {
44 const QString filepath(QString(SRCDIR) + "/../data/projectfiles/simple.cppcheck");
45 ProjectFile pfile(filepath);
46 QVERIFY(pfile.read());
47 QCOMPARE(pfile.getRootPath(), QString("../.."));
48 QStringList includes = pfile.getIncludeDirs();
49 QCOMPARE(includes.size(), 2);
50 QCOMPARE(includes[0], QString("lib/"));
51 QCOMPARE(includes[1], QString("cli/"));
52 QStringList paths = pfile.getCheckPaths();
53 QCOMPARE(paths.size(), 2);
54 QCOMPARE(paths[0], QString("gui/"));
55 QCOMPARE(paths[1], QString("test/"));
56 QStringList excludes = pfile.getExcludedPaths();
57 QCOMPARE(excludes.size(), 1);
58 QCOMPARE(excludes[0], QString("gui/temp/"));
59 QStringList defines = pfile.getDefines();
60 QCOMPARE(defines.size(), 1);
61 QCOMPARE(defines[0], QString("FOO"));
62 }
63
64 // Test that project file with old 'ignore' element works
loadSimpleWithIgnore()65 void TestProjectFile::loadSimpleWithIgnore()
66 {
67 const QString filepath(QString(SRCDIR) + "/../data/projectfiles/simple_ignore.cppcheck");
68 ProjectFile pfile(filepath);
69 QVERIFY(pfile.read());
70 QCOMPARE(pfile.getRootPath(), QString("../.."));
71 QStringList includes = pfile.getIncludeDirs();
72 QCOMPARE(includes.size(), 2);
73 QCOMPARE(includes[0], QString("lib/"));
74 QCOMPARE(includes[1], QString("cli/"));
75 QStringList paths = pfile.getCheckPaths();
76 QCOMPARE(paths.size(), 2);
77 QCOMPARE(paths[0], QString("gui/"));
78 QCOMPARE(paths[1], QString("test/"));
79 QStringList excludes = pfile.getExcludedPaths();
80 QCOMPARE(excludes.size(), 1);
81 QCOMPARE(excludes[0], QString("gui/temp/"));
82 QStringList defines = pfile.getDefines();
83 QCOMPARE(defines.size(), 1);
84 QCOMPARE(defines[0], QString("FOO"));
85 }
86
loadSimpleNoroot()87 void TestProjectFile::loadSimpleNoroot()
88 {
89 const QString filepath(QString(SRCDIR) + "/../data/projectfiles/simple_noroot.cppcheck");
90 ProjectFile pfile(filepath);
91 QVERIFY(pfile.read());
92 QCOMPARE(pfile.getRootPath(), QString());
93 QStringList includes = pfile.getIncludeDirs();
94 QCOMPARE(includes.size(), 2);
95 QCOMPARE(includes[0], QString("lib/"));
96 QCOMPARE(includes[1], QString("cli/"));
97 QStringList paths = pfile.getCheckPaths();
98 QCOMPARE(paths.size(), 2);
99 QCOMPARE(paths[0], QString("gui/"));
100 QCOMPARE(paths[1], QString("test/"));
101 QStringList excludes = pfile.getExcludedPaths();
102 QCOMPARE(excludes.size(), 1);
103 QCOMPARE(excludes[0], QString("gui/temp/"));
104 QStringList defines = pfile.getDefines();
105 QCOMPARE(defines.size(), 1);
106 QCOMPARE(defines[0], QString("FOO"));
107 }
108
109 QTEST_MAIN(TestProjectFile)
110