SurfaceTextureClient_test.cpp revision 5c0c93a8c49b4053744efb8953b915fa7f0923a5
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <EGL/egl.h>
18#include <gtest/gtest.h>
19#include <gui/SurfaceTextureClient.h>
20
21namespace android {
22
23class SurfaceTextureClientTest : public ::testing::Test {
24protected:
25    virtual void SetUp() {
26        mST = new SurfaceTexture(123);
27        mSTC = new SurfaceTextureClient(mST);
28    }
29
30    virtual void TearDown() {
31        mST.clear();
32        mSTC.clear();
33    }
34
35    sp<SurfaceTexture> mST;
36    sp<SurfaceTextureClient> mSTC;
37};
38
39TEST_F(SurfaceTextureClientTest, GetISurfaceTextureIsNotNull) {
40    sp<ISurfaceTexture> ist(mSTC->getISurfaceTexture());
41    ASSERT_TRUE(ist != NULL);
42}
43
44TEST_F(SurfaceTextureClientTest, QueuesToWindowCompositorIsFalse) {
45    sp<ANativeWindow> anw(mSTC);
46    int result = -123;
47    int err = anw->query(anw.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER,
48            &result);
49    EXPECT_EQ(NO_ERROR, err);
50    EXPECT_EQ(0, result);
51}
52
53TEST_F(SurfaceTextureClientTest, ConcreteTypeIsSurfaceTextureClient) {
54    sp<ANativeWindow> anw(mSTC);
55    int result = -123;
56    int err = anw->query(anw.get(), NATIVE_WINDOW_CONCRETE_TYPE, &result);
57    EXPECT_EQ(NO_ERROR, err);
58    EXPECT_EQ(NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT, result);
59}
60
61TEST_F(SurfaceTextureClientTest, ANativeWindowLockFails) {
62    sp<ANativeWindow> anw(mSTC);
63    ANativeWindow_Buffer buf;
64    ASSERT_EQ(BAD_VALUE, ANativeWindow_lock(anw.get(), &buf, NULL));
65}
66
67TEST_F(SurfaceTextureClientTest, EglCreateWindowSurfaceFails) {
68    sp<ANativeWindow> anw(mSTC);
69
70    EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
71    ASSERT_EQ(EGL_SUCCESS, eglGetError());
72    ASSERT_NE(EGL_NO_DISPLAY, dpy);
73
74    EGLint majorVersion;
75    EGLint minorVersion;
76    EXPECT_TRUE(eglInitialize(dpy, &majorVersion, &minorVersion));
77    ASSERT_EQ(EGL_SUCCESS, eglGetError());
78
79    EGLConfig myConfig = {0};
80    EGLint numConfigs = 0;
81    EGLint configAttribs[] = {
82        EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
83        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
84        EGL_RED_SIZE, 8,
85        EGL_GREEN_SIZE, 8,
86        EGL_BLUE_SIZE, 8,
87        EGL_ALPHA_SIZE, 8,
88        EGL_DEPTH_SIZE, 16,
89        EGL_STENCIL_SIZE, 8,
90        EGL_NONE };
91    EXPECT_TRUE(eglChooseConfig(dpy, configAttribs, &myConfig, 1,
92            &numConfigs));
93    ASSERT_EQ(EGL_SUCCESS, eglGetError());
94
95    EGLSurface eglSurface = eglCreateWindowSurface(dpy, myConfig, anw.get(),
96            NULL);
97    ASSERT_EQ(EGL_NO_SURFACE, eglSurface);
98    ASSERT_EQ(EGL_BAD_NATIVE_WINDOW, eglGetError());
99
100    eglTerminate(dpy);
101}
102
103}
104