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
|
|
|
|
|
|
|
class ClientServerOutsideProcess : public ::testing::Test
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
void SetUp();
|
|
|
|
void TearDown();
|
|
|
|
|
2017-11-29 16:53:45 +01:00
|
|
|
protected:
|
|
|
|
NiceMock<MockClangCodeModelClient> mockClangCodeModelClient;
|
|
|
|
ClangBackEnd::ClangCodeModelConnectionClient client{&mockClangCodeModelClient};
|
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));
|
2016-08-17 15:29:37 +02:00
|
|
|
ASSERT_TRUE(client.isProcessRunning());
|
2015-06-01 18:51:55 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
TEST_F(ClientServerOutsideProcess, SendDocumentsOpenedMessage)
|
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"));
|
2018-05-31 15:21:53 +02:00
|
|
|
ClangBackEnd::DocumentsOpenedMessage documentsOpenedMessage({fileContainer},
|
|
|
|
filePath,
|
|
|
|
{filePath});
|
|
|
|
EchoMessage echoMessage(documentsOpenedMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-11-29 16:53:45 +01:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, echo(echoMessage));
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
client.serverProxy().documentsOpened(documentsOpenedMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
ASSERT_TRUE(client.waitForEcho());
|
|
|
|
}
|
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
TEST_F(ClientServerOutsideProcess, SendDocumentsClosedMessage)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 16:28:26 +02:00
|
|
|
FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), Utf8StringLiteral("projectId"));
|
2018-05-31 15:21:53 +02:00
|
|
|
ClangBackEnd::DocumentsClosedMessage documentsClosedMessage({fileContainer});
|
|
|
|
EchoMessage echoMessage(documentsClosedMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-11-29 16:53:45 +01:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, echo(echoMessage));
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
client.serverProxy().documentsClosed(documentsClosedMessage);
|
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
|
|
|
{
|
2018-09-25 09:41:32 +02:00
|
|
|
RequestCompletionsMessage codeCompleteMessage(Utf8StringLiteral("foo.cpp"), 24, 33);
|
2016-02-08 13:23:28 +01:00
|
|
|
EchoMessage echoMessage(codeCompleteMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-11-29 16:53:45 +01:00
|
|
|
EXPECT_CALL(mockClangCodeModelClient, echo(echoMessage));
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2018-05-31 15:21:53 +02:00
|
|
|
client.serverProxy().requestCompletions(codeCompleteMessage);
|
2015-06-01 18:51:55 +02:00
|
|
|
ASSERT_TRUE(client.waitForEcho());
|
|
|
|
}
|
|
|
|
|
2017-11-29 16:53:45 +01:00
|
|
|
void ClientServerOutsideProcess::SetUp()
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2017-11-29 16:53:45 +01:00
|
|
|
QSignalSpy clientSpy(&client, &ConnectionClient::connectedToLocalSocket);
|
|
|
|
client.setProcessPath(Utils::HostOsInfo::withExecutableSuffix(QStringLiteral(ECHOSERVER)));
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-11-29 16:53:45 +01:00
|
|
|
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
|
|
|
|
|
|
|
client.setProcessAliveTimerInterval(1000000);
|
|
|
|
|
|
|
|
ASSERT_TRUE(client.isConnected());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientServerOutsideProcess::TearDown()
|
|
|
|
{
|
2016-07-11 13:44:02 +02:00
|
|
|
client.setProcessAliveTimerInterval(1000000);
|
|
|
|
client.waitForConnected();
|
|
|
|
|
2016-08-17 15:29:37 +02:00
|
|
|
ASSERT_TRUE(client.isProcessRunning());
|
2015-06-01 18:51:55 +02:00
|
|
|
ASSERT_TRUE(client.isConnected());
|
2017-11-29 16:53:45 +01:00
|
|
|
|
|
|
|
client.finishProcess();
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|