forked from qt-creator/qt-creator
CppTools: Tests: Fix leaking IAssistProposal and SymbolSearcher
Change-Id: Ic81a5df88d17375cf0087213d84443845bfd38cc Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
@@ -107,17 +107,18 @@ public:
|
||||
ExplicitlyInvoked, m_snapshot,
|
||||
ProjectPart::HeaderPaths());
|
||||
CppCompletionAssistProcessor processor;
|
||||
IAssistProposal *proposal = processor.perform(ai);
|
||||
if (!proposal)
|
||||
|
||||
const Tests::IAssistProposalScopedPointer proposal(processor.perform(ai));
|
||||
if (!proposal.d)
|
||||
return completions;
|
||||
IAssistProposalModel *model = proposal->model();
|
||||
IAssistProposalModel *model = proposal.d->model();
|
||||
if (!model)
|
||||
return completions;
|
||||
CppAssistProposalModel *listmodel = dynamic_cast<CppAssistProposalModel *>(model);
|
||||
if (!listmodel)
|
||||
return completions;
|
||||
|
||||
const int pos = proposal->basePosition();
|
||||
const int pos = proposal.d->basePosition();
|
||||
const int length = m_position - pos;
|
||||
const QString prefix = Convenience::textAt(QTextCursor(m_editorWidget->document()), pos,
|
||||
length);
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <texteditor/basetexteditor.h>
|
||||
#include <texteditor/codeassist/iassistproposal.h>
|
||||
#include <texteditor/codeassist/iassistproposalmodel.h>
|
||||
|
||||
#include <cplusplus/CppDocument.h>
|
||||
#include <utils/fileutils.h>
|
||||
@@ -212,5 +214,15 @@ FileWriterAndRemover::~FileWriterAndRemover()
|
||||
}
|
||||
}
|
||||
|
||||
IAssistProposalScopedPointer::IAssistProposalScopedPointer(TextEditor::IAssistProposal *proposal)
|
||||
: d(proposal)
|
||||
{}
|
||||
|
||||
IAssistProposalScopedPointer::~IAssistProposalScopedPointer()
|
||||
{
|
||||
if (d && d->model())
|
||||
delete d->model();
|
||||
}
|
||||
|
||||
} // namespace Tests
|
||||
} // namespace CppTools
|
||||
|
||||
@@ -41,8 +41,13 @@ namespace CPlusPlus {
|
||||
class Document;
|
||||
class Snapshot;
|
||||
}
|
||||
|
||||
namespace Core { class IEditor; }
|
||||
namespace TextEditor { class BaseTextEditor; }
|
||||
|
||||
namespace TextEditor {
|
||||
class BaseTextEditor;
|
||||
class IAssistProposal;
|
||||
}
|
||||
|
||||
namespace CppTools {
|
||||
namespace Tests {
|
||||
@@ -108,6 +113,17 @@ private:
|
||||
bool m_writtenSuccessfully;
|
||||
};
|
||||
|
||||
// Normally the proposal is deleted by the ProcessorRunner or the
|
||||
// GenericProposalWidget, but in tests we usually don't make use of them.
|
||||
class CPPTOOLS_EXPORT IAssistProposalScopedPointer
|
||||
{
|
||||
public:
|
||||
IAssistProposalScopedPointer(TextEditor::IAssistProposal *proposal);
|
||||
~IAssistProposalScopedPointer();
|
||||
|
||||
QScopedPointer<TextEditor::IAssistProposal> d;
|
||||
};
|
||||
|
||||
} // namespace Tests
|
||||
} // namespace CppTools
|
||||
|
||||
|
||||
@@ -106,10 +106,10 @@ public:
|
||||
m_modelManager->setIndexingSupport(m_indexingSupportToUse);
|
||||
|
||||
CppIndexingSupport *indexingSupport = m_modelManager->indexingSupport();
|
||||
SymbolSearcher *symbolSearcher = indexingSupport->createSymbolSearcher(searchParameters,
|
||||
QSet<QString>() << testFile);
|
||||
const QScopedPointer<SymbolSearcher> symbolSearcher(
|
||||
indexingSupport->createSymbolSearcher(searchParameters, QSet<QString>() << testFile));
|
||||
QFuture<Core::SearchResultItem> search
|
||||
= QtConcurrent::run(&SymbolSearcher::runSearch, symbolSearcher);
|
||||
= QtConcurrent::run(&SymbolSearcher::runSearch, symbolSearcher.data());
|
||||
search.waitForFinished();
|
||||
ResultDataList results = ResultData::fromSearchResultList(search.results());
|
||||
QCOMPARE(results, expectedResults);
|
||||
|
||||
Reference in New Issue
Block a user