2011-01-31 14:25:51 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2012-01-01 00:05:37 +01:00
|
|
|
* Copyright (C) 2007-2012 Daniel Marjamäki and Cppcheck team.
|
2011-01-31 14:25:51 +01:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2011-02-01 12:34:05 +01:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2011-01-31 14:25:51 +01:00
|
|
|
#include "testsuite.h"
|
|
|
|
#include "pathmatch.h"
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
class TestPathMatch : public TestFixture {
|
2011-01-31 14:25:51 +01:00
|
|
|
public:
|
|
|
|
TestPathMatch() : TestFixture("TestPathMatch")
|
|
|
|
{ }
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void run() {
|
2011-01-31 14:25:51 +01:00
|
|
|
TEST_CASE(emptymaskemptyfile);
|
|
|
|
TEST_CASE(emptymaskpath1);
|
|
|
|
TEST_CASE(emptymaskpath2);
|
|
|
|
TEST_CASE(emptymaskpath3);
|
|
|
|
TEST_CASE(onemaskemptypath);
|
|
|
|
TEST_CASE(onemasksamepath);
|
2011-10-02 10:46:27 +02:00
|
|
|
TEST_CASE(onemasksamepathdifferentcase);
|
2011-01-31 14:25:51 +01:00
|
|
|
TEST_CASE(onemasksamepathwithfile);
|
2011-02-03 07:56:28 +01:00
|
|
|
TEST_CASE(onemaskdifferentdir1);
|
|
|
|
TEST_CASE(onemaskdifferentdir2);
|
|
|
|
TEST_CASE(onemaskdifferentdir3);
|
|
|
|
TEST_CASE(onemaskdifferentdir4);
|
2011-01-31 14:25:51 +01:00
|
|
|
TEST_CASE(onemasklongerpath1);
|
|
|
|
TEST_CASE(onemasklongerpath2);
|
|
|
|
TEST_CASE(onemasklongerpath3);
|
2011-12-15 20:18:52 +01:00
|
|
|
TEST_CASE(twomasklongerpath1);
|
|
|
|
TEST_CASE(twomasklongerpath2);
|
|
|
|
TEST_CASE(twomasklongerpath3);
|
|
|
|
TEST_CASE(twomasklongerpath4);
|
2011-02-03 13:43:42 +01:00
|
|
|
TEST_CASE(filemask1);
|
2011-10-02 10:46:27 +02:00
|
|
|
TEST_CASE(filemaskdifferentcase);
|
2011-02-03 13:43:42 +01:00
|
|
|
TEST_CASE(filemask2);
|
|
|
|
TEST_CASE(filemask3);
|
|
|
|
TEST_CASE(filemaskpath1);
|
|
|
|
TEST_CASE(filemaskpath2);
|
|
|
|
TEST_CASE(filemaskpath3);
|
|
|
|
TEST_CASE(filemaskpath4);
|
2011-01-31 14:25:51 +01:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void emptymaskemptyfile() {
|
2011-01-31 14:25:51 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(!match.Match(""));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void emptymaskpath1() {
|
2011-01-31 14:25:51 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(!match.Match("src/"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void emptymaskpath2() {
|
2011-01-31 14:25:51 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(!match.Match("../src/"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void emptymaskpath3() {
|
2011-01-31 14:25:51 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(!match.Match("/home/user/code/src/"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void onemaskemptypath() {
|
2011-01-31 14:25:51 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(!match.Match(""));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void onemasksamepath() {
|
2011-01-31 14:25:51 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(match.Match("src/"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void onemasksamepathdifferentcase() {
|
2011-10-02 10:46:27 +02:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("sRc/");
|
2012-02-19 17:22:59 +01:00
|
|
|
PathMatch match(masks, false);
|
|
|
|
ASSERT(match.Match("srC/"));
|
2011-10-02 10:46:27 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void onemasksamepathwithfile() {
|
2011-01-31 14:25:51 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(match.Match("src/file.txt"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void onemaskdifferentdir1() {
|
2011-02-03 07:56:28 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(!match.Match("srcfiles/file.txt"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void onemaskdifferentdir2() {
|
2011-02-03 07:56:28 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(!match.Match("proj/srcfiles/file.txt"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void onemaskdifferentdir3() {
|
2011-02-03 07:56:28 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(!match.Match("proj/mysrc/file.txt"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void onemaskdifferentdir4() {
|
2011-02-03 07:56:28 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(!match.Match("proj/mysrcfiles/file.txt"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void onemasklongerpath1() {
|
2011-01-31 14:25:51 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(match.Match("/tmp/src/"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void onemasklongerpath2() {
|
2011-01-31 14:25:51 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(match.Match("src/module/"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void onemasklongerpath3() {
|
2011-01-31 14:25:51 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(match.Match("project/src/module/"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void twomasklongerpath1() {
|
2011-01-31 14:25:51 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/");
|
|
|
|
masks.push_back("module/");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(!match.Match("project/"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void twomasklongerpath2() {
|
2011-01-31 14:25:51 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/");
|
|
|
|
masks.push_back("module/");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(match.Match("project/src/"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void twomasklongerpath3() {
|
2011-01-31 14:25:51 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/");
|
|
|
|
masks.push_back("module/");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(match.Match("project/module/"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void twomasklongerpath4() {
|
2011-01-31 14:25:51 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/");
|
|
|
|
masks.push_back("module/");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(match.Match("project/src/module/"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void filemask1() {
|
2011-02-03 13:43:42 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("foo.cpp");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(match.Match("foo.cpp"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void filemaskdifferentcase() {
|
2011-10-02 10:46:27 +02:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("foo.cPp");
|
2012-02-19 17:22:59 +01:00
|
|
|
PathMatch match(masks, false);
|
|
|
|
ASSERT(match.Match("fOo.cpp"));
|
2011-10-02 10:46:27 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void filemask2() {
|
2011-02-03 13:43:42 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("foo.cpp");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(match.Match("../foo.cpp"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void filemask3() {
|
2011-02-03 13:43:42 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("foo.cpp");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(match.Match("src/foo.cpp"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void filemaskpath1() {
|
2011-02-03 13:43:42 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/foo.cpp");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(match.Match("src/foo.cpp"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void filemaskpath2() {
|
2011-02-03 13:43:42 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/foo.cpp");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(match.Match("proj/src/foo.cpp"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void filemaskpath3() {
|
2011-02-03 13:43:42 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/foo.cpp");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(!match.Match("foo.cpp"));
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
void filemaskpath4() {
|
2011-02-03 13:43:42 +01:00
|
|
|
std::vector<std::string> masks;
|
|
|
|
masks.push_back("src/foo.cpp");
|
|
|
|
PathMatch match(masks);
|
|
|
|
ASSERT(!match.Match("bar/foo.cpp"));
|
|
|
|
}
|
2011-01-31 14:25:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_TEST(TestPathMatch)
|