Refactorizations: Made several test functions const according to cppcheck messages.

This commit is contained in:
PKEuS 2012-08-02 02:13:09 -07:00
parent c8e40773f1
commit 003a9be3ed
6 changed files with 58 additions and 58 deletions

View File

@ -50,13 +50,13 @@ private:
TEST_CASE(recursiveAddFiles);
}
void isDirectory() {
void isDirectory() const {
ASSERT_EQUALS(false, FileLister::isDirectory("readme.txt"));
ASSERT_EQUALS(true, FileLister::isDirectory("lib"));
}
#ifndef _WIN32
void absolutePath() {
void absolutePath() const {
std::vector<char> current_dir;
#ifdef PATH_MAX
current_dir.resize(PATH_MAX);
@ -72,7 +72,7 @@ private:
}
#endif
void recursiveAddFiles() {
void recursiveAddFiles() const {
// Recursively add add files..
std::map<std::string, std::size_t> files;
FileLister::recursiveAddFiles(files, ".");

View File

@ -43,42 +43,42 @@ private:
TEST_CASE(isLessEqual)
}
void isGreater() {
void isGreater() const {
ASSERT_EQUALS(true , MathLib::isGreater("1.0", "0.001"));
ASSERT_EQUALS(false, MathLib::isGreater("-1.0", "0.001"));
}
void isGreaterEqual() {
void isGreaterEqual() const {
ASSERT_EQUALS(true , MathLib::isGreaterEqual("1.00", "1.0"));
ASSERT_EQUALS(true , MathLib::isGreaterEqual("1.001", "1.0"));
ASSERT_EQUALS(true , MathLib::isGreaterEqual("1.0", "0.001"));
ASSERT_EQUALS(false, MathLib::isGreaterEqual("-1.0", "0.001"));
}
void isEqual() {
void isEqual() const {
ASSERT_EQUALS(true , MathLib::isEqual("1.0", "1.0"));
ASSERT_EQUALS(false , MathLib::isEqual("1.", "1.01"));
ASSERT_EQUALS(true , MathLib::isEqual("0.1","1.0E-1"));
}
void isNotEqual() {
void isNotEqual() const {
ASSERT_EQUALS(false , MathLib::isNotEqual("1.0", "1.0"));
ASSERT_EQUALS(true , MathLib::isNotEqual("1.", "1.01"));
}
void isLess() {
void isLess() const {
ASSERT_EQUALS(false , MathLib::isLess("1.0", "0.001"));
ASSERT_EQUALS(true , MathLib::isLess("-1.0", "0.001"));
}
void isLessEqual() {
void isLessEqual() const {
ASSERT_EQUALS(true , MathLib::isLessEqual("1.00", "1.0"));
ASSERT_EQUALS(false , MathLib::isLessEqual("1.001", "1.0"));
ASSERT_EQUALS(false , MathLib::isLessEqual("1.0", "0.001"));
ASSERT_EQUALS(true , MathLib::isLessEqual("-1.0", "0.001"));
}
void calculate() {
void calculate() const {
// addition
ASSERT_EQUALS("256", MathLib::add("0xff", "1"));
ASSERT_EQUALS("249", MathLib::add("250", "-1"));
@ -124,7 +124,7 @@ private:
ASSERT_THROW(MathLib::calculate("1","2",'j'),InternalError);
}
void calculate1() { // mod
void calculate1() const { // mod
ASSERT_EQUALS("0" , MathLib::calculate("2" , "1" , '%'));
ASSERT_EQUALS("0" , MathLib::calculate("2.0" , "1.0" , '%'));
ASSERT_EQUALS("2" , MathLib::calculate("12" , "5" , '%'));
@ -134,7 +134,7 @@ private:
ASSERT_EQUALS("1.7" , MathLib::calculate("18.5" , "4.2" , '%'));
}
void convert() {
void convert() const {
// ------------------
// tolong conversion:
// ------------------
@ -198,7 +198,7 @@ private:
}
void isint() {
void isint() const {
// zero tests
ASSERT_EQUALS(true , MathLib::isInt("0"));
ASSERT_EQUALS(false, MathLib::isInt("0."));
@ -275,7 +275,7 @@ private:
ASSERT_EQUALS(false, MathLib::isInt("LL"));
}
void isnegative() {
void isnegative() const {
ASSERT_EQUALS(true, MathLib::isNegative("-1"));
ASSERT_EQUALS(true, MathLib::isNegative("-1."));
ASSERT_EQUALS(true, MathLib::isNegative("-1.0"));
@ -289,7 +289,7 @@ private:
ASSERT_EQUALS(false, MathLib::isNegative("+1.0E-2"));
}
void isfloat() {
void isfloat() const {
ASSERT_EQUALS(false, MathLib::isFloat("0"));
ASSERT_EQUALS(true , MathLib::isFloat("0."));
ASSERT_EQUALS(true , MathLib::isFloat("0.0"));

View File

@ -561,7 +561,7 @@ private:
}
void call_func() {
void call_func() const {
// whitelist..
ASSERT_EQUALS(true, CheckMemoryLeakInFunction::test_white_list("qsort"));
ASSERT_EQUALS(true, CheckMemoryLeakInFunction::test_white_list("scanf"));

View File

@ -40,56 +40,56 @@ private:
}
void which_test() {
void which_test() const {
const char* argv[] = {"./test_runner", "TestClass"};
options args(sizeof argv / sizeof argv[0], argv);
ASSERT_EQUALS("TestClass", args.which_test());
}
void which_test_method() {
void which_test_method() const {
const char* argv[] = {"./test_runner", "TestClass::TestMethod"};
options args(sizeof argv / sizeof argv[0], argv);
ASSERT_EQUALS("TestClass::TestMethod", args.which_test());
}
void no_test_method() {
void no_test_method() const {
const char* argv[] = {"./test_runner"};
options args(sizeof argv / sizeof argv[0], argv);
ASSERT_EQUALS("", args.which_test());
}
void not_quiet() {
void not_quiet() const {
const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-v"};
options args(sizeof argv / sizeof argv[0], argv);
ASSERT_EQUALS(false, args.quiet());
}
void quiet() {
void quiet() const {
const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-q"};
options args(sizeof argv / sizeof argv[0], argv);
ASSERT_EQUALS(true, args.quiet());
}
void gcc_errors() {
void gcc_errors() const {
const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-g"};
options args(sizeof argv / sizeof argv[0], argv);
ASSERT_EQUALS(true, args.gcc_style_errors());
}
void multiple_testcases() {
void multiple_testcases() const {
const char* argv[] = {"./test_runner", "TestClass::TestMethod", "Ignore::ThisOne"};
options args(sizeof argv / sizeof argv[0], argv);
ASSERT_EQUALS("TestClass::TestMethod", args.which_test());
}
void invalid_switches() {
void invalid_switches() const {
const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-a", "-v", "-q", "-g"};
options args(sizeof argv / sizeof argv[0], argv);
ASSERT_EQUALS("TestClass::TestMethod", args.which_test());

View File

@ -37,7 +37,7 @@ private:
TEST_CASE(is_csharp);
}
void simplify_path() {
void simplify_path() const {
// Path::simplifyPath()
ASSERT_EQUALS("index.h", Path::simplifyPath("index.h"));
ASSERT_EQUALS("index.h", Path::simplifyPath("./index.h"));
@ -65,7 +65,7 @@ private:
ASSERT_EQUALS("the/path to/index.cpp", Path::removeQuotationMarks("\"the/path to/index.cpp\""));
}
void accept_file() {
void accept_file() const {
ASSERT(Path::acceptFile("index.cpp"));
ASSERT(Path::acceptFile("index.invalid.cpp"));
ASSERT(Path::acceptFile("index.invalid.Cpp"));
@ -77,7 +77,7 @@ private:
ASSERT(Path::acceptFile("C")==false);
}
void getRelative() {
void getRelative() const {
std::vector<std::string> basePaths;
basePaths.push_back(""); // Don't crash with empty paths
basePaths.push_back("C:/foo");
@ -91,7 +91,7 @@ private:
ASSERT_EQUALS("C:/foobar/test.cpp", Path::getRelativePath("C:/foobar/test.cpp", basePaths));
}
void is_c() {
void is_c() const {
ASSERT(Path::isC("index.cpp")==false);
ASSERT(Path::isC("")==false);
ASSERT(Path::isC("c")==false);
@ -106,7 +106,7 @@ private:
#endif
}
void is_cpp() {
void is_cpp() const {
ASSERT(Path::isCPP("index.c")==false);
// In unix .C is considered C++
@ -120,14 +120,14 @@ private:
ASSERT(Path::isCPP("C:\\foo\\index.Cpp"));
}
void is_java() {
void is_java() const {
ASSERT(Path::isJava("index.cpp")==false);
ASSERT(Path::isJava("index.java"));
ASSERT(Path::isJava("C:\\foo\\index.java"));
ASSERT(Path::isJava("C:\\foo\\index.Java"));
}
void is_csharp() {
void is_csharp() const {
ASSERT(Path::isCSharp("index.cpp")==false);
ASSERT(Path::isCSharp("index.cs"));
ASSERT(Path::isCSharp("C:\\foo\\index.cs"));

View File

@ -58,108 +58,108 @@ private:
TEST_CASE(filemaskpath4);
}
void emptymaskemptyfile() {
void emptymaskemptyfile() const {
std::vector<std::string> masks;
PathMatch match(masks);
ASSERT(!match.Match(""));
}
void emptymaskpath1() {
void emptymaskpath1() const {
std::vector<std::string> masks;
PathMatch match(masks);
ASSERT(!match.Match("src/"));
}
void emptymaskpath2() {
void emptymaskpath2() const {
std::vector<std::string> masks;
PathMatch match(masks);
ASSERT(!match.Match("../src/"));
}
void emptymaskpath3() {
void emptymaskpath3() const {
std::vector<std::string> masks;
PathMatch match(masks);
ASSERT(!match.Match("/home/user/code/src/"));
}
void onemaskemptypath() {
void onemaskemptypath() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(!match.Match(""));
}
void onemasksamepath() {
void onemasksamepath() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(match.Match("src/"));
}
void onemasksamepathdifferentcase() {
void onemasksamepathdifferentcase() const {
std::vector<std::string> masks;
masks.push_back("sRc/");
PathMatch match(masks, false);
ASSERT(match.Match("srC/"));
}
void onemasksamepathwithfile() {
void onemasksamepathwithfile() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(match.Match("src/file.txt"));
}
void onemaskdifferentdir1() {
void onemaskdifferentdir1() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(!match.Match("srcfiles/file.txt"));
}
void onemaskdifferentdir2() {
void onemaskdifferentdir2() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(!match.Match("proj/srcfiles/file.txt"));
}
void onemaskdifferentdir3() {
void onemaskdifferentdir3() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(!match.Match("proj/mysrc/file.txt"));
}
void onemaskdifferentdir4() {
void onemaskdifferentdir4() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(!match.Match("proj/mysrcfiles/file.txt"));
}
void onemasklongerpath1() {
void onemasklongerpath1() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(match.Match("/tmp/src/"));
}
void onemasklongerpath2() {
void onemasklongerpath2() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(match.Match("src/module/"));
}
void onemasklongerpath3() {
void onemasklongerpath3() const {
std::vector<std::string> masks;
masks.push_back("src/");
PathMatch match(masks);
ASSERT(match.Match("project/src/module/"));
}
void twomasklongerpath1() {
void twomasklongerpath1() const {
std::vector<std::string> masks;
masks.push_back("src/");
masks.push_back("module/");
@ -167,7 +167,7 @@ private:
ASSERT(!match.Match("project/"));
}
void twomasklongerpath2() {
void twomasklongerpath2() const {
std::vector<std::string> masks;
masks.push_back("src/");
masks.push_back("module/");
@ -175,7 +175,7 @@ private:
ASSERT(match.Match("project/src/"));
}
void twomasklongerpath3() {
void twomasklongerpath3() const {
std::vector<std::string> masks;
masks.push_back("src/");
masks.push_back("module/");
@ -183,7 +183,7 @@ private:
ASSERT(match.Match("project/module/"));
}
void twomasklongerpath4() {
void twomasklongerpath4() const {
std::vector<std::string> masks;
masks.push_back("src/");
masks.push_back("module/");
@ -191,56 +191,56 @@ private:
ASSERT(match.Match("project/src/module/"));
}
void filemask1() {
void filemask1() const {
std::vector<std::string> masks;
masks.push_back("foo.cpp");
PathMatch match(masks);
ASSERT(match.Match("foo.cpp"));
}
void filemaskdifferentcase() {
void filemaskdifferentcase() const {
std::vector<std::string> masks;
masks.push_back("foo.cPp");
PathMatch match(masks, false);
ASSERT(match.Match("fOo.cpp"));
}
void filemask2() {
void filemask2() const {
std::vector<std::string> masks;
masks.push_back("foo.cpp");
PathMatch match(masks);
ASSERT(match.Match("../foo.cpp"));
}
void filemask3() {
void filemask3() const {
std::vector<std::string> masks;
masks.push_back("foo.cpp");
PathMatch match(masks);
ASSERT(match.Match("src/foo.cpp"));
}
void filemaskpath1() {
void filemaskpath1() const {
std::vector<std::string> masks;
masks.push_back("src/foo.cpp");
PathMatch match(masks);
ASSERT(match.Match("src/foo.cpp"));
}
void filemaskpath2() {
void filemaskpath2() const {
std::vector<std::string> masks;
masks.push_back("src/foo.cpp");
PathMatch match(masks);
ASSERT(match.Match("proj/src/foo.cpp"));
}
void filemaskpath3() {
void filemaskpath3() const {
std::vector<std::string> masks;
masks.push_back("src/foo.cpp");
PathMatch match(masks);
ASSERT(!match.Match("foo.cpp"));
}
void filemaskpath4() {
void filemaskpath4() const {
std::vector<std::string> masks;
masks.push_back("src/foo.cpp");
PathMatch match(masks);