2015-05-08 15:48:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-05-08 15:48:17 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2015-05-08 15:48:17 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2015-05-08 15:48:17 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "clangcodecompletion_test.h"
|
|
|
|
|
|
2017-02-28 12:01:31 +01:00
|
|
|
#include "clangautomationutils.h"
|
2015-07-06 12:05:02 +02:00
|
|
|
#include "../clangcompletionassistinterface.h"
|
2015-05-08 15:48:17 +02:00
|
|
|
#include "../clangmodelmanagersupport.h"
|
|
|
|
|
|
2015-07-14 19:01:32 +02:00
|
|
|
#include <clangcodemodel/clangeditordocumentprocessor.h>
|
2015-05-08 15:48:17 +02:00
|
|
|
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <cpptools/cpptoolsreuse.h>
|
|
|
|
|
#include <cpptools/cpptoolstestcase.h>
|
|
|
|
|
#include <cpptools/modelmanagertesthelper.h>
|
2016-01-12 12:51:33 +01:00
|
|
|
#include <cpptools/projectinfo.h>
|
2015-07-06 12:05:02 +02:00
|
|
|
#include <texteditor/codeassist/assistproposalitem.h>
|
2015-05-08 15:48:17 +02:00
|
|
|
#include <texteditor/codeassist/genericproposalmodel.h>
|
|
|
|
|
#include <texteditor/textdocument.h>
|
|
|
|
|
#include <texteditor/texteditor.h>
|
|
|
|
|
|
2017-08-24 12:28:01 +02:00
|
|
|
#include <clangsupport/clangcodemodelservermessages.h>
|
2017-06-15 16:43:37 +02:00
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
#include <utils/changeset.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QtTest>
|
|
|
|
|
|
2015-06-16 11:56:00 +02:00
|
|
|
using namespace ClangBackEnd;
|
2015-05-08 15:48:17 +02:00
|
|
|
using namespace ClangCodeModel;
|
|
|
|
|
using namespace ClangCodeModel::Internal;
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
QString qrcPath(const QByteArray relativeFilePath)
|
|
|
|
|
{ return QLatin1String(":/unittests/ClangCodeModel/") + QString::fromUtf8(relativeFilePath); }
|
|
|
|
|
|
2015-07-17 11:18:42 +02:00
|
|
|
CppTools::Tests::TemporaryDir *globalTemporaryDir()
|
|
|
|
|
{
|
|
|
|
|
static CppTools::Tests::TemporaryDir dir;
|
|
|
|
|
QTC_CHECK(dir.isValid());
|
|
|
|
|
return &dir;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
QByteArray readFile(const QString &filePath)
|
|
|
|
|
{
|
|
|
|
|
QFile file(filePath);
|
|
|
|
|
QTC_ASSERT(file.open(QFile::ReadOnly | QFile::Text), return QByteArray());
|
|
|
|
|
return file.readAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool writeFile(const QString &filePath, const QByteArray &contents)
|
|
|
|
|
{
|
|
|
|
|
QFile file(filePath);
|
|
|
|
|
if (!file.open(QFile::WriteOnly | QFile::Text))
|
|
|
|
|
return false;
|
|
|
|
|
if (file.write(contents) != contents.size())
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ChangeDocumentReloadSetting
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ChangeDocumentReloadSetting(Core::IDocument::ReloadSetting reloadSetting)
|
|
|
|
|
: m_previousValue(Core::EditorManager::reloadSetting())
|
|
|
|
|
{
|
|
|
|
|
Core::EditorManager::setReloadSetting(reloadSetting);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~ChangeDocumentReloadSetting()
|
|
|
|
|
{
|
|
|
|
|
Core::EditorManager::setReloadSetting(m_previousValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Core::IDocument::ReloadSetting m_previousValue;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TestDocument
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-11-04 21:44:21 +01:00
|
|
|
TestDocument(const QByteArray &fileName, CppTools::Tests::TemporaryDir *temporaryDir = nullptr)
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!fileName.isEmpty(), return);
|
|
|
|
|
const QResource resource(qrcPath(fileName));
|
|
|
|
|
QTC_ASSERT(resource.isValid(), return);
|
|
|
|
|
const QByteArray contents = QByteArray(reinterpret_cast<const char*>(resource.data()),
|
|
|
|
|
resource.size());
|
2020-08-25 14:32:56 +02:00
|
|
|
finish(fileName, contents, temporaryDir);
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static TestDocument fromExistingFile(const QString &filePath)
|
|
|
|
|
{
|
|
|
|
|
TestDocument testDocument;
|
|
|
|
|
QTC_ASSERT(!filePath.isEmpty(), return testDocument);
|
|
|
|
|
testDocument.filePath = filePath;
|
|
|
|
|
testDocument.cursorPosition = findCursorMarkerPosition(readFile(filePath));
|
|
|
|
|
return testDocument;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-25 14:32:56 +02:00
|
|
|
static TestDocument fromString(const QByteArray &fileName, const QByteArray &contents,
|
|
|
|
|
CppTools::Tests::TemporaryDir *tempDir = nullptr)
|
|
|
|
|
{
|
|
|
|
|
TestDocument testDocument;
|
|
|
|
|
testDocument.finish(fileName, contents, tempDir);
|
|
|
|
|
return testDocument;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
static int findCursorMarkerPosition(const QByteArray &contents)
|
|
|
|
|
{
|
|
|
|
|
return contents.indexOf(" /* COMPLETE HERE */");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isCreated() const { return !filePath.isEmpty(); }
|
|
|
|
|
bool hasValidCursorPosition() const { return cursorPosition >= 0; }
|
|
|
|
|
bool isCreatedAndHasValidCursorPosition() const
|
|
|
|
|
{ return isCreated() && hasValidCursorPosition(); }
|
|
|
|
|
|
|
|
|
|
QString filePath;
|
2018-11-04 21:44:21 +01:00
|
|
|
int cursorPosition = -1;
|
2015-05-08 15:48:17 +02:00
|
|
|
|
|
|
|
|
private:
|
2018-11-04 21:44:21 +01:00
|
|
|
TestDocument() = default;
|
2020-08-25 14:32:56 +02:00
|
|
|
|
|
|
|
|
void finish(const QByteArray &fileName, const QByteArray &contents,
|
|
|
|
|
CppTools::Tests::TemporaryDir *temporaryDir = nullptr)
|
|
|
|
|
{
|
|
|
|
|
cursorPosition = findCursorMarkerPosition(contents);
|
|
|
|
|
if (!contents.isEmpty()) {
|
|
|
|
|
if (!temporaryDir) {
|
|
|
|
|
m_temporaryDir.reset(new CppTools::Tests::TemporaryDir);
|
|
|
|
|
temporaryDir = m_temporaryDir.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filePath = temporaryDir->createFile(fileName, contents);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
QSharedPointer<CppTools::Tests::TemporaryDir> m_temporaryDir;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class OpenEditorAtCursorPosition
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
OpenEditorAtCursorPosition(const TestDocument &testDocument);
|
|
|
|
|
~OpenEditorAtCursorPosition(); // Close editor
|
|
|
|
|
|
2015-07-14 19:01:32 +02:00
|
|
|
bool succeeded() const { return m_editor && m_backendIsNotified; }
|
|
|
|
|
bool waitUntilBackendIsNotified(int timeout = 10000);
|
2015-09-28 17:42:43 +02:00
|
|
|
bool waitUntilProjectPartChanged(const QString &newProjectPartId, int timeout = 10000);
|
|
|
|
|
bool waitUntil(const std::function<bool()> &condition, int timeout);
|
2015-05-08 15:48:17 +02:00
|
|
|
TextEditor::BaseTextEditor *editor() const { return m_editor; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
TextEditor::BaseTextEditor *m_editor;
|
2015-07-14 19:01:32 +02:00
|
|
|
bool m_backendIsNotified = false;
|
2015-05-08 15:48:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
OpenEditorAtCursorPosition::OpenEditorAtCursorPosition(const TestDocument &testDocument)
|
|
|
|
|
{
|
|
|
|
|
Core::IEditor *coreEditor = Core::EditorManager::openEditor(testDocument.filePath);
|
|
|
|
|
m_editor = qobject_cast<TextEditor::BaseTextEditor *>(coreEditor);
|
|
|
|
|
QTC_CHECK(m_editor);
|
2018-02-12 20:09:03 +01:00
|
|
|
if (m_editor) {
|
|
|
|
|
if (testDocument.hasValidCursorPosition())
|
|
|
|
|
m_editor->setCursorPosition(testDocument.cursorPosition);
|
|
|
|
|
m_backendIsNotified = waitUntilBackendIsNotified();
|
|
|
|
|
}
|
2015-07-14 19:01:32 +02:00
|
|
|
QTC_CHECK(m_backendIsNotified);
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenEditorAtCursorPosition::~OpenEditorAtCursorPosition()
|
|
|
|
|
{
|
|
|
|
|
if (m_editor)
|
2020-09-29 10:24:48 +02:00
|
|
|
Core::EditorManager::closeEditors({m_editor}, /* askAboutModifiedEditors= */ false);
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-28 17:42:43 +02:00
|
|
|
|
|
|
|
|
|
2015-07-14 19:01:32 +02:00
|
|
|
bool OpenEditorAtCursorPosition::waitUntilBackendIsNotified(int timeout)
|
|
|
|
|
{
|
2015-09-28 17:42:43 +02:00
|
|
|
const QString filePath = m_editor->document()->filePath().toString();
|
|
|
|
|
|
|
|
|
|
auto condition = [filePath] () {
|
|
|
|
|
const auto *processor = ClangEditorDocumentProcessor::get(filePath);
|
|
|
|
|
return processor && processor->projectPart();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return waitUntil(condition, timeout);
|
|
|
|
|
}
|
2015-07-14 19:01:32 +02:00
|
|
|
|
2015-09-28 17:42:43 +02:00
|
|
|
bool OpenEditorAtCursorPosition::waitUntilProjectPartChanged(const QString &newProjectPartId,
|
|
|
|
|
int timeout)
|
|
|
|
|
{
|
2015-07-14 19:01:32 +02:00
|
|
|
const QString filePath = m_editor->document()->filePath().toString();
|
|
|
|
|
|
2015-09-28 17:42:43 +02:00
|
|
|
auto condition = [newProjectPartId, filePath] () {
|
|
|
|
|
const auto *processor = ClangEditorDocumentProcessor::get(filePath);
|
|
|
|
|
return processor
|
|
|
|
|
&& processor->projectPart()
|
|
|
|
|
&& processor->projectPart()->id() == newProjectPartId;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return waitUntil(condition, timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool OpenEditorAtCursorPosition::waitUntil(const std::function<bool ()> &condition, int timeout)
|
|
|
|
|
{
|
2019-07-05 12:14:08 +02:00
|
|
|
QElapsedTimer time;
|
2015-07-14 19:01:32 +02:00
|
|
|
time.start();
|
|
|
|
|
|
|
|
|
|
forever {
|
|
|
|
|
if (time.elapsed() > timeout)
|
|
|
|
|
return false;
|
|
|
|
|
|
2015-09-28 17:42:43 +02:00
|
|
|
if (condition())
|
2015-07-14 19:01:32 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
QThread::msleep(20);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
CppTools::ProjectPart::Ptr createProjectPart(const QStringList &files,
|
2017-02-07 15:00:38 +01:00
|
|
|
const ProjectExplorer::Macros ¯os)
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
|
|
|
|
using namespace CppTools;
|
|
|
|
|
|
|
|
|
|
ProjectPart::Ptr projectPart(new ProjectPart);
|
|
|
|
|
projectPart->projectFile = QLatin1String("myproject.project");
|
|
|
|
|
foreach (const QString &file, files)
|
|
|
|
|
projectPart->files.append(ProjectFile(file, ProjectFile::classify(file)));
|
2019-08-28 13:04:16 +02:00
|
|
|
projectPart->qtVersion = ::Utils::QtVersion::None;
|
2017-02-07 15:00:38 +01:00
|
|
|
projectPart->projectMacros = macros;
|
2015-05-08 15:48:17 +02:00
|
|
|
|
|
|
|
|
return projectPart;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CppTools::ProjectInfo createProjectInfo(ProjectExplorer::Project *project,
|
|
|
|
|
const QStringList &files,
|
2017-02-07 15:00:38 +01:00
|
|
|
const ProjectExplorer::Macros ¯os)
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
|
|
|
|
using namespace CppTools;
|
|
|
|
|
QTC_ASSERT(project, return ProjectInfo());
|
|
|
|
|
|
2017-02-07 15:00:38 +01:00
|
|
|
const CppTools::ProjectPart::Ptr projectPart = createProjectPart(files, macros);
|
2015-05-08 15:48:17 +02:00
|
|
|
ProjectInfo projectInfo = ProjectInfo(project);
|
|
|
|
|
projectInfo.appendProjectPart(projectPart);
|
|
|
|
|
return projectInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ProjectLoader
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ProjectLoader(const QStringList &projectFiles,
|
2017-02-07 15:00:38 +01:00
|
|
|
const ProjectExplorer::Macros &projectMacros,
|
2015-05-08 15:48:17 +02:00
|
|
|
bool testOnlyForCleanedProjects = false)
|
2018-11-04 21:44:21 +01:00
|
|
|
: m_project(nullptr)
|
2015-05-08 15:48:17 +02:00
|
|
|
, m_projectFiles(projectFiles)
|
2017-02-07 15:00:38 +01:00
|
|
|
, m_projectMacros(projectMacros)
|
2018-11-04 21:44:21 +01:00
|
|
|
, m_helper(nullptr, testOnlyForCleanedProjects)
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool load()
|
|
|
|
|
{
|
|
|
|
|
m_project = m_helper.createProject(QLatin1String("testProject"));
|
|
|
|
|
const CppTools::ProjectInfo projectInfo = createProjectInfo(m_project,
|
|
|
|
|
m_projectFiles,
|
2017-02-07 15:00:38 +01:00
|
|
|
m_projectMacros);
|
2015-05-08 15:48:17 +02:00
|
|
|
const QSet<QString> filesIndexedAfterLoading = m_helper.updateProjectInfo(projectInfo);
|
|
|
|
|
return m_projectFiles.size() == filesIndexedAfterLoading.size();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-07 15:00:38 +01:00
|
|
|
bool updateProject(const ProjectExplorer::Macros &updatedProjectMacros)
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_project, return false);
|
|
|
|
|
const CppTools::ProjectInfo updatedProjectInfo = createProjectInfo(m_project,
|
|
|
|
|
m_projectFiles,
|
2017-02-07 15:00:38 +01:00
|
|
|
updatedProjectMacros);
|
2015-05-08 15:48:17 +02:00
|
|
|
return updateProjectInfo(updatedProjectInfo);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool updateProjectInfo(const CppTools::ProjectInfo &projectInfo)
|
|
|
|
|
{
|
|
|
|
|
const QSet<QString> filesIndexedAfterLoading = m_helper.updateProjectInfo(projectInfo);
|
|
|
|
|
return m_projectFiles.size() == filesIndexedAfterLoading.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::Project *m_project;
|
|
|
|
|
QStringList m_projectFiles;
|
2017-02-07 15:00:38 +01:00
|
|
|
ProjectExplorer::Macros m_projectMacros;
|
2015-05-08 15:48:17 +02:00
|
|
|
CppTools::Tests::ModelManagerTestHelper m_helper;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ProjectLessCompletionTest
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ProjectLessCompletionTest(const QByteArray &testFileName,
|
2016-01-11 15:20:04 +01:00
|
|
|
const QString &textToInsert = QString(),
|
2020-08-25 14:32:56 +02:00
|
|
|
const QStringList &includePaths = QStringList(),
|
|
|
|
|
const QByteArray &contents = {})
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
|
|
|
|
CppTools::Tests::TestCase garbageCollectionGlobalSnapshot;
|
|
|
|
|
QVERIFY(garbageCollectionGlobalSnapshot.succeededSoFar());
|
|
|
|
|
|
2020-08-25 14:32:56 +02:00
|
|
|
const auto testDocument = contents.isEmpty()
|
|
|
|
|
? TestDocument(testFileName, globalTemporaryDir())
|
|
|
|
|
: TestDocument::fromString(testFileName, contents, globalTemporaryDir());
|
2015-05-08 15:48:17 +02:00
|
|
|
QVERIFY(testDocument.isCreatedAndHasValidCursorPosition());
|
|
|
|
|
OpenEditorAtCursorPosition openEditor(testDocument);
|
|
|
|
|
QVERIFY(openEditor.succeeded());
|
2016-01-11 15:20:04 +01:00
|
|
|
|
|
|
|
|
if (!textToInsert.isEmpty())
|
|
|
|
|
openEditor.editor()->insert(textToInsert);
|
|
|
|
|
|
2016-05-10 15:10:15 +02:00
|
|
|
proposal = completionResults(openEditor.editor(), includePaths, 15000);
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
2018-02-14 14:32:51 +01:00
|
|
|
TextEditor::ProposalModelPtr proposal;
|
2015-05-08 15:48:17 +02:00
|
|
|
};
|
|
|
|
|
|
2018-02-14 14:32:51 +01:00
|
|
|
int indexOfItemWithText(TextEditor::ProposalModelPtr model, const QByteArray &text)
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
|
|
|
|
if (!model)
|
2015-08-07 10:58:17 +02:00
|
|
|
return -1;
|
2015-05-08 15:48:17 +02:00
|
|
|
|
|
|
|
|
for (int i = 0, size = model->size(); i < size; ++i) {
|
|
|
|
|
const QString itemText = model->text(i);
|
|
|
|
|
if (itemText == QString::fromUtf8(text))
|
2015-08-07 10:58:17 +02:00
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-14 14:32:51 +01:00
|
|
|
bool hasItem(TextEditor::ProposalModelPtr model, const QByteArray &text)
|
2015-08-07 10:58:17 +02:00
|
|
|
{
|
|
|
|
|
return indexOfItemWithText(model, text) != -1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-29 10:44:48 +02:00
|
|
|
int itemsWithText(TextEditor::ProposalModelPtr model, const QByteArray &text)
|
|
|
|
|
{
|
|
|
|
|
if (!model)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
int amount = 0;
|
|
|
|
|
for (int i = 0, size = model->size(); i < size; ++i) {
|
|
|
|
|
if (model->text(i) == QString::fromUtf8(text))
|
|
|
|
|
++amount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return amount;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-14 14:32:51 +01:00
|
|
|
bool hasItem(TextEditor::ProposalModelPtr model, const QByteArray &text, const QByteArray &detail)
|
2015-08-07 10:58:17 +02:00
|
|
|
{
|
|
|
|
|
const int index = indexOfItemWithText(model, text);
|
|
|
|
|
if (index != -1 && index < model->size()) {
|
|
|
|
|
TextEditor::IAssistProposalModel *imodel = model.data();
|
|
|
|
|
const auto genericModel = static_cast<TextEditor::GenericProposalModel *>(imodel);
|
|
|
|
|
const auto itemDetail = genericModel->detail(index);
|
|
|
|
|
return itemDetail == QString::fromUtf8(detail);
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-14 14:32:51 +01:00
|
|
|
bool hasSnippet(TextEditor::ProposalModelPtr model, const QByteArray &text)
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
|
|
|
|
if (!model)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Snippets seem to end with a whitespace
|
|
|
|
|
const QString snippetText = QString::fromUtf8(text) + QLatin1Char(' ');
|
|
|
|
|
|
|
|
|
|
auto *genericModel = static_cast<TextEditor::GenericProposalModel *>(model.data());
|
|
|
|
|
for (int i = 0, size = genericModel->size(); i < size; ++i) {
|
2016-02-01 14:51:01 +01:00
|
|
|
TextEditor::AssistProposalItemInterface *item = genericModel->proposalItem(i);
|
2015-05-08 15:48:17 +02:00
|
|
|
QTC_ASSERT(item, continue);
|
|
|
|
|
if (item->text() == snippetText)
|
2016-02-01 14:51:01 +01:00
|
|
|
return item->isSnippet();
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-04 11:38:59 +02:00
|
|
|
class MonitorGeneratedUiFile : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
MonitorGeneratedUiFile();
|
|
|
|
|
bool waitUntilGenerated(int timeout = 10000) const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void onUiFileGenerated() { m_isGenerated = true; }
|
|
|
|
|
|
|
|
|
|
bool m_isGenerated = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MonitorGeneratedUiFile::MonitorGeneratedUiFile()
|
|
|
|
|
{
|
|
|
|
|
connect(CppTools::CppModelManager::instance(),
|
|
|
|
|
&CppTools::CppModelManager::abstractEditorSupportContentsUpdated,
|
|
|
|
|
this, &MonitorGeneratedUiFile::onUiFileGenerated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MonitorGeneratedUiFile::waitUntilGenerated(int timeout) const
|
|
|
|
|
{
|
|
|
|
|
if (m_isGenerated)
|
|
|
|
|
return true;
|
|
|
|
|
|
2019-07-05 12:14:08 +02:00
|
|
|
QElapsedTimer time;
|
2015-06-04 11:38:59 +02:00
|
|
|
time.start();
|
|
|
|
|
|
|
|
|
|
forever {
|
|
|
|
|
if (m_isGenerated)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (time.elapsed() > timeout)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
QThread::msleep(20);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-10 10:39:05 +02:00
|
|
|
class WriteFileAndWaitForReloadedDocument : public QObject
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
WriteFileAndWaitForReloadedDocument(const QString &filePath,
|
|
|
|
|
const QByteArray &fileContents,
|
|
|
|
|
Core::IDocument *document)
|
|
|
|
|
: m_filePath(filePath)
|
|
|
|
|
, m_fileContents(fileContents)
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(document);
|
|
|
|
|
connect(document, &Core::IDocument::reloadFinished,
|
|
|
|
|
this, &WriteFileAndWaitForReloadedDocument::onReloadFinished);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onReloadFinished()
|
|
|
|
|
{
|
|
|
|
|
m_onReloadFinished = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool wait() const
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(writeFile(m_filePath, m_fileContents), return false);
|
|
|
|
|
|
2019-07-05 12:14:08 +02:00
|
|
|
QElapsedTimer totalTime;
|
2015-07-10 10:39:05 +02:00
|
|
|
totalTime.start();
|
|
|
|
|
|
2019-07-05 12:14:08 +02:00
|
|
|
QElapsedTimer writeFileAgainTime;
|
2015-07-10 10:39:05 +02:00
|
|
|
writeFileAgainTime.start();
|
|
|
|
|
|
|
|
|
|
forever {
|
|
|
|
|
if (m_onReloadFinished)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (totalTime.elapsed() > 10000)
|
|
|
|
|
return false;
|
|
|
|
|
|
2015-09-02 12:10:00 +02:00
|
|
|
if (writeFileAgainTime.elapsed() > 3000) {
|
2015-07-10 10:39:05 +02:00
|
|
|
// The timestamp did not change, try again now.
|
|
|
|
|
QTC_ASSERT(writeFile(m_filePath, m_fileContents), return false);
|
|
|
|
|
writeFileAgainTime.restart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
QThread::msleep(20);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool m_onReloadFinished = false;
|
|
|
|
|
QString m_filePath;
|
|
|
|
|
QByteArray m_fileContents;
|
|
|
|
|
};
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
|
namespace ClangCodeModel {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
namespace Tests {
|
|
|
|
|
|
|
|
|
|
void ClangCodeCompletionTest::testCompleteDoxygenKeywords()
|
|
|
|
|
{
|
|
|
|
|
ProjectLessCompletionTest t("doxygenKeywordsCompletion.cpp");
|
|
|
|
|
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "brief"));
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "param"));
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "return"));
|
|
|
|
|
QVERIFY(!hasSnippet(t.proposal, "class"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangCodeCompletionTest::testCompletePreprocessorKeywords()
|
|
|
|
|
{
|
|
|
|
|
ProjectLessCompletionTest t("preprocessorKeywordsCompletion.cpp");
|
|
|
|
|
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "ifdef"));
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "endif"));
|
|
|
|
|
QVERIFY(!hasSnippet(t.proposal, "class"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangCodeCompletionTest::testCompleteIncludeDirective()
|
|
|
|
|
{
|
|
|
|
|
CppTools::Tests::TemporaryCopiedDir testDir(qrcPath("exampleIncludeDir"));
|
2016-01-11 15:20:04 +01:00
|
|
|
ProjectLessCompletionTest t("includeDirectiveCompletion.cpp",
|
|
|
|
|
QString(),
|
|
|
|
|
QStringList(testDir.path()));
|
2015-05-08 15:48:17 +02:00
|
|
|
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "file.h"));
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "otherFile.h"));
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "mylib/"));
|
|
|
|
|
QVERIFY(!hasSnippet(t.proposal, "class"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangCodeCompletionTest::testCompleteGlobals()
|
|
|
|
|
{
|
|
|
|
|
ProjectLessCompletionTest t("globalCompletion.cpp");
|
|
|
|
|
|
2015-08-07 10:58:17 +02:00
|
|
|
QVERIFY(hasItem(t.proposal, "globalVariable", "int globalVariable"));
|
2017-07-31 16:24:43 +02:00
|
|
|
QVERIFY(hasItem(t.proposal, "globalFunction", "void globalFunction()"));
|
2015-08-07 10:58:17 +02:00
|
|
|
QVERIFY(hasItem(t.proposal, "GlobalClass", "GlobalClass"));
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "class", "class")); // Keyword
|
2015-05-08 15:48:17 +02:00
|
|
|
QVERIFY(hasSnippet(t.proposal, "class")); // Snippet
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangCodeCompletionTest::testCompleteMembers()
|
|
|
|
|
{
|
|
|
|
|
ProjectLessCompletionTest t("memberCompletion.cpp");
|
|
|
|
|
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "member"));
|
|
|
|
|
QVERIFY(!hasItem(t.proposal, "globalVariable"));
|
|
|
|
|
QVERIFY(!hasItem(t.proposal, "class")); // Keyword
|
|
|
|
|
QVERIFY(!hasSnippet(t.proposal, "class")); // Snippet
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-04 17:15:10 +02:00
|
|
|
void ClangCodeCompletionTest::testCompleteMembersFromInside()
|
|
|
|
|
{
|
|
|
|
|
ProjectLessCompletionTest t("membercompletion-inside.cpp");
|
|
|
|
|
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "publicFunc"));
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "privateFunc"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangCodeCompletionTest::testCompleteMembersFromOutside()
|
|
|
|
|
{
|
|
|
|
|
ProjectLessCompletionTest t("membercompletion-outside.cpp");
|
|
|
|
|
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "publicFunc"));
|
|
|
|
|
QVERIFY(!hasItem(t.proposal, "privateFunc"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangCodeCompletionTest::testCompleteMembersFromFriend()
|
|
|
|
|
{
|
|
|
|
|
ProjectLessCompletionTest t("membercompletion-friend.cpp");
|
|
|
|
|
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "publicFunc"));
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "privateFunc"));
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
void ClangCodeCompletionTest::testCompleteFunctions()
|
|
|
|
|
{
|
|
|
|
|
ProjectLessCompletionTest t("functionCompletion.cpp");
|
|
|
|
|
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "void f()"));
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "void f(int a)"));
|
2015-12-09 17:51:14 +01:00
|
|
|
QVERIFY(hasItem(t.proposal, "void f(const QString &s)"));
|
2018-06-07 14:54:57 +02:00
|
|
|
QVERIFY(hasItem(t.proposal, "void f(char c<i>, int optional = 3</i>)"));
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "void f(char c<i>, int optional1 = 3, int optional2 = 3</i>)"));
|
2015-12-09 17:51:14 +01:00
|
|
|
QVERIFY(hasItem(t.proposal, "void f(const TType<QString> *t)"));
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "TType<QString> f(bool)"));
|
2015-05-08 15:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-28 17:46:40 +02:00
|
|
|
void ClangCodeCompletionTest::testCompleteConstructor()
|
2015-07-22 13:09:44 +02:00
|
|
|
{
|
|
|
|
|
ProjectLessCompletionTest t("constructorCompletion.cpp");
|
|
|
|
|
|
2017-04-28 17:46:40 +02:00
|
|
|
QVERIFY(!hasItem(t.proposal, "globalVariable"));
|
|
|
|
|
QVERIFY(!hasItem(t.proposal, "class"));
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "Foo(int)"));
|
|
|
|
|
QVERIFY(hasItem(t.proposal, "Foo(int, double)"));
|
2015-07-22 13:09:44 +02:00
|
|
|
}
|
|
|
|
|
|
2018-08-29 10:44:48 +02:00
|
|
|
void ClangCodeCompletionTest::testCompleteClassAndConstructor()
|
|
|
|
|
{
|
|
|
|
|
ProjectLessCompletionTest t("classAndConstructorCompletion.cpp");
|
|
|
|
|
|
|
|
|
|
QCOMPARE(itemsWithText(t.proposal, "Foo"), 2);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-23 12:20:28 +02:00
|
|
|
// Explicitly Inserting The Dot
|
|
|
|
|
// ----------------------------
|
|
|
|
|
// Inserting the dot for is important since it will send the editor
|
|
|
|
|
// content to the backend and thus generate an unsaved file on the backend
|
|
|
|
|
// side. The unsaved file enables us to do the dot to arrow correction.
|
|
|
|
|
|
2016-01-11 15:20:04 +01:00
|
|
|
void ClangCodeCompletionTest::testCompleteWithDotToArrowCorrection()
|
|
|
|
|
{
|
|
|
|
|
ProjectLessCompletionTest t("dotToArrowCorrection.cpp",
|
2016-06-23 12:20:28 +02:00
|
|
|
QStringLiteral(".")); // See above "Explicitly Inserting The Dot"
|
2016-01-11 15:20:04 +01:00
|
|
|
|
2018-10-24 10:36:42 +02:00
|
|
|
QVERIFY(hasItem(t.proposal, "member"));
|
2016-01-11 15:20:04 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-23 12:20:28 +02:00
|
|
|
void ClangCodeCompletionTest::testDontCompleteWithDotToArrowCorrectionForFloats()
|
|
|
|
|
{
|
|
|
|
|
ProjectLessCompletionTest t("noDotToArrowCorrectionForFloats.cpp",
|
|
|
|
|
QStringLiteral(".")); // See above "Explicitly Inserting The Dot"
|
|
|
|
|
|
|
|
|
|
QCOMPARE(t.proposal->size(), 0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-16 15:24:59 +02:00
|
|
|
void ClangCodeCompletionTest::testCompleteProjectDependingCode()
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
|
|
|
|
const TestDocument testDocument("completionWithProject.cpp");
|
|
|
|
|
QVERIFY(testDocument.isCreatedAndHasValidCursorPosition());
|
|
|
|
|
|
2017-02-07 15:00:38 +01:00
|
|
|
ProjectLoader projectLoader(QStringList(testDocument.filePath), {{"PROJECT_CONFIGURATION_1"}});
|
2015-05-08 15:48:17 +02:00
|
|
|
QVERIFY(projectLoader.load());
|
|
|
|
|
|
|
|
|
|
OpenEditorAtCursorPosition openEditor(testDocument);
|
|
|
|
|
QVERIFY(openEditor.succeeded());
|
|
|
|
|
|
2018-02-14 14:32:51 +01:00
|
|
|
TextEditor::ProposalModelPtr proposal = completionResults(openEditor.editor());
|
2015-05-08 15:48:17 +02:00
|
|
|
QVERIFY(hasItem(proposal, "projectConfiguration1"));
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-16 15:24:59 +02:00
|
|
|
void ClangCodeCompletionTest::testCompleteProjectDependingCodeAfterChangingProject()
|
2015-05-08 15:48:17 +02:00
|
|
|
{
|
|
|
|
|
const TestDocument testDocument("completionWithProject.cpp");
|
|
|
|
|
QVERIFY(testDocument.isCreatedAndHasValidCursorPosition());
|
|
|
|
|
|
|
|
|
|
OpenEditorAtCursorPosition openEditor(testDocument);
|
|
|
|
|
QVERIFY(openEditor.succeeded());
|
|
|
|
|
|
|
|
|
|
// Check completion without project
|
2018-02-14 14:32:51 +01:00
|
|
|
TextEditor::ProposalModelPtr proposal = completionResults(openEditor.editor());
|
2015-05-08 15:48:17 +02:00
|
|
|
QVERIFY(hasItem(proposal, "noProjectConfigurationDetected"));
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Check completion with project configuration 1
|
|
|
|
|
ProjectLoader projectLoader(QStringList(testDocument.filePath),
|
2017-02-07 15:00:38 +01:00
|
|
|
{{"PROJECT_CONFIGURATION_1"}},
|
2015-05-08 15:48:17 +02:00
|
|
|
/* testOnlyForCleanedProjects= */ true);
|
|
|
|
|
QVERIFY(projectLoader.load());
|
2015-09-28 17:42:43 +02:00
|
|
|
openEditor.waitUntilProjectPartChanged(QLatin1String("myproject.project"));
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
proposal = completionResults(openEditor.editor());
|
|
|
|
|
|
|
|
|
|
QVERIFY(hasItem(proposal, "projectConfiguration1"));
|
|
|
|
|
QVERIFY(!hasItem(proposal, "projectConfiguration2"));
|
|
|
|
|
|
|
|
|
|
// Check completion with project configuration 2
|
2017-02-07 15:00:38 +01:00
|
|
|
QVERIFY(projectLoader.updateProject({{"PROJECT_CONFIGURATION_2"}}));
|
2019-07-18 10:43:09 +02:00
|
|
|
openEditor.waitUntilBackendIsNotified();
|
2015-05-08 15:48:17 +02:00
|
|
|
proposal = completionResults(openEditor.editor());
|
|
|
|
|
|
|
|
|
|
QVERIFY(!hasItem(proposal, "projectConfiguration1"));
|
|
|
|
|
QVERIFY(hasItem(proposal, "projectConfiguration2"));
|
|
|
|
|
} // Project closed
|
|
|
|
|
|
|
|
|
|
// Check again completion without project
|
2015-09-18 12:19:46 +02:00
|
|
|
openEditor.waitUntilProjectPartChanged(QLatin1String(""));
|
2015-05-08 15:48:17 +02:00
|
|
|
proposal = completionResults(openEditor.editor());
|
|
|
|
|
QVERIFY(hasItem(proposal, "noProjectConfigurationDetected"));
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-16 15:24:59 +02:00
|
|
|
void ClangCodeCompletionTest::testCompleteProjectDependingCodeInGeneratedUiFile()
|
|
|
|
|
{
|
|
|
|
|
CppTools::Tests::TemporaryCopiedDir testDir(qrcPath("qt-widgets-app"));
|
|
|
|
|
QVERIFY(testDir.isValid());
|
|
|
|
|
|
|
|
|
|
MonitorGeneratedUiFile monitorGeneratedUiFile;
|
|
|
|
|
|
|
|
|
|
// Open project
|
|
|
|
|
const QString projectFilePath = testDir.absolutePath("qt-widgets-app.pro");
|
|
|
|
|
CppTools::Tests::ProjectOpenerAndCloser projectManager;
|
|
|
|
|
const CppTools::ProjectInfo projectInfo = projectManager.open(projectFilePath, true);
|
|
|
|
|
QVERIFY(projectInfo.isValid());
|
2015-09-15 11:48:25 +02:00
|
|
|
QVERIFY(monitorGeneratedUiFile.waitUntilGenerated());
|
2015-09-16 15:24:59 +02:00
|
|
|
|
|
|
|
|
// Open file with ui object
|
|
|
|
|
const QString completionFile = testDir.absolutePath("mainwindow.cpp");
|
|
|
|
|
const TestDocument testDocument = TestDocument::fromExistingFile(completionFile);
|
|
|
|
|
QVERIFY(testDocument.isCreatedAndHasValidCursorPosition());
|
|
|
|
|
OpenEditorAtCursorPosition openSource(testDocument);
|
|
|
|
|
QVERIFY(openSource.succeeded());
|
|
|
|
|
|
|
|
|
|
// ...and check comletions
|
2018-02-14 14:32:51 +01:00
|
|
|
TextEditor::ProposalModelPtr proposal = completionResults(openSource.editor());
|
2015-09-16 15:24:59 +02:00
|
|
|
QVERIFY(hasItem(proposal, "menuBar"));
|
|
|
|
|
QVERIFY(hasItem(proposal, "statusBar"));
|
|
|
|
|
QVERIFY(hasItem(proposal, "centralWidget"));
|
|
|
|
|
QVERIFY(hasItem(proposal, "setupUi"));
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-25 14:32:56 +02:00
|
|
|
static QByteArray makeSignalCompletionContents(const QByteArray &customContents)
|
|
|
|
|
{
|
|
|
|
|
static const QByteArray definitions = R"(
|
|
|
|
|
class QObject {
|
|
|
|
|
public:
|
|
|
|
|
void aSignal() __attribute__((annotate("qt_signal")));
|
|
|
|
|
void anotherSignal() __attribute__((annotate("qt_signal")));
|
|
|
|
|
void notASignal();
|
|
|
|
|
static void connect();
|
|
|
|
|
static void disconnect();
|
|
|
|
|
};
|
|
|
|
|
class DerivedFromQObject : public QObject {
|
|
|
|
|
public:
|
|
|
|
|
void myOwnSignal() __attribute__((annotate("qt_signal")));
|
|
|
|
|
void alsoNotASignal();
|
|
|
|
|
};
|
|
|
|
|
class NotAQObject {
|
|
|
|
|
public:
|
|
|
|
|
void notASignal();
|
|
|
|
|
void alsoNotASignal();
|
|
|
|
|
static void connect();
|
|
|
|
|
};)";
|
|
|
|
|
|
|
|
|
|
return definitions + customContents + " /* COMPLETE HERE */";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangCodeCompletionTest::testSignalCompletion_data()
|
|
|
|
|
{
|
|
|
|
|
QTest::addColumn<QByteArray>("customContents");
|
|
|
|
|
QTest::addColumn<QByteArrayList>("hits");
|
|
|
|
|
|
|
|
|
|
QTest::addRow("positive: connect() on QObject class")
|
|
|
|
|
<< QByteArray("int main() { QObject::connect(dummy, QObject::")
|
|
|
|
|
<< QByteArrayList{"aSignal", "anotherSignal"};
|
|
|
|
|
QTest::addRow("positive: connect() on QObject object")
|
|
|
|
|
<< QByteArray("int main() { QObject o; o.connect(dummy, QObject::")
|
|
|
|
|
<< QByteArrayList{"aSignal", "anotherSignal"};
|
|
|
|
|
QTest::addRow("positive: connect() on QObject pointer")
|
|
|
|
|
<< QByteArray("int main() { QObject *o; o->connect(dummy, QObject::")
|
|
|
|
|
<< QByteArrayList{"aSignal", "anotherSignal"};
|
|
|
|
|
QTest::addRow("positive: connect() on QObject rvalue")
|
|
|
|
|
<< QByteArray("int main() { QObject().connect(dummy, QObject::")
|
|
|
|
|
<< QByteArrayList{"aSignal", "anotherSignal"};
|
|
|
|
|
QTest::addRow("positive: connect() on QObject pointer rvalue")
|
|
|
|
|
<< QByteArray("int main() { (new QObject)->connect(dummy, QObject::")
|
|
|
|
|
<< QByteArrayList{"aSignal", "anotherSignal"};
|
|
|
|
|
QTest::addRow("positive: disconnect() on QObject")
|
|
|
|
|
<< QByteArray("int main() { QObject::disconnect(dummy, QObject::")
|
|
|
|
|
<< QByteArrayList{"aSignal", "anotherSignal"};
|
|
|
|
|
QTest::addRow("positive: connect() in member function of derived class")
|
|
|
|
|
<< QByteArray("void DerivedFromQObject::alsoNotASignal() { connect(this, DerivedFromQObject::")
|
|
|
|
|
<< QByteArrayList{"aSignal", "anotherSignal", "myOwnSignal"};
|
|
|
|
|
|
|
|
|
|
const QByteArrayList allQObjectFunctions{"aSignal", "anotherSignal", "notASignal", "connect",
|
|
|
|
|
"disconnect", "QObject", "~QObject", "operator="};
|
|
|
|
|
QTest::addRow("negative: different function name")
|
|
|
|
|
<< QByteArray("int main() { QObject::notASignal(dummy, QObject::")
|
|
|
|
|
<< allQObjectFunctions;
|
|
|
|
|
QTest::addRow("negative: connect function from other class")
|
|
|
|
|
<< QByteArray("int main() { NotAQObject::connect(dummy, QObject::")
|
|
|
|
|
<< allQObjectFunctions;
|
|
|
|
|
QTest::addRow("negative: first argument")
|
|
|
|
|
<< QByteArray("int main() { QObject::connect(QObject::")
|
|
|
|
|
<< allQObjectFunctions;
|
|
|
|
|
QTest::addRow("negative: third argument")
|
|
|
|
|
<< QByteArray("int main() { QObject::connect(dummy1, dummy2, QObject::")
|
|
|
|
|
<< allQObjectFunctions;
|
|
|
|
|
|
|
|
|
|
QTest::addRow("negative: not a QObject")
|
|
|
|
|
<< QByteArray("int main() { QObject::connect(dummy, NotAQObject::")
|
|
|
|
|
<< QByteArrayList{"notASignal", "alsoNotASignal", "connect", "NotAQObject",
|
|
|
|
|
"~NotAQObject", "operator="};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ClangCodeCompletionTest::testSignalCompletion()
|
|
|
|
|
{
|
|
|
|
|
QFETCH(QByteArray, customContents);
|
|
|
|
|
QFETCH(QByteArrayList, hits);
|
|
|
|
|
|
|
|
|
|
const QByteArray contents = makeSignalCompletionContents(customContents);
|
|
|
|
|
const ProjectLessCompletionTest t("signalcompletion.cpp", {}, {}, contents);
|
|
|
|
|
|
|
|
|
|
QVERIFY(t.proposal);
|
|
|
|
|
QCOMPARE(t.proposal->size(), hits.size());
|
|
|
|
|
for (const QByteArray &hit : qAsConst(hits))
|
|
|
|
|
QVERIFY(hasItem(t.proposal, hit));
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-08 15:48:17 +02:00
|
|
|
} // namespace Tests
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ClangCodeModel
|
2015-06-04 11:38:59 +02:00
|
|
|
|
|
|
|
|
#include "clangcodecompletion_test.moc"
|