Strip redundant std::string usage from tests.

Done by command:
git grep -l ASSERT_EQUALS | xargs sed -i 's|ASSERT_EQUALS(std::string(\(".\+"\)),|ASSERT_EQUALS(\1,|'

Should be no functional change.
This commit is contained in:
Slava Semushin 2009-06-01 02:48:55 +07:00
parent 2de4c516e9
commit e5c0383594
17 changed files with 181 additions and 181 deletions

View File

@ -74,7 +74,7 @@ private:
"{\n" "{\n"
" int num=2;" " int num=2;"
"res=#}"); "res=#}");
ASSERT_EQUALS(std::string("[test.cpp:3]: (error) Wrong assignement of an auto-variable to an effective parameter of a function\n"), errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Wrong assignement of an auto-variable to an effective parameter of a function\n", errout.str());
} }
void testautovararray() void testautovararray()
{ {
@ -82,7 +82,7 @@ private:
"{\n" "{\n"
" int num=2;" " int num=2;"
"arr[0]=#}"); "arr[0]=#}");
ASSERT_EQUALS(std::string("[test.cpp:3]: (error) Wrong assignement of an auto-variable to an effective parameter of a function\n"), errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Wrong assignement of an auto-variable to an effective parameter of a function\n", errout.str());
} }
void testautovarreturn() void testautovarreturn()
{ {
@ -90,7 +90,7 @@ private:
"{\n" "{\n"
" int num=2;" " int num=2;"
"return #}"); "return #}");
ASSERT_EQUALS(std::string("[test.cpp:3]: (error) Return of the address of an auto-variable\n"), errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Return of the address of an auto-variable\n", errout.str());
} }
}; };

View File

@ -197,7 +197,7 @@ private:
" int data[2];\n" " int data[2];\n"
" data[ sizeof(data[0]) ] = 0;\n" " data[ sizeof(data[0]) ] = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (all) Array index out of bounds\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (all) Array index out of bounds\n", errout.str());
} }
@ -211,7 +211,7 @@ private:
" str[15] = 0;\n" " str[15] = 0;\n"
" str[16] = 0;\n" " str[16] = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (all) Array index out of bounds\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (all) Array index out of bounds\n", errout.str());
} }
@ -223,7 +223,7 @@ private:
" str[15] = 0;\n" " str[15] = 0;\n"
" str[16] = 0;\n" " str[16] = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (all) Array index out of bounds\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (all) Array index out of bounds\n", errout.str());
} }
@ -236,7 +236,7 @@ private:
" for (i = 0; i < 100; i++)\n" " for (i = 0; i < 100; i++)\n"
" sum += val[i];\n" " sum += val[i];\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (all) Buffer overrun\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (all) Buffer overrun\n", errout.str());
} }
{ {
@ -246,7 +246,7 @@ private:
" for (i = 1; i < 100; i++)\n" " for (i = 1; i < 100; i++)\n"
" sum += val[i];\n" " sum += val[i];\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (all) Buffer overrun\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (all) Buffer overrun\n", errout.str());
} }
@ -257,7 +257,7 @@ private:
" for (i = a; i < 100; i++)\n" " for (i = a; i < 100; i++)\n"
" sum += val[i];\n" " sum += val[i];\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (all) Buffer overrun\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (all) Buffer overrun\n", errout.str());
} }
} }
@ -270,7 +270,7 @@ private:
" int i[SIZE];\n" " int i[SIZE];\n"
" i[SIZE] = 0;\n" " i[SIZE] = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (all) Array index out of bounds\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (all) Array index out of bounds\n", errout.str());
} }
@ -281,7 +281,7 @@ private:
" int i[10];\n" " int i[10];\n"
" i[ sizeof(i) - 1 ] = 0;\n" " i[ sizeof(i) - 1 ] = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (all) Array index out of bounds\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (all) Array index out of bounds\n", errout.str());
} }
@ -297,7 +297,7 @@ private:
" struct ABC abc;\n" " struct ABC abc;\n"
" abc.str[10] = 0;\n" " abc.str[10] = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:9]: (all) Array index out of bounds\n"), errout.str()); ASSERT_EQUALS("[test.cpp:9]: (all) Array index out of bounds\n", errout.str());
} }
@ -312,7 +312,7 @@ private:
"{\n" "{\n"
" abc->str[10] = 0;\n" " abc->str[10] = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:8]: (all) Array index out of bounds\n"), errout.str()); ASSERT_EQUALS("[test.cpp:8]: (all) Array index out of bounds\n", errout.str());
} }
@ -330,7 +330,7 @@ private:
" struct ABC abc;\n" " struct ABC abc;\n"
" abc.str[SIZE] = 0;\n" " abc.str[SIZE] = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:11]: (all) Array index out of bounds\n"), errout.str()); ASSERT_EQUALS("[test.cpp:11]: (all) Array index out of bounds\n", errout.str());
} }
void array_index_9() void array_index_9()
@ -345,7 +345,7 @@ private:
" char str[5];\n" " char str[5];\n"
" memclr( str ); // ERROR\n" " memclr( str ); // ERROR\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:9] -> [test.cpp:3]: (all) Array index out of bounds\n"), errout.str()); ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:3]: (all) Array index out of bounds\n", errout.str());
} }
@ -365,7 +365,7 @@ private:
"{\n" "{\n"
" memclr(abc->str);\n" " memclr(abc->str);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:13] -> [test.cpp:8]: (all) Array index out of bounds\n"), errout.str()); ASSERT_EQUALS("[test.cpp:13] -> [test.cpp:8]: (all) Array index out of bounds\n", errout.str());
} }
@ -386,7 +386,7 @@ private:
" abc->str[10] = 0;\n" " abc->str[10] = 0;\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:12]: (all) Array index out of bounds\n"), errout.str()); ASSERT_EQUALS("[test.cpp:12]: (all) Array index out of bounds\n", errout.str());
} }
@ -404,7 +404,7 @@ private:
" str[10] = 0;\n" " str[10] = 0;\n"
"}\n"); "}\n");
std::string err(errout.str()); std::string err(errout.str());
ASSERT_EQUALS(std::string("[test.cpp:10]: (all) Array index out of bounds\n"), err); ASSERT_EQUALS("[test.cpp:10]: (all) Array index out of bounds\n", err);
} }
void buffer_overrun_1() void buffer_overrun_1()
@ -414,7 +414,7 @@ private:
" char str[3];\n" " char str[3];\n"
" strcpy(str, \"abc\");\n" " strcpy(str, \"abc\");\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (all) Buffer overrun\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (all) Buffer overrun\n", errout.str());
} }
@ -429,7 +429,7 @@ private:
"{\n" "{\n"
" strcpy( abc->str, \"abcdef\" );\n" " strcpy( abc->str, \"abcdef\" );\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:8]: (all) Buffer overrun\n"), errout.str()); ASSERT_EQUALS("[test.cpp:8]: (all) Buffer overrun\n", errout.str());
} }
@ -444,7 +444,7 @@ private:
" a[i] = 0;\n" " a[i] = 0;\n"
"}\n"); "}\n");
std::string err(errout.str()); std::string err(errout.str());
ASSERT_EQUALS(std::string("[test.cpp:7]: (all) Buffer overrun\n"), err); ASSERT_EQUALS("[test.cpp:7]: (all) Buffer overrun\n", err);
} }
@ -458,7 +458,7 @@ private:
" char str[3];\n" " char str[3];\n"
" sprintf(str, \"%s\", \"abc\");\n" " sprintf(str, \"%s\", \"abc\");\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (all) Buffer overrun\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (all) Buffer overrun\n", errout.str());
} }
void snprintf1() void snprintf1()
@ -468,7 +468,7 @@ private:
" char str[5];\n" " char str[5];\n"
" snprintf(str, 10, \"%s\", \"abc\");\n" " snprintf(str, 10, \"%s\", \"abc\");\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) snprintf size is out of bounds\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) snprintf size is out of bounds\n", errout.str());
} }
void snprintf2() void snprintf2()
@ -512,7 +512,7 @@ private:
" strncpy(str, a, 10);\n" " strncpy(str, a, 10);\n"
" strncat(str, b, 10);\n" " strncat(str, b, 10);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (all) Dangerous usage of strncat, possible buffer overrun\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (all) Dangerous usage of strncat, possible buffer overrun\n", errout.str());
} }
void strncat2() void strncat2()
@ -522,7 +522,7 @@ private:
" char str[5];\n" " char str[5];\n"
" strncat(str, a, 5);\n" " strncat(str, a, 5);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (all) Dangerous usage of strncat, possible buffer overrun\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (all) Dangerous usage of strncat, possible buffer overrun\n", errout.str());
} }
@ -534,7 +534,7 @@ private:
" char str[10];\n" " char str[10];\n"
" cin >> str;\n" " cin >> str;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (all) Buffer overrun\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (all) Buffer overrun\n", errout.str());
} }
@ -576,7 +576,7 @@ private:
"{\n" "{\n"
" str[3] = 0;\n" " str[3] = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (all) Array index out of bounds\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (all) Array index out of bounds\n", errout.str());
} }
@ -588,14 +588,14 @@ private:
" char *s = new char[10];\n" " char *s = new char[10];\n"
" s[10] = 0;\n" " s[10] = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (all) Array index out of bounds\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (all) Array index out of bounds\n", errout.str());
check("void foo()\n" check("void foo()\n"
"{\n" "{\n"
" char *s = malloc(10);\n" " char *s = malloc(10);\n"
" s[10] = 0;\n" " s[10] = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (all) Array index out of bounds\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (all) Array index out of bounds\n", errout.str());
} }
@ -606,7 +606,7 @@ private:
" char s[10];\n" " char s[10];\n"
" memset(s, 5, '*');\n" " memset(s, 5, '*');\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (all) The size argument is given as a char constant\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (all) The size argument is given as a char constant\n", errout.str());
} }
}; };

View File

@ -72,20 +72,20 @@ private:
" char ch = 0x80;\n" " char ch = 0x80;\n"
" buf[ch] = 0;\n" " buf[ch] = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (style) Warning - using char variable as array index\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (style) Warning - using char variable as array index\n", errout.str());
check("void foo()\n" check("void foo()\n"
"{\n" "{\n"
" signed char ch = 0x80;\n" " signed char ch = 0x80;\n"
" buf[ch] = 0;\n" " buf[ch] = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (style) Warning - using char variable as array index\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (style) Warning - using char variable as array index\n", errout.str());
check("void foo(char ch)\n" check("void foo(char ch)\n"
"{\n" "{\n"
" buf[ch] = 0;\n" " buf[ch] = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Warning - using char variable as array index\n"), errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style) Warning - using char variable as array index\n", errout.str());
} }
@ -96,7 +96,7 @@ private:
" char ch;\n" " char ch;\n"
" result = a | ch;\n" " result = a | ch;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (style) Warning - using char variable in bit operation\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (style) Warning - using char variable in bit operation\n", errout.str());
} }
void bitop2() void bitop2()

View File

@ -92,7 +92,7 @@ private:
checkVirtualDestructor("class Base { };\n" checkVirtualDestructor("class Base { };\n"
"class Derived : public Base { public: ~Derived() { (void)11; } };"); "class Derived : public Base { public: ~Derived() { (void)11; } };");
ASSERT_EQUALS(std::string("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n"), errout.str()); ASSERT_EQUALS("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n", errout.str());
checkVirtualDestructor("class Base { };\n" checkVirtualDestructor("class Base { };\n"
"class Derived : Base { public: ~Derived() { (void)11; } };"); "class Derived : Base { public: ~Derived() { (void)11; } };");
@ -105,11 +105,11 @@ private:
checkVirtualDestructor("class Base { public: ~Base(); };\n" checkVirtualDestructor("class Base { public: ~Base(); };\n"
"class Derived : public Base { public: ~Derived() { (void)11; } };"); "class Derived : public Base { public: ~Derived() { (void)11; } };");
ASSERT_EQUALS(std::string("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n"), errout.str()); ASSERT_EQUALS("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n", errout.str());
checkVirtualDestructor("class Base { public: ~Base(); };\n" checkVirtualDestructor("class Base { public: ~Base(); };\n"
"class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };"); "class Derived : private Fred, public Base { public: ~Derived() { (void)11; } };");
ASSERT_EQUALS(std::string("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n"), errout.str()); ASSERT_EQUALS("[test.cpp:1]: (error) Class Base which is inherited by class Derived does not have a virtual destructor\n", errout.str());
} }
void virtualDestructor4() void virtualDestructor4()
@ -247,7 +247,7 @@ private:
" Foo(int _i) { }\n" " Foo(int _i) { }\n"
"};\n"); "};\n");
TODO_ASSERT_EQUALS(std::string("[test.cpp:7] (style) Member variable not initialized in the constructor Foo::foo"), errout.str()); TODO_ASSERT_EQUALS("[test.cpp:7] (style) Member variable not initialized in the constructor Foo::foo", errout.str());
} }

View File

@ -100,7 +100,7 @@ private:
" Fred() { }\n" " Fred() { }\n"
" int i;\n" " int i;\n"
"};\n"); "};\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (style) Member variable not initialized in the constructor 'Fred::i'\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str());
} }
@ -114,7 +114,7 @@ private:
"};\n" "};\n"
"Fred::Fred()\n" "Fred::Fred()\n"
"{ }\n"); "{ }\n");
ASSERT_EQUALS(std::string("[test.cpp:7]: (style) Member variable not initialized in the constructor 'Fred::i'\n"), errout.str()); ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str());
} }
@ -133,7 +133,7 @@ private:
"{\n" "{\n"
" i = _i;\n" " i = _i;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:8]: (style) Member variable not initialized in the constructor 'Fred::i'\n"), errout.str()); ASSERT_EQUALS("[test.cpp:8]: (style) Member variable not initialized in the constructor 'Fred::i'\n", errout.str());
} }
@ -200,7 +200,7 @@ private:
" void operator=() { }\n" " void operator=() { }\n"
" int i;\n" " int i;\n"
"};\n"); "};\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (all style) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (all style) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='\n", errout.str());
} }
void initvar_operator_eq3() void initvar_operator_eq3()
@ -310,7 +310,7 @@ private:
"};\n" "};\n"
"Fred::Fred()\n" "Fred::Fred()\n"
"{ }"); "{ }");
ASSERT_EQUALS(std::string("[test.cpp:7]: (style) Member variable not initialized in the constructor 'Fred::s'\n"), errout.str()); ASSERT_EQUALS("[test.cpp:7]: (style) Member variable not initialized in the constructor 'Fred::s'\n", errout.str());
} }
@ -369,7 +369,7 @@ private:
"\n" "\n"
"void Fred::operator=(const Fred &f)\n" "void Fred::operator=(const Fred &f)\n"
"{ }", true); "{ }", true);
ASSERT_EQUALS(std::string("[test.cpp:13]: (all style) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='\n"), errout.str()); ASSERT_EQUALS("[test.cpp:13]: (all style) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='\n", errout.str());
} }
}; };

View File

@ -74,7 +74,7 @@ private:
"{\n" "{\n"
" char *x = mktemp(\"/tmp/zxcv\");\n" " char *x = mktemp(\"/tmp/zxcv\");\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Found 'mktemp'. You should use 'mkstemp' instead\n"), errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style) Found 'mktemp'. You should use 'mkstemp' instead\n", errout.str());
} }
void testgets() void testgets()
@ -83,7 +83,7 @@ private:
"{\n" "{\n"
" char *x = gets();\n" " char *x = gets();\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Found 'gets'. You should use 'fgets' instead\n"), errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style) Found 'gets'. You should use 'fgets' instead\n", errout.str());
} }
void testscanf() void testscanf()
@ -93,7 +93,7 @@ private:
" char *x;\n" " char *x;\n"
" scanf(\"%s\", x);\n" " scanf(\"%s\", x);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (style) Found 'scanf'. You should use 'fgets' instead\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (style) Found 'scanf'. You should use 'fgets' instead\n", errout.str());
} }
}; };

View File

@ -74,7 +74,7 @@ private:
" unsigned int uvar = 2;\n" " unsigned int uvar = 2;\n"
" return ivar / uvar;\n" " return ivar / uvar;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (all style) Warning: Division with signed and unsigned operators\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (all style) Warning: Division with signed and unsigned operators\n", errout.str());
} }
void division2() void division2()
@ -85,7 +85,7 @@ private:
" unsigned int uvar = 2;\n" " unsigned int uvar = 2;\n"
" return uvar / ivar;\n" " return uvar / ivar;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (all style) Warning: Division with signed and unsigned operators\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (all style) Warning: Division with signed and unsigned operators\n", errout.str());
} }
void division3() void division3()
@ -98,7 +98,7 @@ private:
" u32 uvar = 2;\n" " u32 uvar = 2;\n"
" return uvar / ivar;\n" " return uvar / ivar;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:7]: (all style) Warning: Division with signed and unsigned operators\n"), errout.str()); ASSERT_EQUALS("[test.cpp:7]: (all style) Warning: Division with signed and unsigned operators\n", errout.str());
} }
void division4() void division4()
@ -134,7 +134,7 @@ private:
" unsigned int val = 32;\n" " unsigned int val = 32;\n"
" int i = val / -2; }\n" " int i = val / -2; }\n"
); );
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Unsigned division. The result will be wrong.\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Unsigned division. The result will be wrong.\n", errout.str());
} }
void division7() void division7()
@ -144,7 +144,7 @@ private:
" unsigned int val = 32;\n" " unsigned int val = 32;\n"
" int i = -96 / val; }\n" " int i = -96 / val; }\n"
); );
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Unsigned division. The result will be wrong.\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Unsigned division. The result will be wrong.\n", errout.str());
} }
}; };

View File

@ -35,16 +35,16 @@ private:
void simplify_path() void simplify_path()
{ {
ASSERT_EQUALS(std::string("index.h"), FileLister::simplifyPath("index.h")); ASSERT_EQUALS("index.h", FileLister::simplifyPath("index.h"));
ASSERT_EQUALS(std::string("/index.h"), FileLister::simplifyPath("/index.h")); ASSERT_EQUALS("/index.h", FileLister::simplifyPath("/index.h"));
ASSERT_EQUALS(std::string("/path/"), FileLister::simplifyPath("/path/")); ASSERT_EQUALS("/path/", FileLister::simplifyPath("/path/"));
ASSERT_EQUALS(std::string("/"), FileLister::simplifyPath("/")); ASSERT_EQUALS("/", FileLister::simplifyPath("/"));
ASSERT_EQUALS(std::string("./index.h"), FileLister::simplifyPath("./index.h")); ASSERT_EQUALS("./index.h", FileLister::simplifyPath("./index.h"));
ASSERT_EQUALS(std::string("../index.h"), FileLister::simplifyPath("../index.h")); ASSERT_EQUALS("../index.h", FileLister::simplifyPath("../index.h"));
ASSERT_EQUALS(std::string("/index.h"), FileLister::simplifyPath("/path/../index.h")); ASSERT_EQUALS("/index.h", FileLister::simplifyPath("/path/../index.h"));
ASSERT_EQUALS(std::string("/index.h"), FileLister::simplifyPath("/path/../other/../index.h")); ASSERT_EQUALS("/index.h", FileLister::simplifyPath("/path/../other/../index.h"));
ASSERT_EQUALS(std::string("/index.h"), FileLister::simplifyPath("/path/../other///././../index.h")); ASSERT_EQUALS("/index.h", FileLister::simplifyPath("/path/../other///././../index.h"));
ASSERT_EQUALS(std::string("../path/index.h"), FileLister::simplifyPath("../path/other/../index.h")); ASSERT_EQUALS("../path/index.h", FileLister::simplifyPath("../path/other/../index.h"));
} }

View File

@ -90,7 +90,7 @@ private:
" \"abc\";\n" " \"abc\";\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Redundant code: Found a statement that begins with string constant\n"), errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style) Redundant code: Found a statement that begins with string constant\n", errout.str());
} }
void test3() void test3()
@ -125,7 +125,7 @@ private:
" 50;\n" " 50;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Redundant code: Found a statement that begins with numeric constant\n"), errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style) Redundant code: Found a statement that begins with numeric constant\n", errout.str());
} }
void test_numeric() void test_numeric()

View File

@ -37,12 +37,12 @@ private:
void calculate() void calculate()
{ {
ASSERT_EQUALS(std::string("256"), MathLib::add("0xff", "1")); ASSERT_EQUALS("256", MathLib::add("0xff", "1"));
ASSERT_EQUALS(std::string("-0.003"), MathLib::multiply("-1e-3", "3")); ASSERT_EQUALS("-0.003", MathLib::multiply("-1e-3", "3"));
ASSERT_EQUALS(std::string("5"), MathLib::divide("25.5", "5.1")); ASSERT_EQUALS("5", MathLib::divide("25.5", "5.1"));
ASSERT_EQUALS(std::string("-11.96"), MathLib::multiply("-2.3", "5.2")); ASSERT_EQUALS("-11.96", MathLib::multiply("-2.3", "5.2"));
ASSERT_EQUALS(std::string("7"), MathLib::divide("21.", "3")); ASSERT_EQUALS("7", MathLib::divide("21.", "3"));
ASSERT_EQUALS(std::string("1"), MathLib::divide("3", "2")); ASSERT_EQUALS("1", MathLib::divide("3", "2"));
} }
void convert() void convert()

View File

@ -234,7 +234,7 @@ private:
"{\n" "{\n"
" int *a = new int[10];\n" " int *a = new int[10];\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Memory leak: a\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: a\n", errout.str());
} }
void simple2() void simple2()
@ -265,7 +265,7 @@ private:
" char *s = new char[100];\n" " char *s = new char[100];\n"
" return 0;\n" " return 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Memory leak: s\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: s\n", errout.str());
} }
@ -351,7 +351,7 @@ private:
" str = new char[20];\n" " str = new char[20];\n"
" delete [] str;\n" " delete [] str;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Memory leak: str\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: str\n", errout.str());
} }
@ -416,7 +416,7 @@ private:
" }\n" " }\n"
" free(str);\n" " free(str);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:6]: (error) Memory leak: str\n"), errout.str()); ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: str\n", errout.str());
} }
@ -442,7 +442,7 @@ private:
" return;\n" " return;\n"
" }\n" " }\n"
"}\n", true); "}\n", true);
ASSERT_EQUALS(std::string("[test.cpp:9]: (all) Memory leak: str\n"), errout.str()); ASSERT_EQUALS("[test.cpp:9]: (all) Memory leak: str\n", errout.str());
} }
@ -492,7 +492,7 @@ private:
" }\n" " }\n"
" return NULL;\n" " return NULL;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:8]: (error) Memory leak: s\n"), errout.str()); ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: s\n", errout.str());
} }
@ -570,7 +570,7 @@ private:
" return;\n" " return;\n"
" foo(p);\n" " foo(p);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:6]: (error) Memory leak: p\n"), errout.str()); ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: p\n", errout.str());
} }
void if2() void if2()
@ -672,7 +672,7 @@ private:
" }\n" " }\n"
" free(c);\n" " free(c);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:11]: (error) Memory leak: c\n"), errout.str()); ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: c\n", errout.str());
} }
void if9() void if9()
@ -702,7 +702,7 @@ private:
" ;\n" " ;\n"
" free(buf);\n" " free(buf);\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS(std::string("[test.cpp:6]: (error) Memory leak: buf\n"), errout.str()); TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: buf\n", errout.str());
} }
void if11() void if11()
@ -716,7 +716,7 @@ private:
" }\n" " }\n"
" delete [] x;\n" " delete [] x;\n"
"}\n", true); "}\n", true);
ASSERT_EQUALS(std::string("[test.cpp:6]: (error) Memory leak: x\n"), errout.str()); ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: x\n", errout.str());
} }
@ -754,7 +754,7 @@ private:
" free(str);\n" " free(str);\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:7]: (error) Memory leak: str\n"), errout.str()); ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: str\n", errout.str());
} }
@ -769,7 +769,7 @@ private:
" }\n" " }\n"
" free(str);\n" " free(str);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Memory leak: str\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: str\n", errout.str());
} }
@ -785,7 +785,7 @@ private:
" }\n" " }\n"
" free(str);\n" " free(str);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Memory leak: str\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: str\n", errout.str());
} }
@ -814,7 +814,7 @@ private:
" str = strdup(a[i]);\n" " str = strdup(a[i]);\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:8]: (error) Memory leak: str\n"), errout.str()); ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: str\n", errout.str());
} }
@ -830,7 +830,7 @@ private:
" free(str);\n" " free(str);\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:7]: (error) Memory leak: str\n"), errout.str()); ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: str\n", errout.str());
} }
@ -853,7 +853,7 @@ private:
"\n" "\n"
" return a;\n" " return a;\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS(std::string("[test.cpp:10]: (error) Memory leak: a\n"), errout.str()); TODO_ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: a\n", errout.str());
} }
@ -895,7 +895,7 @@ private:
"\n" "\n"
" return a;\n" " return a;\n"
"}\n", true); "}\n", true);
ASSERT_EQUALS(std::string("[test.cpp:11]: (error) Memory leak: a\n"), errout.str()); ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: a\n", errout.str());
} }
@ -914,7 +914,7 @@ private:
" while (!str);\n" " while (!str);\n"
" return str;\n" " return str;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:6]: (error) Memory leak: str\n"), errout.str()); ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: str\n", errout.str());
} }
@ -999,7 +999,7 @@ private:
" delete abc;\n" " delete abc;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:6]: (error) Memory leak: abc\n"), errout.str()); ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: abc\n", errout.str());
} }
void ret3() void ret3()
@ -1009,7 +1009,7 @@ private:
" FILE *filep = fopen(\"myfile.txt\",\"w\");\n" " FILE *filep = fopen(\"myfile.txt\",\"w\");\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Resource leak: filep\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Resource leak: filep\n", errout.str());
} }
void ret4() void ret4()
@ -1019,7 +1019,7 @@ private:
" FILE *p = popen( \"ls -l\", \"r\");\n" " FILE *p = popen( \"ls -l\", \"r\");\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Resource leak: p\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Resource leak: p\n", errout.str());
} }
void ret5() void ret5()
@ -1060,7 +1060,7 @@ private:
" int *a = new int[10];\n" " int *a = new int[10];\n"
" free(a);\n" " free(a);\n"
"}\n", true); "}\n", true);
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Mismatching allocation and deallocation: a\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Mismatching allocation and deallocation: a\n", errout.str());
} }
void mismatch2() void mismatch2()
@ -1105,7 +1105,7 @@ private:
" }\n" " }\n"
" delete [] p;\n" " delete [] p;\n"
"}\n", false); "}\n", false);
ASSERT_EQUALS(std::string("[test.cpp:7]: (error) Mismatching allocation and deallocation: p\n"), errout.str()); ASSERT_EQUALS("[test.cpp:7]: (error) Mismatching allocation and deallocation: p\n", errout.str());
} }
@ -1148,7 +1148,7 @@ private:
" char *p = new char[100];\n" " char *p = new char[100];\n"
" foo(p);\n" " foo(p);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:8]: (error) Memory leak: p\n"), errout.str()); ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: p\n", errout.str());
} }
@ -1181,7 +1181,7 @@ private:
" foo(p);\n" " foo(p);\n"
"}\n", true); "}\n", true);
std::string err(errout.str()); std::string err(errout.str());
ASSERT_EQUALS(std::string("[test.cpp:9] -> [test.cpp:3]: (error) Mismatching allocation and deallocation: str\n"), err); ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:3]: (error) Mismatching allocation and deallocation: str\n", err);
} }
@ -1198,7 +1198,7 @@ private:
" foo(p);\n" " foo(p);\n"
"}\n"); "}\n");
std::string err(errout.str()); std::string err(errout.str());
ASSERT_EQUALS(std::string("[test.cpp:10]: (error) Memory leak: p\n"), err); ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: p\n", err);
} }
@ -1217,7 +1217,7 @@ private:
" foo(p);\n" " foo(p);\n"
"}\n"); "}\n");
std::string err(errout.str()); std::string err(errout.str());
TODO_ASSERT_EQUALS(std::string("[test.cpp:11]: (error) Memory leak: p\n"), err); TODO_ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: p\n", err);
} }
@ -1361,7 +1361,7 @@ private:
" delete [] str2;\n" " delete [] str2;\n"
"}\n", true); "}\n", true);
ASSERT_EQUALS(std::string("[test.cpp:4]: (all) Memory leak: Fred::str1\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (all) Memory leak: Fred::str1\n", errout.str());
} }
@ -1386,7 +1386,7 @@ private:
" free(str1);\n" " free(str1);\n"
"}\n", true); "}\n", true);
ASSERT_EQUALS(std::string("[test.cpp:17]: (error) Mismatching allocation and deallocation: Fred::str1\n"), errout.str()); ASSERT_EQUALS("[test.cpp:17]: (error) Mismatching allocation and deallocation: Fred::str1\n", errout.str());
} }
void class3() void class3()
@ -1578,7 +1578,7 @@ private:
" delete [] str;\n" " delete [] str;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Memory leak: str\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: str\n", errout.str());
} }
void throw2() void throw2()
@ -1645,7 +1645,7 @@ private:
std::string err(errout.str()); std::string err(errout.str());
ASSERT_EQUALS(std::string("[test.cpp:12]: (error) Memory leak: s2\n"), err); ASSERT_EQUALS("[test.cpp:12]: (error) Memory leak: s2\n", err);
} }
@ -1656,7 +1656,7 @@ private:
" char *a = (char *)malloc(10);\n" " char *a = (char *)malloc(10);\n"
" a = realloc(a, 100);\n" " a = realloc(a, 100);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Memory leak: a\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: a\n", errout.str());
} }
void realloc2() void realloc2()
@ -1668,7 +1668,7 @@ private:
" free(a);\n" " free(a);\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Memory leak: a\n"), errout.str()); TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: a\n", errout.str());
} }
void realloc3() void realloc3()
@ -1694,7 +1694,7 @@ private:
" free(a);\n" " free(a);\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Memory leak: a\n"), errout.str()); TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: a\n", errout.str());
} }
@ -1707,7 +1707,7 @@ private:
" free(a);\n" " free(a);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Memory leak: a\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: a\n", errout.str());
check("void foo()\n" check("void foo()\n"
"{\n" "{\n"
@ -1776,7 +1776,7 @@ private:
" char *a = reinterpret_cast<char *>(malloc(10));\n" " char *a = reinterpret_cast<char *>(malloc(10));\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Memory leak: a\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: a\n", errout.str());
} }
void cast2() void cast2()
@ -1814,7 +1814,7 @@ private:
" delete abc;\n" " delete abc;\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Memory leak: abc.a\n"), errout.str()); TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: abc.a\n", errout.str());
} }
@ -1828,7 +1828,7 @@ private:
" delete [] s;\n" " delete [] s;\n"
" p = s;\n" " p = s;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Using 's' after it is deallocated / released\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Using 's' after it is deallocated / released\n", errout.str());
} }
void dealloc_use_2() void dealloc_use_2()
@ -1873,7 +1873,7 @@ private:
" free(str);\n" " free(str);\n"
" char c = str[10];\n" " char c = str[10];\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Using 'str' after it is deallocated / released\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Using 'str' after it is deallocated / released\n", errout.str());
} }
void dealloc_use_6() void dealloc_use_6()
@ -1895,7 +1895,7 @@ private:
" delete [] str;\n" " delete [] str;\n"
" str[10] = 0;\n" " str[10] = 0;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Using 'str' after it is deallocated / released\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Using 'str' after it is deallocated / released\n", errout.str());
} }
@ -1907,7 +1907,7 @@ private:
" free(str);\n" " free(str);\n"
" free(str);\n" " free(str);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Deallocating a deallocated pointer: str\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Deallocating a deallocated pointer: str\n", errout.str());
} }
void freefree2() void freefree2()
@ -1948,7 +1948,7 @@ private:
"{\n" "{\n"
" Fred *f = new Fred;\n" " Fred *f = new Fred;\n"
"}\n", true); "}\n", true);
ASSERT_EQUALS(std::string("[test.cpp:4]: (all) Memory leak: f\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (all) Memory leak: f\n", errout.str());
} }
@ -1960,7 +1960,7 @@ private:
" int *p = malloc(3);\n" " int *p = malloc(3);\n"
" free(p);\n" " free(p);\n"
"}\n", false); "}\n", false);
ASSERT_EQUALS(std::string("[test.cpp:3]: (error) The given size 3 is mismatching\n"), errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) The given size 3 is mismatching\n", errout.str());
} }
@ -2174,7 +2174,7 @@ private:
std::string err(errout.str()); std::string err(errout.str());
ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Memory leak: out\n"), err); ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: out\n", err);
} }
void strndup_function() void strndup_function()
@ -2183,7 +2183,7 @@ private:
"{\n" "{\n"
" char *out = strndup(\"text\", 3);\n" " char *out = strndup(\"text\", 3);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Memory leak: out\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: out\n", errout.str());
} }
void fcloseall_function() void fcloseall_function()
@ -2202,7 +2202,7 @@ private:
"{\n" "{\n"
" DIR *f = opendir(\".\");\n" " DIR *f = opendir(\".\");\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Resource leak: f\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Resource leak: f\n", errout.str());
} }
void fdopendir_function() void fdopendir_function()
@ -2211,7 +2211,7 @@ private:
"{\n" "{\n"
" DIR *f = fdopendir(fd);\n" " DIR *f = fdopendir(fd);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Resource leak: f\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Resource leak: f\n", errout.str());
} }
void closedir_function() void closedir_function()
@ -2250,7 +2250,7 @@ private:
" seekdir(f, 2)\n;" " seekdir(f, 2)\n;"
" scandir(f, namelist, filter, comp);\n;" " scandir(f, namelist, filter, comp);\n;"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:10]: (error) Resource leak: f\n"), errout.str()); ASSERT_EQUALS("[test.cpp:10]: (error) Resource leak: f\n", errout.str());
} }
void file_functions() void file_functions()
@ -2277,7 +2277,7 @@ private:
"fgetpos(in, 10);\n" "fgetpos(in, 10);\n"
"fprintf(in, \"text\\n\");\n" "fprintf(in, \"text\\n\");\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:22]: (error) Resource leak: f\n"), errout.str()); ASSERT_EQUALS("[test.cpp:22]: (error) Resource leak: f\n", errout.str());
} }
void pointer_to_pointer() void pointer_to_pointer()

View File

@ -95,7 +95,7 @@ private:
"}"); "}");
ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Division by zero\n"), errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Division by zero\n", errout.str());
} }
void zeroDiv2() void zeroDiv2()
@ -137,28 +137,28 @@ private:
" delete p;\n" " delete p;\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Redundant condition. It is safe to deallocate a NULL pointer\n"), errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style) Redundant condition. It is safe to deallocate a NULL pointer\n", errout.str());
check("void foo()\n" check("void foo()\n"
"{\n" "{\n"
" if (p)\n" " if (p)\n"
" delete p;\n" " delete p;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Redundant condition. It is safe to deallocate a NULL pointer\n"), errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style) Redundant condition. It is safe to deallocate a NULL pointer\n", errout.str());
check("void foo()\n" check("void foo()\n"
"{\n" "{\n"
" if (p != NULL)\n" " if (p != NULL)\n"
" delete p;\n" " delete p;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Redundant condition. It is safe to deallocate a NULL pointer\n"), errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style) Redundant condition. It is safe to deallocate a NULL pointer\n", errout.str());
check("void foo()\n" check("void foo()\n"
"{\n" "{\n"
" if (p)\n" " if (p)\n"
" delete [] p;\n" " delete [] p;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Redundant condition. It is safe to deallocate a NULL pointer\n"), errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style) Redundant condition. It is safe to deallocate a NULL pointer\n", errout.str());
} }
void unreachable1() void unreachable1()
@ -203,7 +203,7 @@ private:
" char buf[100];\n" " char buf[100];\n"
" sprintf(buf,\"%s\",buf);\n" " sprintf(buf,\"%s\",buf);\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Overlapping data buffer buf\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Overlapping data buffer buf\n", errout.str());
} }
void sprintf2() void sprintf2()
@ -271,7 +271,7 @@ private:
"{\n" "{\n"
" const char *p = \"/usr\" + '/';\n" " const char *p = \"/usr\" + '/';\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:3]: (error) Unusual pointer arithmetic\n"), errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Unusual pointer arithmetic\n", errout.str());
} }
void strPlusChar2() void strPlusChar2()
@ -282,7 +282,7 @@ private:
" char ch = '/';\n" " char ch = '/';\n"
" const char *p = \"/usr\" + ch;\n" " const char *p = \"/usr\" + ch;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Unusual pointer arithmetic\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Unusual pointer arithmetic\n", errout.str());
} }
void strPlusChar3() void strPlusChar3()
@ -322,7 +322,7 @@ private:
" char str[100] = {0};\n" " char str[100] = {0};\n"
" return str;\n" " return str;\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Returning pointer to local array variable\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Returning pointer to local array variable\n", errout.str());
} }
void returnLocalVariable2() void returnLocalVariable2()
@ -439,7 +439,7 @@ private:
" while (tok);\n" " while (tok);\n"
" tok = tok->next();\n" " tok = tok->next();\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (error) Possible null pointer dereference\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference\n", errout.str());
} }
void nullpointer2() void nullpointer2()

View File

@ -80,7 +80,7 @@ private:
" if (haystack.find(needle) != haystack.end())\n" " if (haystack.find(needle) != haystack.end())\n"
" haystack.remove(needle);" " haystack.remove(needle);"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Redundant condition. The remove function in the STL will not do anything if element doesn't exist\n"), errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style) Redundant condition. The remove function in the STL will not do anything if element doesn't exist\n", errout.str());
} }
void remove2() void remove2()
@ -92,7 +92,7 @@ private:
" haystack.remove(needle);\n" " haystack.remove(needle);\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Redundant condition. The remove function in the STL will not do anything if element doesn't exist\n"), errout.str()); ASSERT_EQUALS("[test.cpp:3]: (style) Redundant condition. The remove function in the STL will not do anything if element doesn't exist\n", errout.str());
} }
}; };

View File

@ -397,7 +397,7 @@ private:
" a = 10;\n" " a = 10;\n"
" a++;\n" " a++;\n"
"}\n"; "}\n";
ASSERT_EQUALS(std::string("void f ( int a ) { if ( a > 10 ) { a = 5 ; } else { a = 10 ; } a ++ ; } "), tok(code)); ASSERT_EQUALS("void f ( int a ) { if ( a > 10 ) { a = 5 ; } else { a = 10 ; } a ++ ; } ", tok(code));
} }
{ {
@ -409,7 +409,7 @@ private:
" a = 10;\n" " a = 10;\n"
" ++a;\n" " ++a;\n"
"}\n"; "}\n";
ASSERT_EQUALS(std::string("void f ( int a ) { if ( a > 10 ) { a = 5 ; } else { a = 10 ; } ++ a ; } "), tok(code)); ASSERT_EQUALS("void f ( int a ) { if ( a > 10 ) { a = 5 ; } else { a = 10 ; } ++ a ; } ", tok(code));
} }
} }
@ -422,7 +422,7 @@ private:
" if (c>0) { c++; }\n" " if (c>0) { c++; }\n"
" c++;\n" " c++;\n"
"}\n"; "}\n";
ASSERT_EQUALS(std::string("void f ( ) { int c ; c = 3 ; ; { ; } ; } "), tok(code)); ASSERT_EQUALS("void f ( ) { int c ; c = 3 ; ; { ; } ; } ", tok(code));
} }
@ -435,7 +435,7 @@ private:
" if (c>0) { ++c; }\n" " if (c>0) { ++c; }\n"
" ++c;\n" " ++c;\n"
"}\n"; "}\n";
ASSERT_EQUALS(std::string("void f ( ) { int c ; c = 3 ; ; { ; } ; } "), tok(code)); ASSERT_EQUALS("void f ( ) { int c ; c = 3 ; ; { ; } ; } ", tok(code));
} }
@ -496,7 +496,7 @@ private:
" sizeof(i);\n" " sizeof(i);\n"
" sizeof(*i);\n" " sizeof(*i);\n"
"}\n"; "}\n";
ASSERT_EQUALS(std::string(" void foo ( ) { int i [ 4 ] ; 16 ; 4 ; }"), sizeof_(code)); ASSERT_EQUALS(" void foo ( ) { int i [ 4 ] ; 16 ; 4 ; }", sizeof_(code));
} }
void sizeof3() void sizeof3()
@ -507,14 +507,14 @@ private:
" int i[10];\n" " int i[10];\n"
" sizeof(i);\n" " sizeof(i);\n"
"}\n"; "}\n";
ASSERT_EQUALS(std::string(" static int i [ 4 ] ; void f ( ) { int i [ 10 ] ; 40 ; }"), sizeof_(code)); ASSERT_EQUALS(" static int i [ 4 ] ; void f ( ) { int i [ 10 ] ; 40 ; }", sizeof_(code));
} }
void sizeof4() void sizeof4()
{ {
const char code[] = "int i[10];\n" const char code[] = "int i[10];\n"
"sizeof(i[0]);\n"; "sizeof(i[0]);\n";
ASSERT_EQUALS(std::string(" int i [ 10 ] ; 4 ;"), sizeof_(code)); ASSERT_EQUALS(" int i [ 10 ] ; 4 ;", sizeof_(code));
} }
void sizeof5() void sizeof5()
@ -522,7 +522,7 @@ private:
const char code[] = const char code[] =
"for (int i = 0; i < sizeof(g_ReservedNames[0]); i++)" "for (int i = 0; i < sizeof(g_ReservedNames[0]); i++)"
"{}"; "{}";
ASSERT_EQUALS(std::string(" for ( int i = 0 ; i < 100 ; i ++ ) { }"), sizeof_(code)); ASSERT_EQUALS(" for ( int i = 0 ; i < 100 ; i ++ ) { }", sizeof_(code));
} }
void sizeof6() void sizeof6()

View File

@ -144,7 +144,7 @@ private:
" foo[ii] = 0;\n" " foo[ii] = 0;\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:6]: (error) When ii==foo.size(), foo[ii] is out of bounds\n"), errout.str()); ASSERT_EQUALS("[test.cpp:6]: (error) When ii==foo.size(), foo[ii] is out of bounds\n", errout.str());
} }
void STLSizeNoErr() void STLSizeNoErr()

View File

@ -233,7 +233,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" int * f ( int * ) ;"), ostr.str()); ASSERT_EQUALS(" int * f ( int * ) ;", ostr.str());
} }
// remove static_cast.. // remove static_cast..
@ -251,7 +251,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" t = ( & p ) ;"), ostr.str()); ASSERT_EQUALS(" t = ( & p ) ;", ostr.str());
} }
@ -290,7 +290,7 @@ private:
tokenizer.fillFunctionList(); tokenizer.fillFunctionList();
ASSERT_EQUALS(1, static_cast<unsigned int>(tokenizer.getFunctionList().size())); ASSERT_EQUALS(1, static_cast<unsigned int>(tokenizer.getFunctionList().size()));
ASSERT_EQUALS(std::string("b"), tokenizer.getFunctionList()[0]->str()); ASSERT_EQUALS("b", tokenizer.getFunctionList()[0]->str());
} }
void const_and_volatile_functions() void const_and_volatile_functions()
@ -323,9 +323,9 @@ private:
ASSERT_EQUALS(3, static_cast<unsigned int>(tokenizer.getFunctionList().size())); ASSERT_EQUALS(3, static_cast<unsigned int>(tokenizer.getFunctionList().size()));
if (tokenizer.getFunctionList().size() == 3) if (tokenizer.getFunctionList().size() == 3)
{ {
ASSERT_EQUALS(std::string("a"), tokenizer.getFunctionList()[0]->str()); ASSERT_EQUALS("a", tokenizer.getFunctionList()[0]->str());
ASSERT_EQUALS(std::string("b"), tokenizer.getFunctionList()[1]->str()); ASSERT_EQUALS("b", tokenizer.getFunctionList()[1]->str());
ASSERT_EQUALS(std::string("c"), tokenizer.getFunctionList()[2]->str()); ASSERT_EQUALS("c", tokenizer.getFunctionList()[2]->str());
} }
} }
@ -347,7 +347,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { { ; } }"), ostr.str()); ASSERT_EQUALS(" void f ( ) { { ; } }", ostr.str());
} }
void ifAddBraces1() void ifAddBraces1()
@ -368,7 +368,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { if ( a ) { ; } else { ; } }"), ostr.str()); ASSERT_EQUALS(" void f ( ) { if ( a ) { ; } else { ; } }", ostr.str());
} }
void ifAddBraces2() void ifAddBraces2()
@ -388,7 +388,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { if ( a ) { if ( b ) { } } }"), ostr.str()); ASSERT_EQUALS(" void f ( ) { if ( a ) { if ( b ) { } } }", ostr.str());
} }
void ifAddBraces3() void ifAddBraces3()
@ -408,7 +408,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { if ( a ) { for ( ; ; ) { } } }"), ostr.str()); ASSERT_EQUALS(" void f ( ) { if ( a ) { for ( ; ; ) { } } }", ostr.str());
} }
void ifAddBraces4() void ifAddBraces4()
@ -433,7 +433,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" char * foo ( ) { char * str ; str = malloc ( 10 ) ; if ( somecondition ) { for ( ; ; ) { } } return str ; }"), ostr.str()); ASSERT_EQUALS(" char * foo ( ) { char * str ; str = malloc ( 10 ) ; if ( somecondition ) { for ( ; ; ) { } } return str ; }", ostr.str());
} }
void ifAddBraces5() void ifAddBraces5()
@ -458,7 +458,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { for ( int i = 0 ; i < 2 ; i ++ ) { if ( true ) { return ; } } return ; }"), ostr.str()); ASSERT_EQUALS(" void f ( ) { for ( int i = 0 ; i < 2 ; i ++ ) { if ( true ) { return ; } } return ; }", ostr.str());
} }
void ifAddBraces6() void ifAddBraces6()
@ -475,7 +475,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" if ( )"), ostr.str()); ASSERT_EQUALS(" if ( )", ostr.str());
} }
void simplifyKnownVariables1() void simplifyKnownVariables1()
@ -497,7 +497,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { int a ; a = 10 ; if ( 10 ) ; }"), ostr.str()); ASSERT_EQUALS(" void f ( ) { int a ; a = 10 ; if ( 10 ) ; }", ostr.str());
} }
void simplifyKnownVariables2() void simplifyKnownVariables2()
@ -520,7 +520,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { int a ; a = 10 ; a = g ( ) ; if ( a ) ; }"), ostr.str()); ASSERT_EQUALS(" void f ( ) { int a ; a = 10 ; a = g ( ) ; if ( a ) ; }", ostr.str());
} }
void simplifyKnownVariables3() void simplifyKnownVariables3()
@ -546,7 +546,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { int a ; a = 4 ; while ( true ) { break ; a = 10 ; } if ( a ) ; }"), ostr.str()); ASSERT_EQUALS(" void f ( ) { int a ; a = 4 ; while ( true ) { break ; a = 10 ; } if ( a ) ; }", ostr.str());
} }
void simplifyKnownVariables4() void simplifyKnownVariables4()
@ -568,7 +568,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { int a ; a = 4 ; if ( g ( 4 ) ) ; }"), ostr.str()); ASSERT_EQUALS(" void f ( ) { int a ; a = 4 ; if ( g ( 4 ) ) ; }", ostr.str());
} }
void simplifyKnownVariables5() void simplifyKnownVariables5()
@ -590,7 +590,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { int a ; a = 4 ; if ( a = 5 ) ; }"), ostr.str()); ASSERT_EQUALS(" void f ( ) { int a ; a = 4 ; if ( a = 5 ) ; }", ostr.str());
} }
void simplifyKnownVariables6() void simplifyKnownVariables6()
@ -613,7 +613,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { char str [ 2 ] ; int a ; a = 4 ; str [ 4 ] = 0 ; }"), ostr.str()); ASSERT_EQUALS(" void f ( ) { char str [ 2 ] ; int a ; a = 4 ; str [ 4 ] = 0 ; }", ostr.str());
} }
void simplifyKnownVariables7() void simplifyKnownVariables7()
@ -635,7 +635,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void foo ( ) { int i ; i = 24 ; abc [ 22 ] = 1 ; abc [ 24 ] = 2 ; }"), ostr.str()); ASSERT_EQUALS(" void foo ( ) { int i ; i = 24 ; abc [ 22 ] = 1 ; abc [ 24 ] = 2 ; }", ostr.str());
} }
void simplifyKnownVariables8() void simplifyKnownVariables8()
@ -657,7 +657,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void foo ( ) { int i ; i = 23 ; ; abc [ 23 ] = 0 ; }"), ostr.str()); ASSERT_EQUALS(" void foo ( ) { int i ; i = 23 ; ; abc [ 23 ] = 0 ; }", ostr.str());
} }
void simplifyKnownVariables9() void simplifyKnownVariables9()
@ -679,7 +679,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void foo ( ) { int a ; a = 1 ; int b ; b = 2 ; if ( 1 < 2 ) ; }"), ostr.str()); ASSERT_EQUALS(" void foo ( ) { int a ; a = 1 ; int b ; b = 2 ; if ( 1 < 2 ) ; }", ostr.str());
} }
void simplifyKnownVariables10() void simplifyKnownVariables10()
@ -709,7 +709,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
TODO_ASSERT_EQUALS(std::string(" void f ( ) { bool b ; b = false ; { b = true ; } if ( true ) { a ( ) ; } }"), ostr.str()); TODO_ASSERT_EQUALS(" void f ( ) { bool b ; b = false ; { b = true ; } if ( true ) { a ( ) ; } }", ostr.str());
} }
{ {
@ -737,7 +737,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
TODO_ASSERT_EQUALS(std::string(" void f ( ) { bool b ; b = false ; { b = false ; } { b = true ; } if ( true ) { a ( ) ; } }"), ostr.str()); TODO_ASSERT_EQUALS(" void f ( ) { bool b ; b = false ; { b = false ; } { b = true ; } if ( true ) { a ( ) ; } }", ostr.str());
} }
{ {
@ -762,7 +762,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { int b ; b = 0 ; b = 1 ; for ( int i = 0 ; i < 10 ; i ++ ) { } a ( 1 ) ; }"), ostr.str()); ASSERT_EQUALS(" void f ( ) { int b ; b = 0 ; b = 1 ; for ( int i = 0 ; i < 10 ; i ++ ) { } a ( 1 ) ; }", ostr.str());
} }
} }
@ -1553,7 +1553,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( int x ) { }"), ostr.str()); ASSERT_EQUALS(" void f ( int x ) { }", ostr.str());
} }
{ {
@ -1571,7 +1571,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( int x , char y ) { }"), ostr.str()); ASSERT_EQUALS(" void f ( int x , char y ) { }", ostr.str());
} }
{ {
@ -1593,7 +1593,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void foo ( ) { if ( x ) { int x ; } { } }"), ostr.str()); ASSERT_EQUALS(" void foo ( ) { if ( x ) { int x ; } { } }", ostr.str());
} }
} }
@ -1616,7 +1616,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void foo ( ) { free ( p ) ; }"), ostr.str()); ASSERT_EQUALS(" void foo ( ) { free ( p ) ; }", ostr.str());
} }
void removeParantheses2() void removeParantheses2()
@ -1637,7 +1637,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void foo ( ) { if ( ! s ) { return ; } }"), ostr.str()); ASSERT_EQUALS(" void foo ( ) { if ( ! s ) { return ; } }", ostr.str());
} }
void removeParantheses3() void removeParantheses3()
@ -1658,7 +1658,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void foo ( ) { { } }"), ostr.str()); ASSERT_EQUALS(" void foo ( ) { { } }", ostr.str());
} }
{ {
@ -1677,7 +1677,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void foo ( ) { { } }"), ostr.str()); ASSERT_EQUALS(" void foo ( ) { { } }", ostr.str());
} }
{ {
@ -1696,7 +1696,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void foo ( ) { if ( g ( 10 ) ) { } }"), ostr.str()); ASSERT_EQUALS(" void foo ( ) { if ( g ( 10 ) ) { } }", ostr.str());
} }
} }
@ -1722,7 +1722,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { int x ; x = 0 ; if ( ! x ) { } }"), ostr.str()); ASSERT_EQUALS(" void f ( ) { int x ; x = 0 ; if ( ! x ) { } }", ostr.str());
} }
void tokenize_double() void tokenize_double()
@ -1744,7 +1744,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { double a ; a = 4.2 ; float b ; b = 4.2f ; double c ; c = 4.2e+10 ; double d ; d = 4.2e-10 ; int e ; e = 4 + 2 ; }"), ostr.str()); ASSERT_EQUALS(" void f ( ) { double a ; a = 4.2 ; float b ; b = 4.2f ; double c ; c = 4.2e+10 ; double d ; d = 4.2e-10 ; int e ; e = 4 + 2 ; }", ostr.str());
} }
void tokenize_strings() void tokenize_strings()
@ -1768,7 +1768,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { const char * a ; a = { \"hello more world\" } ; }"), ostr.str()); ASSERT_EQUALS(" void f ( ) { const char * a ; a = { \"hello more world\" } ; }", ostr.str());
} }
void simplify_constants() void simplify_constants()
@ -1796,7 +1796,7 @@ private:
std::ostringstream ostr; std::ostringstream ostr;
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS(std::string(" void f ( ) { const int a = 45 ; { int b ; b = 45 ; } } void g ( ) { int a ; a = 2 ; }"), ostr.str()); ASSERT_EQUALS(" void f ( ) { const int a = 45 ; { int b ; b = 45 ; } } void g ( ) { int a ; a = 2 ; }", ostr.str());
} }
void simplify_constants2() void simplify_constants2()
@ -1899,7 +1899,7 @@ private:
Tokenizer tokenizer(s, this); Tokenizer tokenizer(s, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
ASSERT_EQUALS(std::string("[test.cpp:1]: (error) Invalid number of character ({). Can't process file.\n"), errout.str()); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid number of character ({). Can't process file.\n", errout.str());
} }
{ {
@ -1908,7 +1908,7 @@ private:
Tokenizer tokenizer(s, this); Tokenizer tokenizer(s, this);
std::istringstream istr(code); std::istringstream istr(code);
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
ASSERT_EQUALS(std::string("[test.cpp:1]: (error) Invalid number of character ((). Can't process file.\n"), errout.str()); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid number of character ((). Can't process file.\n", errout.str());
} }
{ {

View File

@ -81,7 +81,7 @@ private:
"unsigned int Fred::f()\n" "unsigned int Fred::f()\n"
"{ }\n"); "{ }\n");
ASSERT_EQUALS(std::string("[test.cpp:4]: (style) Unused private function 'Fred::f'\n"), errout.str()); ASSERT_EQUALS("[test.cpp:4]: (style) Unused private function 'Fred::f'\n", errout.str());
} }
@ -163,7 +163,7 @@ private:
"Fred::Fred()\n" "Fred::Fred()\n"
"{}\n"); "{}\n");
ASSERT_EQUALS(std::string("[test.cpp:6]: (style) Unused private function 'Fred::get'\n"), errout.str()); ASSERT_EQUALS("[test.cpp:6]: (style) Unused private function 'Fred::get'\n", errout.str());
} }