summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcompletion_test.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@digia.com>2013-12-16 16:02:45 +0100
committerNikolai Kosjar <nikolai.kosjar@digia.com>2014-01-07 14:19:13 +0100
commit5c8df5fa4ec4a8f30261dc4d53a810f7be65df51 (patch)
tree2abcbc02f94c15f4d26a5399c1ea31b4183923e7 /src/plugins/cpptools/cppcompletion_test.cpp
parent5aa8a63f90934619072242ac0f6f5fca128edd39 (diff)
downloadqt-creator-5c8df5fa4ec4a8f30261dc4d53a810f7be65df51.tar.gz
CppEditor/CppTools: Introduce Test{Case,Document}
Move common functionality of the 12 test classes into base classes. Change-Id: If64d3cec876807ac6f991151189860a99b8ff4ca Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'src/plugins/cpptools/cppcompletion_test.cpp')
-rw-r--r--src/plugins/cpptools/cppcompletion_test.cpp38
1 files changed, 12 insertions, 26 deletions
diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp
index d781a449e0..4fc45144bb 100644
--- a/src/plugins/cpptools/cppcompletion_test.cpp
+++ b/src/plugins/cpptools/cppcompletion_test.cpp
@@ -27,21 +27,22 @@
**
****************************************************************************/
-#include "cpptoolsplugin.h"
#include "cppcompletionassist.h"
#include "cppmodelmanager.h"
+#include "cpptoolsplugin.h"
+#include "cpptoolstestcase.h"
-#include <texteditor/plaintexteditor.h>
#include <texteditor/codeassist/iassistproposal.h>
#include <texteditor/convenience.h>
+#include <texteditor/plaintexteditor.h>
#include <utils/changeset.h>
#include <utils/fileutils.h>
-#include <QtTest>
#include <QDebug>
-#include <QTextDocument>
#include <QDir>
+#include <QTextDocument>
+#include <QtTest>
/*!
Tests for code completion.
@@ -52,15 +53,13 @@ using namespace CppTools::Internal;
using namespace TextEditor;
using namespace Core;
-namespace {
-typedef QByteArray _;
+namespace { typedef QByteArray _; }
-class CompletionTestCase
+class CompletionTestCase : public CppTools::Tests::TestCase
{
public:
CompletionTestCase(const QByteArray &sourceText, const QByteArray &textToInsert = QByteArray())
- : position(-1), editorWidget(0), textDocument(0), editor(0),
- cmm(CppModelManager::instance())
+ : position(-1), editorWidget(0), textDocument(0), editor(0)
{
source = sourceText;
position = source.indexOf('@');
@@ -69,22 +68,20 @@ public:
// Write source to file
const QString fileName = QDir::tempPath() + QLatin1String("/file.h");
- Utils::FileSaver srcSaver(fileName);
- srcSaver.write(source);
- srcSaver.finalize();
+ QVERIFY(writeFile(fileName, source));
// Open in editor
editor = EditorManager::openEditor(fileName);
QVERIFY(editor);
+ closeEditorAtEndOfTestCase(editor);
editorWidget = qobject_cast<TextEditor::BaseTextEditorWidget *>(editor->widget());
QVERIFY(editorWidget);
textDocument = editorWidget->document();
// Get Document
- while (!cmm->snapshot().contains(fileName))
- QCoreApplication::processEvents();
- Document::Ptr document = cmm->snapshot().document(fileName);
+ waitForFileInGlobalSnapshot(fileName);
+ const Document::Ptr document = globalSnapshot().document(fileName);
snapshot.insert(document);
@@ -92,13 +89,6 @@ public:
insertText(textToInsert);
}
- ~CompletionTestCase()
- {
- EditorManager::closeEditor(editor, /*askAboutModifiedEditors=*/ false);
- cmm->GC();
- QVERIFY(cmm->snapshot().isEmpty());
- }
-
QStringList getCompletions(bool *replaceAccessOperator = 0) const
{
QStringList completions;
@@ -151,12 +141,8 @@ private:
BaseTextEditorWidget *editorWidget;
QTextDocument *textDocument;
IEditor *editor;
-
- CppModelManager *cmm;
};
-} // namespace
-
void CppToolsPlugin::test_completion_basic_1()
{
const QByteArray source =