forked from qt-creator/qt-creator
CppEditor: Use a timeout in waitForRehighlightedSemanticDocument()
As in all the other wait() functions. This makes sure we never hang indefinitely in tests. Change-Id: I119cc0d6d6146f193ffde37207a94f61b3c70d87 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -488,7 +488,7 @@ void DoxygenTest::runTest(const QByteArray &original,
|
|||||||
// testDocument.m_editorWidget->unfoldAll();
|
// testDocument.m_editorWidget->unfoldAll();
|
||||||
testDocument.m_editor->setCursorPosition(testDocument.m_cursorPosition);
|
testDocument.m_editor->setCursorPosition(testDocument.m_cursorPosition);
|
||||||
|
|
||||||
TestCase::waitForRehighlightedSemanticDocument(testDocument.m_editorWidget);
|
QVERIFY(TestCase::waitForRehighlightedSemanticDocument(testDocument.m_editorWidget));
|
||||||
|
|
||||||
// Send 'ENTER' key press
|
// Send 'ENTER' key press
|
||||||
QKeyEvent event(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
|
QKeyEvent event(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
|
||||||
|
@@ -295,10 +295,18 @@ bool TestCase::waitForProcessedEditorDocument(const FilePath &filePath, int time
|
|||||||
return waitForProcessedEditorDocument_internal(editorDocument, timeOutInMs);
|
return waitForProcessedEditorDocument_internal(editorDocument, timeOutInMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
CPlusPlus::Document::Ptr TestCase::waitForRehighlightedSemanticDocument(CppEditorWidget *editorWidget)
|
CPlusPlus::Document::Ptr TestCase::waitForRehighlightedSemanticDocument(
|
||||||
|
CppEditorWidget *editorWidget, int timeoutInMs)
|
||||||
{
|
{
|
||||||
while (!editorWidget->isSemanticInfoValid())
|
QElapsedTimer timer;
|
||||||
|
timer.start();
|
||||||
|
|
||||||
|
while (!editorWidget->isSemanticInfoValid()) {
|
||||||
|
if (timer.elapsed() >= timeoutInMs)
|
||||||
|
return {};
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
|
QThread::msleep(20);
|
||||||
|
}
|
||||||
return editorWidget->semanticInfo().doc;
|
return editorWidget->semanticInfo().doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -140,7 +140,7 @@ public:
|
|||||||
const Utils::FilePath &filePath, int timeOutInMs = 5000);
|
const Utils::FilePath &filePath, int timeOutInMs = 5000);
|
||||||
|
|
||||||
static CPlusPlus::Document::Ptr waitForRehighlightedSemanticDocument(
|
static CPlusPlus::Document::Ptr waitForRehighlightedSemanticDocument(
|
||||||
CppEditorWidget *editorWidget);
|
CppEditorWidget *editorWidget, int timeoutInMs = defaultTimeOutInMs);
|
||||||
|
|
||||||
enum { defaultTimeOutInMs = 30 * 1000 /*= 30 secs*/ };
|
enum { defaultTimeOutInMs = 30 * 1000 /*= 30 secs*/ };
|
||||||
static bool waitUntilProjectIsFullyOpened(ProjectExplorer::Project *project,
|
static bool waitUntilProjectIsFullyOpened(ProjectExplorer::Project *project,
|
||||||
|
@@ -77,7 +77,7 @@ UseSelectionsTestCase::UseSelectionsTestCase(CppTestDocument &testFile,
|
|||||||
closeEditorAtEndOfTestCase(testFile.m_editor);
|
closeEditorAtEndOfTestCase(testFile.m_editor);
|
||||||
|
|
||||||
testFile.m_editor->setCursorPosition(testFile.m_cursorPosition);
|
testFile.m_editor->setCursorPosition(testFile.m_cursorPosition);
|
||||||
waitForRehighlightedSemanticDocument(m_editorWidget);
|
QVERIFY(waitForRehighlightedSemanticDocument(m_editorWidget));
|
||||||
|
|
||||||
bool hasTimedOut;
|
bool hasTimedOut;
|
||||||
const SelectionList selections = waitForUseSelections(&hasTimedOut);
|
const SelectionList selections = waitForUseSelections(&hasTimedOut);
|
||||||
|
@@ -164,7 +164,7 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti
|
|||||||
QVERIFY(CppModelManager::workingCopy().get(filePath));
|
QVERIFY(CppModelManager::workingCopy().get(filePath));
|
||||||
|
|
||||||
// Rehighlight
|
// Rehighlight
|
||||||
waitForRehighlightedSemanticDocument(editorWidget);
|
QVERIFY(waitForRehighlightedSemanticDocument(editorWidget));
|
||||||
|
|
||||||
// Run all file actions
|
// Run all file actions
|
||||||
executeActionsOnEditorWidget(editorWidget, fileActions);
|
executeActionsOnEditorWidget(editorWidget, fileActions);
|
||||||
|
@@ -310,7 +310,7 @@ F2TestCase::F2TestCase(CppEditorAction action,
|
|||||||
|
|
||||||
// Rehighlight
|
// Rehighlight
|
||||||
if (!useClangd)
|
if (!useClangd)
|
||||||
waitForRehighlightedSemanticDocument(testFile->m_editorWidget);
|
QVERIFY(waitForRehighlightedSemanticDocument(testFile->m_editorWidget));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activate editor of initial test file
|
// Activate editor of initial test file
|
||||||
|
@@ -104,7 +104,7 @@ BaseQuickFixTestCase::BaseQuickFixTestCase(const QList<TestDocumentPtr> &testDoc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rehighlight
|
// Rehighlight
|
||||||
waitForRehighlightedSemanticDocument(document->m_editorWidget);
|
QVERIFY(waitForRehighlightedSemanticDocument(document->m_editorWidget));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enforce the default cpp code style, so we are independent of config file settings.
|
// Enforce the default cpp code style, so we are independent of config file settings.
|
||||||
|
Reference in New Issue
Block a user