From 82e8e1a737873a257998a34d942bdc9f754389e3 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Fri, 17 Jun 2011 13:46:40 +0300 Subject: [PATCH] GUITESTS: Add simple test for FileList. These tests check that FileList only accepts existing files with accepted filename extensions. --- gui/test/common.pri | 2 ++ gui/test/data/files/bar1 | 1 + gui/test/data/files/bar1.foo | 1 + gui/test/data/files/foo1.cpp | 1 + gui/test/data/files/foo2.cxx | 1 + gui/test/data/files/foo3.cc | 1 + gui/test/data/files/foo4.c | 1 + gui/test/data/files/foo5.c++ | 1 + gui/test/data/files/foo6.txx | 1 + gui/test/data/files/foo7.tpp | 1 + gui/test/filelist/filelist.pro | 15 ++++++++ gui/test/filelist/testfilelist.cpp | 57 ++++++++++++++++++++++++++++++ gui/test/filelist/testfilelist.h | 30 ++++++++++++++++ gui/test/test.pro | 3 +- 14 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 gui/test/data/files/bar1 create mode 100644 gui/test/data/files/bar1.foo create mode 100644 gui/test/data/files/foo1.cpp create mode 100644 gui/test/data/files/foo2.cxx create mode 100644 gui/test/data/files/foo3.cc create mode 100644 gui/test/data/files/foo4.c create mode 100644 gui/test/data/files/foo5.c++ create mode 100644 gui/test/data/files/foo6.txx create mode 100644 gui/test/data/files/foo7.tpp create mode 100644 gui/test/filelist/filelist.pro create mode 100644 gui/test/filelist/testfilelist.cpp create mode 100644 gui/test/filelist/testfilelist.h diff --git a/gui/test/common.pri b/gui/test/common.pri index b10cf885c..782751732 100644 --- a/gui/test/common.pri +++ b/gui/test/common.pri @@ -10,6 +10,7 @@ include($$PWD/../../lib/lib.pri) # GUI SOURCES += ../../erroritem.cpp \ + ../../filelist.cpp \ ../../projectfile.cpp \ ../../report.cpp \ ../../translationhandler.cpp \ @@ -18,6 +19,7 @@ SOURCES += ../../erroritem.cpp \ ../../xmlreportv2.cpp HEADERS += ../../erroritem.h \ + ../../filelist.h \ ../../projectfile.h \ ../../report.h \ ../../translationhandler.h \ diff --git a/gui/test/data/files/bar1 b/gui/test/data/files/bar1 new file mode 100644 index 000000000..e4294ad5e --- /dev/null +++ b/gui/test/data/files/bar1 @@ -0,0 +1 @@ +Dummy test file. diff --git a/gui/test/data/files/bar1.foo b/gui/test/data/files/bar1.foo new file mode 100644 index 000000000..e4294ad5e --- /dev/null +++ b/gui/test/data/files/bar1.foo @@ -0,0 +1 @@ +Dummy test file. diff --git a/gui/test/data/files/foo1.cpp b/gui/test/data/files/foo1.cpp new file mode 100644 index 000000000..e4294ad5e --- /dev/null +++ b/gui/test/data/files/foo1.cpp @@ -0,0 +1 @@ +Dummy test file. diff --git a/gui/test/data/files/foo2.cxx b/gui/test/data/files/foo2.cxx new file mode 100644 index 000000000..e4294ad5e --- /dev/null +++ b/gui/test/data/files/foo2.cxx @@ -0,0 +1 @@ +Dummy test file. diff --git a/gui/test/data/files/foo3.cc b/gui/test/data/files/foo3.cc new file mode 100644 index 000000000..e4294ad5e --- /dev/null +++ b/gui/test/data/files/foo3.cc @@ -0,0 +1 @@ +Dummy test file. diff --git a/gui/test/data/files/foo4.c b/gui/test/data/files/foo4.c new file mode 100644 index 000000000..e4294ad5e --- /dev/null +++ b/gui/test/data/files/foo4.c @@ -0,0 +1 @@ +Dummy test file. diff --git a/gui/test/data/files/foo5.c++ b/gui/test/data/files/foo5.c++ new file mode 100644 index 000000000..e4294ad5e --- /dev/null +++ b/gui/test/data/files/foo5.c++ @@ -0,0 +1 @@ +Dummy test file. diff --git a/gui/test/data/files/foo6.txx b/gui/test/data/files/foo6.txx new file mode 100644 index 000000000..e4294ad5e --- /dev/null +++ b/gui/test/data/files/foo6.txx @@ -0,0 +1 @@ +Dummy test file. diff --git a/gui/test/data/files/foo7.tpp b/gui/test/data/files/foo7.tpp new file mode 100644 index 000000000..e4294ad5e --- /dev/null +++ b/gui/test/data/files/foo7.tpp @@ -0,0 +1 @@ +Dummy test file. diff --git a/gui/test/filelist/filelist.pro b/gui/test/filelist/filelist.pro new file mode 100644 index 000000000..75fedadd7 --- /dev/null +++ b/gui/test/filelist/filelist.pro @@ -0,0 +1,15 @@ +TEMPLATE = app +TARGET = test-filelist +DEPENDPATH += . +INCLUDEPATH += . +OBJECTS_DIR = ../build +MOC_DIR = ../build + +include(../common.pri) + +DEFINES += SRCDIR=\\\"$$PWD\\\" + +# tests +SOURCES += testfilelist.cpp + +HEADERS += testfilelist.h diff --git a/gui/test/filelist/testfilelist.cpp b/gui/test/filelist/testfilelist.cpp new file mode 100644 index 000000000..5fe7bcbbc --- /dev/null +++ b/gui/test/filelist/testfilelist.cpp @@ -0,0 +1,57 @@ +/* + * 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 "testfilelist.h" +#include "filelist.h" + +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(); + QCOMPARE(files.size(), 7); +} + +void TestFileList::addFile_notexist() +{ + FileList list; + 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(); + QCOMPARE(files.size(), 0); +} + + +QTEST_MAIN(TestFileList) diff --git a/gui/test/filelist/testfilelist.h b/gui/test/filelist/testfilelist.h new file mode 100644 index 000000000..98b5debb6 --- /dev/null +++ b/gui/test/filelist/testfilelist.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 TestFileList: public QObject +{ + Q_OBJECT + +private slots: + void addFile(); + void addFile_notexist(); + void addFile_unknown(); +}; diff --git a/gui/test/test.pro b/gui/test/test.pro index 9bdb71aef..f18c7bdd9 100644 --- a/gui/test/test.pro +++ b/gui/test/test.pro @@ -1,7 +1,8 @@ CONFIG += ordered TEMPLATE = subdirs -SUBDIRS = projectfile \ +SUBDIRS = filelist \ + projectfile \ translationhandler \ xmlreport \ xmlreportv1 \