summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcompletion_test.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@digia.com>2013-12-19 01:30:49 +0100
committerNikolai Kosjar <nikolai.kosjar@digia.com>2014-01-07 14:19:21 +0100
commitc7f3ac407394d3c4d7fe817a6a913cd3256c37e5 (patch)
treea3006da3814715ed01ebd7abe0e5856ba00f26f9 /src/plugins/cpptools/cppcompletion_test.cpp
parent5c8df5fa4ec4a8f30261dc4d53a810f7be65df51 (diff)
downloadqt-creator-c7f3ac407394d3c4d7fe817a6a913cd3256c37e5.tar.gz
CppEditor/CppTools: Clean up *Test* classes
* Unify class names * Fix coding style Change-Id: I7498192ba9e6b9fc0e97d3d4f0dbb30f1853a0c9 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.cpp61
1 files changed, 33 insertions, 28 deletions
diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp
index 4fc45144bb..173181c412 100644
--- a/src/plugins/cpptools/cppcompletion_test.cpp
+++ b/src/plugins/cpptools/cppcompletion_test.cpp
@@ -53,37 +53,39 @@ using namespace CppTools::Internal;
using namespace TextEditor;
using namespace Core;
-namespace { typedef QByteArray _; }
+namespace {
+
+typedef QByteArray _;
class CompletionTestCase : public CppTools::Tests::TestCase
{
public:
CompletionTestCase(const QByteArray &sourceText, const QByteArray &textToInsert = QByteArray())
- : position(-1), editorWidget(0), textDocument(0), editor(0)
+ : m_position(-1), m_editorWidget(0), m_textDocument(0), m_editor(0)
{
- source = sourceText;
- position = source.indexOf('@');
- QVERIFY(position != -1);
- source[position] = ' ';
+ m_source = sourceText;
+ m_position = m_source.indexOf('@');
+ QVERIFY(m_position != -1);
+ m_source[m_position] = ' ';
// Write source to file
const QString fileName = QDir::tempPath() + QLatin1String("/file.h");
- QVERIFY(writeFile(fileName, source));
+ QVERIFY(writeFile(fileName, m_source));
// Open in editor
- editor = EditorManager::openEditor(fileName);
- QVERIFY(editor);
- closeEditorAtEndOfTestCase(editor);
- editorWidget = qobject_cast<TextEditor::BaseTextEditorWidget *>(editor->widget());
- QVERIFY(editorWidget);
+ m_editor = EditorManager::openEditor(fileName);
+ QVERIFY(m_editor);
+ closeEditorAtEndOfTestCase(m_editor);
+ m_editorWidget = qobject_cast<TextEditor::BaseTextEditorWidget *>(m_editor->widget());
+ QVERIFY(m_editorWidget);
- textDocument = editorWidget->document();
+ m_textDocument = m_editorWidget->document();
// Get Document
waitForFileInGlobalSnapshot(fileName);
const Document::Ptr document = globalSnapshot().document(fileName);
- snapshot.insert(document);
+ m_snapshot.insert(document);
if (!textToInsert.isEmpty())
insertText(textToInsert);
@@ -93,9 +95,9 @@ public:
{
QStringList completions;
CppCompletionAssistInterface *ai
- = new CppCompletionAssistInterface(editorWidget->document(), position,
- editorWidget->baseTextDocument()->filePath(),
- ExplicitlyInvoked, snapshot,
+ = new CppCompletionAssistInterface(m_editorWidget->document(), m_position,
+ m_editorWidget->baseTextDocument()->filePath(),
+ ExplicitlyInvoked, m_snapshot,
QStringList(), QStringList());
CppCompletionAssistProcessor processor;
IAssistProposal *proposal = processor.perform(ai);
@@ -109,8 +111,9 @@ public:
return completions;
const int pos = proposal->basePosition();
- const int length = position - pos;
- const QString prefix = Convenience::textAt(QTextCursor(editorWidget->document()), pos, length);
+ const int length = m_position - pos;
+ const QString prefix = Convenience::textAt(QTextCursor(m_editorWidget->document()), pos,
+ length);
if (!prefix.isEmpty())
listmodel->filter(prefix);
if (listmodel->isSortable(prefix))
@@ -128,21 +131,23 @@ public:
void insertText(const QByteArray &text)
{
Utils::ChangeSet change;
- change.insert(position, QLatin1String(text));
- QTextCursor cursor(textDocument);
+ change.insert(m_position, QLatin1String(text));
+ QTextCursor cursor(m_textDocument);
change.apply(&cursor);
- position += text.length();
+ m_position += text.length();
}
private:
- QByteArray source;
- int position;
- Snapshot snapshot;
- BaseTextEditorWidget *editorWidget;
- QTextDocument *textDocument;
- IEditor *editor;
+ QByteArray m_source;
+ int m_position;
+ Snapshot m_snapshot;
+ BaseTextEditorWidget *m_editorWidget;
+ QTextDocument *m_textDocument;
+ IEditor *m_editor;
};
+} // anonymous namespace
+
void CppToolsPlugin::test_completion_basic_1()
{
const QByteArray source =