Moved some unit tests to testgarbage.cpp

This commit is contained in:
PKEuS 2015-08-16 14:48:56 +02:00
parent 2665fb9481
commit 0babc4f38f
3 changed files with 40 additions and 46 deletions

View File

@ -49,12 +49,12 @@ private:
TEST_CASE(garbageCode7);
TEST_CASE(garbageCode8); // #5511
TEST_CASE(garbageCode9); // #5604
TEST_CASE(garbageCode10); // #6127
TEST_CASE(garbageCode10); // #6127
TEST_CASE(garbageCode11);
TEST_CASE(garbageCode12);
TEST_CASE(garbageCode13); // Ticket #2607 - crash
TEST_CASE(garbageCode14); // Ticket #5595 - crash
TEST_CASE(garbageCode15); // Ticket #5203
TEST_CASE(garbageCode13); // #2607
TEST_CASE(garbageCode14); // #5595
TEST_CASE(garbageCode15); // #5203
TEST_CASE(garbageCode16);
TEST_CASE(garbageCode17);
TEST_CASE(garbageCode18);
@ -63,7 +63,7 @@ private:
TEST_CASE(garbageCode21);
TEST_CASE(garbageCode22);
TEST_CASE(garbageCode23);
TEST_CASE(garbageCode24); // Ticket #6361 - crash
TEST_CASE(garbageCode24); // #6361
TEST_CASE(garbageCode25);
TEST_CASE(garbageCode26);
TEST_CASE(garbageCode27);
@ -153,6 +153,11 @@ private:
TEST_CASE(garbageCode111);
TEST_CASE(garbageCode112);
TEST_CASE(garbageCode113);
TEST_CASE(garbageCode114);
TEST_CASE(garbageCode115); // #5506
TEST_CASE(garbageCode116); // #5356
TEST_CASE(garbageCode117); // #6121
TEST_CASE(garbageCode118); // #5600
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
@ -859,6 +864,36 @@ private:
checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }");
}
void garbageCode114() { // #2118
ASSERT_THROW(checkCode("Q_GLOBAL_STATIC_WITH_INITIALIZER(Qt4NodeStaticData, qt4NodeStaticData, {\n"
" for (unsigned i = 0 ; i < count; i++) {\n"
" }\n"
"});"), InternalError);
}
void garbageCode115() { // #5506
checkCode("A template < int { int = -1 ; } template < int N > struct B { int [ A < N > :: zero ] ; } ; B < 0 > b ;");
}
void garbageCode116() { // #5356
checkCode("struct template<int { = }; > struct B { }; B < 0 > b;");
}
void garbageCode117() { // #6121
ASSERT_THROW(checkCode("enum E { f = {} };\n"
"int a = f;"), InternalError);
}
void garbageCode118() { // #5600 - missing include causes invalid enum
ASSERT_THROW(checkCode("enum {\n"
" NUM_OPCODES = \n"
// #include "definition"
"};\n"
"struct bytecode {};\n"
"jv jq_next() { opcode = ((opcode) +NUM_OPCODES);\n"
"}"), InternalError);
}
void garbageValueFlow() {
// #6089
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"

View File

@ -197,7 +197,6 @@ private:
TEST_CASE(enum44);
TEST_CASE(enumscope1); // ticket #3949
TEST_CASE(duplicateDefinition); // ticket #3565
TEST_CASE(invalid_enum); // #5600
// remove "std::" on some standard functions
TEST_CASE(removestd);
@ -3435,17 +3434,6 @@ private:
ASSERT_EQUALS(false, tokenizer.duplicateDefinition(&x_token, tokenizer.tokens()));
}
void invalid_enum() { // #5600: missing include causes invalid enum
const char code [] = "enum {\n"
" NUM_OPCODES = \n"
// #include "definition"
"};\n"
"struct bytecode {};\n"
"jv jq_next() { opcode = ((opcode) +NUM_OPCODES);\n"
"}";
ASSERT_THROW(checkSimplifyEnum(code), InternalError);
}
void removestd() {
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));
ASSERT_EQUALS("; strcat ( a , b ) ;", tok("; std::strcat(a,b);"));

View File

@ -47,7 +47,6 @@ private:
TEST_CASE(tokenize9);
TEST_CASE(tokenize10);
TEST_CASE(tokenize11);
TEST_CASE(tokenize12);
TEST_CASE(tokenize13); // bailout if the code contains "@" - that is not handled well.
TEST_CASE(tokenize14); // tokenize "0X10" => 16
TEST_CASE(tokenize15); // tokenize ".123"
@ -63,12 +62,9 @@ private:
TEST_CASE(tokenize26); // #4245 (segmentation fault)
TEST_CASE(tokenize27); // #4525 (segmentation fault)
TEST_CASE(tokenize28); // #4725 (writing asm() around "^{}")
TEST_CASE(tokenize29); // #5506 (segmentation fault upon invalid code)
TEST_CASE(tokenize30); // #5356 (segmentation fault upon invalid code)
TEST_CASE(tokenize31); // #3503 (Wrong handling of member function taking function pointer as argument)
TEST_CASE(tokenize32); // #5884 (fsanitize=undefined: left shift of negative value -10000 in lib/templatesimplifier.cpp:852:46)
TEST_CASE(tokenize33); // #5780 Various crashes on valid template code
TEST_CASE(tokenize34); // #6121 (crash upon invalid enum)
TEST_CASE(syntax_case_default);
TEST_CASE(simplifyFileAndLineMacro); // tokenize "return - __LINE__;"
@ -664,15 +660,6 @@ private:
ASSERT_EQUALS("X * sizeof ( Y ( ) ) ;", tokenizeAndStringify("X * sizeof(Y());", false));
}
// ticket #2118 - invalid syntax error
void tokenize12() {
const char code[] = "Q_GLOBAL_STATIC_WITH_INITIALIZER(Qt4NodeStaticData, qt4NodeStaticData, {\n"
" for (unsigned i = 0 ; i < count; i++) {\n"
" }\n"
"});";
ASSERT_THROW(tokenizeAndStringify(code), InternalError);
}
// bailout if there is "@" - it is not handled well
void tokenize13() {
const char code[] = "@implementation\n"
@ -784,16 +771,6 @@ private:
ASSERT_EQUALS("; asm ( \"voidf^{return}intmain\" ) ; ( ) { }", tokenizeAndStringify("; void f ^ { return } int main ( ) { }"));
}
// #5506 - segmentation fault upon invalid code
void tokenize29() {
tokenizeAndStringify("A template < int { int = -1 ; } template < int N > struct B { int [ A < N > :: zero ] ; } ; B < 0 > b ;");
}
// #5356 - segmentation fault upon invalid code
void tokenize30() {
tokenizeAndStringify("struct template<int { = }; > struct B { }; B < 0 > b;");
}
// #3503 - don't "simplify" SetFunction member function to a variable
void tokenize31() {
ASSERT_EQUALS("struct TTestClass { TTestClass ( ) { }\n"
@ -827,12 +804,6 @@ private:
tokenizeAndStringify(code, true);
}
void tokenize34() { // #6121
const char code[] = "enum E { f = {} };\n"
"int a = f;";
ASSERT_THROW(tokenizeAndStringify(code, true), InternalError);
}
void syntax_case_default() { // correct syntax
tokenizeAndStringify("void f() {switch (n) { case 0: z(); break;}}");
ASSERT_EQUALS("", errout.str());