ASSERT_EQUALS("[test.cpp:3]: (style) Found obsolete function 'bsd_signal'. It is recommended that new applications use the 'sigaction' function\n",errout.str());
check("int f()\n"
"{\n"
" int bsd_signal(0);\n"
" return bsd_signal;\n"
"}\n");
ASSERT_EQUALS("",errout.str());
}
voidtestgethostbyname()
{
check("void f()\n"
"{\n"
" struct hostent *hp;\n"
" if(!hp = gethostbyname('127.0.0.1')) {\n"
" exit(1);\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (style) Found obsolete function 'gethostbyname'. It is recommended that new applications use the 'getnameinfo' function\n",errout.str());
ASSERT_EQUALS("[test.cpp:5]: (style) Found obsolete function 'gethostbyaddr'. It is recommended that new applications use the 'getaddrinfo' function\n",errout.str());
}
voidtestusleep()
{
check("void f()\n"
"{\n"
" usleep( 1000 );\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Found obsolete function 'usleep'. It is recommended that new applications use the 'nanosleep' or 'setitimer' function\n",errout.str());
}
voidtestindex()
{
check("namespace n1 {\n"
" int index(){};\n"
"}\n"
"int main()\n"
"{\n"
" n1::index();\n"
"}\n");
ASSERT_EQUALS("",errout.str());
check("std::size_t f()\n"
"{\n"
" std::size_t index(0);\n"
" index++;\n"
" return index;\n"
"}\n");
ASSERT_EQUALS("",errout.str());
check("int f()\n"
"{\n"
" return this->index();\n"
"}\n");
ASSERT_EQUALS("",errout.str());
check("void f()\n"
"{\n"
" int index( 0 );\n"
"}\n");
ASSERT_EQUALS("",errout.str());
check("const char f()\n"
"{\n"
" const char var[6] = 'index';\n"
" const char i = index(var, 0);\n"
" return i;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (style) Found obsolete function 'index'. It is recommended to use the function 'strchr' instead\n",errout.str());
}
voidtestrindex()
{
check("void f()\n"
"{\n"
" int rindex( 0 );\n"
"}\n");
ASSERT_EQUALS("",errout.str());
check("void f()\n"
"{\n"
" const char var[7] = 'rindex';\n"
" print(rindex(var, 0));\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (style) Found obsolete function 'rindex'. It is recommended to use the function 'strrchr' instead\n",errout.str());