~ubuntu-branches/ubuntu/vivid/mir/vivid

« back to all changes in this revision

Viewing changes to tests/unit-tests/graphics/android/test_android_platform.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-10-10 14:01:26 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20141010140126-n1czko8na1kuz4ll
Tags: upstream-0.8.0+14.10.20141010
Import upstream version 0.8.0+14.10.20141010

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: Kevin DuBois <kevin.dubois@canonical.com>
17
 
 */
18
 
 
19
 
#include "src/server/report/null_report_factory.h"
20
 
#include "mir/graphics/native_platform.h"
21
 
#include "mir/graphics/buffer_ipc_packer.h"
22
 
#include "mir/options/program_option.h"
23
 
#include "src/platform/graphics/android/android_platform.h"
24
 
#include "mir_test_doubles/mock_buffer.h"
25
 
#include "mir_test_doubles/mock_android_hw.h"
26
 
#include "mir_test_doubles/mock_buffer_packer.h"
27
 
#include "mir_test_doubles/mock_display_report.h"
28
 
#include "mir_test_doubles/stub_display_builder.h"
29
 
#include "mir_test_doubles/fd_matcher.h"
30
 
#include "mir_test/fake_shared.h"
31
 
#include "mir_test_doubles/mock_android_native_buffer.h"
32
 
#include <system/window.h>
33
 
#include <gtest/gtest.h>
34
 
 
35
 
namespace mg=mir::graphics;
36
 
namespace mga=mir::graphics::android;
37
 
namespace mt=mir::test;
38
 
namespace mtd=mir::test::doubles;
39
 
namespace mr=mir::report;
40
 
namespace geom=mir::geometry;
41
 
namespace mo=mir::options;
42
 
 
43
 
class PlatformBufferIPCPackaging : public ::testing::Test
44
 
{
45
 
protected:
46
 
    virtual void SetUp()
47
 
    {
48
 
        using namespace testing;
49
 
 
50
 
        stub_display_builder = std::make_shared<mtd::StubDisplayBuilder>();
51
 
        stub_display_report = mr::null_display_report();
52
 
        stride = geom::Stride(300*4);
53
 
 
54
 
        num_ints = 43;
55
 
        num_fds = 55;
56
 
        auto handle_size = sizeof(native_handle_t) + (sizeof(int)*(num_ints + num_fds));
57
 
        auto native_buffer_raw = (native_handle_t*) ::operator new(handle_size);
58
 
        native_buffer_handle = std::shared_ptr<native_handle_t>(native_buffer_raw);
59
 
 
60
 
        native_buffer_handle->numInts = num_ints;
61
 
        native_buffer_handle->numFds = num_fds;
62
 
        for(auto i=0u; i< (num_ints+num_fds); i++)
63
 
        {
64
 
            native_buffer_handle->data[i] = i;
65
 
        }
66
 
 
67
 
        native_buffer = std::make_shared<mtd::StubAndroidNativeBuffer>();
68
 
        mock_buffer = std::make_shared<NiceMock<mtd::MockBuffer>>();
69
 
 
70
 
        ON_CALL(*native_buffer, handle())
71
 
            .WillByDefault(Return(native_buffer_handle.get()));
72
 
        ON_CALL(*mock_buffer, native_buffer_handle())
73
 
            .WillByDefault(Return(native_buffer));
74
 
        ON_CALL(*mock_buffer, stride())
75
 
            .WillByDefault(Return(stride));
76
 
    }
77
 
 
78
 
    std::shared_ptr<mtd::MockAndroidNativeBuffer> native_buffer;
79
 
    std::shared_ptr<mtd::StubDisplayBuilder> stub_display_builder;
80
 
    std::shared_ptr<mtd::MockBuffer> mock_buffer;
81
 
    std::shared_ptr<native_handle_t> native_buffer_handle;
82
 
    std::shared_ptr<mg::DisplayReport> stub_display_report;
83
 
    geom::Stride stride;
84
 
    unsigned int num_ints, num_fds;
85
 
};
86
 
 
87
 
/* ipc packaging tests */
88
 
TEST_F(PlatformBufferIPCPackaging, test_ipc_data_packed_correctly_for_full_ipc)
89
 
{
90
 
    using namespace ::testing;
91
 
 
92
 
    mga::AndroidPlatform platform(stub_display_builder, stub_display_report);
93
 
 
94
 
    mtd::MockPacker mock_packer;
95
 
    int offset = 0;
96
 
    for(auto i=0u; i<num_fds; i++)
97
 
    {
98
 
        EXPECT_CALL(mock_packer, pack_fd(mtd::RawFdMatcher(native_buffer_handle->data[offset++])))
99
 
            .Times(1);
100
 
    }
101
 
    for(auto i=0u; i<num_ints; i++)
102
 
    {
103
 
        EXPECT_CALL(mock_packer, pack_data(native_buffer_handle->data[offset++]))
104
 
            .Times(1);
105
 
    }
106
 
 
107
 
    EXPECT_CALL(*mock_buffer, stride())
108
 
        .WillOnce(Return(stride));
109
 
    EXPECT_CALL(mock_packer, pack_stride(stride))
110
 
        .Times(1);
111
 
 
112
 
    EXPECT_CALL(*mock_buffer, size())
113
 
        .WillOnce(Return(mir::geometry::Size{123, 456}));
114
 
    EXPECT_CALL(mock_packer, pack_size(_))
115
 
        .Times(1);
116
 
 
117
 
    EXPECT_CALL(*native_buffer, ensure_available_for(mga::BufferAccess::write))
118
 
        .Times(1);
119
 
 
120
 
    platform.fill_buffer_package(
121
 
        &mock_packer, mock_buffer.get(), mg::BufferIpcMsgType::full_msg);
122
 
}
123
 
 
124
 
TEST_F(PlatformBufferIPCPackaging, test_ipc_data_packed_correctly_for_partial_ipc)
125
 
{
126
 
    using namespace ::testing;
127
 
 
128
 
    mga::AndroidPlatform platform(stub_display_builder, stub_display_report);
129
 
 
130
 
    mtd::MockPacker mock_packer;
131
 
    EXPECT_CALL(mock_packer, pack_fd(_))
132
 
        .Times(0);
133
 
    EXPECT_CALL(mock_packer, pack_data(_))
134
 
        .Times(0);
135
 
    EXPECT_CALL(mock_packer, pack_stride(_))
136
 
        .Times(0);
137
 
    EXPECT_CALL(mock_packer, pack_size(_))
138
 
        .Times(0);
139
 
 
140
 
    /* TODO: instead of waiting, pass the fd along */
141
 
    EXPECT_CALL(*native_buffer, ensure_available_for(mga::BufferAccess::write))
142
 
        .Times(1);
143
 
 
144
 
    platform.fill_buffer_package(
145
 
        &mock_packer, mock_buffer.get(), mg::BufferIpcMsgType::update_msg);
146
 
}
147
 
 
148
 
TEST(AndroidGraphicsPlatform, egl_native_display_is_egl_default_display)
149
 
{
150
 
    mga::AndroidPlatform platform(
151
 
        std::make_shared<mtd::StubDisplayBuilder>(),
152
 
        mr::null_display_report());
153
 
 
154
 
    EXPECT_EQ(EGL_DEFAULT_DISPLAY, platform.egl_native_display());
155
 
}
156
 
 
157
 
TEST(NestedPlatformCreation, doesnt_access_display_hardware)
158
 
{
159
 
    using namespace testing;
160
 
 
161
 
    mtd::HardwareAccessMock hwaccess;
162
 
    mtd::MockDisplayReport stub_report;
163
 
 
164
 
    EXPECT_CALL(hwaccess, hw_get_module(StrEq(HWC_HARDWARE_MODULE_ID), _))
165
 
        .Times(0);
166
 
    EXPECT_CALL(hwaccess, hw_get_module(StrEq(GRALLOC_HARDWARE_MODULE_ID), _))
167
 
        .Times(AtMost(1));
168
 
 
169
 
    auto platform = mg::create_native_platform(mt::fake_shared(stub_report));
170
 
}