Craig Donner | 4e1b9a7 | 2017-02-24 16:20:20 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | #define LOG_TAG "Gralloc1Mapper_test" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | #include <errno.h> |
| 21 | #include <sys/types.h> |
| 22 | #include <sys/socket.h> |
| 23 | #include <sys/un.h> |
| 24 | |
| 25 | #include <ui/GraphicBuffer.h> |
| 26 | #include <ui/GraphicBufferMapper.h> |
| 27 | #include <utils/Errors.h> |
| 28 | |
| 29 | #include <gtest/gtest.h> |
| 30 | |
| 31 | using namespace android; |
| 32 | |
| 33 | class Gralloc1MapperTest : public ::testing::Test |
| 34 | { |
| 35 | public: |
| 36 | ~Gralloc1MapperTest() override = default; |
| 37 | |
| 38 | protected: |
| 39 | void SetUp() override { |
| 40 | buffer = new GraphicBuffer(4, 8, HAL_PIXEL_FORMAT_RGBA_8888, 1, |
| 41 | GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN, |
| 42 | GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN, "Gralloc1MapperTest"); |
| 43 | ASSERT_NE(nullptr, buffer.get()); |
| 44 | |
| 45 | handle = static_cast<buffer_handle_t>(buffer->handle); |
| 46 | |
| 47 | mapper = &GraphicBufferMapper::get(); |
| 48 | } |
| 49 | |
| 50 | sp<GraphicBuffer> buffer; |
| 51 | buffer_handle_t handle; |
| 52 | GraphicBufferMapper* mapper; |
| 53 | }; |
| 54 | |
| 55 | TEST_F(Gralloc1MapperTest, Gralloc1MapperTest_getDimensions) { |
| 56 | uint32_t width = 0; |
| 57 | uint32_t height = 0; |
| 58 | status_t err = mapper->getDimensions(handle, &width, &height); |
| 59 | ASSERT_EQ(GRALLOC1_ERROR_NONE, err); |
| 60 | EXPECT_EQ(4U, width); |
| 61 | EXPECT_EQ(8U, height); |
| 62 | } |
| 63 | |
| 64 | TEST_F(Gralloc1MapperTest, Gralloc1MapperTest_getFormat) { |
| 65 | int32_t value = 0; |
| 66 | status_t err = mapper->getFormat(handle, &value); |
| 67 | ASSERT_EQ(GRALLOC1_ERROR_NONE, err); |
| 68 | EXPECT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, value); |
| 69 | } |
| 70 | |
| 71 | TEST_F(Gralloc1MapperTest, Gralloc1MapperTest_getLayerCount) { |
| 72 | uint32_t value = 0; |
| 73 | status_t err = mapper->getLayerCount(handle, &value); |
| 74 | if (err != GRALLOC1_ERROR_UNSUPPORTED) { |
| 75 | EXPECT_EQ(1U, value); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | TEST_F(Gralloc1MapperTest, Gralloc1MapperTest_getProducerUsage) { |
| 80 | uint64_t value = 0; |
| 81 | status_t err = mapper->getProducerUsage(handle, &value); |
| 82 | ASSERT_EQ(GRALLOC1_ERROR_NONE, err); |
| 83 | EXPECT_EQ(GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN, value); |
| 84 | } |
| 85 | |
| 86 | TEST_F(Gralloc1MapperTest, Gralloc1MapperTest_getConsumerUsage) { |
| 87 | uint64_t value = 0; |
| 88 | status_t err = mapper->getConsumerUsage(handle, &value); |
| 89 | ASSERT_EQ(GRALLOC1_ERROR_NONE, err); |
| 90 | EXPECT_EQ(GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN, value); |
| 91 | } |
| 92 | |
| 93 | TEST_F(Gralloc1MapperTest, Gralloc1MapperTest_getBackingStore) { |
| 94 | uint64_t value = 0; |
| 95 | status_t err = mapper->getBackingStore(handle, &value); |
| 96 | ASSERT_EQ(GRALLOC1_ERROR_NONE, err); |
| 97 | } |
| 98 | |
| 99 | TEST_F(Gralloc1MapperTest, Gralloc1MapperTest_getStride) { |
| 100 | uint32_t value = 0; |
| 101 | status_t err = mapper->getStride(handle, &value); |
| 102 | ASSERT_EQ(GRALLOC1_ERROR_NONE, err); |
| 103 | // The stride should be at least the width of the buffer. |
| 104 | EXPECT_LE(4U, value); |
| 105 | } |