Jiwen 'Steve' Cai | 2daf518 | 2018-10-16 00:14:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 "GraphicBufferTest" |
| 18 | |
| 19 | #include <ui/BufferHubBuffer.h> |
| 20 | #include <ui/GraphicBuffer.h> |
| 21 | |
| 22 | #include <gtest/gtest.h> |
| 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | namespace { |
| 27 | |
| 28 | constexpr uint32_t kTestWidth = 1024; |
| 29 | constexpr uint32_t kTestHeight = 1; |
| 30 | constexpr uint32_t kTestFormat = HAL_PIXEL_FORMAT_BLOB; |
| 31 | constexpr uint32_t kTestLayerCount = 1; |
| 32 | constexpr uint64_t kTestUsage = GraphicBuffer::USAGE_SW_WRITE_OFTEN; |
| 33 | |
| 34 | } // namespace |
| 35 | |
| 36 | class GraphicBufferTest : public testing::Test {}; |
| 37 | |
| 38 | TEST_F(GraphicBufferTest, CreateFromBufferHubBuffer) { |
| 39 | std::unique_ptr<BufferHubBuffer> b1 = |
| 40 | BufferHubBuffer::Create(kTestWidth, kTestHeight, kTestLayerCount, kTestFormat, |
| 41 | kTestUsage, /*userMetadataSize=*/0); |
| 42 | EXPECT_TRUE(b1->IsValid()); |
| 43 | |
| 44 | sp<GraphicBuffer> gb(new GraphicBuffer(std::move(b1))); |
| 45 | EXPECT_TRUE(gb->isBufferHubBuffer()); |
| 46 | |
| 47 | EXPECT_EQ(gb->getWidth(), kTestWidth); |
| 48 | EXPECT_EQ(gb->getHeight(), kTestHeight); |
| 49 | EXPECT_EQ(static_cast<uint32_t>(gb->getPixelFormat()), kTestFormat); |
| 50 | EXPECT_EQ(gb->getUsage(), kTestUsage); |
| 51 | EXPECT_EQ(gb->getLayerCount(), kTestLayerCount); |
| 52 | } |
| 53 | |
| 54 | } // namespace android |