GUI: fix tests
This commit is contained in:
parent
649f7b4d73
commit
184e621364
|
@ -17,7 +17,6 @@ SOURCES += $${PWD}/../erroritem.cpp \
|
|||
$${PWD}/../report.cpp \
|
||||
$${PWD}/../translationhandler.cpp \
|
||||
$${PWD}/../xmlreport.cpp \
|
||||
$${PWD}/../xmlreportv1.cpp \
|
||||
$${PWD}/../xmlreportv2.cpp
|
||||
|
||||
HEADERS += $${PWD}/../erroritem.h \
|
||||
|
@ -26,7 +25,6 @@ HEADERS += $${PWD}/../erroritem.h \
|
|||
$${PWD}/../report.h \
|
||||
$${PWD}/../translationhandler.h \
|
||||
$${PWD}/../xmlreport.h \
|
||||
$${PWD}/../xmlreportv1.h \
|
||||
$${PWD}/../xmlreportv2.h
|
||||
|
||||
contains(QMAKE_CC, gcc) {
|
||||
|
|
|
@ -27,14 +27,14 @@ void TestFileList::addFile()
|
|||
{
|
||||
// Accepted extensions: *.cpp, *.cxx, *.cc, *.c, *.c++, *.txx, *.tpp"
|
||||
FileList list;
|
||||
list.AddFile(QString(SRCDIR) + "/../data/files/foo1.cpp");
|
||||
list.AddFile(QString(SRCDIR) + "/../data/files/foo2.cxx");
|
||||
list.AddFile(QString(SRCDIR) + "/../data/files/foo3.cc");
|
||||
list.AddFile(QString(SRCDIR) + "/../data/files/foo4.c");
|
||||
list.AddFile(QString(SRCDIR) + "/../data/files/foo5.c++");
|
||||
list.AddFile(QString(SRCDIR) + "/../data/files/foo6.txx");
|
||||
list.AddFile(QString(SRCDIR) + "/../data/files/foo7.tpp");
|
||||
QStringList files = list.GetFileList();
|
||||
list.addFile(QString(SRCDIR) + "/../data/files/foo1.cpp");
|
||||
list.addFile(QString(SRCDIR) + "/../data/files/foo2.cxx");
|
||||
list.addFile(QString(SRCDIR) + "/../data/files/foo3.cc");
|
||||
list.addFile(QString(SRCDIR) + "/../data/files/foo4.c");
|
||||
list.addFile(QString(SRCDIR) + "/../data/files/foo5.c++");
|
||||
list.addFile(QString(SRCDIR) + "/../data/files/foo6.txx");
|
||||
list.addFile(QString(SRCDIR) + "/../data/files/foo7.tpp");
|
||||
QStringList files = list.getFileList();
|
||||
QCOMPARE(files.size(), 7);
|
||||
}
|
||||
|
||||
|
@ -50,41 +50,41 @@ void TestFileList::addPathList()
|
|||
paths << QString(SRCDIR) + "/../data/files/foo6.txx";
|
||||
paths << QString(SRCDIR) + "/../data/files/foo7.tpp";
|
||||
FileList list;
|
||||
list.AddPathList(paths);
|
||||
QStringList files = list.GetFileList();
|
||||
list.addPathList(paths);
|
||||
QStringList files = list.getFileList();
|
||||
QCOMPARE(files.size(), 7);
|
||||
}
|
||||
|
||||
void TestFileList::addFile_notexist()
|
||||
{
|
||||
FileList list;
|
||||
list.AddFile(QString(SRCDIR) + "/../data/files/bar1.cpp");
|
||||
QStringList files = list.GetFileList();
|
||||
list.addFile(QString(SRCDIR) + "/../data/files/bar1.cpp");
|
||||
QStringList files = list.getFileList();
|
||||
QCOMPARE(files.size(), 0);
|
||||
}
|
||||
|
||||
void TestFileList::addFile_unknown()
|
||||
{
|
||||
FileList list;
|
||||
list.AddFile(QString(SRCDIR) + "/../data/files/bar1");
|
||||
list.AddFile(QString(SRCDIR) + "/../data/files/bar1.foo");
|
||||
QStringList files = list.GetFileList();
|
||||
list.addFile(QString(SRCDIR) + "/../data/files/bar1");
|
||||
list.addFile(QString(SRCDIR) + "/../data/files/bar1.foo");
|
||||
QStringList files = list.getFileList();
|
||||
QCOMPARE(files.size(), 0);
|
||||
}
|
||||
|
||||
void TestFileList::addDirectory()
|
||||
{
|
||||
FileList list;
|
||||
list.AddDirectory(QString(SRCDIR) + "/../data/files");
|
||||
QStringList files = list.GetFileList();
|
||||
list.addDirectory(QString(SRCDIR) + "/../data/files");
|
||||
QStringList files = list.getFileList();
|
||||
QCOMPARE(files.size(), 7);
|
||||
}
|
||||
|
||||
void TestFileList::addDirectory_recursive()
|
||||
{
|
||||
FileList list;
|
||||
list.AddDirectory(QString(SRCDIR) + "/../data/files", true);
|
||||
QStringList files = list.GetFileList();
|
||||
list.addDirectory(QString(SRCDIR) + "/../data/files", true);
|
||||
QStringList files = list.getFileList();
|
||||
QCOMPARE(files.size(), 10);
|
||||
QDir dir(QString(SRCDIR) + "/../data/files");
|
||||
QString base = dir.canonicalPath();
|
||||
|
@ -98,15 +98,15 @@ void TestFileList::filterFiles()
|
|||
FileList list;
|
||||
QStringList filters;
|
||||
filters << "foo1.cpp" << "foo3.cc";
|
||||
list.AddExcludeList(filters);
|
||||
list.AddFile(QString(SRCDIR) + "/../data/files/foo1.cpp");
|
||||
list.AddFile(QString(SRCDIR) + "/../data/files/foo2.cxx");
|
||||
list.AddFile(QString(SRCDIR) + "/../data/files/foo3.cc");
|
||||
list.AddFile(QString(SRCDIR) + "/../data/files/foo4.c");
|
||||
list.AddFile(QString(SRCDIR) + "/../data/files/foo5.c++");
|
||||
list.AddFile(QString(SRCDIR) + "/../data/files/foo6.txx");
|
||||
list.AddFile(QString(SRCDIR) + "/../data/files/foo7.tpp");
|
||||
QStringList files = list.GetFileList();
|
||||
list.addExcludeList(filters);
|
||||
list.addFile(QString(SRCDIR) + "/../data/files/foo1.cpp");
|
||||
list.addFile(QString(SRCDIR) + "/../data/files/foo2.cxx");
|
||||
list.addFile(QString(SRCDIR) + "/../data/files/foo3.cc");
|
||||
list.addFile(QString(SRCDIR) + "/../data/files/foo4.c");
|
||||
list.addFile(QString(SRCDIR) + "/../data/files/foo5.c++");
|
||||
list.addFile(QString(SRCDIR) + "/../data/files/foo6.txx");
|
||||
list.addFile(QString(SRCDIR) + "/../data/files/foo7.tpp");
|
||||
QStringList files = list.getFileList();
|
||||
QCOMPARE(files.size(), 5);
|
||||
QDir dir(QString(SRCDIR) + "/../data/files");
|
||||
QString base = dir.canonicalPath();
|
||||
|
@ -119,9 +119,9 @@ void TestFileList::filterFiles2()
|
|||
FileList list;
|
||||
QStringList filters;
|
||||
filters << "foo1.cpp" << "foo3.cc";
|
||||
list.AddExcludeList(filters);
|
||||
list.AddDirectory(QString(SRCDIR) + "/../data/files");
|
||||
QStringList files = list.GetFileList();
|
||||
list.addExcludeList(filters);
|
||||
list.addDirectory(QString(SRCDIR) + "/../data/files");
|
||||
QStringList files = list.getFileList();
|
||||
QCOMPARE(files.size(), 5);
|
||||
QDir dir(QString(SRCDIR) + "/../data/files");
|
||||
QString base = dir.canonicalPath();
|
||||
|
@ -134,9 +134,9 @@ void TestFileList::filterFiles3()
|
|||
FileList list;
|
||||
QStringList filters;
|
||||
filters << "foo1.cpp" << "foo3.cc";
|
||||
list.AddExcludeList(filters);
|
||||
list.AddDirectory(QString(SRCDIR) + "/../data/files", true);
|
||||
QStringList files = list.GetFileList();
|
||||
list.addExcludeList(filters);
|
||||
list.addDirectory(QString(SRCDIR) + "/../data/files", true);
|
||||
QStringList files = list.getFileList();
|
||||
QCOMPARE(files.size(), 6);
|
||||
QDir dir(QString(SRCDIR) + "/../data/files");
|
||||
QString base = dir.canonicalPath();
|
||||
|
@ -151,9 +151,9 @@ void TestFileList::filterFiles4()
|
|||
FileList list;
|
||||
QStringList filters;
|
||||
filters << "dir1/";
|
||||
list.AddExcludeList(filters);
|
||||
list.AddDirectory(QString(SRCDIR) + "/../data/files", true);
|
||||
QStringList files = list.GetFileList();
|
||||
list.addExcludeList(filters);
|
||||
list.addDirectory(QString(SRCDIR) + "/../data/files", true);
|
||||
QStringList files = list.getFileList();
|
||||
QCOMPARE(files.size(), 8);
|
||||
QDir dir(QString(SRCDIR) + "/../data/files");
|
||||
QString base = dir.canonicalPath();
|
||||
|
@ -166,9 +166,9 @@ void TestFileList::filterFiles5()
|
|||
FileList list;
|
||||
QStringList filters;
|
||||
filters << QDir(QString(SRCDIR) + "/../data/files/dir1/").absolutePath() + "/";
|
||||
list.AddExcludeList(filters);
|
||||
list.AddDirectory(QString(SRCDIR) + "/../data/files", true);
|
||||
QStringList files = list.GetFileList();
|
||||
list.addExcludeList(filters);
|
||||
list.addDirectory(QString(SRCDIR) + "/../data/files", true);
|
||||
QStringList files = list.getFileList();
|
||||
QCOMPARE(files.size(), 8);
|
||||
QDir dir(QString(SRCDIR) + "/../data/files");
|
||||
QString base = dir.canonicalPath();
|
||||
|
|
|
@ -25,27 +25,27 @@ void TestProjectFile::loadInexisting()
|
|||
{
|
||||
const QString filepath(QString(SRCDIR) + "/../data/projectfiles/foo.cppcheck");
|
||||
ProjectFile pfile(filepath);
|
||||
QCOMPARE(pfile.Read(), false);
|
||||
QCOMPARE(pfile.read(), false);
|
||||
}
|
||||
|
||||
void TestProjectFile::loadSimple()
|
||||
{
|
||||
const QString filepath(QString(SRCDIR) + "/../data/projectfiles/simple.cppcheck");
|
||||
ProjectFile pfile(filepath);
|
||||
QVERIFY(pfile.Read());
|
||||
QCOMPARE(pfile.GetRootPath(), QString("../.."));
|
||||
QStringList includes = pfile.GetIncludeDirs();
|
||||
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();
|
||||
QStringList paths = pfile.getCheckPaths();
|
||||
QCOMPARE(paths.size(), 2);
|
||||
QCOMPARE(paths[0], QString("gui/"));
|
||||
QCOMPARE(paths[1], QString("test/"));
|
||||
QStringList excludes = pfile.GetExcludedPaths();
|
||||
QStringList excludes = pfile.getExcludedPaths();
|
||||
QCOMPARE(excludes.size(), 1);
|
||||
QCOMPARE(excludes[0], QString("gui/temp/"));
|
||||
QStringList defines = pfile.GetDefines();
|
||||
QStringList defines = pfile.getDefines();
|
||||
QCOMPARE(defines.size(), 1);
|
||||
QCOMPARE(defines[0], QString("FOO"));
|
||||
}
|
||||
|
@ -55,20 +55,20 @@ void TestProjectFile::loadSimpleWithIgnore()
|
|||
{
|
||||
const QString filepath(QString(SRCDIR) + "/../data/projectfiles/simple_ignore.cppcheck");
|
||||
ProjectFile pfile(filepath);
|
||||
QVERIFY(pfile.Read());
|
||||
QCOMPARE(pfile.GetRootPath(), QString("../.."));
|
||||
QStringList includes = pfile.GetIncludeDirs();
|
||||
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();
|
||||
QStringList paths = pfile.getCheckPaths();
|
||||
QCOMPARE(paths.size(), 2);
|
||||
QCOMPARE(paths[0], QString("gui/"));
|
||||
QCOMPARE(paths[1], QString("test/"));
|
||||
QStringList excludes = pfile.GetExcludedPaths();
|
||||
QStringList excludes = pfile.getExcludedPaths();
|
||||
QCOMPARE(excludes.size(), 1);
|
||||
QCOMPARE(excludes[0], QString("gui/temp/"));
|
||||
QStringList defines = pfile.GetDefines();
|
||||
QStringList defines = pfile.getDefines();
|
||||
QCOMPARE(defines.size(), 1);
|
||||
QCOMPARE(defines[0], QString("FOO"));
|
||||
}
|
||||
|
@ -77,20 +77,20 @@ void TestProjectFile::loadSimpleNoroot()
|
|||
{
|
||||
const QString filepath(QString(SRCDIR) + "/../data/projectfiles/simple_noroot.cppcheck");
|
||||
ProjectFile pfile(filepath);
|
||||
QVERIFY(pfile.Read());
|
||||
QCOMPARE(pfile.GetRootPath(), QString());
|
||||
QStringList includes = pfile.GetIncludeDirs();
|
||||
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();
|
||||
QStringList paths = pfile.getCheckPaths();
|
||||
QCOMPARE(paths.size(), 2);
|
||||
QCOMPARE(paths[0], QString("gui/"));
|
||||
QCOMPARE(paths[1], QString("test/"));
|
||||
QStringList excludes = pfile.GetExcludedPaths();
|
||||
QStringList excludes = pfile.getExcludedPaths();
|
||||
QCOMPARE(excludes.size(), 1);
|
||||
QCOMPARE(excludes[0], QString("gui/temp/"));
|
||||
QStringList defines = pfile.GetDefines();
|
||||
QStringList defines = pfile.getDefines();
|
||||
QCOMPARE(defines.size(), 1);
|
||||
QCOMPARE(defines[0], QString("FOO"));
|
||||
}
|
||||
|
|
|
@ -6,5 +6,4 @@ SUBDIRS = benchmark \
|
|||
projectfile \
|
||||
translationhandler \
|
||||
xmlreport \
|
||||
xmlreportv1 \
|
||||
xmlreportv2
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
void TestTranslationHandler::construct()
|
||||
{
|
||||
TranslationHandler handler;
|
||||
QCOMPARE(handler.GetNames().size(), 13); // 12 translations + english
|
||||
QCOMPARE(handler.GetCurrentLanguage(), QString("en"));
|
||||
QCOMPARE(handler.getNames().size(), 13); // 12 translations + english
|
||||
QCOMPARE(handler.getCurrentLanguage(), QString("en"));
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestTranslationHandler)
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* Cppcheck - A tool for static C/C++ code analysis
|
||||
* Copyright (C) 2007-2016 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtTest>
|
||||
#include <QObject>
|
||||
#include "testxmlreportv1.h"
|
||||
#include "xmlreportv1.h"
|
||||
#include "erroritem.h"
|
||||
#include "errorlogger.h"
|
||||
|
||||
void TestXmlReportV1::readXml()
|
||||
{
|
||||
const QString filepath(QString(SRCDIR) + "/../data/xmlfiles/xmlreport_v1.xml");
|
||||
XmlReportV1 report(filepath);
|
||||
QVERIFY(report.Open());
|
||||
QList<ErrorItem> errors = report.Read();
|
||||
QCOMPARE(errors.size(), 6);
|
||||
|
||||
ErrorItem item = errors[0];
|
||||
QCOMPARE(item.file, QString("test.cxx"));
|
||||
QCOMPARE(item.lines[0], (unsigned int)11);
|
||||
QCOMPARE(item.errorId, QString("unreadVariable"));
|
||||
QCOMPARE(GuiSeverity::toString(item.severity), QString("style"));
|
||||
QCOMPARE(item.summary, QString("Variable 'a' is assigned a value that is never used"));
|
||||
QCOMPARE(item.message, QString("Variable 'a' is assigned a value that is never used"));
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestXmlReportV1)
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* Cppcheck - A tool for static C/C++ code analysis
|
||||
* Copyright (C) 2007-2016 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtTest>
|
||||
#include <QObject>
|
||||
|
||||
class TestXmlReportV1: public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void readXml();
|
||||
};
|
|
@ -1,15 +0,0 @@
|
|||
TEMPLATE = app
|
||||
TARGET = test-xmlreportv1
|
||||
DEPENDPATH += .
|
||||
INCLUDEPATH += .
|
||||
OBJECTS_DIR = ../build
|
||||
MOC_DIR = ../build
|
||||
|
||||
include(../common.pri)
|
||||
|
||||
DEFINES += SRCDIR=\\\"$$PWD\\\"
|
||||
|
||||
# tests
|
||||
SOURCES += testxmlreportv1.cpp
|
||||
|
||||
HEADERS += testxmlreportv1.h
|
|
@ -27,29 +27,25 @@ void TestXmlReportV2::readXml()
|
|||
{
|
||||
const QString filepath(QString(SRCDIR) + "/../data/xmlfiles/xmlreport_v2.xml");
|
||||
XmlReportV2 report(filepath);
|
||||
QVERIFY(report.Open());
|
||||
QList<ErrorItem> errors = report.Read();
|
||||
QVERIFY(report.open());
|
||||
QList<ErrorItem> errors = report.read();
|
||||
QCOMPARE(errors.size(), 6);
|
||||
|
||||
ErrorItem item = errors[0];
|
||||
QCOMPARE(item.file, QString("test.cxx"));
|
||||
QCOMPARE(item.files.size(), 1);
|
||||
QCOMPARE(item.lines.size(), 1);
|
||||
QCOMPARE(item.files[0], QString("test.cxx"));
|
||||
QCOMPARE(item.lines[0], (unsigned int)11);
|
||||
const ErrorItem &item = errors[0];
|
||||
QCOMPARE(item.errorPath.size(), 1);
|
||||
QCOMPARE(item.errorPath[0].file, QString("test.cxx"));
|
||||
QCOMPARE(item.errorPath[0].line, (unsigned int)11);
|
||||
QCOMPARE(item.errorId, QString("unreadVariable"));
|
||||
QCOMPARE(GuiSeverity::toString(item.severity), QString("style"));
|
||||
QCOMPARE(item.summary, QString("Variable 'a' is assigned a value that is never used"));
|
||||
QCOMPARE(item.message, QString("Variable 'a' is assigned a value that is never used"));
|
||||
|
||||
ErrorItem item2 = errors[3];
|
||||
QCOMPARE(item2.file, QString("test.cxx"));
|
||||
QCOMPARE(item2.files.size(), 2);
|
||||
QCOMPARE(item2.lines.size(), 2);
|
||||
QCOMPARE(item2.files[0], QString("test.cxx"));
|
||||
QCOMPARE(item2.lines[0], (unsigned int)32);
|
||||
QCOMPARE(item2.files[1], QString("test.cxx"));
|
||||
QCOMPARE(item2.lines[1], (unsigned int)16);
|
||||
const ErrorItem &item2 = errors[3];
|
||||
QCOMPARE(item2.errorPath.size(), 2);
|
||||
QCOMPARE(item2.errorPath[0].file, QString("test.cxx"));
|
||||
QCOMPARE(item2.errorPath[0].line, (unsigned int)16);
|
||||
QCOMPARE(item2.errorPath[1].file, QString("test.cxx"));
|
||||
QCOMPARE(item2.errorPath[1].line, (unsigned int)32);
|
||||
QCOMPARE(item2.errorId, QString("mismatchAllocDealloc"));
|
||||
QCOMPARE(GuiSeverity::toString(item2.severity), QString("error"));
|
||||
QCOMPARE(item2.summary, QString("Mismatching allocation and deallocation: k"));
|
||||
|
|
Loading…
Reference in New Issue