Commit a22d281c authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

CppEditor: Add failing tests for "Move Definition Outside Class"...



... when macros are used in function definition

Task-number: QTCREATORBUG-12314
Change-Id: I811f93cde3dffa75fb71684569706f284939d7f5
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 52ef1419
......@@ -182,6 +182,7 @@ private slots:
void test_quickfix_MoveFuncDefOutside_afterClass();
void test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames1();
void test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames2();
void test_quickfix_MoveFuncDefOutside_macroUses();
void test_quickfix_MoveFuncDefToDecl_MemberFunc();
void test_quickfix_MoveFuncDefToDecl_MemberFuncOutside();
......@@ -192,6 +193,7 @@ private slots:
void test_quickfix_MoveFuncDefToDecl_FreeFuncToCppNS();
void test_quickfix_MoveFuncDefToDecl_CtorWithInitialization();
void test_quickfix_MoveFuncDefToDecl_structWithAssignedVariable();
void test_quickfix_MoveFuncDefToDecl_macroUses();
void test_quickfix_AssignToLocalVariable_templates();
......
......@@ -124,7 +124,8 @@ static QString &removeTrailingWhitespace(QString &input)
QuickFixTestCase::QuickFixTestCase(const QList<QuickFixTestDocument::Ptr> &theTestFiles,
CppQuickFixFactory *factory,
const ProjectPart::HeaderPaths &headerPaths,
int resultIndex)
int resultIndex,
const QByteArray &expectedFailMessage)
: m_testFiles(theTestFiles)
, m_cppCodeStylePreferences(0)
, m_restoreHeaderPaths(false)
......@@ -196,6 +197,8 @@ QuickFixTestCase::QuickFixTestCase(const QList<QuickFixTestDocument::Ptr> &theTe
// Check
QString result = testFile->m_editorWidget->document()->toPlainText();
removeTrailingWhitespace(result);
if (!expectedFailMessage.isEmpty())
QEXPECT_FAIL("", expectedFailMessage.data(), Continue);
QCOMPARE(result, testFile->m_expectedSource);
// Undo the change
......@@ -3007,6 +3010,39 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames2
QuickFixTestCase(singleDocument(original, expected), &factory);
}
void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_macroUses()
{
QByteArray original =
"#define CONST const\n"
"#define VOLATILE volatile\n"
"class Foo\n"
"{\n"
" int fu@nc(int a, int b) CONST VOLATILE\n"
" {\n"
" return 42;\n"
" }\n"
"};\n";
QByteArray expected =
"#define CONST const\n"
"#define VOLATILE volatile\n"
"class Foo\n"
"{\n"
" int func(int a, int b) CONST VOLATILE;\n"
"};\n"
"\n"
"\n"
// const volatile become lowercase: QTCREATORBUG-12620
"int Foo::func(int a, int b) const volatile\n"
"{\n"
" return 42;\n"
"}\n"
;
MoveFuncDefOutside factory;
QuickFixTestCase(singleDocument(original, expected), &factory,
ProjectPart::HeaderPaths(), 0, "QTCREATORBUG-12314");
}
/// Check: revert test_quickfix_MoveFuncDefOutside_MemberFuncToCpp()
void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFunc()
{
......@@ -3310,6 +3346,37 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_structWithAssignedVariable
QuickFixTestCase(singleDocument(original, expected), &factory);
}
void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_macroUses()
{
QByteArray original =
"#define CONST const\n"
"#define VOLATILE volatile\n"
"class Foo\n"
"{\n"
" int func(int a, int b) CONST VOLATILE;\n"
"};\n"
"\n"
"\n"
"int Foo::fu@nc(int a, int b) CONST VOLATILE"
"{\n"
" return 42;\n"
"}\n";
QByteArray expected =
"#define CONST const\n"
"#define VOLATILE volatile\n"
"class Foo\n"
"{\n"
" int func(int a, int b) CONST VOLATILE\n"
" {\n"
" return 42;\n"
" }\n"
"};\n\n\n\n";
MoveFuncDefToDecl factory;
QuickFixTestCase(singleDocument(original, expected), &factory,
ProjectPart::HeaderPaths(), 0, "QTCREATORBUG-12314");
}
void CppEditorPlugin::test_quickfix_AssignToLocalVariable_templates()
{
......
......@@ -76,7 +76,8 @@ public:
CppQuickFixFactory *factory,
const CppTools::ProjectPart::HeaderPaths &includePaths =
CppTools::ProjectPart::HeaderPaths(),
int resultIndex = 0);
int resultIndex = 0,
const QByteArray &expectedFailMessage = QByteArray());
~QuickFixTestCase();
static void run(const QList<QuickFixTestDocument::Ptr> &theTestFiles,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment