2015-10-01 12:45:06 +02:00
|
|
|
/****************************************************************************
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
2016-01-15 14:55:33 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-06-01 18:51:55 +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:55:33 +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-06-01 18:51:55 +02:00
|
|
|
**
|
2016-01-15 14:55:33 +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-06-01 18:51:55 +02:00
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
#include "mockclangcodemodelclient.h"
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
#include <clangcodemodelserver.h>
|
2015-11-18 17:07:44 +01:00
|
|
|
#include <highlightingchangedmessage.h>
|
|
|
|
#include <highlightingmarkcontainer.h>
|
2016-06-29 16:49:56 +02:00
|
|
|
#include <clangcodemodelclientproxy.h>
|
|
|
|
#include <clangcodemodelserverproxy.h>
|
2015-11-18 17:07:44 +01:00
|
|
|
#include <requesthighlightingmessage.h>
|
2015-06-01 18:51:55 +02:00
|
|
|
#include <translationunitdoesnotexistexception.h>
|
|
|
|
#include <translationunitparseerrorexception.h>
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
#include <cmbcodecompletedmessage.h>
|
|
|
|
#include <cmbcompletecodemessage.h>
|
|
|
|
#include <cmbechomessage.h>
|
2015-08-31 14:36:58 +02:00
|
|
|
#include <cmbregisterprojectsforeditormessage.h>
|
|
|
|
#include <cmbregistertranslationunitsforeditormessage.h>
|
|
|
|
#include <cmbunregisterprojectsforeditormessage.h>
|
|
|
|
#include <cmbunregistertranslationunitsforeditormessage.h>
|
2015-11-18 17:07:44 +01:00
|
|
|
#include <highlightingchangedmessage.h>
|
2015-08-31 16:28:26 +02:00
|
|
|
#include <diagnosticschangedmessage.h>
|
2015-08-19 12:36:43 +02:00
|
|
|
#include <projectpartsdonotexistmessage.h>
|
|
|
|
#include <translationunitdoesnotexistmessage.h>
|
2015-10-13 15:56:41 +02:00
|
|
|
#include <updatetranslationunitsforeditormessage.h>
|
2015-11-25 15:29:28 +01:00
|
|
|
#include <updatevisibletranslationunitsmessage.h>
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
#include <QBuffer>
|
|
|
|
#include <QFile>
|
|
|
|
|
2015-06-16 12:38:04 +02:00
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include <gmock/gmock-matchers.h>
|
|
|
|
#include <gtest/gtest.h>
|
2015-07-01 14:50:35 +02:00
|
|
|
#include "gtest-qt-printing.h"
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
using testing::Property;
|
|
|
|
using testing::Contains;
|
|
|
|
using testing::Not;
|
|
|
|
using testing::Eq;
|
2015-10-13 15:56:41 +02:00
|
|
|
using testing::PrintToString;
|
2015-11-18 17:07:44 +01:00
|
|
|
using testing::_;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
using ClangBackEnd::RegisterTranslationUnitForEditorMessage;
|
|
|
|
using ClangBackEnd::UnregisterTranslationUnitsForEditorMessage;
|
|
|
|
using ClangBackEnd::RegisterProjectPartsForEditorMessage;
|
|
|
|
using ClangBackEnd::UnregisterProjectPartsForEditorMessage;
|
2015-08-19 12:36:43 +02:00
|
|
|
using ClangBackEnd::CompleteCodeMessage;
|
|
|
|
using ClangBackEnd::CodeCompletedMessage;
|
2015-06-16 11:56:00 +02:00
|
|
|
using ClangBackEnd::CodeCompletion;
|
|
|
|
using ClangBackEnd::FileContainer;
|
|
|
|
using ClangBackEnd::ProjectPartContainer;
|
2015-08-19 12:36:43 +02:00
|
|
|
using ClangBackEnd::TranslationUnitDoesNotExistMessage;
|
|
|
|
using ClangBackEnd::ProjectPartsDoNotExistMessage;
|
2015-10-13 15:56:41 +02:00
|
|
|
using ClangBackEnd::UpdateTranslationUnitsForEditorMessage;
|
2015-11-25 15:29:28 +01:00
|
|
|
using ClangBackEnd::UpdateVisibleTranslationUnitsMessage;
|
2015-11-18 17:07:44 +01:00
|
|
|
using ClangBackEnd::RequestHighlightingMessage;
|
|
|
|
using ClangBackEnd::HighlightingChangedMessage;
|
|
|
|
using ClangBackEnd::HighlightingMarkContainer;
|
2016-03-03 13:02:29 +01:00
|
|
|
using ClangBackEnd::HighlightingTypes;
|
2015-10-13 15:56:41 +02:00
|
|
|
|
2015-11-23 13:31:46 +01:00
|
|
|
MATCHER_P5(HasDirtyTranslationUnit,
|
|
|
|
filePath,
|
|
|
|
projectPartId,
|
|
|
|
documentRevision,
|
|
|
|
isNeedingReparse,
|
|
|
|
hasNewDiagnostics,
|
2015-10-13 15:56:41 +02:00
|
|
|
std::string(negation ? "isn't" : "is")
|
|
|
|
+ " translation unit with file path "+ PrintToString(filePath)
|
|
|
|
+ " and project " + PrintToString(projectPartId)
|
|
|
|
+ " and document revision " + PrintToString(documentRevision)
|
2015-11-23 13:31:46 +01:00
|
|
|
+ " and isNeedingReparse = " + PrintToString(isNeedingReparse)
|
|
|
|
+ " and hasNewDiagnostics = " + PrintToString(hasNewDiagnostics)
|
2015-10-13 15:56:41 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
auto &&translationUnits = arg.translationUnitsForTestOnly();
|
|
|
|
try {
|
|
|
|
auto translationUnit = translationUnits.translationUnit(filePath, projectPartId);
|
|
|
|
|
|
|
|
if (translationUnit.documentRevision() == documentRevision) {
|
|
|
|
|
2015-11-23 13:31:46 +01:00
|
|
|
if (translationUnit.hasNewDiagnostics() && !hasNewDiagnostics) {
|
|
|
|
*result_listener << "hasNewDiagnostics is true";
|
|
|
|
return false;
|
|
|
|
} else if (!translationUnit.hasNewDiagnostics() && hasNewDiagnostics) {
|
|
|
|
*result_listener << "hasNewDiagnostics is false";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (translationUnit.isNeedingReparse() && !isNeedingReparse) {
|
|
|
|
*result_listener << "isNeedingReparse is true";
|
|
|
|
return false;
|
|
|
|
} else if (!translationUnit.isNeedingReparse() && isNeedingReparse) {
|
2015-10-13 15:56:41 +02:00
|
|
|
*result_listener << "isNeedingReparse is false";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-23 13:31:46 +01:00
|
|
|
return true;
|
2015-10-13 15:56:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*result_listener << "revision number is " << PrintToString(translationUnit.documentRevision());
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} catch (...) {
|
|
|
|
*result_listener << "has no translation unit";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
class ClangClangCodeModelServer : public ::testing::Test
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
void SetUp() override;
|
|
|
|
|
|
|
|
void registerFiles();
|
|
|
|
void registerProjectPart();
|
|
|
|
void changeProjectPartArguments();
|
|
|
|
void changeProjectPartArgumentsToWrongValues();
|
2015-11-25 15:29:28 +01:00
|
|
|
void updateVisibilty(const Utf8String ¤tEditor, const Utf8String &additionalVisibleEditor);
|
2015-06-01 18:51:55 +02:00
|
|
|
static const Utf8String unsavedContent(const QString &unsavedFilePath);
|
|
|
|
|
|
|
|
protected:
|
2016-06-29 16:49:56 +02:00
|
|
|
MockClangCodeModelClient mockClangCodeModelClient;
|
|
|
|
ClangBackEnd::ClangCodeModelServer clangServer;
|
2015-11-25 15:29:28 +01:00
|
|
|
const ClangBackEnd::TranslationUnits &translationUnits = clangServer.translationUnitsForTestOnly();
|
2015-06-01 18:51:55 +02:00
|
|
|
const Utf8String projectPartId = Utf8StringLiteral("pathToProjectPart.pro");
|
|
|
|
const Utf8String functionTestFilePath = Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp");
|
|
|
|
const Utf8String variableTestFilePath = Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_variable.cpp");
|
|
|
|
const QString unsavedTestFilePath = QStringLiteral(TESTDATA_DIR) + QStringLiteral("/complete_extractor_function_unsaved.cpp");
|
|
|
|
const QString updatedUnsavedTestFilePath = QStringLiteral(TESTDATA_DIR) + QStringLiteral("/complete_extractor_function_unsaved_2.cpp");
|
|
|
|
const Utf8String parseErrorTestFilePath = Utf8StringLiteral(TESTDATA_DIR"/complete_translationunit_parse_error.cpp");
|
|
|
|
};
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, GetCodeCompletion)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-19 12:36:43 +02:00
|
|
|
CompleteCodeMessage completeCodeMessage(functionTestFilePath,
|
2015-06-01 18:51:55 +02:00
|
|
|
20,
|
|
|
|
1,
|
|
|
|
projectPartId);
|
|
|
|
CodeCompletion codeCompletion(Utf8StringLiteral("Function"),
|
|
|
|
34,
|
|
|
|
CodeCompletion::FunctionCompletionKind);
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, codeCompleted(Property(&CodeCompletedMessage::codeCompletions, Contains(codeCompletion))))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
clangServer.completeCode(completeCodeMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, RequestHighlighting)
|
2015-11-18 17:07:44 +01:00
|
|
|
{
|
|
|
|
RequestHighlightingMessage requestHighlightingMessage({variableTestFilePath, projectPartId});
|
2016-03-03 13:02:29 +01:00
|
|
|
HighlightingTypes types;
|
|
|
|
types.mainHighlightingType = ClangBackEnd::HighlightingType::Function;
|
|
|
|
types.mixinHighlightingTypes.push_back(ClangBackEnd::HighlightingType::Declaration);
|
|
|
|
HighlightingMarkContainer highlightingMarkContainer(1, 6, 8, types);
|
2015-11-18 17:07:44 +01:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, highlightingChanged(Property(&HighlightingChangedMessage::highlightingMarks, Contains(highlightingMarkContainer))))
|
2015-11-18 17:07:44 +01:00
|
|
|
.Times(1);
|
|
|
|
|
|
|
|
clangServer.requestHighlighting(requestHighlightingMessage);
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, GetCodeCompletionDependingOnArgumets)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-19 12:36:43 +02:00
|
|
|
CompleteCodeMessage completeCodeMessage(variableTestFilePath,
|
2015-06-01 18:51:55 +02:00
|
|
|
35,
|
|
|
|
1,
|
|
|
|
projectPartId);
|
|
|
|
CodeCompletion codeCompletion(Utf8StringLiteral("ArgumentDefinitionVariable"),
|
|
|
|
34,
|
|
|
|
CodeCompletion::VariableCompletionKind);
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, codeCompleted(Property(&CodeCompletedMessage::codeCompletions, Contains(codeCompletion))))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
|
|
|
changeProjectPartArguments();
|
2015-08-19 12:36:43 +02:00
|
|
|
clangServer.completeCode(completeCodeMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, GetTranslationUnitDoesNotExistForEditorOnNonExistingTranslationUnit)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-19 12:36:43 +02:00
|
|
|
CompleteCodeMessage completeCodeMessage(Utf8StringLiteral("dontexists.cpp"),
|
2015-06-01 18:51:55 +02:00
|
|
|
34,
|
|
|
|
1,
|
|
|
|
projectPartId);
|
2015-08-19 12:36:43 +02:00
|
|
|
TranslationUnitDoesNotExistMessage translationUnitDoesNotExistMessage(Utf8StringLiteral("dontexists.cpp"), projectPartId);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, translationUnitDoesNotExist(translationUnitDoesNotExistMessage))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
clangServer.completeCode(completeCodeMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, GetTranslationUnitDoesNotExistForCompletingUnregisteredFile)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-19 12:36:43 +02:00
|
|
|
CompleteCodeMessage completeCodeMessage(parseErrorTestFilePath,
|
2015-06-01 18:51:55 +02:00
|
|
|
20,
|
|
|
|
1,
|
|
|
|
projectPartId);
|
2015-08-19 12:36:43 +02:00
|
|
|
TranslationUnitDoesNotExistMessage translationUnitDoesNotExistMessage(parseErrorTestFilePath, projectPartId);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, translationUnitDoesNotExist(translationUnitDoesNotExistMessage))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
clangServer.completeCode(completeCodeMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, GetCodeCompletionForUnsavedFile)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-19 12:36:43 +02:00
|
|
|
CompleteCodeMessage completeCodeMessage(functionTestFilePath,
|
2015-06-01 18:51:55 +02:00
|
|
|
20,
|
|
|
|
1,
|
|
|
|
projectPartId);
|
|
|
|
CodeCompletion codeCompletion(Utf8StringLiteral("Method2"),
|
|
|
|
34,
|
|
|
|
CodeCompletion::FunctionCompletionKind);
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, codeCompleted(Property(&CodeCompletedMessage::codeCompletions, Contains(codeCompletion))))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
clangServer.completeCode(completeCodeMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, GetNoCodeCompletionAfterRemovingUnsavedFile)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-11-05 13:57:57 +01:00
|
|
|
clangServer.updateTranslationUnitsForEditor(UpdateTranslationUnitsForEditorMessage(
|
|
|
|
{FileContainer(functionTestFilePath, projectPartId, Utf8StringVector(), 74)}));
|
2015-08-19 12:36:43 +02:00
|
|
|
CompleteCodeMessage completeCodeMessage(functionTestFilePath,
|
2015-06-01 18:51:55 +02:00
|
|
|
20,
|
|
|
|
1,
|
|
|
|
projectPartId);
|
|
|
|
CodeCompletion codeCompletion(Utf8StringLiteral("Method2"),
|
|
|
|
34,
|
|
|
|
CodeCompletion::FunctionCompletionKind);
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, codeCompleted(Property(&CodeCompletedMessage::codeCompletions, Not(Contains(codeCompletion)))))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
clangServer.completeCode(completeCodeMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, GetNewCodeCompletionAfterUpdatingUnsavedFile)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-10-13 15:56:41 +02:00
|
|
|
clangServer.updateTranslationUnitsForEditor(UpdateTranslationUnitsForEditorMessage({{functionTestFilePath,
|
|
|
|
projectPartId,
|
|
|
|
unsavedContent(updatedUnsavedTestFilePath),
|
|
|
|
true,
|
|
|
|
74}}));
|
2015-08-19 12:36:43 +02:00
|
|
|
CompleteCodeMessage completeCodeMessage(functionTestFilePath,
|
2015-06-01 18:51:55 +02:00
|
|
|
20,
|
|
|
|
1,
|
|
|
|
projectPartId);
|
|
|
|
CodeCompletion codeCompletion(Utf8StringLiteral("Method3"),
|
|
|
|
34,
|
|
|
|
CodeCompletion::FunctionCompletionKind);
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, codeCompleted(Property(&CodeCompletedMessage::codeCompletions, Contains(codeCompletion))))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
clangServer.completeCode(completeCodeMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, GetTranslationUnitDoesNotExistForUnregisterTranslationUnitWithWrongFilePath)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), projectPartId);
|
2015-08-31 14:36:58 +02:00
|
|
|
UnregisterTranslationUnitsForEditorMessage message({fileContainer});
|
2015-08-19 12:36:43 +02:00
|
|
|
TranslationUnitDoesNotExistMessage translationUnitDoesNotExistMessage(fileContainer);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, translationUnitDoesNotExist(translationUnitDoesNotExistMessage))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
clangServer.unregisterTranslationUnitsForEditor(message);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, UnregisterTranslationUnitAndTestFailingCompletion)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
FileContainer fileContainer(functionTestFilePath, projectPartId);
|
2015-08-31 14:36:58 +02:00
|
|
|
UnregisterTranslationUnitsForEditorMessage message({fileContainer});
|
|
|
|
clangServer.unregisterTranslationUnitsForEditor(message);
|
2015-08-19 12:36:43 +02:00
|
|
|
CompleteCodeMessage completeCodeMessage(functionTestFilePath,
|
2015-06-01 18:51:55 +02:00
|
|
|
20,
|
|
|
|
1,
|
|
|
|
projectPartId);
|
2015-08-19 12:36:43 +02:00
|
|
|
TranslationUnitDoesNotExistMessage translationUnitDoesNotExistMessage(fileContainer);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, translationUnitDoesNotExist(translationUnitDoesNotExistMessage))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
clangServer.completeCode(completeCodeMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, GetProjectPartDoesNotExistUnregisterProjectPartInexistingProjectPart)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
Utf8StringVector inexistingProjectPartFilePath = {Utf8StringLiteral("projectpartsdoesnotexist.pro"), Utf8StringLiteral("project2doesnotexists.pro")};
|
2015-08-31 14:36:58 +02:00
|
|
|
UnregisterProjectPartsForEditorMessage unregisterProjectPartsForEditorMessage(inexistingProjectPartFilePath);
|
2015-08-19 12:36:43 +02:00
|
|
|
ProjectPartsDoNotExistMessage projectPartsDoNotExistMessage(inexistingProjectPartFilePath);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, projectPartsDoNotExist(projectPartsDoNotExistMessage))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
clangServer.unregisterProjectPartsForEditor(unregisterProjectPartsForEditorMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, GetProjectPartDoesNotExistRegisterTranslationUnitWithInexistingProjectPart)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
Utf8String inexistingProjectPartFilePath = Utf8StringLiteral("projectpartsdoesnotexist.pro");
|
2015-12-02 13:31:07 +01:00
|
|
|
RegisterTranslationUnitForEditorMessage registerFileForEditorMessage({FileContainer(variableTestFilePath, inexistingProjectPartFilePath)},
|
|
|
|
variableTestFilePath,
|
|
|
|
{variableTestFilePath});
|
2015-08-19 12:36:43 +02:00
|
|
|
ProjectPartsDoNotExistMessage projectPartsDoNotExistMessage({inexistingProjectPartFilePath});
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, projectPartsDoNotExist(projectPartsDoNotExistMessage))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
clangServer.registerTranslationUnitsForEditor(registerFileForEditorMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, GetProjectPartDoesNotExistUnregisterTranslationUnitWithInexistingProjectPart)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
Utf8String inexistingProjectPartFilePath = Utf8StringLiteral("projectpartsdoesnotexist.pro");
|
2015-08-31 14:36:58 +02:00
|
|
|
UnregisterTranslationUnitsForEditorMessage unregisterFileForEditorMessage({FileContainer(variableTestFilePath, inexistingProjectPartFilePath)});
|
2015-08-19 12:36:43 +02:00
|
|
|
ProjectPartsDoNotExistMessage projectPartsDoNotExistMessage({inexistingProjectPartFilePath});
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, projectPartsDoNotExist(projectPartsDoNotExistMessage))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
clangServer.unregisterTranslationUnitsForEditor(unregisterFileForEditorMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, GetProjectPartDoesNotExistForCompletingProjectPartFile)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
Utf8String inexistingProjectPartFilePath = Utf8StringLiteral("projectpartsdoesnotexist.pro");
|
2015-08-19 12:36:43 +02:00
|
|
|
CompleteCodeMessage completeCodeMessage(variableTestFilePath,
|
2015-06-01 18:51:55 +02:00
|
|
|
20,
|
|
|
|
1,
|
|
|
|
inexistingProjectPartFilePath);
|
2015-08-19 12:36:43 +02:00
|
|
|
ProjectPartsDoNotExistMessage projectPartsDoNotExistMessage({inexistingProjectPartFilePath});
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, projectPartsDoNotExist(projectPartsDoNotExistMessage))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
clangServer.completeCode(completeCodeMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, GetProjectPartDoesNotExistForCompletingUnregisteredFile)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-19 12:36:43 +02:00
|
|
|
CompleteCodeMessage completeCodeMessage(parseErrorTestFilePath,
|
2015-06-01 18:51:55 +02:00
|
|
|
20,
|
|
|
|
1,
|
|
|
|
projectPartId);
|
2015-08-19 12:36:43 +02:00
|
|
|
TranslationUnitDoesNotExistMessage translationUnitDoesNotExistMessage(parseErrorTestFilePath, projectPartId);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, translationUnitDoesNotExist(translationUnitDoesNotExistMessage))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
clangServer.completeCode(completeCodeMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, TicketNumberIsForwarded)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-19 12:36:43 +02:00
|
|
|
CompleteCodeMessage completeCodeMessage(functionTestFilePath,
|
2015-06-01 18:51:55 +02:00
|
|
|
20,
|
|
|
|
1,
|
|
|
|
projectPartId);
|
|
|
|
CodeCompletion codeCompletion(Utf8StringLiteral("Function"),
|
|
|
|
34,
|
|
|
|
CodeCompletion::FunctionCompletionKind);
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, codeCompleted(Property(&CodeCompletedMessage::ticketNumber, Eq(completeCodeMessage.ticketNumber()))))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
clangServer.completeCode(completeCodeMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
2015-10-13 15:56:41 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, TranslationUnitAfterCreationNeedsNoReparseAndHasNoNewDiagnostics)
|
2015-10-13 15:56:41 +02:00
|
|
|
{
|
2015-12-02 13:31:07 +01:00
|
|
|
ASSERT_THAT(clangServer, HasDirtyTranslationUnit(functionTestFilePath, projectPartId, 0U, false, false));
|
2015-10-13 15:56:41 +02:00
|
|
|
}
|
2015-11-23 13:31:46 +01:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, SetCurrentAndVisibleEditor)
|
2015-11-25 15:29:28 +01:00
|
|
|
{
|
|
|
|
auto functionTranslationUnit = translationUnits.translationUnit(functionTestFilePath, projectPartId);
|
|
|
|
auto variableTranslationUnit = translationUnits.translationUnit(variableTestFilePath, projectPartId);
|
|
|
|
|
|
|
|
updateVisibilty(functionTestFilePath, variableTestFilePath);
|
|
|
|
|
|
|
|
ASSERT_TRUE(functionTranslationUnit.isUsedByCurrentEditor());
|
|
|
|
ASSERT_TRUE(functionTranslationUnit.isVisibleInEditor());
|
|
|
|
ASSERT_TRUE(variableTranslationUnit.isVisibleInEditor());
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, IsNotCurrentCurrentAndVisibleEditorAnymore)
|
2015-11-25 15:29:28 +01:00
|
|
|
{
|
|
|
|
auto functionTranslationUnit = translationUnits.translationUnit(functionTestFilePath, projectPartId);
|
|
|
|
auto variableTranslationUnit = translationUnits.translationUnit(variableTestFilePath, projectPartId);
|
|
|
|
updateVisibilty(functionTestFilePath, variableTestFilePath);
|
|
|
|
|
|
|
|
updateVisibilty(variableTestFilePath, Utf8String());
|
|
|
|
|
|
|
|
ASSERT_FALSE(functionTranslationUnit.isUsedByCurrentEditor());
|
|
|
|
ASSERT_FALSE(functionTranslationUnit.isVisibleInEditor());
|
|
|
|
ASSERT_TRUE(variableTranslationUnit.isUsedByCurrentEditor());
|
|
|
|
ASSERT_TRUE(variableTranslationUnit.isVisibleInEditor());
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
void ClangClangCodeModelServer::SetUp()
|
2015-11-25 15:29:28 +01:00
|
|
|
{
|
2016-07-04 16:14:42 +02:00
|
|
|
clangServer.setClient(&mockClangCodeModelClient);
|
2015-11-25 15:29:28 +01:00
|
|
|
registerProjectPart();
|
|
|
|
registerFiles();
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
void ClangClangCodeModelServer::registerFiles()
|
2015-11-25 15:29:28 +01:00
|
|
|
{
|
|
|
|
RegisterTranslationUnitForEditorMessage message({FileContainer(functionTestFilePath, projectPartId, unsavedContent(unsavedTestFilePath), true),
|
2015-12-02 13:31:07 +01:00
|
|
|
FileContainer(variableTestFilePath, projectPartId)},
|
|
|
|
functionTestFilePath,
|
|
|
|
{functionTestFilePath, variableTestFilePath});
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, diagnosticsChanged(_)).Times(2);
|
|
|
|
EXPECT_CALL(mockClangCodeModelClient, highlightingChanged(_)).Times(2);
|
2015-11-25 15:29:28 +01:00
|
|
|
|
|
|
|
clangServer.registerTranslationUnitsForEditor(message);
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
void ClangClangCodeModelServer::registerProjectPart()
|
2015-11-25 15:29:28 +01:00
|
|
|
{
|
|
|
|
RegisterProjectPartsForEditorMessage message({ProjectPartContainer(projectPartId)});
|
|
|
|
|
|
|
|
clangServer.registerProjectPartsForEditor(message);
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
void ClangClangCodeModelServer::changeProjectPartArguments()
|
2015-11-25 15:29:28 +01:00
|
|
|
{
|
|
|
|
RegisterProjectPartsForEditorMessage message({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-DArgumentDefinition")})});
|
|
|
|
|
|
|
|
clangServer.registerProjectPartsForEditor(message);
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
void ClangClangCodeModelServer::changeProjectPartArgumentsToWrongValues()
|
2015-11-25 15:29:28 +01:00
|
|
|
{
|
|
|
|
RegisterProjectPartsForEditorMessage message({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-blah")})});
|
|
|
|
|
|
|
|
clangServer.registerProjectPartsForEditor(message);
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
void ClangClangCodeModelServer::updateVisibilty(const Utf8String ¤tEditor, const Utf8String &additionalVisibleEditor)
|
2015-11-25 15:29:28 +01:00
|
|
|
{
|
|
|
|
UpdateVisibleTranslationUnitsMessage message(currentEditor,
|
|
|
|
{currentEditor, additionalVisibleEditor});
|
|
|
|
|
|
|
|
clangServer.updateVisibleTranslationUnits(message);
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
const Utf8String ClangClangCodeModelServer::unsavedContent(const QString &unsavedFilePath)
|
2015-11-25 15:29:28 +01:00
|
|
|
{
|
|
|
|
QFile unsavedFileContentFile(unsavedFilePath);
|
|
|
|
bool isOpen = unsavedFileContentFile.open(QIODevice::ReadOnly | QIODevice::Text);
|
|
|
|
if (!isOpen)
|
|
|
|
ADD_FAILURE() << "File with the unsaved content cannot be opened!";
|
|
|
|
|
|
|
|
return Utf8String::fromByteArray(unsavedFileContentFile.readAll());
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
TEST_F(ClangClangCodeModelServer, TranslationUnitAfterUpdateNeedsReparseAndHasNewDiagnostics)
|
2015-11-23 13:31:46 +01:00
|
|
|
{
|
|
|
|
const auto fileContainer = FileContainer(functionTestFilePath, projectPartId,unsavedContent(unsavedTestFilePath), true, 1);
|
|
|
|
|
|
|
|
clangServer.updateTranslationUnitsForEditor({{fileContainer}});
|
|
|
|
|
|
|
|
ASSERT_THAT(clangServer, HasDirtyTranslationUnit(functionTestFilePath, projectPartId, 1U, true, true));
|
|
|
|
}
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|