| Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2019 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 | #undef LOG_TAG | 
|  | 18 | #define LOG_TAG "LibSurfaceFlingerUnittests" | 
|  | 19 |  | 
|  | 20 | #include <binder/Parcel.h> | 
|  | 21 | #include <gmock/gmock.h> | 
|  | 22 | #include <gtest/gtest.h> | 
|  | 23 | #include <gui/LayerMetadata.h> | 
|  | 24 | #include <log/log.h> | 
|  | 25 |  | 
|  | 26 | namespace android { | 
|  | 27 | namespace { | 
|  | 28 |  | 
|  | 29 | class LayerMetadataTest : public testing::Test { | 
|  | 30 | public: | 
|  | 31 | LayerMetadataTest(); | 
|  | 32 | ~LayerMetadataTest() override; | 
|  | 33 | }; | 
|  | 34 |  | 
|  | 35 | LayerMetadataTest::LayerMetadataTest() { | 
|  | 36 | const ::testing::TestInfo* const test_info = | 
|  | 37 | ::testing::UnitTest::GetInstance()->current_test_info(); | 
|  | 38 | ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); | 
|  | 39 | } | 
|  | 40 |  | 
|  | 41 | LayerMetadataTest::~LayerMetadataTest() { | 
|  | 42 | const ::testing::TestInfo* const test_info = | 
|  | 43 | ::testing::UnitTest::GetInstance()->current_test_info(); | 
|  | 44 | ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | TEST_F(LayerMetadataTest, testLayerMetadata) { | 
|  | 48 | LayerMetadata metadata; | 
|  | 49 |  | 
|  | 50 | ASSERT_EQ(0, metadata.mMap.size()); | 
|  | 51 |  | 
|  | 52 | // Test non-set | 
|  | 53 | ASSERT_EQ(3, metadata.getInt32(4, 3)); | 
|  | 54 |  | 
|  | 55 | // Make sure it's still unset | 
|  | 56 | ASSERT_EQ(5, metadata.getInt32(4, 5)); | 
|  | 57 |  | 
|  | 58 | metadata.setInt32(4, 2); | 
|  | 59 | ASSERT_EQ(2, metadata.getInt32(4, 0)); | 
|  | 60 |  | 
|  | 61 | // data is too small | 
|  | 62 | metadata.mMap[2] = std::vector<uint8_t>{'a', 'b'}; | 
|  | 63 | ASSERT_EQ(0, metadata.getInt32(2, 0)); | 
|  | 64 |  | 
|  | 65 | LayerMetadata second; | 
|  | 66 | std::vector<uint8_t> someData{'c', 'd', '\0'}; | 
|  | 67 | second.mMap[2] = someData; | 
|  | 68 | second.setInt32(6, 5); | 
|  | 69 | metadata.merge(second); | 
|  | 70 |  | 
|  | 71 | ASSERT_EQ(3, metadata.mMap.size()); | 
|  | 72 | ASSERT_EQ(someData, second.mMap[2]); | 
|  | 73 | ASSERT_EQ(5, metadata.getInt32(6, 0)); | 
|  | 74 | ASSERT_EQ(2, metadata.getInt32(4, 0)); | 
|  | 75 |  | 
|  | 76 | Parcel p; | 
|  | 77 | metadata.writeToParcel(&p); | 
|  | 78 | LayerMetadata reconstructed; | 
|  | 79 | reconstructed.setInt32(3, 1); // to make sure it gets replaced | 
|  | 80 | p.setDataPosition(0); | 
|  | 81 | reconstructed.readFromParcel(&p); | 
|  | 82 | ASSERT_EQ(metadata.mMap, reconstructed.mMap); | 
|  | 83 | } | 
|  | 84 |  | 
|  | 85 | } // namespace | 
|  | 86 | } // namespace android |