2
* Copyright © 2012 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: Alexandros Frantzis <alexandros.frantzis@canonical.com>
19
#include "mir/frontend/session_mediator_report.h"
20
#include "src/server/frontend/session_mediator.h"
21
#include "src/server/frontend/resource_cache.h"
22
#include "src/server/scene/application_session.h"
23
#include "mir/frontend/shell.h"
24
#include "mir/graphics/display.h"
25
#include "mir/graphics/drm_authenticator.h"
26
#include "mir/frontend/event_sink.h"
28
#include <boost/exception/errinfo_errno.hpp>
29
#include <boost/throw_exception.hpp>
31
#include "mir_test_doubles/null_display.h"
32
#include "mir_test_doubles/null_event_sink.h"
33
#include "mir_test_doubles/null_display_changer.h"
34
#include "mir_test_doubles/null_platform.h"
35
#include "mir_test_doubles/mock_session.h"
36
#include "mir_test_doubles/stub_shell.h"
38
#include <gtest/gtest.h>
39
#include <gmock/gmock.h>
41
namespace mf = mir::frontend;
42
namespace mg = mir::graphics;
43
namespace geom = mir::geometry;
44
namespace mp = mir::protobuf;
45
namespace msh = mir::shell;
46
namespace mtd = mir::test::doubles;
51
class MockAuthenticatingPlatform : public mtd::NullPlatform, public mg::DRMAuthenticator
54
std::shared_ptr<mg::GraphicBufferAllocator> create_buffer_allocator(
55
const std::shared_ptr<mg::BufferInitializer>& /*buffer_initializer*/) override
57
return std::shared_ptr<mg::GraphicBufferAllocator>();
60
MOCK_METHOD1(drm_auth_magic, void(drm_magic_t));
63
struct SessionMediatorGBMTest : public ::testing::Test
65
SessionMediatorGBMTest()
66
: shell{std::make_shared<mtd::StubShell>()},
67
mock_platform{std::make_shared<MockAuthenticatingPlatform>()},
68
display_changer{std::make_shared<mtd::NullDisplayChanger>()},
69
surface_pixel_formats{geom::PixelFormat::argb_8888, geom::PixelFormat::xrgb_8888},
70
report{std::make_shared<mf::NullSessionMediatorReport>()},
71
resource_cache{std::make_shared<mf::ResourceCache>()},
72
mediator{shell, mock_platform, display_changer,
73
surface_pixel_formats, report,
74
std::make_shared<mtd::NullEventSink>(),
76
null_callback{google::protobuf::NewPermanentCallback(google::protobuf::DoNothing)}
80
std::shared_ptr<mtd::StubShell> const shell;
81
std::shared_ptr<MockAuthenticatingPlatform> const mock_platform;
82
std::shared_ptr<mf::DisplayChanger> const display_changer;
83
std::vector<geom::PixelFormat> const surface_pixel_formats;
84
std::shared_ptr<mf::SessionMediatorReport> const report;
85
std::shared_ptr<mf::ResourceCache> const resource_cache;
86
mf::SessionMediator mediator;
88
std::unique_ptr<google::protobuf::Closure> null_callback;
93
TEST_F(SessionMediatorGBMTest, drm_auth_magic_uses_drm_authenticator)
95
mp::ConnectParameters connect_parameters;
96
mp::Connection connection;
98
drm_magic_t const drm_magic{0x10111213};
99
int const no_error{0};
101
EXPECT_CALL(*mock_platform, drm_auth_magic(drm_magic))
104
mediator.connect(nullptr, &connect_parameters, &connection, null_callback.get());
107
mp::DRMAuthMagicStatus status;
108
magic.set_magic(drm_magic);
110
mediator.drm_auth_magic(nullptr, &magic, &status, null_callback.get());
112
EXPECT_EQ(no_error, status.status_code());
115
TEST_F(SessionMediatorGBMTest, drm_auth_magic_sets_status_code_on_error)
117
using namespace testing;
119
mp::ConnectParameters connect_parameters;
120
mp::Connection connection;
122
drm_magic_t const drm_magic{0x10111213};
123
int const error_number{667};
125
EXPECT_CALL(*mock_platform, drm_auth_magic(drm_magic))
126
.WillOnce(Throw(::boost::enable_error_info(std::exception())
127
<< boost::errinfo_errno(error_number)));
129
mediator.connect(nullptr, &connect_parameters, &connection, null_callback.get());
132
mp::DRMAuthMagicStatus status;
133
magic.set_magic(drm_magic);
135
mediator.drm_auth_magic(nullptr, &magic, &status, null_callback.get());
137
EXPECT_EQ(error_number, status.status_code());