2015-06-01 18:51:55 +02:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
** Contact: http://www.qt.io/licensing
|
|
|
|
**
|
|
|
|
** 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
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
2015-06-16 12:38:04 +02:00
|
|
|
#include "mockipclient.h"
|
|
|
|
#include "mockipcserver.h"
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-06-16 12:38:04 +02:00
|
|
|
#include <ipcclientproxy.h>
|
|
|
|
#include <ipcserverproxy.h>
|
2015-08-19 12:36:43 +02:00
|
|
|
#include <projectpartsdonotexistmessage.h>
|
|
|
|
|
|
|
|
#include <cmbalivemessage.h>
|
|
|
|
#include <cmbcodecompletedmessage.h>
|
|
|
|
#include <cmbmessages.h>
|
|
|
|
#include <cmbcompletecodemessage.h>
|
|
|
|
#include <cmbechomessage.h>
|
|
|
|
#include <cmbendmessage.h>
|
|
|
|
#include <cmbregisterprojectsforcodecompletionmessage.h>
|
|
|
|
#include <cmbregistertranslationunitsforcodecompletionmessage.h>
|
|
|
|
#include <cmbunregisterprojectsforcodecompletionmessage.h>
|
|
|
|
#include <cmbunregistertranslationunitsforcodecompletionmessage.h>
|
2015-08-31 16:28:26 +02:00
|
|
|
#include <diagnosticschangedmessage.h>
|
|
|
|
#include <requestdiagnosticsmessage.h>
|
2015-08-19 12:36:43 +02:00
|
|
|
#include <readmessageblock.h>
|
|
|
|
#include <translationunitdoesnotexistmessage.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>
|
|
|
|
|
|
|
|
#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
|
|
|
|
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
|
|
|
|
|
|
|
QBuffer buffer;
|
|
|
|
MockIpcClient mockIpcClient;
|
|
|
|
MockIpcServer mockIpcServer;
|
|
|
|
|
2015-06-16 11:56:00 +02:00
|
|
|
ClangBackEnd::IpcServerProxy serverProxy;
|
|
|
|
ClangBackEnd::IpcClientProxy 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
|
|
|
{
|
|
|
|
EXPECT_CALL(mockIpcServer, end())
|
|
|
|
.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
|
|
|
{
|
|
|
|
EXPECT_CALL(mockIpcClient, alive())
|
|
|
|
.Times(1);
|
|
|
|
|
|
|
|
clientProxy.alive();
|
2015-08-19 12:36:43 +02:00
|
|
|
scheduleClientMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendRegisterTranslationUnitForCodeCompletionMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-06-16 11:56:00 +02:00
|
|
|
ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"),
|
2015-08-31 16:28:26 +02:00
|
|
|
Utf8StringLiteral("projectId"));
|
2015-08-19 12:36:43 +02:00
|
|
|
ClangBackEnd::RegisterTranslationUnitForCodeCompletionMessage message({fileContainer});
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
EXPECT_CALL(mockIpcServer, registerTranslationUnitsForCodeCompletion(message))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
serverProxy.registerTranslationUnitsForCodeCompletion(message);
|
|
|
|
scheduleServerMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendUnregisterTranslationUnitsForCodeCompletionMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 16:28:26 +02:00
|
|
|
ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), Utf8StringLiteral("projectId"));
|
2015-08-19 12:36:43 +02:00
|
|
|
ClangBackEnd::UnregisterTranslationUnitsForCodeCompletionMessage message({fileContainer});
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
EXPECT_CALL(mockIpcServer, unregisterTranslationUnitsForCodeCompletion(message))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
serverProxy.unregisterTranslationUnitsForCodeCompletion(message);
|
|
|
|
scheduleServerMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendCompleteCodeMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-19 12:36:43 +02:00
|
|
|
ClangBackEnd::CompleteCodeMessage message(Utf8StringLiteral("foo.cpp"), 24, 33, Utf8StringLiteral("do what I want"));
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
EXPECT_CALL(mockIpcServer, completeCode(message))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
serverProxy.completeCode(message);
|
|
|
|
scheduleServerMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2015-08-31 16:28:26 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendRequestDiagnosticsMessage)
|
|
|
|
{
|
|
|
|
ClangBackEnd::RequestDiagnosticsMessage message({Utf8StringLiteral("foo.cpp"),
|
|
|
|
Utf8StringLiteral("projectId")},
|
|
|
|
1);
|
|
|
|
|
|
|
|
EXPECT_CALL(mockIpcServer, requestDiagnostics(message))
|
|
|
|
.Times(1);
|
|
|
|
|
|
|
|
serverProxy.requestDiagnostics(message);
|
|
|
|
scheduleServerMessages();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendCodeCompletedMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-07-22 17:33:27 +02:00
|
|
|
ClangBackEnd::CodeCompletions codeCompletions({Utf8StringLiteral("newFunction()")});
|
2015-08-19 12:36:43 +02:00
|
|
|
ClangBackEnd::CodeCompletedMessage message(codeCompletions, 1);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
EXPECT_CALL(mockIpcClient, codeCompleted(message))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
clientProxy.codeCompleted(message);
|
|
|
|
scheduleClientMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendRegisterProjectPartsForCodeCompletionMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-06-16 11:56:00 +02:00
|
|
|
ClangBackEnd::ProjectPartContainer projectContainer(Utf8StringLiteral(TESTDATA_DIR"/complete.pro"));
|
2015-08-19 12:36:43 +02:00
|
|
|
ClangBackEnd::RegisterProjectPartsForCodeCompletionMessage message({projectContainer});
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
EXPECT_CALL(mockIpcServer, registerProjectPartsForCodeCompletion(message))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
serverProxy.registerProjectPartsForCodeCompletion(message);
|
|
|
|
scheduleServerMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendUnregisterProjectPartsForCodeCompletionMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-19 12:36:43 +02:00
|
|
|
ClangBackEnd::UnregisterProjectPartsForCodeCompletionMessage message({Utf8StringLiteral(TESTDATA_DIR"/complete.pro")});
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
EXPECT_CALL(mockIpcServer, unregisterProjectPartsForCodeCompletion(message))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
serverProxy.unregisterProjectPartsForCodeCompletion(message);
|
|
|
|
scheduleServerMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendTranslationUnitDoesNotExistMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-06-16 11:56:00 +02:00
|
|
|
ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"),
|
2015-08-31 16:28:26 +02:00
|
|
|
Utf8StringLiteral("projectId"));
|
2015-08-19 12:36:43 +02:00
|
|
|
ClangBackEnd::TranslationUnitDoesNotExistMessage message(fileContainer);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
EXPECT_CALL(mockIpcClient, translationUnitDoesNotExist(message))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
clientProxy.translationUnitDoesNotExist(message);
|
|
|
|
scheduleClientMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendProjectPartDoesNotExistMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 16:28:26 +02:00
|
|
|
ClangBackEnd::ProjectPartsDoNotExistMessage message({Utf8StringLiteral("projectId")});
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
EXPECT_CALL(mockIpcClient, projectPartsDoNotExist(message))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
clientProxy.projectPartsDoNotExist(message);
|
|
|
|
scheduleClientMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
2015-08-31 16:28:26 +02:00
|
|
|
|
|
|
|
TEST_F(ClientServerInProcess, SendDiagnosticsChangedMessage)
|
|
|
|
{
|
|
|
|
ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"),
|
|
|
|
Utf8StringLiteral("projectId"));
|
|
|
|
ClangBackEnd::DiagnosticContainer container(Utf8StringLiteral("don't do that"),
|
|
|
|
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}}},
|
|
|
|
{},
|
|
|
|
{});
|
|
|
|
ClangBackEnd::DiagnosticsChangedMessage message(fileContainer,
|
|
|
|
{container},
|
|
|
|
1);
|
|
|
|
|
|
|
|
EXPECT_CALL(mockIpcClient, diagnosticsChanged(message))
|
|
|
|
.Times(1);
|
|
|
|
|
|
|
|
clientProxy.diagnosticsChanged(message);
|
|
|
|
scheduleClientMessages();
|
|
|
|
}
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
ClientServerInProcess::ClientServerInProcess()
|
|
|
|
: serverProxy(&mockIpcClient, &buffer),
|
|
|
|
clientProxy(&mockIpcServer, &buffer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|