1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
/*
* Copyright © Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 or 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "src/server/scene/broadcasting_session_event_sink.h"
#include <mir/test/doubles/stub_session.h>
#include <mir/test/fake_shared.h>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
namespace ms = mir::scene;
namespace mtd = mir::test::doubles;
namespace mt = mir::test;
using namespace testing;
namespace
{
struct MockEventSink : ms::SessionEventSink
{
MOCK_METHOD(void, handle_focus_change, (std::shared_ptr<ms::Session> const& session), (override));
MOCK_METHOD(void, handle_session_stopping, (std::shared_ptr<ms::Session> const& session), (override));
MOCK_METHOD(void, handle_no_focus, (), (override));
};
}
TEST(BroadcastingSessionEventSinkTest, emits_and_handles_focus_change)
{
mtd::StubSession session1;
MockEventSink handler_called[3];
ms::BroadcastingSessionEventSink events;
std::shared_ptr<ms::Session> session1ptr{mt::fake_shared(session1)};
for (auto& h : handler_called)
{
events.add(&h);
EXPECT_CALL(h, handle_focus_change(session1ptr)).Times(1);
}
events.handle_focus_change(session1ptr);
}
TEST(BroadcastingSessionEventSinkTest, emits_and_handles_no_focus)
{
mtd::StubSession session1;
MockEventSink handler_called[3];
ms::BroadcastingSessionEventSink events;
for (auto& h : handler_called)
{
events.add(&h);
EXPECT_CALL(h, handle_no_focus()).Times(1);
}
events.handle_no_focus();
}
TEST(BroadcastingSessionEventSinkTest, emits_and_handles_session_stopping)
{
mtd::StubSession session1;
MockEventSink handler_called[3];
ms::BroadcastingSessionEventSink events;
std::shared_ptr<ms::Session> session1ptr{mt::fake_shared(session1)};
for (auto& h : handler_called)
{
events.add(&h);
EXPECT_CALL(h, handle_session_stopping(session1ptr)).Times(1);
}
events.handle_session_stopping(session1ptr);
}
|