Refactor TestIO, split test case

This commit is contained in:
Daniel Marjamäki 2016-01-12 15:06:42 +01:00
parent 5079b6d95e
commit 89b23bb698
1 changed files with 54 additions and 189 deletions

View File

@ -799,6 +799,31 @@ private:
#define TEST_SCANF_HU_ERR(TYPE) TEST_SCANF_ERR("%hu", "unsigned short", TYPE)
#define TEST_SCANF_HU(TYPE) \
check(TEST_SCANF_CODE("%hu",TYPE), true, false, Settings::Unix32); \
ASSERT_EQUALS(TEST_SCANF_HU_ERR(TYPE), errout.str()); \
check(TEST_SCANF_CODE("%hu",TYPE), true, false, Settings::Unix64); \
ASSERT_EQUALS(TEST_SCANF_HU_ERR(TYPE), errout.str()); \
check(TEST_SCANF_CODE("%hu",TYPE), true, false, Settings::Win32A); \
ASSERT_EQUALS(TEST_SCANF_HU_ERR(TYPE), errout.str()); \
check(TEST_SCANF_CODE("%hu",TYPE), true, false, Settings::Win64); \
ASSERT_EQUALS(TEST_SCANF_HU_ERR(TYPE), errout.str());
#define TEST_SCANF_HU_ERR_AKA(TYPE,AKATYPE) TEST_SCANF_ERR_AKA("%hu", "unsigned short", TYPE, AKATYPE)
#define TEST_SCANF_HU_AKA(TYPE, AKATYPE, AKATYPE_WIN64) \
check(TEST_SCANF_CODE("%hu",TYPE), true, false, Settings::Unix32); \
ASSERT_EQUALS(TEST_SCANF_HU_ERR_AKA(TYPE,AKATYPE), errout.str()); \
check(TEST_SCANF_CODE("%hu",TYPE), true, false, Settings::Unix64); \
ASSERT_EQUALS(TEST_SCANF_HU_ERR_AKA(TYPE,AKATYPE), errout.str()); \
check(TEST_SCANF_CODE("%hu",TYPE), true, false, Settings::Win32A); \
ASSERT_EQUALS(TEST_SCANF_HU_ERR_AKA(TYPE,AKATYPE), errout.str()); \
check(TEST_SCANF_CODE("%hu",TYPE), true, false, Settings::Win64); \
ASSERT_EQUALS(TEST_SCANF_HU_ERR_AKA(TYPE,AKATYPE_WIN64), errout.str());
void testScanfArgument() { void testScanfArgument() {
check("void foo() {\n" check("void foo() {\n"
" scanf(\"%1d\", &foo);\n" " scanf(\"%1d\", &foo);\n"
@ -953,195 +978,35 @@ private:
TEST_SCANF_LLU_AKA("std::intptr_t", "long", "long long"); TEST_SCANF_LLU_AKA("std::intptr_t", "long", "long long");
// TODO TEST_SCANF_LLU_AKA("std::uintptr_t", "unsigned long", "unsigned long long"); // TODO TEST_SCANF_LLU_AKA("std::uintptr_t", "unsigned long", "unsigned long long");
TEST_SCANF_HU("bool");
{ TEST_SCANF_HU("char");
const char * code = "void foo() {\n" TEST_SCANF_HU("signed char");
" bool b;\n" TEST_SCANF_HU("unsigned char");
" char c;\n" TEST_SCANF_HU("short");
" signed char sc;\n" TEST_SCANF_HU("signed short");
" unsigned char uc;\n" TEST_SCANF_HU("unsigned short");
" short s;\n" TEST_SCANF_HU("int");
" unsigned short us;\n" TEST_SCANF_HU("signed int");
" int i;\n" TEST_SCANF_HU("long");
" unsigned int ui;\n" TEST_SCANF_HU("signed long");
" long l;\n" TEST_SCANF_HU("unsigned long");
" unsigned long ul;\n" TEST_SCANF_HU("long long");
" long long ll;\n" TEST_SCANF_HU("signed long long");
" unsigned long long ull;\n" TEST_SCANF_HU("unsigned long long");
" float f;\n" TEST_SCANF_HU("float");
" double d;\n" TEST_SCANF_HU("double");
" long double ld;\n" TEST_SCANF_HU("long double");
" size_t st;\n" TEST_SCANF_HU_AKA("size_t", "unsigned long", "unsigned long long");
" ssize_t sst;\n" TEST_SCANF_HU_AKA("ssize_t", "long", "long long");
" ptrdiff_t pt;\n" TEST_SCANF_HU_AKA("ptrdiff_t", "long", "long long");
" intmax_t it;\n" TEST_SCANF_HU_AKA("intmax_t", "long", "long long");
" uintmax_t ut;\n" TEST_SCANF_HU_AKA("uintmax_t", "unsigned long", "unsigned long long");
" void * vp;\n" TEST_SCANF_HU("void *");
" std::size_t stdst;\n" TEST_SCANF_HU_AKA("std::size_t", "unsigned long", "unsigned long long");
" std::ssize_t stdsst;\n" TEST_SCANF_HU_AKA("std::ssize_t", "long", "long long");
" std::ptrdiff_t stdpt;\n" TEST_SCANF_HU_AKA("std::ptrdiff_t", "long", "long long");
" std::intptr_t stdipt;\n" TEST_SCANF_HU_AKA("std::intptr_t", "long", "long long");
" std::uintptr_t stduipt;\n" TEST_SCANF_HU_AKA("std::uintptr_t", "unsigned long", "unsigned long long");
" scanf(\"%llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu\",\n"
" &b, &c, &sc, &uc, &s, &us, &i, &ui, &l, &ul, &ll, &ull, &f, &d, &ld, &st, &sst, &pt, &it, &ut, &vp, vp,\n"
" &unknown, unknown, &stdst, &stdsst, &stdpt, &stdipt, &stduipt);\n"
"}\n";
std::string result("[test.cpp:28]: (warning) %llu in format string (no. 1) requires 'unsigned long long *' but the argument type is 'bool *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 2) requires 'unsigned long long *' but the argument type is 'char *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 3) requires 'unsigned long long *' but the argument type is 'signed char *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 4) requires 'unsigned long long *' but the argument type is 'unsigned char *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 5) requires 'unsigned long long *' but the argument type is 'short *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 6) requires 'unsigned long long *' but the argument type is 'unsigned short *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 7) requires 'unsigned long long *' but the argument type is 'int *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 8) requires 'unsigned long long *' but the argument type is 'unsigned int *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 9) requires 'unsigned long long *' but the argument type is 'long *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 10) requires 'unsigned long long *' but the argument type is 'unsigned long *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 11) requires 'unsigned long long *' but the argument type is 'long long *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 13) requires 'unsigned long long *' but the argument type is 'float *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 14) requires 'unsigned long long *' but the argument type is 'double *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 15) requires 'unsigned long long *' but the argument type is 'long double *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 16) requires 'unsigned long long *' but the argument type is 'size_t * {aka unsigned long *}'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 17) requires 'unsigned long long *' but the argument type is 'ssize_t * {aka long *}'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 18) requires 'unsigned long long *' but the argument type is 'ptrdiff_t * {aka long *}'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 19) requires 'unsigned long long *' but the argument type is 'intmax_t * {aka long *}'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 20) requires 'unsigned long long *' but the argument type is 'uintmax_t * {aka unsigned long *}'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 21) requires 'unsigned long long *' but the argument type is 'void * *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 22) requires 'unsigned long long *' but the argument type is 'void *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 25) requires 'unsigned long long *' but the argument type is 'std::size_t * {aka unsigned long *}'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 26) requires 'unsigned long long *' but the argument type is 'std::ssize_t * {aka long *}'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 27) requires 'unsigned long long *' but the argument type is 'std::ptrdiff_t * {aka long *}'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 28) requires 'unsigned long long *' but the argument type is 'std::intptr_t * {aka long *}'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 29) requires 'unsigned long long *' but the argument type is 'std::uintptr_t * {aka unsigned long *}'.\n");
std::string result_win64("[test.cpp:28]: (warning) %llu in format string (no. 1) requires 'unsigned long long *' but the argument type is 'bool *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 2) requires 'unsigned long long *' but the argument type is 'char *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 3) requires 'unsigned long long *' but the argument type is 'signed char *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 4) requires 'unsigned long long *' but the argument type is 'unsigned char *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 5) requires 'unsigned long long *' but the argument type is 'short *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 6) requires 'unsigned long long *' but the argument type is 'unsigned short *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 7) requires 'unsigned long long *' but the argument type is 'int *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 8) requires 'unsigned long long *' but the argument type is 'unsigned int *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 9) requires 'unsigned long long *' but the argument type is 'long *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 10) requires 'unsigned long long *' but the argument type is 'unsigned long *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 11) requires 'unsigned long long *' but the argument type is 'long long *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 13) requires 'unsigned long long *' but the argument type is 'float *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 14) requires 'unsigned long long *' but the argument type is 'double *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 15) requires 'unsigned long long *' but the argument type is 'long double *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 16) requires 'unsigned long long *' but the argument type is 'size_t * {aka unsigned long long *}'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 17) requires 'unsigned long long *' but the argument type is 'ssize_t * {aka long long *}'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 18) requires 'unsigned long long *' but the argument type is 'ptrdiff_t * {aka long long *}'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 19) requires 'unsigned long long *' but the argument type is 'intmax_t * {aka long long *}'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 20) requires 'unsigned long long *' but the argument type is 'uintmax_t * {aka unsigned long long *}'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 21) requires 'unsigned long long *' but the argument type is 'void * *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 22) requires 'unsigned long long *' but the argument type is 'void *'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 25) requires 'unsigned long long *' but the argument type is 'std::size_t * {aka unsigned long long *}'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 26) requires 'unsigned long long *' but the argument type is 'std::ssize_t * {aka long long *}'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 27) requires 'unsigned long long *' but the argument type is 'std::ptrdiff_t * {aka long long *}'.\n"
"[test.cpp:28]: (warning) %llu in format string (no. 28) requires 'unsigned long long *' but the argument type is 'std::intptr_t * {aka long long *}'.\n");
check(code, true, false, Settings::Unix32);
ASSERT_EQUALS(result, errout.str());
check(code, true, false, Settings::Unix64);
ASSERT_EQUALS(result, errout.str());
check(code, true, false, Settings::Win32A);
ASSERT_EQUALS(result, errout.str());
check(code, true, false, Settings::Win64);
ASSERT_EQUALS(result_win64, errout.str());
}
{
const char * code = "void foo() {\n"
" bool b;\n"
" char c;\n"
" signed char sc;\n"
" unsigned char uc;\n"
" short s;\n"
" unsigned short us;\n"
" int i;\n"
" unsigned int ui;\n"
" long l;\n"
" unsigned long ul;\n"
" long long ll;\n"
" unsigned long long ull;\n"
" float f;\n"
" double d;\n"
" long double ld;\n"
" size_t st;\n"
" ssize_t sst;\n"
" ptrdiff_t pt;\n"
" intmax_t it;\n"
" uintmax_t ut;\n"
" void * vp;\n"
" std::size_t stdst;\n"
" std::ssize_t stdsst;\n"
" std::ptrdiff_t stdpt;\n"
" std::intptr_t stdipt;\n"
" std::uintptr_t stduipt;\n"
" scanf(\"%hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu %hu\",\n"
" &b, &c, &sc, &uc, &s, &us, &i, &ui, &l, &ul, &ll, &ull, &f, &d, &ld, &st, &sst, &pt, &it, &ut, &vp, vp,\n"
" &unknown, unknown, &stdst, &stdsst, &stdpt, &stdipt, &stduipt);\n"
"}\n";
std::string result("[test.cpp:28]: (warning) %hu in format string (no. 1) requires 'unsigned short *' but the argument type is 'bool *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 2) requires 'unsigned short *' but the argument type is 'char *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 3) requires 'unsigned short *' but the argument type is 'signed char *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 4) requires 'unsigned short *' but the argument type is 'unsigned char *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 5) requires 'unsigned short *' but the argument type is 'short *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 7) requires 'unsigned short *' but the argument type is 'int *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 8) requires 'unsigned short *' but the argument type is 'unsigned int *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 9) requires 'unsigned short *' but the argument type is 'long *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 10) requires 'unsigned short *' but the argument type is 'unsigned long *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 11) requires 'unsigned short *' but the argument type is 'long long *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 12) requires 'unsigned short *' but the argument type is 'unsigned long long *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 13) requires 'unsigned short *' but the argument type is 'float *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 14) requires 'unsigned short *' but the argument type is 'double *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 15) requires 'unsigned short *' but the argument type is 'long double *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 16) requires 'unsigned short *' but the argument type is 'size_t * {aka unsigned long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 17) requires 'unsigned short *' but the argument type is 'ssize_t * {aka long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 18) requires 'unsigned short *' but the argument type is 'ptrdiff_t * {aka long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 19) requires 'unsigned short *' but the argument type is 'intmax_t * {aka long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 20) requires 'unsigned short *' but the argument type is 'uintmax_t * {aka unsigned long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 21) requires 'unsigned short *' but the argument type is 'void * *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 22) requires 'unsigned short *' but the argument type is 'void *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 25) requires 'unsigned short *' but the argument type is 'std::size_t * {aka unsigned long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 26) requires 'unsigned short *' but the argument type is 'std::ssize_t * {aka long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 27) requires 'unsigned short *' but the argument type is 'std::ptrdiff_t * {aka long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 28) requires 'unsigned short *' but the argument type is 'std::intptr_t * {aka long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 29) requires 'unsigned short *' but the argument type is 'std::uintptr_t * {aka unsigned long *}'.\n");
std::string result_win64("[test.cpp:28]: (warning) %hu in format string (no. 1) requires 'unsigned short *' but the argument type is 'bool *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 2) requires 'unsigned short *' but the argument type is 'char *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 3) requires 'unsigned short *' but the argument type is 'signed char *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 4) requires 'unsigned short *' but the argument type is 'unsigned char *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 5) requires 'unsigned short *' but the argument type is 'short *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 7) requires 'unsigned short *' but the argument type is 'int *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 8) requires 'unsigned short *' but the argument type is 'unsigned int *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 9) requires 'unsigned short *' but the argument type is 'long *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 10) requires 'unsigned short *' but the argument type is 'unsigned long *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 11) requires 'unsigned short *' but the argument type is 'long long *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 12) requires 'unsigned short *' but the argument type is 'unsigned long long *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 13) requires 'unsigned short *' but the argument type is 'float *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 14) requires 'unsigned short *' but the argument type is 'double *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 15) requires 'unsigned short *' but the argument type is 'long double *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 16) requires 'unsigned short *' but the argument type is 'size_t * {aka unsigned long long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 17) requires 'unsigned short *' but the argument type is 'ssize_t * {aka long long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 18) requires 'unsigned short *' but the argument type is 'ptrdiff_t * {aka long long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 19) requires 'unsigned short *' but the argument type is 'intmax_t * {aka long long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 20) requires 'unsigned short *' but the argument type is 'uintmax_t * {aka unsigned long long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 21) requires 'unsigned short *' but the argument type is 'void * *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 22) requires 'unsigned short *' but the argument type is 'void *'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 25) requires 'unsigned short *' but the argument type is 'std::size_t * {aka unsigned long long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 26) requires 'unsigned short *' but the argument type is 'std::ssize_t * {aka long long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 27) requires 'unsigned short *' but the argument type is 'std::ptrdiff_t * {aka long long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 28) requires 'unsigned short *' but the argument type is 'std::intptr_t * {aka long long *}'.\n"
"[test.cpp:28]: (warning) %hu in format string (no. 29) requires 'unsigned short *' but the argument type is 'std::uintptr_t * {aka unsigned long long *}'.\n");
check(code, true, false, Settings::Unix32);
ASSERT_EQUALS(result, errout.str());
check(code, true, false, Settings::Unix64);
ASSERT_EQUALS(result, errout.str());
check(code, true, false, Settings::Win32A);
ASSERT_EQUALS(result, errout.str());
check(code, true, false, Settings::Win64);
ASSERT_EQUALS(result_win64, errout.str());
}
{ {
const char * code = "void foo() {\n" const char * code = "void foo() {\n"