2
* Copyright © 2013 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Kevin DuBois <kevin.dubois@canonical.com>
19
#include "src/server/frontend/socket_session.h"
20
#include "src/server/frontend/message_receiver.h"
21
#include "src/server/frontend/message_processor.h"
23
#include "mir_test/fake_shared.h"
25
#include <gmock/gmock.h>
26
#include <gtest/gtest.h>
28
namespace mfd = mir::frontend::detail;
29
namespace ba = boost::asio;
30
namespace mt = mir::test;
34
struct MockReceiver : public mfd::MessageReceiver
36
MOCK_METHOD3(async_receive_msg, void(std::function<void(boost::system::error_code const&, size_t)> const&,
37
boost::asio::streambuf&, size_t));
38
MOCK_METHOD0(client_pid, pid_t());
41
struct MockProcessor : public mfd::MessageProcessor
43
MOCK_METHOD1(process_message, bool(std::istream&));
46
struct SocketSessionTest : public ::testing::Test
48
testing::NiceMock<MockProcessor> mock_processor;
49
testing::NiceMock<MockReceiver> mock_receiver;
52
TEST_F(SocketSessionTest, basic_msg)
54
using namespace testing;
56
std::shared_ptr<mfd::ConnectedSessions<mfd::SocketSession>> null_sessions;
57
std::function<void(boost::system::error_code const&, size_t)> header_read, body_read;
59
size_t header_size = 2;
60
EXPECT_CALL(mock_receiver, async_receive_msg(_,_, header_size))
62
.WillOnce(SaveArg<0>(&header_read));
64
mfd::SocketSession session(mt::fake_shared(mock_receiver), 0, null_sessions, mt::fake_shared(mock_processor));
66
//trigger wait for header
67
session.read_next_message();
68
testing::Mock::VerifyAndClearExpectations(&mock_receiver);
71
EXPECT_CALL(mock_receiver, async_receive_msg(_,_,_))
73
.WillOnce(SaveArg<0>(&body_read));
75
boost::system::error_code code;
78
testing::Mock::VerifyAndClearExpectations(&mock_receiver);
80
//trigger message process
81
EXPECT_CALL(mock_processor, process_message(_))
83
.WillOnce(Return(true));