refactoring: fixed the teststl so it is runnable again

This commit is contained in:
Daniel Marjamäki 2009-03-19 19:35:08 +01:00
parent 16b6a7a605
commit 75171cae08
1 changed files with 49 additions and 88 deletions

View File

@ -35,7 +35,6 @@ public:
private: private:
void run() void run()
{ {
/*
TEST_CASE(iterator1); TEST_CASE(iterator1);
TEST_CASE(iterator2); TEST_CASE(iterator2);
TEST_CASE(STLSize); TEST_CASE(STLSize);
@ -48,10 +47,8 @@ private:
TEST_CASE(pushback1); TEST_CASE(pushback1);
TEST_CASE(invalidcode); TEST_CASE(invalidcode);
*/
} }
/*
void check(const char code[]) void check(const char code[])
{ {
// Tokenize.. // Tokenize..
@ -62,10 +59,9 @@ private:
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
// Check char variable usage.. // Check..
CheckStl checkStl(&tokenizer, this); CheckStl checkStl;
checkStl.iterators(); checkStl.runChecks(&tokenizer, (const Settings *)0, this);
checkStl.stlOutOfBounds();
} }
@ -154,85 +150,68 @@ private:
void checkErase(const char code[])
{
// Tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Clear the error buffer..
errout.str("");
// Check char variable usage..
CheckStl checkStl(&tokenizer, this);
checkStl.erase();
}
void erase() void erase()
{ {
checkErase("void f()\n" check("void f()\n"
"{\n" "{\n"
" for (it = foo.begin(); it != foo.end(); ++it)\n" " for (it = foo.begin(); it != foo.end(); ++it)\n"
" {\n" " {\n"
" foo.erase(it);\n" " foo.erase(it);\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of erase\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Dangerous usage of erase\n", errout.str());
} }
void eraseBreak() void eraseBreak()
{ {
checkErase("void f()\n" check("void f()\n"
"{\n" "{\n"
" for (it = foo.begin(); it != foo.end(); ++it)\n" " for (it = foo.begin(); it != foo.end(); ++it)\n"
" {\n" " {\n"
" foo.erase(it);\n" " foo.erase(it);\n"
" break;\n" " break;\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void eraseReturn() void eraseReturn()
{ {
checkErase("void f()\n" check("void f()\n"
"{\n" "{\n"
" for (it = foo.begin(); it != foo.end(); ++it)\n" " for (it = foo.begin(); it != foo.end(); ++it)\n"
" {\n" " {\n"
" foo.erase(it);\n" " foo.erase(it);\n"
" return;\n" " return;\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void eraseGoto() void eraseGoto()
{ {
checkErase("void f()\n" check("void f()\n"
"{\n" "{\n"
" for (it = foo.begin(); it != foo.end(); ++it)\n" " for (it = foo.begin(); it != foo.end(); ++it)\n"
" {\n" " {\n"
" foo.erase(it);\n" " foo.erase(it);\n"
" goto abc;\n" " goto abc;\n"
" }\n" " }\n"
"bar:\n" "bar:\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void eraseAssign() void eraseAssign()
{ {
checkErase("void f()\n" check("void f()\n"
"{\n" "{\n"
" for (it = foo.begin(); it != foo.end(); ++it)\n" " for (it = foo.begin(); it != foo.end(); ++it)\n"
" {\n" " {\n"
" foo.erase(it);\n" " foo.erase(it);\n"
" it = foo.begin();\n" " it = foo.begin();\n"
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
@ -240,31 +219,14 @@ private:
void checkPushback(const char code[])
{
// Tokenize..
Tokenizer tokenizer;
std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp");
// Clear the error buffer..
errout.str("");
// Check char variable usage..
CheckStl checkStl(&tokenizer, this);
checkStl.pushback();
}
void pushback1() void pushback1()
{ {
checkPushback("void f()\n" check("void f()\n"
"{\n" "{\n"
" std::vector<int>::const_iterator it = foo.begin();\n" " std::vector<int>::const_iterator it = foo.begin();\n"
" foo.push_back(123);\n" " foo.push_back(123);\n"
" *it;\n" " *it;\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) After push_back or push_front, the iterator 'it' may be invalid\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) After push_back or push_front, the iterator 'it' may be invalid\n", errout.str());
} }
@ -276,7 +238,6 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
*/
}; };
REGISTER_TEST(TestStl) REGISTER_TEST(TestStl)