forked from qt-creator/qt-creator
Clang: Remove test testUpdateBackendAfterRestart()
* It's skipped / must be rewritten. * It does not belong to ClangCodeCompletionTest Change-Id: If6708d28602cc8c3478a968b87bae542ae859590 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -26,7 +26,6 @@
|
|||||||
#include "clangcodecompletion_test.h"
|
#include "clangcodecompletion_test.h"
|
||||||
|
|
||||||
#include "clangautomationutils.h"
|
#include "clangautomationutils.h"
|
||||||
#include "../clangbackendipcintegration.h"
|
|
||||||
#include "../clangcompletionassistinterface.h"
|
#include "../clangcompletionassistinterface.h"
|
||||||
#include "../clangmodelmanagersupport.h"
|
#include "../clangmodelmanagersupport.h"
|
||||||
|
|
||||||
@@ -61,9 +60,6 @@ namespace {
|
|||||||
QString qrcPath(const QByteArray relativeFilePath)
|
QString qrcPath(const QByteArray relativeFilePath)
|
||||||
{ return QLatin1String(":/unittests/ClangCodeModel/") + QString::fromUtf8(relativeFilePath); }
|
{ return QLatin1String(":/unittests/ClangCodeModel/") + QString::fromUtf8(relativeFilePath); }
|
||||||
|
|
||||||
QString fileName(const QString &filePath)
|
|
||||||
{ return QFileInfo(filePath).fileName(); }
|
|
||||||
|
|
||||||
CppTools::Tests::TemporaryDir *globalTemporaryDir()
|
CppTools::Tests::TemporaryDir *globalTemporaryDir()
|
||||||
{
|
{
|
||||||
static CppTools::Tests::TemporaryDir dir;
|
static CppTools::Tests::TemporaryDir dir;
|
||||||
@@ -71,77 +67,6 @@ CppTools::Tests::TemporaryDir *globalTemporaryDir()
|
|||||||
return &dir;
|
return &dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LogOutput
|
|
||||||
{
|
|
||||||
LogOutput(const QString &text) : text(text.toUtf8()) {}
|
|
||||||
LogOutput(const char text[]) : text(text) {}
|
|
||||||
QByteArray text;
|
|
||||||
};
|
|
||||||
|
|
||||||
void printRawLines(QTextStream &out, const QList<QByteArray> &lines)
|
|
||||||
{
|
|
||||||
foreach (const QByteArray &line, lines) {
|
|
||||||
QByteArray rawLine = line;
|
|
||||||
rawLine.prepend("\"");
|
|
||||||
rawLine.append("\\n\"\n");
|
|
||||||
out << rawLine;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void printDifference(const LogOutput &actual, const LogOutput &expected)
|
|
||||||
{
|
|
||||||
QTextStream out(stderr);
|
|
||||||
|
|
||||||
const QList<QByteArray> actualLines = actual.text.split('\n');
|
|
||||||
const QList<QByteArray> expectedLines = expected.text.split('\n');
|
|
||||||
|
|
||||||
out << "-- ACTUAL:\n";
|
|
||||||
printRawLines(out, actualLines);
|
|
||||||
out << "-- EXPECTED:\n";
|
|
||||||
printRawLines(out, expectedLines);
|
|
||||||
|
|
||||||
if (actualLines.size() != expectedLines.size()) {
|
|
||||||
out << "-- DIFFERENCE IN LINE COUNT:\n"
|
|
||||||
<< " actual lines:" << actualLines.size() << '\n'
|
|
||||||
<< " expected lines:" << expectedLines.size() << '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
out << "-- FIRST LINE THAT DIFFERS:\n";
|
|
||||||
auto actualLineIt = actualLines.cbegin();
|
|
||||||
auto expectedLineIt = expectedLines.cbegin();
|
|
||||||
int line = 1;
|
|
||||||
forever {
|
|
||||||
if (actualLineIt == actualLines.cend() && expectedLineIt != expectedLines.cend()) {
|
|
||||||
out << " line: " << line << '\n';
|
|
||||||
out << " actual: <none>\n";
|
|
||||||
out << " expected: \"" << *expectedLineIt << "\"\n";
|
|
||||||
} else if (actualLineIt != actualLines.cend() && expectedLineIt == expectedLines.cend()) {
|
|
||||||
out << " line: " << line << '\n';
|
|
||||||
out << " actual: \"" << *actualLineIt << "\"\n";
|
|
||||||
out << " expected: <none>\n";
|
|
||||||
} else {
|
|
||||||
if (*actualLineIt != *expectedLineIt) {
|
|
||||||
out << " line: " << line << '\n';
|
|
||||||
out << " actual: \"" << *actualLineIt << "\"\n";
|
|
||||||
out << " expected: \"" << *expectedLineIt << "\"\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
++line;
|
|
||||||
++actualLineIt;
|
|
||||||
++expectedLineIt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool compare(const LogOutput &actual, const LogOutput &expected)
|
|
||||||
{
|
|
||||||
const bool isEqual = actual.text == expected.text;
|
|
||||||
if (!isEqual)
|
|
||||||
printDifference(actual, expected);
|
|
||||||
return isEqual;
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray readFile(const QString &filePath)
|
QByteArray readFile(const QString &filePath)
|
||||||
{
|
{
|
||||||
QFile file(filePath);
|
QFile file(filePath);
|
||||||
@@ -186,197 +111,6 @@ private:
|
|||||||
Core::IDocument::ReloadSetting m_previousValue;
|
Core::IDocument::ReloadSetting m_previousValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ChangeIpcSender
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ChangeIpcSender(IpcSenderInterface *ipcSender)
|
|
||||||
{
|
|
||||||
auto &ipc = ModelManagerSupportClang::instance()->ipcCommunicator();
|
|
||||||
m_previousSender = ipc.setIpcSender(ipcSender);
|
|
||||||
}
|
|
||||||
|
|
||||||
~ChangeIpcSender()
|
|
||||||
{
|
|
||||||
auto &ipc = ModelManagerSupportClang::instance()->ipcCommunicator();
|
|
||||||
ipc.setIpcSender(m_previousSender);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
IpcSenderInterface *m_previousSender;
|
|
||||||
};
|
|
||||||
|
|
||||||
QString toString(const FileContainer &fileContainer)
|
|
||||||
{
|
|
||||||
QString out;
|
|
||||||
QTextStream ts(&out);
|
|
||||||
ts << " Path: " << fileName(fileContainer.filePath().toString())
|
|
||||||
<< " ProjectPart: " << fileName(fileContainer.projectPartId().toString()) << "\n";
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString toString(const QVector<FileContainer> &fileContainers)
|
|
||||||
{
|
|
||||||
QString out;
|
|
||||||
QTextStream ts(&out);
|
|
||||||
foreach (const FileContainer &fileContainer, fileContainers)
|
|
||||||
ts << toString(fileContainer);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString toString(const ProjectPartContainer &projectPartContainer)
|
|
||||||
{
|
|
||||||
QString out;
|
|
||||||
QTextStream ts(&out);
|
|
||||||
ts << " ProjectPartContainer"
|
|
||||||
<< " id: " << fileName(projectPartContainer.projectPartId().toString());
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString toString(const QVector<ProjectPartContainer> &projectPartContainers)
|
|
||||||
{
|
|
||||||
QString out;
|
|
||||||
QTextStream ts(&out);
|
|
||||||
foreach (const ProjectPartContainer &projectPartContainer, projectPartContainers)
|
|
||||||
ts << toString(projectPartContainer);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString toString(const EndMessage &)
|
|
||||||
{
|
|
||||||
return QLatin1String("EndMessage\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString toString(const RegisterTranslationUnitForEditorMessage &message)
|
|
||||||
{
|
|
||||||
QString out;
|
|
||||||
QTextStream ts(&out);
|
|
||||||
|
|
||||||
ts << "RegisterTranslationUnitForEditorMessage\n"
|
|
||||||
<< toString(message.fileContainers());
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString toString(const UpdateTranslationUnitsForEditorMessage &message)
|
|
||||||
{
|
|
||||||
QString out;
|
|
||||||
QTextStream ts(&out);
|
|
||||||
|
|
||||||
ts << "UpdateTranslationUnitForEditorMessage\n"
|
|
||||||
<< toString(message.fileContainers());
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString toString(const UnregisterTranslationUnitsForEditorMessage &)
|
|
||||||
{
|
|
||||||
return QLatin1String("UnregisterTranslationUnitsForEditorMessage\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString toString(const RegisterProjectPartsForEditorMessage &message)
|
|
||||||
{
|
|
||||||
QString out;
|
|
||||||
QTextStream ts(&out);
|
|
||||||
|
|
||||||
ts << "RegisterProjectPartsForEditorMessage\n"
|
|
||||||
<< toString(message.projectContainers()) << "\n";
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString toString(const UnregisterProjectPartsForEditorMessage &message)
|
|
||||||
{
|
|
||||||
QString out;
|
|
||||||
QTextStream ts(&out);
|
|
||||||
|
|
||||||
ts << "UnregisterProjectPartsForEditorMessage\n"
|
|
||||||
<< message.projectPartIds().join(Utf8String::fromUtf8(",")).toByteArray() << "\n";
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString toString(const RegisterUnsavedFilesForEditorMessage &message)
|
|
||||||
{
|
|
||||||
QString out;
|
|
||||||
QTextStream ts(&out);
|
|
||||||
|
|
||||||
ts << "RegisterUnsavedFilesForEditorMessage\n"
|
|
||||||
<< toString(message.fileContainers());
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString toString(const UnregisterUnsavedFilesForEditorMessage &)
|
|
||||||
{
|
|
||||||
return QLatin1String("UnregisterUnsavedFilesForEditorMessage\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString toString(const CompleteCodeMessage &)
|
|
||||||
{
|
|
||||||
return QLatin1String("CompleteCodeMessage\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString toString(const RequestDocumentAnnotationsMessage &)
|
|
||||||
{
|
|
||||||
return QStringLiteral("RequestDocumentAnnotationsMessage\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString toString(const RequestReferencesMessage &)
|
|
||||||
{
|
|
||||||
return QStringLiteral("RequestReferencesMessage\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString toString(const RequestFollowSymbolMessage &)
|
|
||||||
{
|
|
||||||
return QStringLiteral("RequestFollowSymbolMessage\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString toString(const UpdateVisibleTranslationUnitsMessage &)
|
|
||||||
{
|
|
||||||
return QStringLiteral("UpdateVisibleTranslationUnitsMessage\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
class IpcSenderSpy : public IpcSenderInterface
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void end() override
|
|
||||||
{ senderLog.append(toString(EndMessage())); }
|
|
||||||
|
|
||||||
void registerTranslationUnitsForEditor(const RegisterTranslationUnitForEditorMessage &message) override
|
|
||||||
{ senderLog.append(toString(message)); }
|
|
||||||
|
|
||||||
void updateTranslationUnitsForEditor(const UpdateTranslationUnitsForEditorMessage &message) override
|
|
||||||
{ senderLog.append(toString(message)); }
|
|
||||||
|
|
||||||
void unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message) override
|
|
||||||
{ senderLog.append(toString(message)); }
|
|
||||||
|
|
||||||
void registerProjectPartsForEditor(const RegisterProjectPartsForEditorMessage &message) override
|
|
||||||
{ senderLog.append(toString(message)); }
|
|
||||||
|
|
||||||
void unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message) override
|
|
||||||
{ senderLog.append(toString(message)); }
|
|
||||||
|
|
||||||
void registerUnsavedFilesForEditor(const RegisterUnsavedFilesForEditorMessage &message) override
|
|
||||||
{ senderLog.append(toString(message)); }
|
|
||||||
|
|
||||||
void unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message) override
|
|
||||||
{ senderLog.append(toString(message)); }
|
|
||||||
|
|
||||||
void completeCode(const CompleteCodeMessage &message) override
|
|
||||||
{ senderLog.append(toString(message)); }
|
|
||||||
|
|
||||||
void requestDocumentAnnotations(const RequestDocumentAnnotationsMessage &message) override
|
|
||||||
{ senderLog.append(toString(message)); }
|
|
||||||
|
|
||||||
void requestReferences(const RequestReferencesMessage &message) override
|
|
||||||
{ senderLog.append(toString(message)); }
|
|
||||||
|
|
||||||
void requestFollowSymbol(const RequestFollowSymbolMessage &message) override
|
|
||||||
{ senderLog.append(toString(message)); }
|
|
||||||
|
|
||||||
void updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message) override
|
|
||||||
{ senderLog.append(toString(message)); }
|
|
||||||
|
|
||||||
public:
|
|
||||||
QString senderLog;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TestDocument
|
class TestDocument
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -1060,85 +794,6 @@ void ClangCodeCompletionTest::testCompleteAfterChangingIncludedAndNotOpenHeaderE
|
|||||||
QVERIFY(hasItem(proposal, "globalFromHeaderReloaded"));
|
QVERIFY(hasItem(proposal, "globalFromHeaderReloaded"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangCodeCompletionTest::testUpdateBackendAfterRestart()
|
|
||||||
{
|
|
||||||
QSKIP("Must be rewritten with a more robust approach instead of sender log!");
|
|
||||||
IpcSenderSpy spy;
|
|
||||||
ChangeIpcSender changeIpcSender(&spy);
|
|
||||||
|
|
||||||
CppTools::Tests::TemporaryCopiedDir testDir(qrcPath("qt-widgets-app"));
|
|
||||||
QVERIFY(testDir.isValid());
|
|
||||||
|
|
||||||
// Open file not part of any project...
|
|
||||||
const TestDocument headerDocument("myheader.h", &testDir);
|
|
||||||
QVERIFY(headerDocument.isCreated());
|
|
||||||
OpenEditorAtCursorPosition openHeader(headerDocument);
|
|
||||||
QVERIFY(openHeader.succeeded());
|
|
||||||
// ... and modify it, so we have an unsaved file.
|
|
||||||
insertTextAtTopOfEditor(openHeader.editor(), "int someGlobal;\n");
|
|
||||||
// Open project ...
|
|
||||||
MonitorGeneratedUiFile monitorGeneratedUiFile;
|
|
||||||
const QString projectFilePath = testDir.absolutePath("qt-widgets-app.pro");
|
|
||||||
CppTools::Tests::ProjectOpenerAndCloser projectManager;
|
|
||||||
const CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true);
|
|
||||||
QVERIFY(projectInfo.isValid());
|
|
||||||
QVERIFY(monitorGeneratedUiFile.waitUntilGenerated());
|
|
||||||
// ...and a file of the project
|
|
||||||
const QString completionFile = testDir.absolutePath("mainwindow.cpp");
|
|
||||||
const TestDocument testDocument = TestDocument::fromExistingFile(completionFile);
|
|
||||||
QVERIFY(testDocument.isCreatedAndHasValidCursorPosition());
|
|
||||||
OpenEditorAtCursorPosition openSource(testDocument);
|
|
||||||
QVERIFY(openSource.succeeded());
|
|
||||||
|
|
||||||
// Check messages that would have been sent
|
|
||||||
QVERIFY(compare(LogOutput(spy.senderLog),
|
|
||||||
LogOutput(
|
|
||||||
"RegisterTranslationUnitForEditorMessage\n"
|
|
||||||
" Path: myheader.h ProjectPart: \n"
|
|
||||||
"RegisterTranslationUnitForEditorMessage\n"
|
|
||||||
" Path: myheader.h ProjectPart: \n"
|
|
||||||
"RequestDiagnosticsMessage\n"
|
|
||||||
" ProjectPartContainer id: qt-widgets-app.pro qt-widgets-app\n"
|
|
||||||
"RegisterTranslationUnitForEditorMessage\n"
|
|
||||||
" Path: myheader.h ProjectPart: \n"
|
|
||||||
"RequestDiagnosticsMessage\n"
|
|
||||||
"RegisterTranslationUnitForEditorMessage\n"
|
|
||||||
" Path: myheader.h ProjectPart: \n"
|
|
||||||
"RequestDiagnosticsMessage\n"
|
|
||||||
"RegisterTranslationUnitForEditorMessage\n"
|
|
||||||
" Path: ui_mainwindow.h ProjectPart: \n"
|
|
||||||
"RegisterTranslationUnitForEditorMessage\n"
|
|
||||||
" Path: myheader.h ProjectPart: \n"
|
|
||||||
"RegisterTranslationUnitForEditorMessage\n"
|
|
||||||
" Path: mainwindow.cpp ProjectPart: qt-widgets-app.pro qt-widgets-app\n"
|
|
||||||
"RegisterTranslationUnitForEditorMessage\n"
|
|
||||||
" Path: mainwindow.cpp ProjectPart: qt-widgets-app.pro qt-widgets-app\n"
|
|
||||||
"RequestDiagnosticsMessage\n"
|
|
||||||
|
|
||||||
)));
|
|
||||||
spy.senderLog.clear();
|
|
||||||
|
|
||||||
// Kill backend process...
|
|
||||||
auto &ipcCommunicator = ModelManagerSupportClang::instance()->ipcCommunicator();
|
|
||||||
ipcCommunicator.killBackendProcess();
|
|
||||||
QSignalSpy waitForReinitializedBackend(&ipcCommunicator,
|
|
||||||
SIGNAL(backendReinitialized()));
|
|
||||||
QVERIFY(waitForReinitializedBackend.wait());
|
|
||||||
|
|
||||||
// ...and check if code model backend would have been provided with current data
|
|
||||||
QVERIFY(compare(LogOutput(spy.senderLog),
|
|
||||||
LogOutput(
|
|
||||||
"RegisterProjectPartsForEditorMessage\n"
|
|
||||||
" ProjectPartContainer id: \n"
|
|
||||||
"RegisterProjectPartsForEditorMessage\n"
|
|
||||||
" ProjectPartContainer id: qt-widgets-app.pro qt-widgets-app\n"
|
|
||||||
"RegisterTranslationUnitForEditorMessage\n"
|
|
||||||
" Path: myheader.h ProjectPart: \n"
|
|
||||||
"RegisterTranslationUnitForEditorMessage\n"
|
|
||||||
" Path: ui_mainwindow.h ProjectPart: \n"
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Tests
|
} // namespace Tests
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace ClangCodeModel
|
} // namespace ClangCodeModel
|
||||||
|
@@ -58,8 +58,6 @@ private slots:
|
|||||||
void testCompleteAfterModifyingIncludedHeaderByRefactoringActions();
|
void testCompleteAfterModifyingIncludedHeaderByRefactoringActions();
|
||||||
void testCompleteAfterChangingIncludedAndOpenHeaderExternally();
|
void testCompleteAfterChangingIncludedAndOpenHeaderExternally();
|
||||||
void testCompleteAfterChangingIncludedAndNotOpenHeaderExternally();
|
void testCompleteAfterChangingIncludedAndNotOpenHeaderExternally();
|
||||||
|
|
||||||
void testUpdateBackendAfterRestart();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Tests
|
} // namespace Tests
|
||||||
|
Reference in New Issue
Block a user