summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcompletion_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/cpptools/cppcompletion_test.cpp')
-rw-r--r--src/plugins/cpptools/cppcompletion_test.cpp223
1 files changed, 112 insertions, 111 deletions
diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp
index e52b2cb1e5..5c84ec9307 100644
--- a/src/plugins/cpptools/cppcompletion_test.cpp
+++ b/src/plugins/cpptools/cppcompletion_test.cpp
@@ -58,7 +58,7 @@ namespace {
typedef QByteArray _;
-class CompletionTestCase : public CppTools::Tests::TestCase
+class CompletionTestCase : public Tests::TestCase
{
public:
CompletionTestCase(const QByteArray &sourceText, const QByteArray &textToInsert = QByteArray())
@@ -73,14 +73,16 @@ public:
m_source[m_position] = ' ';
// Write source to file
- const QString fileName = QDir::tempPath() + QLatin1String("/file.h");
- QVERIFY(writeFile(fileName, m_source));
+ m_temporaryDir.reset(new Tests::TemporaryDir());
+ QVERIFY(m_temporaryDir->isValid());
+ const QString fileName = m_temporaryDir->createFile("file.h", m_source);
+ QVERIFY(!fileName.isEmpty());
// Open in editor
m_editor = EditorManager::openEditor(fileName);
QVERIFY(m_editor);
closeEditorAtEndOfTestCase(m_editor);
- m_editorWidget = qobject_cast<TextEditor::TextEditorWidget *>(m_editor->widget());
+ m_editorWidget = qobject_cast<TextEditorWidget *>(m_editor->widget());
QVERIFY(m_editorWidget);
m_textDocument = m_editorWidget->document();
@@ -103,11 +105,11 @@ public:
{
QStringList completions;
CppCompletionAssistInterface *ai
- = new CppCompletionAssistInterface(m_editorWidget->textDocument()->filePath(),
+ = new CppCompletionAssistInterface(m_editorWidget->textDocument()->filePath().toString(),
m_editorWidget->document(), m_position,
ExplicitlyInvoked, m_snapshot,
ProjectPart::HeaderPaths());
- CppCompletionAssistProcessor processor;
+ InternalCppCompletionAssistProcessor processor;
const Tests::IAssistProposalScopedPointer proposal(processor.perform(ai));
if (!proposal.d)
@@ -150,6 +152,7 @@ private:
QByteArray m_source;
int m_position;
Snapshot m_snapshot;
+ QScopedPointer<Tests::TemporaryDir> m_temporaryDir;
TextEditorWidget *m_editorWidget;
QTextDocument *m_textDocument;
IEditor *m_editor;
@@ -307,10 +310,40 @@ void CppToolsPlugin::test_completion()
actualCompletions.sort();
expectedCompletions.sort();
- QEXPECT_FAIL("enum_in_function_in_struct_in_function", "doesn't work", Abort);
+ QEXPECT_FAIL("enum_in_function_in_struct_in_function", "QTCREATORBUG-13757", Abort);
+ QEXPECT_FAIL("enum_in_function_in_struct_in_function_cxx11", "QTCREATORBUG-13757", Abort);
+ QEXPECT_FAIL("enum_in_function_in_struct_in_function_anon", "QTCREATORBUG-13757", Abort);
+ QEXPECT_FAIL("enum_in_class_accessed_in_member_func_cxx11", "QTCREATORBUG-13757", Abort);
+ QEXPECT_FAIL("enum_in_class_accessed_in_member_func_inline_cxx11", "QTCREATORBUG-13757", Abort);
QCOMPARE(actualCompletions, expectedCompletions);
}
+static void enumTestCase(const QByteArray &tag, const QByteArray &source,
+ const QByteArray &prefix = QByteArray())
+{
+ QByteArray fullSource = source;
+ fullSource.replace('$', "enum E { val1, val2, val3 };");
+ QTest::newRow(tag) << fullSource << (prefix + "val")
+ << (QStringList()
+ << QLatin1String("val1")
+ << QLatin1String("val2")
+ << QLatin1String("val3"));
+
+ QTest::newRow(tag + "_cxx11") << fullSource << (prefix + "E::")
+ << (QStringList()
+ << QLatin1String("E")
+ << QLatin1String("val1")
+ << QLatin1String("val2")
+ << QLatin1String("val3"));
+
+ fullSource.replace("enum E ", "enum ");
+ QTest::newRow(tag + "_anon") << fullSource << (prefix + "val")
+ << (QStringList()
+ << QLatin1String("val1")
+ << QLatin1String("val2")
+ << QLatin1String("val3"));
+}
+
void CppToolsPlugin::test_completion_data()
{
QTest::addColumn<QByteArray>("code");
@@ -1759,103 +1792,94 @@ void CppToolsPlugin::test_completion_data()
<< QLatin1String("staticFun2")
<< QLatin1String("m2"));
- QTest::newRow("enum_inside_block_inside_function_cxx11_QTCREATORBUG5456") << _(
- "void foo()\n"
- "{\n"
- " {\n"
- " enum E { e1, e2, e3 };\n"
- " @\n"
- " }\n"
- "}\n"
- ) << _("E::") << (QStringList()
- << QLatin1String("E")
- << QLatin1String("e1")
- << QLatin1String("e2")
- << QLatin1String("e3"));
-
- QTest::newRow("enum_inside_function") << _(
+ enumTestCase(
+ "enum_inside_block_inside_function",
+ "void foo()\n"
+ "{\n"
+ " {\n"
+ " $\n"
+ " @\n"
+ " }\n"
+ "}\n"
+ );
+
+ enumTestCase(
+ "enum_inside_function",
"void foo()\n"
"{\n"
- " enum E { val1, val2, val3 };\n"
+ " $\n"
" @\n"
"}\n"
- ) << _("val") << (QStringList()
- << QLatin1String("val1")
- << QLatin1String("val2")
- << QLatin1String("val3"));
+ );
- QTest::newRow("anon_enum_inside_function") << _(
- "void foo()\n"
- "{\n"
- " enum { val1, val2, val3 };\n"
- " @\n"
- "}\n"
- ) << _("val") << (QStringList()
- << QLatin1String("val1")
- << QLatin1String("val2")
- << QLatin1String("val3"));
-
- QTest::newRow("enum_in_function_in_struct_in_function") << _(
+ enumTestCase(
+ "enum_in_function_in_struct_in_function",
"void foo()\n"
"{\n"
" struct S {\n"
" void fun()\n"
" {\n"
- " enum E { val1, val2, val3 };\n"
+ " $\n"
" @\n"
" }\n"
" };\n"
"}\n"
- ) << _("val") << (QStringList()
- << QLatin1String("val1")
- << QLatin1String("val2")
- << QLatin1String("val3"));
+ );
- QTest::newRow("enum_inside_function_cxx11_QTCREATORBUG5456") << _(
- "void foo()\n"
+ enumTestCase(
+ "enum_inside_class",
+ "struct Foo\n"
"{\n"
- " enum E { e1, e2, e3 };\n"
+ " $\n"
" @\n"
- "}\n"
- ) << _("E::") << (QStringList()
- << QLatin1String("E")
- << QLatin1String("e1")
- << QLatin1String("e2")
- << QLatin1String("e3"));
+ "};\n",
+ "Foo::"
+ );
- QTest::newRow("enum_inside_class") << _(
- "struct Foo\n"
+ enumTestCase(
+ "enum_inside_namespace",
+ "namespace Ns\n"
"{\n"
- " enum E { val1, val2, val3 };\n"
+ " $\n"
" @\n"
- "};\n"
- ) << _("Foo::v") << (QStringList()
- << QLatin1String("val1")
- << QLatin1String("val2")
- << QLatin1String("val3"));
+ "}\n",
+ "Ns::"
+ );
- QTest::newRow("enum_inside_class_cxx11") << _(
- "struct Foo\n"
+ enumTestCase(
+ "enum_inside_member_function",
+ "class Foo { void func(); };\n"
+ "void Foo::func()\n"
"{\n"
- " enum E { val1, val2, val3 };\n"
+ " $\n"
" @\n"
+ "}\n"
+ );
+
+ enumTestCase(
+ "enum_in_class_accessed_in_member_func_inline",
+ "class Foo\n"
+ "{\n"
+ " $\n"
+ " void func()\n"
+ " {\n"
+ " @\n"
+ " }\n"
"};\n"
- ) << _("Foo::E::") << (QStringList()
- << QLatin1String("E")
- << QLatin1String("val1")
- << QLatin1String("val2")
- << QLatin1String("val3"));
+ );
- QTest::newRow("anon_enum_inside_class") << _(
- "struct Foo\n"
+ enumTestCase(
+ "enum_in_class_accessed_in_member_func",
+ "class Foo\n"
"{\n"
- " enum { val1, val2, val3 };\n"
- " @\n"
+ " $\n"
+ " void func();\n"
"};\n"
- ) << _("Foo::v") << (QStringList()
- << QLatin1String("val1")
- << QLatin1String("val2")
- << QLatin1String("val3"));
+ "void Foo::func()\n"
+ "{\n"
+ " @\n"
+ "}\n"
+ );
QTest::newRow("nested_anonymous_with___attribute__") << _(
"struct Enclosing\n"
@@ -1871,40 +1895,6 @@ void CppToolsPlugin::test_completion_data()
<< QLatin1String("Enclosing")
<< QLatin1String("i"));
- QTest::newRow("enum_inside_namespace") << _(
- "namespace Ns\n"
- "{\n"
- " enum E { val1, val2, val3 };\n"
- " @\n"
- "}\n"
- ) << _("Ns::v") << (QStringList()
- << QLatin1String("val1")
- << QLatin1String("val2")
- << QLatin1String("val3"));
-
- QTest::newRow("enum_inside_namespace_cxx11") << _(
- "namespace Ns\n"
- "{\n"
- " enum E { val1, val2, val3 };\n"
- " @\n"
- "}\n"
- ) << _("Ns::E::") << (QStringList()
- << QLatin1String("E")
- << QLatin1String("val1")
- << QLatin1String("val2")
- << QLatin1String("val3"));
-
- QTest::newRow("anon_enum_inside_namespace") << _(
- "namespace Ns\n"
- "{\n"
- " enum { val1, val2, val3 };\n"
- " @\n"
- "}\n"
- ) << _("Ns::v") << (QStringList()
- << QLatin1String("val1")
- << QLatin1String("val2")
- << QLatin1String("val3"));
-
QTest::newRow("lambdaCalls_1") << _(
"struct S { int bar; };\n"
"void foo()\n"
@@ -2394,6 +2384,17 @@ void CppToolsPlugin::test_completion_data()
"}\n"
) << _("s.") << (QStringList()
<< QLatin1String("S"));
+
+ QTest::newRow("auto_declaration_in_if_condition") << _(
+ "struct Foo { int bar; };\n"
+ "void fun() {\n"
+ " if (auto s = new Foo) {\n"
+ " @\n"
+ " }\n"
+ "}\n"
+ ) << _("s->") << (QStringList()
+ << QLatin1String("Foo")
+ << QLatin1String("bar"));
}
void CppToolsPlugin::test_completion_member_access_operator()