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-09-15 17:41:41 +02:00
|
|
|
#include "googletest.h"
|
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
#include "mockclangcodemodelclient.h"
|
|
|
|
#include "mockclangcodemodelserver.h"
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
#include <clangcodemodelclientproxy.h>
|
|
|
|
#include <clangcodemodelserverproxy.h>
|
2015-08-19 12:36:43 +02:00
|
|
|
|
2017-06-15 16:43:37 +02:00
|
|
|
#include <clangcodemodelservermessages.h>
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
#include <readmessageblock.h>
|
|
|
|
#include <writemessageblock.h>
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-06-16 12:38:04 +02:00
|
|
|
#include <QBuffer>
|
|
|
|
#include <QString>
|
|
|
|
#include <QVariant>
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-06-16 12:38:04 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2015-06-16 11:56:00 +02:00
|
|
|
using namespace ClangBackEnd;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using ::testing::Args;
|
|
|
|
using ::testing::Property;
|
|
|
|
using ::testing::Eq;
|
|
|
|
|
|
|
|
class ClientServerInProcess : public ::testing::Test
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
ClientServerInProcess();
|
|
|
|
|
|
|
|
void SetUp();
|
|
|
|
void TearDown();
|
|
|
|
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
void scheduleServerMessages();
|
|
|
|
void scheduleClientMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-08-31 16:10:36 +02:00
|
|
|
protected:
|
2015-12-02 13:31:07 +01:00
|
|
|
Utf8String filePath{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp")};
|
|
|
|
ClangBackEnd::FileContainer fileContainer{filePath,
|
2015-08-31 16:10:36 +02:00
|
|
|
Utf8StringLiteral("unsaved content"),
|
|
|
|
true,
|
|
|
|
1};
|
2015-06-01 18:51:55 +02:00
|
|
|
QBuffer buffer;
|
2016-06-29 16:49:56 +02:00
|
|
|
MockClangCodeModelClient mockClangCodeModelClient;
|
|
|
|
MockClangCodeModelServer mockClangCodeModelServer;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
ClangBackEnd::ClangCodeModelServerProxy serverProxy;
|
|
|
|
ClangBackEnd::ClangCodeModelClientProxy clientProxy;
|
2015-06-01 18:51:55 +02:00
|
|
|
};
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendEndMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelServer, end())
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
|
|
|
serverProxy.end();
|
2015-08-19 12:36:43 +02:00
|
|
|
scheduleServerMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendAliveMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, alive())
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
|
|
|
clientProxy.alive();
|
2015-08-19 12:36:43 +02:00
|
|
|
scheduleClientMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendDocumentsOpenedMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2018-05-31 15:21:53 +02:00
|
|
|
ClangBackEnd::DocumentsOpenedMessage message({fileContainer}, filePath, {filePath});
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelServer, documentsOpened(message))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
serverProxy.documentsOpened(message);
|
2015-08-19 12:36:43 +02:00
|
|
|
scheduleServerMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2015-10-13 15:56:41 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendUpdateTranslationUnitsForEditorMessage)
|
|
|
|
{
|
2018-05-31 15:21:53 +02:00
|
|
|
ClangBackEnd::DocumentsChangedMessage message({fileContainer});
|
2015-10-13 15:56:41 +02:00
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelServer, documentsChanged(message))
|
2015-10-13 15:56:41 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
serverProxy.documentsChanged(message);
|
2015-10-13 15:56:41 +02:00
|
|
|
scheduleServerMessages();
|
|
|
|
}
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendDocumentsClosedMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2018-05-31 15:21:53 +02:00
|
|
|
ClangBackEnd::DocumentsClosedMessage message({fileContainer});
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelServer, documentsClosed(message))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
serverProxy.documentsClosed(message);
|
2015-08-19 12:36:43 +02:00
|
|
|
scheduleServerMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2015-08-31 16:10:36 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendRegisterUnsavedFilesForEditorMessage)
|
|
|
|
{
|
2018-05-31 15:21:53 +02:00
|
|
|
ClangBackEnd::UnsavedFilesUpdatedMessage message({fileContainer});
|
2015-08-31 16:10:36 +02:00
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelServer, unsavedFilesUpdated(message))
|
2015-08-31 16:10:36 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
serverProxy.unsavedFilesUpdated(message);
|
2015-08-31 16:10:36 +02:00
|
|
|
scheduleServerMessages();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ClientServerInProcess, SendUnregisterUnsavedFilesForEditorMessage)
|
|
|
|
{
|
2018-05-31 15:21:53 +02:00
|
|
|
ClangBackEnd::UnsavedFilesRemovedMessage message({fileContainer});
|
2015-08-31 16:10:36 +02:00
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelServer, unsavedFilesRemoved(message))
|
2015-08-31 16:10:36 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
serverProxy.unsavedFilesRemoved(message);
|
2015-08-31 16:10:36 +02:00
|
|
|
scheduleServerMessages();
|
|
|
|
}
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendCompleteCodeMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2018-09-25 09:41:32 +02:00
|
|
|
ClangBackEnd::RequestCompletionsMessage message(Utf8StringLiteral("foo.cpp"), 24, 33);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelServer, requestCompletions(message))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
serverProxy.requestCompletions(message);
|
2015-08-19 12:36:43 +02:00
|
|
|
scheduleServerMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendRequestAnnotationsMessage)
|
2015-08-31 16:28:26 +02:00
|
|
|
{
|
2018-05-31 15:21:53 +02:00
|
|
|
ClangBackEnd::RequestAnnotationsMessage message(
|
|
|
|
{Utf8StringLiteral("foo.cpp"), Utf8StringLiteral("projectId")});
|
2015-08-31 16:28:26 +02:00
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelServer, requestAnnotations(message))
|
2015-08-31 16:28:26 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
serverProxy.requestAnnotations(message);
|
2015-11-18 17:07:44 +01:00
|
|
|
scheduleServerMessages();
|
|
|
|
}
|
2015-08-31 16:28:26 +02:00
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendCompletionsMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-07-22 17:33:27 +02:00
|
|
|
ClangBackEnd::CodeCompletions codeCompletions({Utf8StringLiteral("newFunction()")});
|
2018-06-15 14:35:58 +02:00
|
|
|
ClangBackEnd::CompletionsMessage message(codeCompletions, 1);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, completions(message))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
clientProxy.completions(message);
|
2015-08-19 12:36:43 +02:00
|
|
|
scheduleClientMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
TEST_F(ClientServerInProcess, DocumentVisibilityChangedMessage)
|
2015-11-25 15:29:28 +01:00
|
|
|
{
|
2018-05-31 15:21:53 +02:00
|
|
|
ClangBackEnd::DocumentVisibilityChangedMessage
|
|
|
|
message(Utf8StringLiteral(TESTDATA_DIR "/fileone.cpp"),
|
|
|
|
{Utf8StringLiteral(TESTDATA_DIR "/fileone.cpp"),
|
|
|
|
Utf8StringLiteral(TESTDATA_DIR "/filetwo.cpp")});
|
2015-11-25 15:29:28 +01:00
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelServer, documentVisibilityChanged(message))
|
2015-11-25 15:29:28 +01:00
|
|
|
.Times(1);
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
serverProxy.documentVisibilityChanged(message);
|
2015-11-25 15:29:28 +01:00
|
|
|
scheduleServerMessages();
|
|
|
|
}
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendAnnotationsMessage)
|
2015-08-31 16:28:26 +02:00
|
|
|
{
|
2018-02-23 12:28:30 +01:00
|
|
|
ClangBackEnd::HighlightingTypes types;
|
|
|
|
types.mainHighlightingType = ClangBackEnd::HighlightingType::Keyword;
|
|
|
|
ClangBackEnd::TokenInfoContainer tokenInfo(1, 1, 1, types);
|
2016-06-09 12:55:42 +02:00
|
|
|
ClangBackEnd::DiagnosticContainer diagnostic(Utf8StringLiteral("don't do that"),
|
2015-08-31 16:28:26 +02:00
|
|
|
Utf8StringLiteral("warning"),
|
|
|
|
{Utf8StringLiteral("-Wpadded"), Utf8StringLiteral("-Wno-padded")},
|
|
|
|
ClangBackEnd::DiagnosticSeverity::Warning,
|
|
|
|
{Utf8StringLiteral("foo.cpp"), 20u, 103u},
|
|
|
|
{{{Utf8StringLiteral("foo.cpp"), 20u, 103u}, {Utf8StringLiteral("foo.cpp"), 20u, 110u}}},
|
|
|
|
{},
|
|
|
|
{});
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
ClangBackEnd::AnnotationsMessage message(fileContainer,
|
|
|
|
{diagnostic},
|
|
|
|
{},
|
|
|
|
{tokenInfo},
|
|
|
|
QVector<SourceRangeContainer>());
|
2015-08-31 16:28:26 +02:00
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, annotations(message))
|
2015-11-18 17:07:44 +01:00
|
|
|
.Times(1);
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
clientProxy.annotations(message);
|
2015-11-18 17:07:44 +01:00
|
|
|
scheduleClientMessages();
|
|
|
|
}
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
ClientServerInProcess::ClientServerInProcess()
|
2016-06-29 16:49:56 +02:00
|
|
|
: serverProxy(&mockClangCodeModelClient, &buffer),
|
|
|
|
clientProxy(&mockClangCodeModelServer, &buffer)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientServerInProcess::SetUp()
|
|
|
|
{
|
|
|
|
buffer.open(QIODevice::ReadWrite);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientServerInProcess::TearDown()
|
|
|
|
{
|
|
|
|
buffer.close();
|
|
|
|
}
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
void ClientServerInProcess::scheduleServerMessages()
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
buffer.seek(0);
|
2015-08-19 12:36:43 +02:00
|
|
|
clientProxy.readMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
buffer.buffer().clear();
|
|
|
|
}
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
void ClientServerInProcess::scheduleClientMessages()
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
|
|
|
buffer.seek(0);
|
2015-08-19 12:36:43 +02:00
|
|
|
serverProxy.readMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
buffer.buffer().clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|