Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 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 | |
Jamie Gennis | bae716b | 2011-03-14 15:34:04 -0700 | [diff] [blame] | 17 | #include <EGL/egl.h> |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 18 | #include <gtest/gtest.h> |
Jamie Gennis | bae716b | 2011-03-14 15:34:04 -0700 | [diff] [blame] | 19 | #include <gui/SurfaceTextureClient.h> |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 20 | |
| 21 | namespace android { |
| 22 | |
| 23 | class SurfaceTextureClientTest : public ::testing::Test { |
| 24 | protected: |
| 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 | |
Jamie Gennis | f95a9f0 | 2011-03-14 15:08:53 -0700 | [diff] [blame] | 39 | TEST_F(SurfaceTextureClientTest, GetISurfaceTextureIsNotNull) { |
| 40 | sp<ISurfaceTexture> ist(mSTC->getISurfaceTexture()); |
| 41 | ASSERT_TRUE(ist != NULL); |
| 42 | } |
| 43 | |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 44 | TEST_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 | |
Jamie Gennis | c4ca7c5 | 2011-03-14 15:00:06 -0700 | [diff] [blame] | 53 | TEST_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 | |
Jamie Gennis | bae716b | 2011-03-14 15:34:04 -0700 | [diff] [blame] | 61 | TEST_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 | |
| 67 | TEST_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 | |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 103 | } |