~hikiko/mir/mir.unity8-desktop-session

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Daniel van Vugt, Ubuntu daily release
  • Date: 2013-11-20 07:36:15 UTC
  • mfrom: (1.1.52)
  • Revision ID: package-import@ubuntu.com-20131120073615-47my1n59hszj1y6z
Tags: 0.1.1+14.04.20131120-0ubuntu1
[ Daniel van Vugt ]
* New upstream release 0.1.1
  - Add unit tests for V/H scroll events.
  - surfaces: avoid publishing some internal headers, tidy up default
    configuration, integrate surfaces report.
  - client: Add mir_connection_drm_set_gbm_device()
  - graphics: avoid publishing some internal headers.
  - Fixed: unity-system-compositor FTBFS on trusty against new Mir
    (libmirserver9) (LP: #1244192)
  - compositor: avoid publishing some internal headers.
  - shell: Add set_lifecycle_state() to the Session interface.
  - frontend: avoid publishing some internal headers
  - logging: avoid publishing some internal headers.
  - Allow specifying the nested server name by passing --name= or setting
    MIR_SERVER_NAME=.
  - graphics,gbm: Inform the EGL platform about the used gbm device when
    using the native GBM platform
  - examples: Restore GL state after initializing buffers, fixing crashes 
    observed in render_surfaces (LP: #1234563)
  - Continue refactoring the mir android display classes.
  - shell: Hoist focus control functions needed by unity-mir into
    FocusController interface
  - client: Remove the timeout for detecting server crashes
  - Avoid a race condition that could lead to spurious failures of server
    shutdown tests (LP: #1245336)
  - test_client_input.cpp: Bump reception time-out in client test fixture.
    (LP: #1227683)
  - Ensure StubBufferAllocator returns buffers with the properties requested,
    and not the same old hardcoded constants.
  - Update docs and scripting for trusty.
  - compositor: Make DefaultDisplayBufferCompositorFactory private to the
    compositor component.
  - Ignore warnings clang treats as errors, about unused functions being
    generated from macros in <lttng/tracepoint.h> (LP: #1246590)
  - Add resize() support to BufferBundle. This is the first step and lowest
    level of surface resize support.
  - Clean up constants relating to SwitchingBundle.
  - Fix the armhf chroot setup script to point to the right library, so
    cross compiling can work again (LP: #1246975)
  - shell: avoid publishing some internal headers.
  - input: avoid publishing some internal headers.
* Bump timeouts used in socket testing. It seems 100ms isn't always
  enough, which leads to spurious test failures (LP: #1252144) (LP:
  #1252144)
* Fix uninitialized variable causing random drm_auth_magic test
  failures. (LP: #1252144). (LP: #1252144)

[ Ubuntu daily release ]
* Automatic snapshot from revision 1165

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/graphics/android/android_framebuffer_window.h"
20
 
 
21
 
#include "mir_test_doubles/mock_egl.h"
22
 
 
23
 
#include <memory>
24
 
#include <system/window.h>
25
 
#include <gtest/gtest.h>
26
 
#include <stdexcept>
27
 
 
28
 
namespace mga = mir::graphics::android;
29
 
namespace mtd = mir::test::doubles;
30
 
 
31
 
class ANativeWindowInterface
32
 
{
33
 
public:
34
 
    virtual ~ANativeWindowInterface() = default;
35
 
    virtual int query_interface(const ANativeWindow* win , int code, int* value) const = 0;
36
 
};
37
 
 
38
 
class MockANativeWindow : public ANativeWindowInterface,
39
 
    public ANativeWindow
40
 
{
41
 
public:
42
 
    MockANativeWindow()
43
 
        : fake_visual_id(5)
44
 
    {
45
 
        using namespace testing;
46
 
 
47
 
        query = hook_query;
48
 
 
49
 
        ON_CALL(*this, query_interface(_,_,_))
50
 
        .WillByDefault(DoAll(
51
 
                           SetArgPointee<2>(fake_visual_id),
52
 
                           Return(0)));
53
 
    }
54
 
 
55
 
    ~MockANativeWindow() noexcept {}
56
 
 
57
 
    static int hook_query(const ANativeWindow* anw, int code, int *ret)
58
 
    {
59
 
        const MockANativeWindow* mocker = static_cast<const MockANativeWindow*>(anw);
60
 
        return mocker->query_interface(anw, code, ret);
61
 
    }
62
 
 
63
 
    MOCK_CONST_METHOD3(query_interface,int(const ANativeWindow*,int,int*));
64
 
 
65
 
    int fake_visual_id;
66
 
};
67
 
 
68
 
class AndroidFramebufferWindowConfigSelection : public ::testing::Test
69
 
{
70
 
protected:
71
 
    virtual void SetUp()
72
 
    {
73
 
        using namespace testing;
74
 
 
75
 
        /* silence uninteresting warning messages */
76
 
        mock_egl.silence_uninteresting();
77
 
 
78
 
        mock_anw = std::make_shared<MockANativeWindow>();
79
 
        fb_win = std::make_shared<mga::AndroidFramebufferWindow>(mock_anw);
80
 
 
81
 
        EXPECT_CALL(*mock_anw, query_interface(_,_,_))
82
 
        .Times(AtLeast(0));
83
 
    }
84
 
 
85
 
    std::shared_ptr<MockANativeWindow> mock_anw;
86
 
    std::shared_ptr<mga::AndroidFramebufferWindow> fb_win;
87
 
    mtd::MockEGL mock_egl;
88
 
};
89
 
 
90
 
TEST_F(AndroidFramebufferWindowConfigSelection, queries_for_native_visual_id)
91
 
{
92
 
    using namespace testing;
93
 
    EXPECT_CALL(*mock_anw, query_interface(_,NATIVE_WINDOW_FORMAT,_))
94
 
    .Times(AtLeast(1));
95
 
 
96
 
    fb_win->android_display_egl_config(mock_egl.fake_egl_display);
97
 
}
98
 
 
99
 
TEST_F(AndroidFramebufferWindowConfigSelection, eglChooseConfig_attr_is_terminated_by_null)
100
 
{
101
 
    using namespace testing;
102
 
 
103
 
    const EGLint *attr;
104
 
 
105
 
    EXPECT_CALL(mock_egl, eglChooseConfig(mock_egl.fake_egl_display, _, _, _, _))
106
 
    .Times(AtLeast(0))
107
 
    .WillOnce(DoAll(
108
 
                  SaveArg<1>(&attr),
109
 
                  SetArgPointee<2>(mock_egl.fake_configs),
110
 
                  SetArgPointee<4>(mock_egl.fake_configs_num),
111
 
                  Return(EGL_TRUE)));
112
 
 
113
 
    fb_win->android_display_egl_config(mock_egl.fake_egl_display);
114
 
 
115
 
    int i=0;
116
 
    while(attr[i++] != EGL_NONE);
117
 
 
118
 
    SUCCEED();
119
 
}
120
 
 
121
 
TEST_F(AndroidFramebufferWindowConfigSelection, eglChooseConfig_attr_contains_window_bit)
122
 
{
123
 
    using namespace testing;
124
 
 
125
 
    const EGLint *attr;
126
 
 
127
 
    EXPECT_CALL(mock_egl, eglChooseConfig(mock_egl.fake_egl_display, _, _, _, _))
128
 
    .Times(AtLeast(0))
129
 
    .WillOnce(DoAll(
130
 
                  SaveArg<1>(&attr),
131
 
                  SetArgPointee<2>(mock_egl.fake_configs),
132
 
                  SetArgPointee<4>(mock_egl.fake_configs_num),
133
 
                  Return(EGL_TRUE)));
134
 
 
135
 
    fb_win->android_display_egl_config(mock_egl.fake_egl_display);
136
 
 
137
 
    int i=0;
138
 
    bool validated = false;
139
 
    while(attr[i] != EGL_NONE)
140
 
    {
141
 
        if ((attr[i] == EGL_SURFACE_TYPE) && (attr[i+1] == EGL_WINDOW_BIT))
142
 
        {
143
 
            validated = true;
144
 
            break;
145
 
        }
146
 
        i++;
147
 
    };
148
 
 
149
 
    EXPECT_TRUE(validated);
150
 
}
151
 
 
152
 
TEST_F(AndroidFramebufferWindowConfigSelection, eglChooseConfig_attr_requests_ogl2)
153
 
{
154
 
    using namespace testing;
155
 
 
156
 
    const EGLint *attr;
157
 
 
158
 
    EXPECT_CALL(mock_egl, eglChooseConfig(mock_egl.fake_egl_display, _, _, _, _))
159
 
    .Times(AtLeast(0))
160
 
    .WillOnce(DoAll(
161
 
                  SaveArg<1>(&attr),
162
 
                  SetArgPointee<2>(mock_egl.fake_configs),
163
 
                  SetArgPointee<4>(mock_egl.fake_configs_num),
164
 
                  Return(EGL_TRUE)));
165
 
 
166
 
    fb_win->android_display_egl_config(mock_egl.fake_egl_display);
167
 
 
168
 
    int i=0;
169
 
    bool validated = false;
170
 
    while(attr[i] != EGL_NONE)
171
 
    {
172
 
        if ((attr[i] == EGL_RENDERABLE_TYPE) && (attr[i+1] == EGL_OPENGL_ES2_BIT))
173
 
        {
174
 
            validated = true;
175
 
            break;
176
 
        }
177
 
        i++;
178
 
    };
179
 
 
180
 
    EXPECT_TRUE(validated);
181
 
}
182
 
 
183
 
TEST_F(AndroidFramebufferWindowConfigSelection, queries_with_enough_room_for_all_potential_cfg)
184
 
{
185
 
    using namespace testing;
186
 
 
187
 
    int num_cfg = 43;
188
 
    const EGLint *attr;
189
 
 
190
 
    EXPECT_CALL(mock_egl, eglGetConfigs(mock_egl.fake_egl_display, NULL, 0, _))
191
 
    .Times(AtLeast(1))
192
 
    .WillOnce(DoAll(
193
 
                  SetArgPointee<3>(num_cfg),
194
 
                  Return(EGL_TRUE)));
195
 
 
196
 
    EXPECT_CALL(mock_egl, eglChooseConfig(mock_egl.fake_egl_display, _, _, num_cfg, _))
197
 
    .Times(AtLeast(1))
198
 
    .WillOnce(DoAll(
199
 
                  SaveArg<1>(&attr),
200
 
                  SetArgPointee<2>(mock_egl.fake_configs),
201
 
                  SetArgPointee<4>(mock_egl.fake_configs_num),
202
 
                  Return(EGL_TRUE)));
203
 
 
204
 
    fb_win->android_display_egl_config(mock_egl.fake_egl_display);
205
 
 
206
 
    /* should be able to ref this spot */
207
 
    EGLint test_last_spot = attr[num_cfg-1];
208
 
    EXPECT_EQ(test_last_spot, test_last_spot);
209
 
 
210
 
}
211
 
 
212
 
TEST_F(AndroidFramebufferWindowConfigSelection, creates_with_proper_visual_id)
213
 
{
214
 
    using namespace testing;
215
 
 
216
 
    EGLConfig cfg, chosen_cfg;
217
 
 
218
 
    EXPECT_CALL(mock_egl, eglGetConfigAttrib(mock_egl.fake_egl_display, _, EGL_NATIVE_VISUAL_ID, _))
219
 
    .Times(AtLeast(1))
220
 
    .WillRepeatedly(DoAll(
221
 
                        SetArgPointee<3>(mock_anw->fake_visual_id),
222
 
                        SaveArg<1>(&cfg),
223
 
                        Return(EGL_TRUE)));
224
 
 
225
 
    chosen_cfg = fb_win->android_display_egl_config(mock_egl.fake_egl_display);
226
 
 
227
 
    EXPECT_EQ(cfg, chosen_cfg);
228
 
}
229
 
 
230
 
TEST_F(AndroidFramebufferWindowConfigSelection, creates_with_proper_visual_id_mixed_valid_invalid)
231
 
{
232
 
    using namespace testing;
233
 
 
234
 
    EGLConfig cfg, chosen_cfg;
235
 
 
236
 
    int bad_id = mock_anw->fake_visual_id + 1;
237
 
 
238
 
    EXPECT_CALL(mock_egl, eglGetConfigAttrib(mock_egl.fake_egl_display, _, EGL_NATIVE_VISUAL_ID, _))
239
 
    .Times(AtLeast(1))
240
 
    .WillOnce(DoAll(
241
 
                  SetArgPointee<3>(bad_id),
242
 
                  Return(EGL_TRUE)))
243
 
    .WillOnce(DoAll(
244
 
                  SetArgPointee<3>(mock_anw->fake_visual_id),
245
 
                  SaveArg<1>(&cfg),
246
 
                  Return(EGL_TRUE)))
247
 
    .WillRepeatedly(DoAll(
248
 
                        SetArgPointee<3>(bad_id),
249
 
                        Return(EGL_TRUE)));
250
 
 
251
 
    chosen_cfg = fb_win->android_display_egl_config(mock_egl.fake_egl_display);
252
 
 
253
 
    EXPECT_EQ(cfg, chosen_cfg);
254
 
}
255
 
 
256
 
TEST_F(AndroidFramebufferWindowConfigSelection, without_proper_visual_id_throws)
257
 
{
258
 
    using namespace testing;
259
 
 
260
 
    EGLConfig cfg;
261
 
 
262
 
    int bad_id = mock_anw->fake_visual_id + 1;
263
 
    EXPECT_CALL(mock_egl, eglGetConfigAttrib(mock_egl.fake_egl_display, _, EGL_NATIVE_VISUAL_ID, _))
264
 
    .Times(AtLeast(1))
265
 
    .WillRepeatedly(DoAll(
266
 
                        SetArgPointee<3>(bad_id),
267
 
                        SaveArg<1>(&cfg),
268
 
                        Return(EGL_TRUE)));
269
 
 
270
 
    EXPECT_THROW(
271
 
    {
272
 
        fb_win->android_display_egl_config(mock_egl.fake_egl_display);
273
 
    }, std::runtime_error );
274
 
}
275
 
 
276
 
TEST_F(AndroidFramebufferWindowConfigSelection, anw_is_not_null)
277
 
{
278
 
    using namespace testing;
279
 
 
280
 
    auto win_handle = fb_win->android_native_window_type();
281
 
 
282
 
    EXPECT_NE(win_handle, (EGLNativeWindowType) NULL);
283
 
}