diff --git a/gui/test/common.pri b/gui/test/common.pri index 64c0d5a78..b10cf885c 100644 --- a/gui/test/common.pri +++ b/gui/test/common.pri @@ -10,6 +10,7 @@ include($$PWD/../../lib/lib.pri) # GUI SOURCES += ../../erroritem.cpp \ + ../../projectfile.cpp \ ../../report.cpp \ ../../translationhandler.cpp \ ../../xmlreport.cpp \ @@ -17,6 +18,7 @@ SOURCES += ../../erroritem.cpp \ ../../xmlreportv2.cpp HEADERS += ../../erroritem.h \ + ../../projectfile.h \ ../../report.h \ ../../translationhandler.h \ ../../xmlreport.h \ diff --git a/gui/test/projectfile/projectfile.pro b/gui/test/projectfile/projectfile.pro new file mode 100644 index 000000000..054ade280 --- /dev/null +++ b/gui/test/projectfile/projectfile.pro @@ -0,0 +1,15 @@ +TEMPLATE = app +TARGET = test-projectfile +DEPENDPATH += . +INCLUDEPATH += . +OBJECTS_DIR = ../build +MOC_DIR = ../build + +include(../common.pri) + +DEFINES += SRCDIR=\\\"$$PWD\\\" + +# tests +SOURCES += testprojectfile.cpp + +HEADERS += testprojectfile.h diff --git a/gui/test/projectfile/testprojectfile.cpp b/gui/test/projectfile/testprojectfile.cpp new file mode 100644 index 000000000..888798646 --- /dev/null +++ b/gui/test/projectfile/testprojectfile.cpp @@ -0,0 +1,75 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2011 Daniel Marjamäki and 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 . + */ + +#include +#include +#include "testprojectfile.h" +#include "projectfile.h" + +void TestProjectFile::loadInexisting() +{ + const QString filepath(QString(SRCDIR) + "/../projectfiles/foo.cppcheck"); + ProjectFile pfile(filepath); + QCOMPARE(false, pfile.Read()); +} + +void TestProjectFile::loadSimple() +{ + const QString filepath(QString(SRCDIR) + "/../projectfiles/simple.cppcheck"); + ProjectFile pfile(filepath); + QVERIFY(pfile.Read()); + QCOMPARE(pfile.GetRootPath(), QString("../..")); + QStringList includes = pfile.GetIncludeDirs(); + QCOMPARE(includes.size(), 2); + QCOMPARE(includes[0], QString("lib/")); + QCOMPARE(includes[1], QString("cli/")); + QStringList paths = pfile.GetCheckPaths(); + QCOMPARE(paths.size(), 2); + QCOMPARE(paths[0], QString("gui/")); + QCOMPARE(paths[1], QString("test/")); + QStringList ignores = pfile.GetIgnoredPaths(); + QCOMPARE(ignores.size(), 1); + QCOMPARE(ignores[0], QString("gui/temp/")); + QStringList defines = pfile.GetDefines(); + QCOMPARE(defines.size(), 1); + QCOMPARE(defines[0], QString("FOO")); +} + +void TestProjectFile::loadSimpleNoroot() +{ + const QString filepath(QString(SRCDIR) + "/../projectfiles/simple_noroot.cppcheck"); + ProjectFile pfile(filepath); + QVERIFY(pfile.Read()); + QCOMPARE(pfile.GetRootPath(), QString()); + QStringList includes = pfile.GetIncludeDirs(); + QCOMPARE(includes.size(), 2); + QCOMPARE(includes[0], QString("lib/")); + QCOMPARE(includes[1], QString("cli/")); + QStringList paths = pfile.GetCheckPaths(); + QCOMPARE(paths.size(), 2); + QCOMPARE(paths[0], QString("gui/")); + QCOMPARE(paths[1], QString("test/")); + QStringList ignores = pfile.GetIgnoredPaths(); + QCOMPARE(ignores.size(), 1); + QCOMPARE(ignores[0], QString("gui/temp/")); + QStringList defines = pfile.GetDefines(); + QCOMPARE(defines.size(), 1); + QCOMPARE(defines[0], QString("FOO")); +} + +QTEST_MAIN(TestProjectFile) diff --git a/gui/test/projectfile/testprojectfile.h b/gui/test/projectfile/testprojectfile.h new file mode 100644 index 000000000..1116cf4e7 --- /dev/null +++ b/gui/test/projectfile/testprojectfile.h @@ -0,0 +1,30 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2011 Daniel Marjamäki and 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 . + */ + +#include +#include + +class TestProjectFile: public QObject +{ + Q_OBJECT + +private slots: + void loadInexisting(); + void loadSimple(); + void loadSimpleNoroot(); +}; diff --git a/gui/test/projectfiles/simple.cppcheck b/gui/test/projectfiles/simple.cppcheck new file mode 100644 index 000000000..7e2ae6c91 --- /dev/null +++ b/gui/test/projectfiles/simple.cppcheck @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/gui/test/projectfiles/simple_noroot.cppcheck b/gui/test/projectfiles/simple_noroot.cppcheck new file mode 100644 index 000000000..94a7d20bb --- /dev/null +++ b/gui/test/projectfiles/simple_noroot.cppcheck @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/gui/test/test.pro b/gui/test/test.pro index 2939b5ade..9bdb71aef 100644 --- a/gui/test/test.pro +++ b/gui/test/test.pro @@ -1,7 +1,8 @@ CONFIG += ordered TEMPLATE = subdirs -SUBDIRS = translationhandler \ +SUBDIRS = projectfile \ + translationhandler \ xmlreport \ xmlreportv1 \ xmlreportv2