Jamie Gennis | 134f042 | 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 | |
| 17 | #include <gtest/gtest.h> |
| 18 | #include <surfaceflinger/ISurfaceComposer.h> |
| 19 | #include <surfaceflinger/Surface.h> |
| 20 | #include <surfaceflinger/SurfaceComposerClient.h> |
| 21 | |
| 22 | #include <utils/String8.h> |
| 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | class SurfaceTest : public ::testing::Test { |
| 27 | protected: |
| 28 | virtual sp<SurfaceComposerClient> getSurfaceComposerClient() { |
| 29 | return sp<SurfaceComposerClient>(new SurfaceComposerClient); |
| 30 | } |
| 31 | |
| 32 | virtual void SetUp() { |
| 33 | mComposerClient = getSurfaceComposerClient(); |
| 34 | ASSERT_EQ(NO_ERROR, mComposerClient->initCheck()); |
| 35 | |
| 36 | mSurfaceControl = mComposerClient->createSurface(getpid(), |
| 37 | String8("Test Surface"), 0, 32, 32, PIXEL_FORMAT_RGB_888, 0); |
| 38 | |
| 39 | ASSERT_TRUE(mSurfaceControl != NULL); |
| 40 | ASSERT_TRUE(mSurfaceControl->isValid()); |
| 41 | |
| 42 | ASSERT_EQ(NO_ERROR, mComposerClient->openTransaction()); |
| 43 | ASSERT_EQ(NO_ERROR, mSurfaceControl->setLayer(30000)); |
| 44 | ASSERT_EQ(NO_ERROR, mSurfaceControl->show()); |
| 45 | ASSERT_EQ(NO_ERROR, mComposerClient->closeTransaction()); |
| 46 | |
| 47 | mSurface = mSurfaceControl->getSurface(); |
| 48 | ASSERT_TRUE(mSurface != NULL); |
| 49 | } |
| 50 | |
| 51 | virtual void TearDown() { |
| 52 | mComposerClient->dispose(); |
| 53 | } |
| 54 | |
| 55 | sp<Surface> mSurface; |
| 56 | sp<SurfaceComposerClient> mComposerClient; |
| 57 | sp<SurfaceControl> mSurfaceControl; |
| 58 | }; |
| 59 | |
| 60 | TEST_F(SurfaceTest, QueuesToWindowComposerIsTrueWhenVisible) { |
| 61 | sp<ANativeWindow> anw(mSurface); |
| 62 | int result = -123; |
| 63 | int err = anw->query(anw.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER, |
| 64 | &result); |
| 65 | EXPECT_EQ(NO_ERROR, err); |
| 66 | EXPECT_EQ(1, result); |
| 67 | } |
| 68 | |
| 69 | TEST_F(SurfaceTest, QueuesToWindowComposerIsTrueWhenPurgatorized) { |
| 70 | mSurfaceControl.clear(); |
| 71 | |
| 72 | sp<ANativeWindow> anw(mSurface); |
| 73 | int result = -123; |
| 74 | int err = anw->query(anw.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER, |
| 75 | &result); |
| 76 | EXPECT_EQ(NO_ERROR, err); |
| 77 | EXPECT_EQ(1, result); |
| 78 | } |
| 79 | |
| 80 | } |