[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdevelop/assistantpopup-ng] languages/clang: Reinstantiate assistant unit tests
From:       Kevin Funk <kfunk () kde ! org>
Date:       2016-06-30 21:46:27
Message-ID: E1bIjn1-0001FN-L8 () code ! kde ! org
[Download RAW message or body]

Git commit 12391c96d33848010fe4ff9aaa59f919a3f3df4b by Kevin Funk.
Committed on 30/06/2016 at 21:45.
Pushed by kfunk into branch 'assistantpopup-ng'.

Reinstantiate assistant unit tests

CCMAIL: mail@svenbrauch.de

M  +6    -1    languages/clang/codegen/adaptsignatureassistant.cpp
M  +261  -192  languages/clang/tests/test_assistants.cpp
M  +7    -7    languages/clang/tests/test_assistants.h

http://commits.kde.org/kdevelop/12391c96d33848010fe4ff9aaa59f919a3f3df4b

diff --git a/languages/clang/codegen/adaptsignatureassistant.cpp \
b/languages/clang/codegen/adaptsignatureassistant.cpp index 2083041..a403cb2 100644
--- a/languages/clang/codegen/adaptsignatureassistant.cpp
+++ b/languages/clang/codegen/adaptsignatureassistant.cpp
@@ -305,7 +305,12 @@ void AdaptSignatureAssistant::updateReady(const \
KDevelop::IndexedString& documen  emit actionsChanged();
 }
 
-KTextEditor::Range AdaptSignatureAssistant::displayRange() const {
+KTextEditor::Range AdaptSignatureAssistant::displayRange() const
+{
+    if (!m_document) {
+        return {};
+    }
+
     auto s = m_lastEditPosition;
     KTextEditor::Range ran = {s.line(), 0, s.line(), \
m_document->lineLength(s.line())};  qDebug() << "display range:" << ran;
diff --git a/languages/clang/tests/test_assistants.cpp \
b/languages/clang/tests/test_assistants.cpp index 7d54721..5b4d60f 100644
--- a/languages/clang/tests/test_assistants.cpp
+++ b/languages/clang/tests/test_assistants.cpp
@@ -41,6 +41,7 @@
 #include <language/assistant/staticassistant.h>
 #include <language/assistant/staticassistantsmanager.h>
 #include <language/assistant/renameaction.h>
+#include <language/assistant/renameassistant.h>
 #include <language/backgroundparser/backgroundparser.h>
 #include <language/duchain/duchain.h>
 #include <language/duchain/duchainlock.h>
@@ -66,7 +67,7 @@ void TestAssistants::initTestCase()
     ));
     QVERIFY(qputenv("KDEV_DISABLE_PLUGINS", "kdevcppsupport"));
     QVERIFY(qputenv("KDEV_CLANG_DISPLAY_DIAGS", "1"));
-    AutoTestShell::init({QStringLiteral("kdevclangsupport")});
+    AutoTestShell::init({QStringLiteral("kdevclangsupport"), \
QStringLiteral("kdevproblemreporter")});  TestCore::initialize();
     DUChain::self()->disablePersistentStorage();
     Core::self()->languageController()->backgroundParser()->setDelay(0);
@@ -229,7 +230,6 @@ struct StateChange
 Q_DECLARE_METATYPE(StateChange)
 Q_DECLARE_METATYPE(QList<StateChange>)
 
-/*
 void TestAssistants::testRenameAssistant_data()
 {
     QTest::addColumn<QString>("fileContents");
@@ -291,201 +291,259 @@ void TestAssistants::testRenameAssistant_data()
             << StateChange(Testbed::CppDoc, Range(0,17,0,17), "f", "abcdefg")
         )
         << "int foo(int abcdefg)\n { abcdefg = 0; return abcdefg; }";
-}*/
-
-// void TestAssistants::testRenameAssistant()
-// {
-//     QFETCH(QString, fileContents);
-//     Testbed testbed("", fileContents);
-//
-//     QFETCH(QString, oldDeclarationName);
-//     QFETCH(QList<StateChange>, stateChanges);
-//     foreach(StateChange stateChange, stateChanges)
-//     {
-//         testbed.changeDocument(Testbed::CppDoc, stateChange.range, \
                stateChange.newText);
-//         if (stateChange.result.isEmpty()) {
-//             QVERIFY(!staticAssistantsManager()->activeAssistant() || \
                !staticAssistantsManager()->activeAssistant()->actions().size());
-//         } else {
-//             QVERIFY(staticAssistantsManager()->activeAssistant() && \
                staticAssistantsManager()->activeAssistant()->actions().size());
-//             RenameAction *r = \
qobject_cast<RenameAction*>(staticAssistantsManager()->activeAssistant()->actions().first().data());
                
-//             QCOMPARE(r->oldDeclarationName(), oldDeclarationName);
-//             QCOMPARE(r->newDeclarationName(), stateChange.result);
-//         }
-//     }
-//     if (staticAssistantsManager()->activeAssistant() && \
                staticAssistantsManager()->activeAssistant()->actions().size()) {
-//             staticAssistantsManager()->activeAssistant()->actions().first()->execute();
                
-//     }
-//     QFETCH(QString, finalFileContents);
-//     QCOMPARE(testbed.documentText(Testbed::CppDoc), finalFileContents);
-// }
-//
-// void TestAssistants::testRenameAssistantUndoRename()
-// {
-//     Testbed testbed("", "int foo(int i)\n { i = 0; return i; }");
-//     testbed.changeDocument(Testbed::CppDoc, Range(0,13,0,13), "d");
-//     QVERIFY(staticAssistantsManager()->activeAssistant());
-//     QVERIFY(staticAssistantsManager()->activeAssistant()->actions().size() > 0);
-//     RenameAction *r = \
qobject_cast<RenameAction*>(staticAssistantsManager()->activeAssistant()->actions().first().data());
                
-//     QVERIFY(r);
-//
-//     // now rename the variable back to its original identifier
-//     testbed.changeDocument(Testbed::CppDoc, Range(0,13,0,14), "");
-//     // there should be no assistant anymore
-//     QVERIFY(!staticAssistantsManager()->activeAssistant());
-// }
+}
+
+ProblemPointer findStaticAssistantProblem(const QList<ProblemPointer>& problems)
+{
+    const auto renameProblemIt = std::find_if(problems.cbegin(), problems.cend(), \
[](const ProblemPointer& p) { +        return dynamic_cast<const \
StaticAssistantProblem*>(p.constData()); +    });
+    if (renameProblemIt != problems.cend())
+        return *renameProblemIt;
+
+    return {};
+}
+
+void TestAssistants::testRenameAssistant()
+{
+    QFETCH(QString, fileContents);
+    Testbed testbed("", fileContents);
+
+    const auto document = testbed.document(Testbed::CppDoc);
+    QVERIFY(document);
+
+    QExplicitlySharedDataPointer<IAssistant> assistant;
+
+    QFETCH(QString, oldDeclarationName);
+    QFETCH(QList<StateChange>, stateChanges);
+    foreach(StateChange stateChange, stateChanges)
+    {
+        testbed.changeDocument(Testbed::CppDoc, stateChange.range, \
stateChange.newText, true); +
+        DUChainReadLocker lock;
+
+        auto topCtx = DUChain::self()->chainForDocument(document->url());
+        QVERIFY(topCtx);
+
+        const auto problem = findStaticAssistantProblem(topCtx->problems());
+        if (problem)
+            assistant = problem->solutionAssistant();
+
+        if (stateChange.result.isEmpty()) {
+            QVERIFY(!assistant || !assistant->actions().size());
+        } else {
+            QVERIFY(assistant && assistant->actions().size());
+            RenameAction *r = \
qobject_cast<RenameAction*>(assistant->actions().first().data()); +            \
QCOMPARE(r->oldDeclarationName(), oldDeclarationName); +            \
QCOMPARE(r->newDeclarationName(), stateChange.result); +        }
+    }
+
+    if (assistant && assistant->actions().size()) {
+        assistant->actions().first()->execute();
+    }
+    QFETCH(QString, finalFileContents);
+    QCOMPARE(testbed.documentText(Testbed::CppDoc), finalFileContents);
+}
+
+void TestAssistants::testRenameAssistantUndoRename()
+{
+    Testbed testbed("", "int foo(int i)\n { i = 0; return i; }");
+    testbed.changeDocument(Testbed::CppDoc, Range(0,13,0,13), "d", true);
+
+    const auto document = testbed.document(Testbed::CppDoc);
+    QVERIFY(document);
+
+    DUChainReadLocker lock;
+    auto topCtx = DUChain::self()->chainForDocument(document->url());
+    QVERIFY(topCtx);
+
+    auto firstProblem = findStaticAssistantProblem(topCtx->problems());
+    auto assistant = firstProblem->solutionAssistant();
+    QVERIFY(assistant);
+
+    QVERIFY(assistant->actions().size() > 0);
+    RenameAction *r = \
qobject_cast<RenameAction*>(assistant->actions().first().data()); +    qWarning() << \
topCtx->problems() << assistant->actions().first().data() << \
assistant->actions().size(); +    QVERIFY(r);
+
+    // now rename the variable back to its original identifier
+    testbed.changeDocument(Testbed::CppDoc, Range(0,13,0,14), "");
+    // there should be no assistant anymore
+    QVERIFY(!assistant);
+}
 
 const QString SHOULD_ASSIST = "SHOULD_ASSIST"; //An assistant will be visible
 const QString NO_ASSIST = "NO_ASSIST";               //No assistant visible
 
-// void TestAssistants::testSignatureAssistant_data()
-// {
-//     QTest::addColumn<QString>("headerContents");
-//     QTest::addColumn<QString>("cppContents");
-//     QTest::addColumn<QList<StateChange> >("stateChanges");
-//     QTest::addColumn<QString>("finalHeaderContents");
-//     QTest::addColumn<QString>("finalCppContents");
-//
-//     QTest::newRow("change_argument_type")
-//       << "class Foo {\nint bar(int a, char* b, int c = 10); \n};"
-//       << "int Foo::bar(int a, char* b, int c)\n{ a = c; b = new char; return a + \
                *b; }"
-//       << (QList<StateChange>() << StateChange(Testbed::HeaderDoc, \
                Range(1,8,1,11), "char", SHOULD_ASSIST))
-//       << "class Foo {\nint bar(char a, char* b, int c = 10); \n};"
-//       << "int Foo::bar(char a, char* b, int c)\n{ a = c; b = new char; return a + \
                *b; }";
-//
-//     QTest::newRow("prepend_arg_header")
-//       << "class Foo { void bar(int i); };"
-//       << "void Foo::bar(int i)\n{}"
-//       << (QList<StateChange>() << StateChange(Testbed::HeaderDoc, Range(0, 21, 0, \
                21), "char c, ", SHOULD_ASSIST))
-//       << "class Foo { void bar(char c, int i); };"
-//       << "void Foo::bar(char c, int i)\n{}";
-//
-//     QTest::newRow("prepend_arg_cpp")
-//       << "class Foo { void bar(int i); };"
-//       << "void Foo::bar(int i)\n{}"
-//       << (QList<StateChange>() << StateChange(Testbed::CppDoc, Range(0, 14, 0, \
                14), "char c, ", SHOULD_ASSIST))
-//       << "class Foo { void bar(char c, int i); };"
-//       << "void Foo::bar(char c, int i)\n{}";
-//
-//     QTest::newRow("change_default_parameter")
-//         << "class Foo {\nint bar(int a, char* b, int c = 10); \n};"
-//         << "int Foo::bar(int a, char* b, int c)\n{ a = c; b = new char; return a \
                + *b; }"
-//         << (QList<StateChange>() << StateChange(Testbed::HeaderDoc, \
                Range(1,29,1,34), "", NO_ASSIST))
-//         << "class Foo {\nint bar(int a, char* b, int c); \n};"
-//         << "int Foo::bar(int a, char* b, int c)\n{ a = c; b = new char; return a \
                + *b; }";
-//
-//     QTest::newRow("change_function_type")
-//         << "class Foo {\nint bar(int a, char* b, int c = 10); \n};"
-//         << "int Foo::bar(int a, char* b, int c)\n{ a = c; b = new char; return a \
                + *b; }"
-//         << (QList<StateChange>() << StateChange(Testbed::CppDoc, Range(0,0,0,3), \
                "char", SHOULD_ASSIST))
-//         << "class Foo {\nchar bar(int a, char* b, int c = 10); \n};"
-//         << "char Foo::bar(int a, char* b, int c)\n{ a = c; b = new char; return a \
                + *b; }";
-//
-//     QTest::newRow("swap_args_definition_side")
-//         << "class Foo {\nint bar(int a, char* b, int c = 10); \n};"
-//         << "int Foo::bar(int a, char* b, int c)\n{ a = c; b = new char; return a \
                + *b; }"
-//         << (QList<StateChange>() << StateChange(Testbed::CppDoc, \
                Range(0,13,0,28), "char* b, int a,", SHOULD_ASSIST))
-//         << "class Foo {\nint bar(char* b, int a, int c = 10); \n};"
-//         << "int Foo::bar(char* b, int a, int c)\n{ a = c; b = new char; return a \
+ *b; }"; +void TestAssistants::testSignatureAssistant_data()
+{
+    QTest::addColumn<QString>("headerContents");
+    QTest::addColumn<QString>("cppContents");
+    QTest::addColumn<QList<StateChange> >("stateChanges");
+    QTest::addColumn<QString>("finalHeaderContents");
+    QTest::addColumn<QString>("finalCppContents");
+
+    QTest::newRow("change_argument_type")
+      << "class Foo {\nint bar(int a, char* b, int c = 10); \n};"
+      << "int Foo::bar(int a, char* b, int c)\n{ a = c; b = new char; return a + *b; \
}" +      << (QList<StateChange>() << StateChange(Testbed::HeaderDoc, \
Range(1,8,1,11), "char", SHOULD_ASSIST)) +      << "class Foo {\nint bar(char a, \
char* b, int c = 10); \n};" +      << "int Foo::bar(char a, char* b, int c)\n{ a = c; \
b = new char; return a + *b; }"; +
+    QTest::newRow("prepend_arg_header")
+      << "class Foo { void bar(int i); };"
+      << "void Foo::bar(int i)\n{}"
+      << (QList<StateChange>() << StateChange(Testbed::HeaderDoc, Range(0, 21, 0, \
21), "char c, ", SHOULD_ASSIST)) +      << "class Foo { void bar(char c, int i); };"
+      << "void Foo::bar(char c, int i)\n{}";
+
+    QTest::newRow("prepend_arg_cpp")
+      << "class Foo { void bar(int i); };"
+      << "void Foo::bar(int i)\n{}"
+      << (QList<StateChange>() << StateChange(Testbed::CppDoc, Range(0, 14, 0, 14), \
"char c, ", SHOULD_ASSIST)) +      << "class Foo { void bar(char c, int i); };"
+      << "void Foo::bar(char c, int i)\n{}";
+
+    QTest::newRow("change_default_parameter")
+        << "class Foo {\nint bar(int a, char* b, int c = 10); \n};"
+        << "int Foo::bar(int a, char* b, int c)\n{ a = c; b = new char; return a + \
*b; }" +        << (QList<StateChange>() << StateChange(Testbed::HeaderDoc, \
Range(1,29,1,34), "", NO_ASSIST)) +        << "class Foo {\nint bar(int a, char* b, \
int c); \n};" +        << "int Foo::bar(int a, char* b, int c)\n{ a = c; b = new \
char; return a + *b; }"; +
+    QTest::newRow("change_function_type")
+        << "class Foo {\nint bar(int a, char* b, int c = 10); \n};"
+        << "int Foo::bar(int a, char* b, int c)\n{ a = c; b = new char; return a + \
*b; }" +        << (QList<StateChange>() << StateChange(Testbed::CppDoc, \
Range(0,0,0,3), "char", SHOULD_ASSIST)) +        << "class Foo {\nchar bar(int a, \
char* b, int c = 10); \n};" +        << "char Foo::bar(int a, char* b, int c)\n{ a = \
c; b = new char; return a + *b; }"; +
+    QTest::newRow("swap_args_definition_side")
+        << "class Foo {\nint bar(int a, char* b, int c = 10); \n};"
+        << "int Foo::bar(int a, char* b, int c)\n{ a = c; b = new char; return a + \
*b; }" +        << (QList<StateChange>() << StateChange(Testbed::CppDoc, \
Range(0,13,0,28), "char* b, int a,", SHOULD_ASSIST)) +        << "class Foo {\nint \
bar(char* b, int a, int c = 10); \n};" +        << "int Foo::bar(char* b, int a, int \
c)\n{ a = c; b = new char; return a + *b; }";  
     // see https://bugs.kde.org/show_bug.cgi?id=299393
     // actually related to the whitespaces in the header...
-//     QTest::newRow("change_function_constness")
-//         << "class Foo {\nvoid bar(const Foo&) const;\n};"
-//         << "void Foo::bar(const Foo&) const\n{}"
-//         << (QList<StateChange>() << StateChange(Testbed::CppDoc, \
                Range(0,25,0,31), "", SHOULD_ASSIST))
-//         << "class Foo {\nvoid bar(const Foo&);\n};"
-//         << "void Foo::bar(const Foo&)\n{}";
-//
-//     // see https://bugs.kde.org/show_bug.cgi?id=356179
-//     QTest::newRow("keep_static_cpp")
-//         << "class Foo { static void bar(int i); };"
-//         << "void Foo::bar(int i)\n{}"
-//         << (QList<StateChange>() << StateChange(Testbed::CppDoc, Range(0, 19, 0, \
                19), ", char c", SHOULD_ASSIST))
-//         << "class Foo { static void bar(int i, char c); };"
-//         << "void Foo::bar(int i, char c)\n{}";
-//     QTest::newRow("keep_static_header")
-//         << "class Foo { static void bar(int i); };"
-//         << "void Foo::bar(int i)\n{}"
-//         << (QList<StateChange>() << StateChange(Testbed::HeaderDoc, Range(0, 33, \
                0, 33), ", char c", SHOULD_ASSIST))
-//         << "class Foo { static void bar(int i, char c); };"
-//         << "void Foo::bar(int i, char c)\n{}";
+    QTest::newRow("change_function_constness")
+        << "class Foo {\nvoid bar(const Foo&) const;\n};"
+        << "void Foo::bar(const Foo&) const\n{}"
+        << (QList<StateChange>() << StateChange(Testbed::CppDoc, Range(0,25,0,31), \
"", SHOULD_ASSIST)) +        << "class Foo {\nvoid bar(const Foo&);\n};"
+        << "void Foo::bar(const Foo&)\n{}";
+
+    // see https://bugs.kde.org/show_bug.cgi?id=356179
+    QTest::newRow("keep_static_cpp")
+        << "class Foo { static void bar(int i); };"
+        << "void Foo::bar(int i)\n{}"
+        << (QList<StateChange>() << StateChange(Testbed::CppDoc, Range(0, 19, 0, \
19), ", char c", SHOULD_ASSIST)) +        << "class Foo { static void bar(int i, char \
c); };" +        << "void Foo::bar(int i, char c)\n{}";
+    QTest::newRow("keep_static_header")
+        << "class Foo { static void bar(int i); };"
+        << "void Foo::bar(int i)\n{}"
+        << (QList<StateChange>() << StateChange(Testbed::HeaderDoc, Range(0, 33, 0, \
33), ", char c", SHOULD_ASSIST)) +        << "class Foo { static void bar(int i, char \
c); };" +        << "void Foo::bar(int i, char c)\n{}";
 
     // see https://bugs.kde.org/show_bug.cgi?id=356178
-//     QTest::newRow("keep_default_args_cpp_before")
-//         << "class Foo { void bar(bool b, int i = 0); };"
-//         << "void Foo::bar(bool b, int i)\n{}"
-//         << (QList<StateChange>() << StateChange(Testbed::CppDoc, Range(0, 14, 0, \
                14), "char c, ", SHOULD_ASSIST))
-//         << "class Foo { void bar(char c, bool b, int i = 0); };"
-//         << "void Foo::bar(char c, bool b, int i)\n{}";
-//     QTest::newRow("keep_default_args_cpp_after")
-//         << "class Foo { void bar(bool b, int i = 0); };"
-//         << "void Foo::bar(bool b, int i)\n{}"
-//         << (QList<StateChange>() << StateChange(Testbed::CppDoc, Range(0, 27, 0, \
                27), ", char c", SHOULD_ASSIST))
-//         << "class Foo { void bar(bool b, int i = 0, char c = {} /* TODO */); };"
-//         << "void Foo::bar(bool b, int i, char c)\n{}";
-//     QTest::newRow("keep_default_args_header_before")
-//         << "class Foo { void bar(bool b, int i = 0); };"
-//         << "void Foo::bar(bool b, int i)\n{}"
-//         << (QList<StateChange>() << StateChange(Testbed::HeaderDoc, Range(0, 29, \
                0, 29), "char c = 'A', ", SHOULD_ASSIST))
-//         << "class Foo { void bar(bool b, char c = 'A', int i = 0); };"
-//         << "void Foo::bar(bool b, char c, int i)\n{}";
-//     QTest::newRow("keep_default_args_header_after")
-//         << "class Foo { void bar(bool b, int i = 0); };"
-//         << "void Foo::bar(bool b, int i)\n{}"
-//         << (QList<StateChange>() << StateChange(Testbed::HeaderDoc, Range(0, 38, \
                0, 38), ", char c = 'A'", SHOULD_ASSIST))
-//         << "class Foo { void bar(bool b, int i = 0, char c = 'A'); };"
-//         << "void Foo::bar(bool b, int i, char c)\n{}";
+    QTest::newRow("keep_default_args_cpp_before")
+        << "class Foo { void bar(bool b, int i = 0); };"
+        << "void Foo::bar(bool b, int i)\n{}"
+        << (QList<StateChange>() << StateChange(Testbed::CppDoc, Range(0, 14, 0, \
14), "char c, ", SHOULD_ASSIST)) +        << "class Foo { void bar(char c, bool b, \
int i = 0); };" +        << "void Foo::bar(char c, bool b, int i)\n{}";
+    QTest::newRow("keep_default_args_cpp_after")
+        << "class Foo { void bar(bool b, int i = 0); };"
+        << "void Foo::bar(bool b, int i)\n{}"
+        << (QList<StateChange>() << StateChange(Testbed::CppDoc, Range(0, 27, 0, \
27), ", char c", SHOULD_ASSIST)) +        << "class Foo { void bar(bool b, int i = 0, \
char c = {} /* TODO */); };" +        << "void Foo::bar(bool b, int i, char c)\n{}";
+    QTest::newRow("keep_default_args_header_before")
+        << "class Foo { void bar(bool b, int i = 0); };"
+        << "void Foo::bar(bool b, int i)\n{}"
+        << (QList<StateChange>() << StateChange(Testbed::HeaderDoc, Range(0, 29, 0, \
29), "char c = 'A', ", SHOULD_ASSIST)) +        << "class Foo { void bar(bool b, char \
c = 'A', int i = 0); };" +        << "void Foo::bar(bool b, char c, int i)\n{}";
+    QTest::newRow("keep_default_args_header_after")
+        << "class Foo { void bar(bool b, int i = 0); };"
+        << "void Foo::bar(bool b, int i)\n{}"
+        << (QList<StateChange>() << StateChange(Testbed::HeaderDoc, Range(0, 38, 0, \
38), ", char c = 'A'", SHOULD_ASSIST)) +        << "class Foo { void bar(bool b, int \
i = 0, char c = 'A'); };" +        << "void Foo::bar(bool b, int i, char c)\n{}";
 
     // see https://bugs.kde.org/show_bug.cgi?id=355356
-//     QTest::newRow("no_retval_on_ctor")
-//         << "class Foo { Foo(); };"
-//         << "Foo::Foo()\n{}"
-//         << (QList<StateChange>() << StateChange(Testbed::HeaderDoc, Range(0, 16, \
                0, 16), "char c", SHOULD_ASSIST))
-//         << "class Foo { Foo(char c); };"
-//         << "Foo::Foo(char c)\n{}";
-//
-//     // see https://bugs.kde.org/show_bug.cgi?id=298511
-//     QTest::newRow("change_return_type_header")
-//         << "struct Foo { int bar(); };"
-//         << "int Foo::bar()\n{}"
-//         << (QList<StateChange>() << StateChange(Testbed::HeaderDoc, Range(0, 13, \
                0, 16), "char", SHOULD_ASSIST))
-//         << "struct Foo { char bar(); };"
-//         << "char Foo::bar()\n{}";
-//     QTest::newRow("change_return_type_impl")
-//         << "struct Foo { int bar(); };"
-//         << "int Foo::bar()\n{}"
-//         << (QList<StateChange>() << StateChange(Testbed::CppDoc, Range(0, 0, 0, \
                3), "char", SHOULD_ASSIST))
-//         << "struct Foo { char bar(); };"
-//         << "char Foo::bar()\n{}";
-// }
-//
-// void TestAssistants::testSignatureAssistant()
-// {
-//     QFETCH(QString, headerContents);
-//     QFETCH(QString, cppContents);
-//     Testbed testbed(headerContents, cppContents);
-//
-//     QFETCH(QList<StateChange>, stateChanges);
-//     foreach (StateChange stateChange, stateChanges)
-//     {
-//         testbed.changeDocument(stateChange.document, stateChange.range, \
                stateChange.newText, true);
-//
-//         if (stateChange.result == SHOULD_ASSIST) {
-//             QEXPECT_FAIL("change_function_type", "Clang sees that return type of \
out-of-line definition differs from that in the declaration and won't parse the \
                code...", Abort);
-//             QEXPECT_FAIL("change_return_type_impl", "Clang sees that return type \
of out-of-line definition differs from that in the declaration and won't include the \
                function's AST and thus we never get updated about the new return \
                type...", Abort);
-//             QVERIFY(staticAssistantsManager()->activeAssistant() && \
                !staticAssistantsManager()->activeAssistant()->actions().isEmpty());
-//         } else {
-//             QVERIFY(!staticAssistantsManager()->activeAssistant() || \
                staticAssistantsManager()->activeAssistant()->actions().isEmpty());
-//         }
-//     }
-//     if (staticAssistantsManager()->activeAssistant() && \
                !staticAssistantsManager()->activeAssistant()->actions().isEmpty())
-//         staticAssistantsManager()->activeAssistant()->actions().first()->execute();
                
-//
-//     QFETCH(QString, finalHeaderContents);
-//     QFETCH(QString, finalCppContents);
-//     QCOMPARE(testbed.documentText(Testbed::HeaderDoc), finalHeaderContents);
-//     QCOMPARE(testbed.documentText(Testbed::CppDoc), finalCppContents);
-// }
+    QTest::newRow("no_retval_on_ctor")
+        << "class Foo { Foo(); };"
+        << "Foo::Foo()\n{}"
+        << (QList<StateChange>() << StateChange(Testbed::HeaderDoc, Range(0, 16, 0, \
16), "char c", SHOULD_ASSIST)) +        << "class Foo { Foo(char c); };"
+        << "Foo::Foo(char c)\n{}";
+
+    // see https://bugs.kde.org/show_bug.cgi?id=298511
+    QTest::newRow("change_return_type_header")
+        << "struct Foo { int bar(); };"
+        << "int Foo::bar()\n{}"
+        << (QList<StateChange>() << StateChange(Testbed::HeaderDoc, Range(0, 13, 0, \
16), "char", SHOULD_ASSIST)) +        << "struct Foo { char bar(); };"
+        << "char Foo::bar()\n{}";
+    QTest::newRow("change_return_type_impl")
+        << "struct Foo { int bar(); };"
+        << "int Foo::bar()\n{}"
+        << (QList<StateChange>() << StateChange(Testbed::CppDoc, Range(0, 0, 0, 3), \
"char", SHOULD_ASSIST)) +        << "struct Foo { char bar(); };"
+        << "char Foo::bar()\n{}";
+}
+
+void TestAssistants::testSignatureAssistant()
+{
+    QFETCH(QString, headerContents);
+    QFETCH(QString, cppContents);
+    Testbed testbed(headerContents, cppContents);
+
+    QExplicitlySharedDataPointer<IAssistant> assistant;
+
+    QFETCH(QList<StateChange>, stateChanges);
+    foreach (StateChange stateChange, stateChanges)
+    {
+        testbed.changeDocument(stateChange.document, stateChange.range, \
stateChange.newText, true); +
+        const auto document = testbed.document(stateChange.document);
+        QVERIFY(document);
+
+        DUChainReadLocker lock;
+
+        auto topCtx = DUChain::self()->chainForDocument(document->url());
+        QVERIFY(topCtx);
+
+        const auto problem = findStaticAssistantProblem(topCtx->problems());
+        if (problem) {
+            assistant = problem->solutionAssistant();
+        }
+
+        if (stateChange.result == SHOULD_ASSIST) {
+            QEXPECT_FAIL("change_function_type", "Clang sees that return type of \
out-of-line definition differs from that in the declaration and won't parse the \
code...", Abort); +            QEXPECT_FAIL("change_return_type_impl", "Clang sees \
that return type of out-of-line definition differs from that in the declaration and \
won't include the function's AST and thus we never get updated about the new return \
type...", Abort); +            QVERIFY(assistant && !assistant->actions().isEmpty());
+        } else {
+            QVERIFY(!assistant || assistant->actions().isEmpty());
+        }
+    }
+
+    DUChainReadLocker lock;
+
+    // FIXME:
+    if (assistant && !assistant->actions().isEmpty())
+        assistant->actions().first()->execute();
+
+    QFETCH(QString, finalHeaderContents);
+    QFETCH(QString, finalCppContents);
+    QCOMPARE(testbed.documentText(Testbed::HeaderDoc), finalHeaderContents);
+    QCOMPARE(testbed.documentText(Testbed::CppDoc), finalCppContents);
+}
 
 enum UnknownDeclarationActions
 {
@@ -495,7 +553,7 @@ enum UnknownDeclarationActions
 };
 
 Q_DECLARE_METATYPE(UnknownDeclarationActions)
-/*
+
 void TestAssistants::testUnknownDeclarationAssistant_data()
 {
     QTest::addColumn<QString>("headerContents");
@@ -520,16 +578,27 @@ void TestAssistants::testUnknownDeclarationAssistant()
 
     static const auto cppContents = QStringLiteral("%1\nvoid f_u_n_c_t_i_o_n() \
                {\n}");
     Testbed testbed(headerContents, cppContents.arg(globalText), \
                Testbed::NoAutoInclude);
-    const int line = testbed.document(Testbed::CppDoc)->lines() - 1;
+    const auto document = testbed.document(Testbed::CppDoc);
+    QVERIFY(document);
+    const int line = document->lines() - 1;
     testbed.changeDocument(Testbed::CppDoc, Range(line, 0, line, 0), functionText, \
true);  
+    DUChainReadLocker lock;
+
+    auto topCtx = DUChain::self()->chainForDocument(document->url());
+    QVERIFY(topCtx);
+
+    const auto problems = topCtx->problems();
+
     if (actions == NoUnknownDeclaration) {
-        QVERIFY(!staticAssistantsManager()->activeAssistant());
+        QVERIFY(!problems.isEmpty());
         return;
     }
 
-    QVERIFY(staticAssistantsManager()->activeAssistant());
-    const auto assistantActions = \
staticAssistantsManager()->activeAssistant()->actions(); +    auto firstProblem = \
problems.first(); +    auto assistant = firstProblem->solutionAssistant();
+    QVERIFY(assistant);
+    const auto assistantActions = assistant->actions();
     QStringList actionDescriptions;
     for (auto action: assistantActions) {
         actionDescriptions << action->description();
@@ -550,7 +619,7 @@ void TestAssistants::testUnknownDeclarationAssistant()
         const bool hasMissingInclude = actionDescriptions.contains(description);
         QCOMPARE(hasMissingInclude, static_cast<bool>(actions & MissingInclude));
     }
-}*/
+}
 
 void TestAssistants::testMoveIntoSource()
 {
diff --git a/languages/clang/tests/test_assistants.h \
b/languages/clang/tests/test_assistants.h index 9315e16..88cd679 100644
--- a/languages/clang/tests/test_assistants.h
+++ b/languages/clang/tests/test_assistants.h
@@ -29,13 +29,13 @@ private slots:
     void initTestCase();
     void cleanupTestCase();
 
-//     void testRenameAssistant_data();
-//     void testRenameAssistant();
-//     void testRenameAssistantUndoRename();
-//     void testSignatureAssistant_data();
-//     void testSignatureAssistant();
-//     void testUnknownDeclarationAssistant_data();
-//     void testUnknownDeclarationAssistant();
+    void testRenameAssistant_data();
+    void testRenameAssistant();
+    void testRenameAssistantUndoRename();
+    void testSignatureAssistant_data();
+    void testSignatureAssistant();
+    void testUnknownDeclarationAssistant_data();
+    void testUnknownDeclarationAssistant();
 
     void testMoveIntoSource_data();
     void testMoveIntoSource();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic