Skip to content

Commit 003a9be

Browse files
committed
Refactorizations: Made several test functions const according to cppcheck messages.
1 parent c8e4077 commit 003a9be

6 files changed

Lines changed: 58 additions & 58 deletions

File tree

test/testfilelister.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ class TestFileLister: public TestFixture {
5050
TEST_CASE(recursiveAddFiles);
5151
}
5252

53-
void isDirectory() {
53+
void isDirectory() const {
5454
ASSERT_EQUALS(false, FileLister::isDirectory("readme.txt"));
5555
ASSERT_EQUALS(true, FileLister::isDirectory("lib"));
5656
}
5757

5858
#ifndef _WIN32
59-
void absolutePath() {
59+
void absolutePath() const {
6060
std::vector<char> current_dir;
6161
#ifdef PATH_MAX
6262
current_dir.resize(PATH_MAX);
@@ -72,7 +72,7 @@ class TestFileLister: public TestFixture {
7272
}
7373
#endif
7474

75-
void recursiveAddFiles() {
75+
void recursiveAddFiles() const {
7676
// Recursively add add files..
7777
std::map<std::string, std::size_t> files;
7878
FileLister::recursiveAddFiles(files, ".");

test/testmathlib.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,42 +43,42 @@ class TestMathLib : public TestFixture {
4343
TEST_CASE(isLessEqual)
4444
}
4545

46-
void isGreater() {
46+
void isGreater() const {
4747
ASSERT_EQUALS(true , MathLib::isGreater("1.0", "0.001"));
4848
ASSERT_EQUALS(false, MathLib::isGreater("-1.0", "0.001"));
4949
}
5050

51-
void isGreaterEqual() {
51+
void isGreaterEqual() const {
5252
ASSERT_EQUALS(true , MathLib::isGreaterEqual("1.00", "1.0"));
5353
ASSERT_EQUALS(true , MathLib::isGreaterEqual("1.001", "1.0"));
5454
ASSERT_EQUALS(true , MathLib::isGreaterEqual("1.0", "0.001"));
5555
ASSERT_EQUALS(false, MathLib::isGreaterEqual("-1.0", "0.001"));
5656
}
5757

58-
void isEqual() {
58+
void isEqual() const {
5959
ASSERT_EQUALS(true , MathLib::isEqual("1.0", "1.0"));
6060
ASSERT_EQUALS(false , MathLib::isEqual("1.", "1.01"));
6161
ASSERT_EQUALS(true , MathLib::isEqual("0.1","1.0E-1"));
6262
}
6363

64-
void isNotEqual() {
64+
void isNotEqual() const {
6565
ASSERT_EQUALS(false , MathLib::isNotEqual("1.0", "1.0"));
6666
ASSERT_EQUALS(true , MathLib::isNotEqual("1.", "1.01"));
6767
}
6868

69-
void isLess() {
69+
void isLess() const {
7070
ASSERT_EQUALS(false , MathLib::isLess("1.0", "0.001"));
7171
ASSERT_EQUALS(true , MathLib::isLess("-1.0", "0.001"));
7272
}
7373

74-
void isLessEqual() {
74+
void isLessEqual() const {
7575
ASSERT_EQUALS(true , MathLib::isLessEqual("1.00", "1.0"));
7676
ASSERT_EQUALS(false , MathLib::isLessEqual("1.001", "1.0"));
7777
ASSERT_EQUALS(false , MathLib::isLessEqual("1.0", "0.001"));
7878
ASSERT_EQUALS(true , MathLib::isLessEqual("-1.0", "0.001"));
7979
}
8080

81-
void calculate() {
81+
void calculate() const {
8282
// addition
8383
ASSERT_EQUALS("256", MathLib::add("0xff", "1"));
8484
ASSERT_EQUALS("249", MathLib::add("250", "-1"));
@@ -124,7 +124,7 @@ class TestMathLib : public TestFixture {
124124
ASSERT_THROW(MathLib::calculate("1","2",'j'),InternalError);
125125
}
126126

127-
void calculate1() { // mod
127+
void calculate1() const { // mod
128128
ASSERT_EQUALS("0" , MathLib::calculate("2" , "1" , '%'));
129129
ASSERT_EQUALS("0" , MathLib::calculate("2.0" , "1.0" , '%'));
130130
ASSERT_EQUALS("2" , MathLib::calculate("12" , "5" , '%'));
@@ -134,7 +134,7 @@ class TestMathLib : public TestFixture {
134134
ASSERT_EQUALS("1.7" , MathLib::calculate("18.5" , "4.2" , '%'));
135135
}
136136

137-
void convert() {
137+
void convert() const {
138138
// ------------------
139139
// tolong conversion:
140140
// ------------------
@@ -198,7 +198,7 @@ class TestMathLib : public TestFixture {
198198

199199
}
200200

201-
void isint() {
201+
void isint() const {
202202
// zero tests
203203
ASSERT_EQUALS(true , MathLib::isInt("0"));
204204
ASSERT_EQUALS(false, MathLib::isInt("0."));
@@ -275,7 +275,7 @@ class TestMathLib : public TestFixture {
275275
ASSERT_EQUALS(false, MathLib::isInt("LL"));
276276
}
277277

278-
void isnegative() {
278+
void isnegative() const {
279279
ASSERT_EQUALS(true, MathLib::isNegative("-1"));
280280
ASSERT_EQUALS(true, MathLib::isNegative("-1."));
281281
ASSERT_EQUALS(true, MathLib::isNegative("-1.0"));
@@ -289,7 +289,7 @@ class TestMathLib : public TestFixture {
289289
ASSERT_EQUALS(false, MathLib::isNegative("+1.0E-2"));
290290
}
291291

292-
void isfloat() {
292+
void isfloat() const {
293293
ASSERT_EQUALS(false, MathLib::isFloat("0"));
294294
ASSERT_EQUALS(true , MathLib::isFloat("0."));
295295
ASSERT_EQUALS(true , MathLib::isFloat("0.0"));

test/testmemleak.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ class TestMemleakInFunction : public TestFixture {
561561
}
562562

563563

564-
void call_func() {
564+
void call_func() const {
565565
// whitelist..
566566
ASSERT_EQUALS(true, CheckMemoryLeakInFunction::test_white_list("qsort"));
567567
ASSERT_EQUALS(true, CheckMemoryLeakInFunction::test_white_list("scanf"));

test/testoptions.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,56 +40,56 @@ class TestOptions: public TestFixture {
4040
}
4141

4242

43-
void which_test() {
43+
void which_test() const {
4444
const char* argv[] = {"./test_runner", "TestClass"};
4545
options args(sizeof argv / sizeof argv[0], argv);
4646
ASSERT_EQUALS("TestClass", args.which_test());
4747
}
4848

4949

50-
void which_test_method() {
50+
void which_test_method() const {
5151
const char* argv[] = {"./test_runner", "TestClass::TestMethod"};
5252
options args(sizeof argv / sizeof argv[0], argv);
5353
ASSERT_EQUALS("TestClass::TestMethod", args.which_test());
5454
}
5555

5656

57-
void no_test_method() {
57+
void no_test_method() const {
5858
const char* argv[] = {"./test_runner"};
5959
options args(sizeof argv / sizeof argv[0], argv);
6060
ASSERT_EQUALS("", args.which_test());
6161
}
6262

6363

64-
void not_quiet() {
64+
void not_quiet() const {
6565
const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-v"};
6666
options args(sizeof argv / sizeof argv[0], argv);
6767
ASSERT_EQUALS(false, args.quiet());
6868
}
6969

7070

71-
void quiet() {
71+
void quiet() const {
7272
const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-q"};
7373
options args(sizeof argv / sizeof argv[0], argv);
7474
ASSERT_EQUALS(true, args.quiet());
7575
}
7676

7777

78-
void gcc_errors() {
78+
void gcc_errors() const {
7979
const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-g"};
8080
options args(sizeof argv / sizeof argv[0], argv);
8181
ASSERT_EQUALS(true, args.gcc_style_errors());
8282
}
8383

8484

85-
void multiple_testcases() {
85+
void multiple_testcases() const {
8686
const char* argv[] = {"./test_runner", "TestClass::TestMethod", "Ignore::ThisOne"};
8787
options args(sizeof argv / sizeof argv[0], argv);
8888
ASSERT_EQUALS("TestClass::TestMethod", args.which_test());
8989
}
9090

9191

92-
void invalid_switches() {
92+
void invalid_switches() const {
9393
const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-a", "-v", "-q", "-g"};
9494
options args(sizeof argv / sizeof argv[0], argv);
9595
ASSERT_EQUALS("TestClass::TestMethod", args.which_test());

test/testpath.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class TestPath : public TestFixture {
3737
TEST_CASE(is_csharp);
3838
}
3939

40-
void simplify_path() {
40+
void simplify_path() const {
4141
// Path::simplifyPath()
4242
ASSERT_EQUALS("index.h", Path::simplifyPath("index.h"));
4343
ASSERT_EQUALS("index.h", Path::simplifyPath("./index.h"));
@@ -65,7 +65,7 @@ class TestPath : public TestFixture {
6565
ASSERT_EQUALS("the/path to/index.cpp", Path::removeQuotationMarks("\"the/path to/index.cpp\""));
6666
}
6767

68-
void accept_file() {
68+
void accept_file() const {
6969
ASSERT(Path::acceptFile("index.cpp"));
7070
ASSERT(Path::acceptFile("index.invalid.cpp"));
7171
ASSERT(Path::acceptFile("index.invalid.Cpp"));
@@ -77,7 +77,7 @@ class TestPath : public TestFixture {
7777
ASSERT(Path::acceptFile("C")==false);
7878
}
7979

80-
void getRelative() {
80+
void getRelative() const {
8181
std::vector<std::string> basePaths;
8282
basePaths.push_back(""); // Don't crash with empty paths
8383
basePaths.push_back("C:/foo");
@@ -91,7 +91,7 @@ class TestPath : public TestFixture {
9191
ASSERT_EQUALS("C:/foobar/test.cpp", Path::getRelativePath("C:/foobar/test.cpp", basePaths));
9292
}
9393

94-
void is_c() {
94+
void is_c() const {
9595
ASSERT(Path::isC("index.cpp")==false);
9696
ASSERT(Path::isC("")==false);
9797
ASSERT(Path::isC("c")==false);
@@ -106,7 +106,7 @@ class TestPath : public TestFixture {
106106
#endif
107107
}
108108

109-
void is_cpp() {
109+
void is_cpp() const {
110110
ASSERT(Path::isCPP("index.c")==false);
111111

112112
// In unix .C is considered C++
@@ -120,14 +120,14 @@ class TestPath : public TestFixture {
120120
ASSERT(Path::isCPP("C:\\foo\\index.Cpp"));
121121
}
122122

123-
void is_java() {
123+
void is_java() const {
124124
ASSERT(Path::isJava("index.cpp")==false);
125125
ASSERT(Path::isJava("index.java"));
126126
ASSERT(Path::isJava("C:\\foo\\index.java"));
127127
ASSERT(Path::isJava("C:\\foo\\index.Java"));
128128
}
129129

130-
void is_csharp() {
130+
void is_csharp() const {
131131
ASSERT(Path::isCSharp("index.cpp")==false);
132132
ASSERT(Path::isCSharp("index.cs"));
133133
ASSERT(Path::isCSharp("C:\\foo\\index.cs"));

0 commit comments

Comments
 (0)