~ubuntu-branches/ubuntu/wily/mir/wily-proposed

« back to all changes in this revision

Viewing changes to tests/unit-tests/frontend/test_session_mediator_gbm.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-01-08 02:04:38 UTC
  • mto: This revision was merged to the branch mainline in revision 58.
  • Revision ID: package-import@ubuntu.com-20140108020438-e1npu0pm7qdv5wc4
Tags: upstream-0.1.3+14.04.20140108
Import upstream version 0.1.3+14.04.20140108

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2012 Canonical Ltd.
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 *
16
 
 * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17
 
 */
18
 
 
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"
27
 
 
28
 
#include <boost/exception/errinfo_errno.hpp>
29
 
#include <boost/throw_exception.hpp>
30
 
 
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"
37
 
 
38
 
#include <gtest/gtest.h>
39
 
#include <gmock/gmock.h>
40
 
 
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;
47
 
 
48
 
namespace
49
 
{
50
 
 
51
 
class MockAuthenticatingPlatform : public mtd::NullPlatform, public mg::DRMAuthenticator
52
 
{
53
 
 public:
54
 
    std::shared_ptr<mg::GraphicBufferAllocator> create_buffer_allocator(
55
 
        const std::shared_ptr<mg::BufferInitializer>& /*buffer_initializer*/) override
56
 
    {
57
 
        return std::shared_ptr<mg::GraphicBufferAllocator>();
58
 
    }
59
 
 
60
 
    MOCK_METHOD1(drm_auth_magic, void(drm_magic_t));
61
 
};
62
 
 
63
 
struct SessionMediatorGBMTest : public ::testing::Test
64
 
{
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>(),
75
 
                   resource_cache},
76
 
          null_callback{google::protobuf::NewPermanentCallback(google::protobuf::DoNothing)}
77
 
    {
78
 
    }
79
 
 
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;
87
 
 
88
 
    std::unique_ptr<google::protobuf::Closure> null_callback;
89
 
};
90
 
 
91
 
}
92
 
 
93
 
TEST_F(SessionMediatorGBMTest, drm_auth_magic_uses_drm_authenticator)
94
 
{
95
 
    mp::ConnectParameters connect_parameters;
96
 
    mp::Connection connection;
97
 
 
98
 
    drm_magic_t const drm_magic{0x10111213};
99
 
    int const no_error{0};
100
 
 
101
 
    EXPECT_CALL(*mock_platform, drm_auth_magic(drm_magic))
102
 
        .Times(1);
103
 
 
104
 
    mediator.connect(nullptr, &connect_parameters, &connection, null_callback.get());
105
 
 
106
 
    mp::DRMMagic magic;
107
 
    mp::DRMAuthMagicStatus status;
108
 
    magic.set_magic(drm_magic);
109
 
 
110
 
    mediator.drm_auth_magic(nullptr, &magic, &status, null_callback.get());
111
 
 
112
 
    EXPECT_EQ(no_error, status.status_code());
113
 
}
114
 
 
115
 
TEST_F(SessionMediatorGBMTest, drm_auth_magic_sets_status_code_on_error)
116
 
{
117
 
    using namespace testing;
118
 
 
119
 
    mp::ConnectParameters connect_parameters;
120
 
    mp::Connection connection;
121
 
 
122
 
    drm_magic_t const drm_magic{0x10111213};
123
 
    int const error_number{667};
124
 
 
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)));
128
 
 
129
 
    mediator.connect(nullptr, &connect_parameters, &connection, null_callback.get());
130
 
 
131
 
    mp::DRMMagic magic;
132
 
    mp::DRMAuthMagicStatus status;
133
 
    magic.set_magic(drm_magic);
134
 
 
135
 
    mediator.drm_auth_magic(nullptr, &magic, &status, null_callback.get());
136
 
 
137
 
    EXPECT_EQ(error_number, status.status_code());
138
 
}