~mir-team/mir/in-process-egl+input-conglomeration

« back to all changes in this revision

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

Merged trunk and fixed issues

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2013 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/graphics/android/internal_client_window.h"
 
20
#include "mir_test_doubles/mock_buffer.h"
 
21
#include "mir_test_doubles/mock_swapper.h"
 
22
#include "mir_test_doubles/mock_interpreter_resource_cache.h"
 
23
#include "mir/frontend/surface.h"
 
24
 
 
25
#include <gtest/gtest.h>
 
26
#include <stdexcept>
 
27
 
 
28
namespace mc=mir::compositor;
 
29
namespace mtd=mir::test::doubles;
 
30
namespace mga=mir::graphics::android;
 
31
namespace geom=mir::geometry;
 
32
namespace mf=mir::frontend;
 
33
 
 
34
namespace
 
35
{
 
36
struct MockSurface : public mf::Surface
 
37
{
 
38
    MOCK_METHOD0(destroy, void());
 
39
    MOCK_METHOD0(force_requests_to_complete, void());
 
40
    MOCK_CONST_METHOD0(size, geom::Size());
 
41
    MOCK_CONST_METHOD0(pixel_format, geom::PixelFormat());
 
42
 
 
43
    MOCK_METHOD0(advance_client_buffer, void());
 
44
    MOCK_CONST_METHOD0(client_buffer, std::shared_ptr<mc::Buffer>());
 
45
 
 
46
    MOCK_CONST_METHOD0(supports_input, bool());
 
47
    MOCK_CONST_METHOD0(client_input_fd, int());
 
48
    MOCK_METHOD2(configure, int(MirSurfaceAttrib, int));
 
49
};
 
50
 
 
51
struct InternalClientWindow : public ::testing::Test
 
52
{
 
53
    void SetUp()
 
54
    {
 
55
        using namespace testing;
 
56
        sz = geom::Size{geom::Width{4}, geom::Height{23}};
 
57
        pf = geom::PixelFormat::abgr_8888;
 
58
        mock_cache = std::make_shared<mtd::MockInterpreterResourceCache>();
 
59
        mock_surface = std::make_shared<MockSurface>();
 
60
        mock_buffer = std::make_shared<mtd::MockBuffer>();
 
61
        stub_anw = std::make_shared<ANativeWindowBuffer>();
 
62
 
 
63
        ON_CALL(*mock_surface, client_buffer())
 
64
            .WillByDefault(Return(mock_buffer));
 
65
        ON_CALL(*mock_surface, pixel_format())
 
66
            .WillByDefault(Return(geom::PixelFormat::abgr_8888));
 
67
        ON_CALL(*mock_buffer, native_buffer_handle())
 
68
            .WillByDefault(Return(stub_anw));
 
69
    }
 
70
 
 
71
    std::shared_ptr<ANativeWindowBuffer> stub_anw;
 
72
    std::shared_ptr<mtd::MockInterpreterResourceCache> mock_cache;
 
73
    std::shared_ptr<MockSurface> mock_surface;
 
74
    std::shared_ptr<mtd::MockBuffer> mock_buffer;
 
75
    geom::Size sz;
 
76
    geom::PixelFormat pf;
 
77
};
 
78
}
 
79
 
 
80
TEST_F(InternalClientWindow, driver_requests_buffer)
 
81
{
 
82
    using namespace testing;
 
83
    EXPECT_CALL(*mock_surface, client_buffer())
 
84
        .Times(1);
 
85
    EXPECT_CALL(*mock_buffer, native_buffer_handle())
 
86
        .Times(1);
 
87
    std::shared_ptr<mc::Buffer> tmp = mock_buffer;
 
88
    EXPECT_CALL(*mock_cache, store_buffer(tmp, stub_anw.get()))
 
89
        .Times(1);
 
90
 
 
91
    mga::InternalClientWindow interpreter(mock_surface, mock_cache);
 
92
    auto test_buffer = interpreter.driver_requests_buffer();
 
93
    EXPECT_EQ(stub_anw.get(), test_buffer); 
 
94
}
 
95
 
 
96
TEST_F(InternalClientWindow, driver_returns_buffer)
 
97
{
 
98
    using namespace testing;
 
99
    std::shared_ptr<mga::SyncObject> fake_sync;
 
100
 
 
101
    EXPECT_CALL(*mock_cache, retrieve_buffer(stub_anw.get()))
 
102
        .Times(1)
 
103
        .WillOnce(Return(mock_buffer));
 
104
 
 
105
    mga::InternalClientWindow interpreter(mock_surface, mock_cache);
 
106
    auto test_bufferptr = interpreter.driver_requests_buffer();
 
107
    interpreter.driver_returns_buffer(test_bufferptr, fake_sync);
 
108
}
 
109
 
 
110
TEST_F(InternalClientWindow, size_test)
 
111
{
 
112
    using namespace testing;
 
113
    EXPECT_CALL(*mock_surface, size())
 
114
        .Times(2)
 
115
        .WillOnce(Return(sz)) 
 
116
        .WillOnce(Return(sz)); 
 
117
    mga::InternalClientWindow interpreter(mock_surface, mock_cache);
 
118
 
 
119
    unsigned int rc_width = interpreter.driver_requests_info(NATIVE_WINDOW_WIDTH);
 
120
    unsigned int rc_height = interpreter.driver_requests_info(NATIVE_WINDOW_HEIGHT);
 
121
 
 
122
    EXPECT_EQ(sz.width.as_uint32_t(), rc_width); 
 
123
    EXPECT_EQ(sz.height.as_uint32_t(), rc_height); 
 
124
}
 
125
 
 
126
TEST_F(InternalClientWindow, driver_default_format)
 
127
{
 
128
    using namespace testing;
 
129
    EXPECT_CALL(*mock_surface, pixel_format())
 
130
        .Times(1);
 
131
 
 
132
    mga::InternalClientWindow interpreter(mock_surface, mock_cache);
 
133
 
 
134
    auto rc_format = interpreter.driver_requests_info(NATIVE_WINDOW_FORMAT);
 
135
    EXPECT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, rc_format); 
 
136
}
 
137
 
 
138
TEST_F(InternalClientWindow, driver_sets_format)
 
139
{
 
140
    using namespace testing;
 
141
    EXPECT_CALL(*mock_surface, pixel_format())
 
142
        .Times(AtLeast(1))
 
143
        .WillRepeatedly(Return(geom::PixelFormat::abgr_8888));
 
144
    mga::InternalClientWindow interpreter(mock_surface, mock_cache);
 
145
 
 
146
    interpreter.dispatch_driver_request_format(HAL_PIXEL_FORMAT_RGBA_8888);
 
147
    auto rc_format = interpreter.driver_requests_info(NATIVE_WINDOW_FORMAT);
 
148
    EXPECT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, rc_format); 
 
149
}