| Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright 2020 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 <ui/DisplayId.h> | 
 | 18 |  | 
 | 19 | #include <gtest/gtest.h> | 
 | 20 |  | 
 | 21 | namespace android::ui { | 
 | 22 |  | 
 | 23 | TEST(DisplayIdTest, createPhysicalIdFromEdid) { | 
 | 24 |     constexpr uint8_t port = 1; | 
 | 25 |     constexpr uint16_t manufacturerId = 13; | 
 | 26 |     constexpr uint32_t modelHash = 42; | 
 | 27 |     PhysicalDisplayId id = PhysicalDisplayId::fromEdid(port, manufacturerId, modelHash); | 
 | 28 |     EXPECT_EQ(port, id.getPort()); | 
 | 29 |     EXPECT_EQ(manufacturerId, id.getManufacturerId()); | 
 | 30 |     EXPECT_FALSE(VirtualDisplayId::tryCast(id)); | 
 | 31 |     EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); | 
 | 32 |     EXPECT_FALSE(GpuVirtualDisplayId::tryCast(id)); | 
 | 33 |     EXPECT_TRUE(PhysicalDisplayId::tryCast(id)); | 
 | 34 |     EXPECT_TRUE(HalDisplayId::tryCast(id)); | 
 | 35 | } | 
 | 36 |  | 
 | 37 | TEST(DisplayIdTest, createPhysicalIdFromPort) { | 
 | 38 |     constexpr uint8_t port = 3; | 
 | 39 |     PhysicalDisplayId id = PhysicalDisplayId::fromPort(port); | 
 | 40 |     EXPECT_EQ(port, id.getPort()); | 
 | 41 |     EXPECT_FALSE(VirtualDisplayId::tryCast(id)); | 
 | 42 |     EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); | 
 | 43 |     EXPECT_FALSE(GpuVirtualDisplayId::tryCast(id)); | 
 | 44 |     EXPECT_TRUE(PhysicalDisplayId::tryCast(id)); | 
 | 45 |     EXPECT_TRUE(HalDisplayId::tryCast(id)); | 
 | 46 | } | 
 | 47 |  | 
 | 48 | TEST(DisplayIdTest, createGpuVirtualId) { | 
 | 49 |     GpuVirtualDisplayId id(42); | 
 | 50 |     EXPECT_TRUE(VirtualDisplayId::tryCast(id)); | 
 | 51 |     EXPECT_TRUE(GpuVirtualDisplayId::tryCast(id)); | 
 | 52 |     EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); | 
 | 53 |     EXPECT_FALSE(PhysicalDisplayId::tryCast(id)); | 
 | 54 |     EXPECT_FALSE(HalDisplayId::tryCast(id)); | 
 | 55 | } | 
 | 56 |  | 
 | 57 | TEST(DisplayIdTest, createHalVirtualId) { | 
 | 58 |     HalVirtualDisplayId id(42); | 
 | 59 |     EXPECT_TRUE(VirtualDisplayId::tryCast(id)); | 
 | 60 |     EXPECT_TRUE(HalVirtualDisplayId::tryCast(id)); | 
 | 61 |     EXPECT_FALSE(GpuVirtualDisplayId::tryCast(id)); | 
 | 62 |     EXPECT_FALSE(PhysicalDisplayId::tryCast(id)); | 
 | 63 |     EXPECT_TRUE(HalDisplayId::tryCast(id)); | 
 | 64 | } | 
 | 65 |  | 
 | 66 | } // namespace android::ui |