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 <cmbcompletecodemessage.h>
|
|
|
|
#include <cmbechomessage.h>
|
|
|
|
#include <cmbendmessage.h>
|
2015-08-31 16:10:36 +02:00
|
|
|
#include <cmbmessages.h>
|
2015-08-31 14:36:58 +02:00
|
|
|
#include <cmbregisterprojectsforeditormessage.h>
|
|
|
|
#include <cmbregistertranslationunitsforeditormessage.h>
|
|
|
|
#include <cmbunregisterprojectsforeditormessage.h>
|
|
|
|
#include <cmbunregistertranslationunitsforeditormessage.h>
|
2015-08-31 16:28:26 +02:00
|
|
|
#include <diagnosticschangedmessage.h>
|
2015-08-19 12:36:43 +02:00
|
|
|
#include <readmessageblock.h>
|
2015-08-31 16:10:36 +02:00
|
|
|
#include <registerunsavedfilesforeditormessage.h>
|
|
|
|
#include <requestdiagnosticsmessage.h>
|
2015-08-19 12:36:43 +02:00
|
|
|
#include <translationunitdoesnotexistmessage.h>
|
2015-08-31 16:10:36 +02:00
|
|
|
#include <unregisterunsavedfilesforeditormessage.h>
|
2015-10-13 15:56:41 +02:00
|
|
|
#include <updatetranslationunitsforeditormessage.h>
|
2015-08-19 12:36:43 +02:00
|
|
|
#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
|
|
|
|
2015-08-31 16:10:36 +02:00
|
|
|
protected:
|
|
|
|
ClangBackEnd::FileContainer fileContainer{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"),
|
|
|
|
Utf8StringLiteral("projectPartId"),
|
|
|
|
Utf8StringLiteral("unsaved content"),
|
|
|
|
true,
|
|
|
|
1};
|
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-31 14:36:58 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendRegisterTranslationUnitForEditorMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 14:36:58 +02:00
|
|
|
ClangBackEnd::RegisterTranslationUnitForEditorMessage message({fileContainer});
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
EXPECT_CALL(mockIpcServer, registerTranslationUnitsForEditor(message))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
serverProxy.registerTranslationUnitsForEditor(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)
|
|
|
|
{
|
|
|
|
ClangBackEnd::UpdateTranslationUnitsForEditorMessage message({fileContainer});
|
|
|
|
|
|
|
|
EXPECT_CALL(mockIpcServer, updateTranslationUnitsForEditor(message))
|
|
|
|
.Times(1);
|
|
|
|
|
|
|
|
serverProxy.updateTranslationUnitsForEditor(message);
|
|
|
|
scheduleServerMessages();
|
|
|
|
}
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendUnregisterTranslationUnitsForEditorMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 14:36:58 +02:00
|
|
|
ClangBackEnd::UnregisterTranslationUnitsForEditorMessage message({fileContainer});
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
EXPECT_CALL(mockIpcServer, unregisterTranslationUnitsForEditor(message))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
serverProxy.unregisterTranslationUnitsForEditor(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)
|
|
|
|
{
|
|
|
|
ClangBackEnd::RegisterUnsavedFilesForEditorMessage message({fileContainer});
|
|
|
|
|
|
|
|
EXPECT_CALL(mockIpcServer, registerUnsavedFilesForEditor(message))
|
|
|
|
.Times(1);
|
|
|
|
|
|
|
|
serverProxy.registerUnsavedFilesForEditor(message);
|
|
|
|
scheduleServerMessages();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ClientServerInProcess, SendUnregisterUnsavedFilesForEditorMessage)
|
|
|
|
{
|
|
|
|
ClangBackEnd::UnregisterUnsavedFilesForEditorMessage message({fileContainer});
|
|
|
|
|
|
|
|
EXPECT_CALL(mockIpcServer, unregisterUnsavedFilesForEditor(message))
|
|
|
|
.Times(1);
|
|
|
|
|
|
|
|
serverProxy.unregisterUnsavedFilesForEditor(message);
|
|
|
|
scheduleServerMessages();
|
|
|
|
}
|
|
|
|
|
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"),
|
2015-08-31 12:40:14 +02:00
|
|
|
Utf8StringLiteral("projectId")});
|
2015-08-31 16:28:26 +02:00
|
|
|
|
|
|
|
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-31 14:36:58 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendRegisterProjectPartsForEditorMessage)
|
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-31 14:36:58 +02:00
|
|
|
ClangBackEnd::RegisterProjectPartsForEditorMessage message({projectContainer});
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
EXPECT_CALL(mockIpcServer, registerProjectPartsForEditor(message))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
serverProxy.registerProjectPartsForEditor(message);
|
2015-08-19 12:36:43 +02:00
|
|
|
scheduleServerMessages();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
TEST_F(ClientServerInProcess, SendUnregisterProjectPartsForEditorMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 14:36:58 +02:00
|
|
|
ClangBackEnd::UnregisterProjectPartsForEditorMessage message({Utf8StringLiteral(TESTDATA_DIR"/complete.pro")});
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
EXPECT_CALL(mockIpcServer, unregisterProjectPartsForEditor(message))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
serverProxy.unregisterProjectPartsForEditor(message);
|
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, SendTranslationUnitDoesNotExistMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
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::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,
|
2015-08-31 12:40:14 +02:00
|
|
|
{container});
|
2015-08-31 16:28:26 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|