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"
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-07-04 14:55:58 +02:00
|
|
|
#include <clangcodemodelconnectionclient.h>
|
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
|
|
|
|
2016-06-21 12:23:44 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
|
|
|
|
2015-06-16 12:38:04 +02:00
|
|
|
#include <QBuffer>
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QString>
|
|
|
|
#include <QVariant>
|
|
|
|
|
2017-01-30 10:05:42 +01:00
|
|
|
#include <memory>
|
2015-06-16 12:38:04 +02:00
|
|
|
#include <vector>
|
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
|
|
|
|
|
|
|
using ::testing::Eq;
|
2016-07-11 13:44:02 +02:00
|
|
|
using ::testing::SizeIs;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-01-30 10:05:42 +01:00
|
|
|
struct Data {
|
|
|
|
Data() : client(&mockClangCodeModelClient) {}
|
|
|
|
|
|
|
|
MockClangCodeModelClient mockClangCodeModelClient;
|
|
|
|
ClangBackEnd::ClangCodeModelConnectionClient client;
|
|
|
|
};
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
class ClientServerOutsideProcess : public ::testing::Test
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
void SetUp();
|
|
|
|
void TearDown();
|
|
|
|
|
|
|
|
static void SetUpTestCase();
|
|
|
|
static void TearDownTestCase();
|
|
|
|
|
2017-01-30 10:05:42 +01:00
|
|
|
static std::unique_ptr<Data> d;
|
|
|
|
MockClangCodeModelClient &mockClangCodeModelClient = d->mockClangCodeModelClient;
|
|
|
|
ClangBackEnd::ClangCodeModelConnectionClient &client = d->client;
|
2015-06-01 18:51:55 +02:00
|
|
|
};
|
|
|
|
|
2017-01-30 10:05:42 +01:00
|
|
|
std::unique_ptr<Data> ClientServerOutsideProcess::d;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-01-04 11:39:17 +01:00
|
|
|
using ClientServerOutsideProcessSlowTest = ClientServerOutsideProcess;
|
|
|
|
|
|
|
|
TEST_F(ClientServerOutsideProcessSlowTest, RestartProcessAsynchronously)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2016-07-11 13:44:02 +02:00
|
|
|
QSignalSpy clientSpy(&client, &ConnectionClient::connectedToLocalSocket);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-07-11 13:44:02 +02:00
|
|
|
client.restartProcessAsynchronously();
|
|
|
|
|
|
|
|
ASSERT_TRUE(clientSpy.wait(100000));
|
2015-06-01 18:51:55 +02:00
|
|
|
ASSERT_TRUE(client.isProcessIsRunning());
|
|
|
|
ASSERT_TRUE(client.isConnected());
|
|
|
|
}
|
|
|
|
|
2017-01-04 11:39:17 +01:00
|
|
|
TEST_F(ClientServerOutsideProcessSlowTest, RestartProcessAfterAliveTimeout)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2016-07-11 13:44:02 +02:00
|
|
|
QSignalSpy clientSpy(&client, &ConnectionClient::connectedToLocalSocket);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
client.setProcessAliveTimerInterval(1);
|
|
|
|
|
|
|
|
ASSERT_TRUE(clientSpy.wait(100000));
|
2016-07-11 13:44:02 +02:00
|
|
|
ASSERT_THAT(clientSpy, SizeIs(1));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2017-01-04 11:39:17 +01:00
|
|
|
TEST_F(ClientServerOutsideProcessSlowTest, RestartProcessAfterTermination)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2016-07-11 13:44:02 +02:00
|
|
|
QSignalSpy clientSpy(&client, &ConnectionClient::connectedToLocalSocket);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
client.processForTestOnly()->kill();
|
|
|
|
|
|
|
|
ASSERT_TRUE(clientSpy.wait(100000));
|
2016-07-11 13:44:02 +02:00
|
|
|
ASSERT_THAT(clientSpy, SizeIs(1));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
TEST_F(ClientServerOutsideProcess, SendRegisterTranslationUnitForEditorMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-12-02 13:31:07 +01:00
|
|
|
auto filePath = Utf8StringLiteral("foo.cpp");
|
|
|
|
ClangBackEnd::FileContainer fileContainer(filePath, Utf8StringLiteral("projectId"));
|
|
|
|
ClangBackEnd::RegisterTranslationUnitForEditorMessage registerTranslationUnitForEditorMessage({fileContainer},
|
|
|
|
filePath,
|
|
|
|
{filePath});
|
2016-02-08 13:23:28 +01:00
|
|
|
EchoMessage echoMessage(registerTranslationUnitForEditorMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, echo(echoMessage))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
client.serverProxy().registerTranslationUnitsForEditor(registerTranslationUnitForEditorMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
ASSERT_TRUE(client.waitForEcho());
|
|
|
|
}
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
TEST_F(ClientServerOutsideProcess, SendUnregisterTranslationUnitsForEditorMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 16:28:26 +02:00
|
|
|
FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), Utf8StringLiteral("projectId"));
|
2015-08-31 14:36:58 +02:00
|
|
|
ClangBackEnd::UnregisterTranslationUnitsForEditorMessage unregisterTranslationUnitsForEditorMessage ({fileContainer});
|
2016-02-08 13:23:28 +01:00
|
|
|
EchoMessage echoMessage(unregisterTranslationUnitsForEditorMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, echo(echoMessage))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
client.serverProxy().unregisterTranslationUnitsForEditor(unregisterTranslationUnitsForEditorMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
ASSERT_TRUE(client.waitForEcho());
|
|
|
|
}
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
TEST_F(ClientServerOutsideProcess, SendCompleteCodeMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-19 12:36:43 +02:00
|
|
|
CompleteCodeMessage codeCompleteMessage(Utf8StringLiteral("foo.cpp"), 24, 33, Utf8StringLiteral("do what I want"));
|
2016-02-08 13:23:28 +01:00
|
|
|
EchoMessage echoMessage(codeCompleteMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, echo(echoMessage))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-19 12:36:43 +02:00
|
|
|
client.serverProxy().completeCode(codeCompleteMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
ASSERT_TRUE(client.waitForEcho());
|
|
|
|
}
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
TEST_F(ClientServerOutsideProcess, 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 registerProjectPartsForEditorMessage({projectContainer});
|
2016-02-08 13:23:28 +01:00
|
|
|
EchoMessage echoMessage(registerProjectPartsForEditorMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, echo(echoMessage))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
client.serverProxy().registerProjectPartsForEditor(registerProjectPartsForEditorMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
ASSERT_TRUE(client.waitForEcho());
|
|
|
|
}
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
TEST_F(ClientServerOutsideProcess, SendUnregisterProjectPartsForEditorMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 14:36:58 +02:00
|
|
|
ClangBackEnd::UnregisterProjectPartsForEditorMessage unregisterProjectPartsForEditorMessage({Utf8StringLiteral(TESTDATA_DIR"/complete.pro")});
|
2016-02-08 13:23:28 +01:00
|
|
|
EchoMessage echoMessage(unregisterProjectPartsForEditorMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-29 16:49:56 +02:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, echo(echoMessage))
|
2015-06-01 18:51:55 +02:00
|
|
|
.Times(1);
|
|
|
|
|
2015-08-31 14:36:58 +02:00
|
|
|
client.serverProxy().unregisterProjectPartsForEditor(unregisterProjectPartsForEditorMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
ASSERT_TRUE(client.waitForEcho());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientServerOutsideProcess::SetUpTestCase()
|
|
|
|
{
|
2017-01-30 10:05:42 +01:00
|
|
|
d.reset(new Data);
|
|
|
|
|
|
|
|
QSignalSpy clientSpy(&d->client, &ConnectionClient::connectedToLocalSocket);
|
|
|
|
d->client.setProcessPath(Utils::HostOsInfo::withExecutableSuffix(QStringLiteral(ECHOSERVER)));
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-01-30 10:05:42 +01:00
|
|
|
d->client.startProcessAndConnectToServerAsynchronously();
|
2016-07-11 13:44:02 +02:00
|
|
|
|
|
|
|
ASSERT_TRUE(clientSpy.wait(100000));
|
|
|
|
ASSERT_THAT(clientSpy, SizeIs(1));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientServerOutsideProcess::TearDownTestCase()
|
|
|
|
{
|
2017-01-30 10:05:42 +01:00
|
|
|
d->client.finishProcess();
|
|
|
|
d.reset();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
void ClientServerOutsideProcess::SetUp()
|
|
|
|
{
|
|
|
|
client.setProcessAliveTimerInterval(1000000);
|
|
|
|
|
|
|
|
ASSERT_TRUE(client.isConnected());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientServerOutsideProcess::TearDown()
|
|
|
|
{
|
2016-07-11 13:44:02 +02:00
|
|
|
client.setProcessAliveTimerInterval(1000000);
|
|
|
|
client.waitForConnected();
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
ASSERT_TRUE(client.isProcessIsRunning());
|
|
|
|
ASSERT_TRUE(client.isConnected());
|
|
|
|
}
|