| 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)); | 
| Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 35 |  | 
|  | 36 | EXPECT_EQ(id, DisplayId::fromValue(id.value)); | 
|  | 37 | EXPECT_EQ(id, DisplayId::fromValue<PhysicalDisplayId>(id.value)); | 
| Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 38 | } | 
|  | 39 |  | 
|  | 40 | TEST(DisplayIdTest, createPhysicalIdFromPort) { | 
|  | 41 | constexpr uint8_t port = 3; | 
|  | 42 | PhysicalDisplayId id = PhysicalDisplayId::fromPort(port); | 
|  | 43 | EXPECT_EQ(port, id.getPort()); | 
|  | 44 | EXPECT_FALSE(VirtualDisplayId::tryCast(id)); | 
|  | 45 | EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); | 
|  | 46 | EXPECT_FALSE(GpuVirtualDisplayId::tryCast(id)); | 
|  | 47 | EXPECT_TRUE(PhysicalDisplayId::tryCast(id)); | 
|  | 48 | EXPECT_TRUE(HalDisplayId::tryCast(id)); | 
| Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 49 |  | 
|  | 50 | EXPECT_EQ(id, DisplayId::fromValue(id.value)); | 
|  | 51 | EXPECT_EQ(id, DisplayId::fromValue<PhysicalDisplayId>(id.value)); | 
| Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 52 | } | 
|  | 53 |  | 
|  | 54 | TEST(DisplayIdTest, createGpuVirtualId) { | 
|  | 55 | GpuVirtualDisplayId id(42); | 
|  | 56 | EXPECT_TRUE(VirtualDisplayId::tryCast(id)); | 
|  | 57 | EXPECT_TRUE(GpuVirtualDisplayId::tryCast(id)); | 
|  | 58 | EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); | 
|  | 59 | EXPECT_FALSE(PhysicalDisplayId::tryCast(id)); | 
|  | 60 | EXPECT_FALSE(HalDisplayId::tryCast(id)); | 
| Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 61 |  | 
|  | 62 | EXPECT_EQ(id, DisplayId::fromValue(id.value)); | 
|  | 63 | EXPECT_EQ(id, DisplayId::fromValue<GpuVirtualDisplayId>(id.value)); | 
| Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 64 | } | 
|  | 65 |  | 
|  | 66 | TEST(DisplayIdTest, createHalVirtualId) { | 
|  | 67 | HalVirtualDisplayId id(42); | 
|  | 68 | EXPECT_TRUE(VirtualDisplayId::tryCast(id)); | 
|  | 69 | EXPECT_TRUE(HalVirtualDisplayId::tryCast(id)); | 
|  | 70 | EXPECT_FALSE(GpuVirtualDisplayId::tryCast(id)); | 
|  | 71 | EXPECT_FALSE(PhysicalDisplayId::tryCast(id)); | 
|  | 72 | EXPECT_TRUE(HalDisplayId::tryCast(id)); | 
| Dominik Laskowski | f183385 | 2021-03-23 15:06:50 -0700 | [diff] [blame] | 73 |  | 
|  | 74 | EXPECT_EQ(id, DisplayId::fromValue(id.value)); | 
|  | 75 | EXPECT_EQ(id, DisplayId::fromValue<HalVirtualDisplayId>(id.value)); | 
| Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 76 | } | 
|  | 77 |  | 
|  | 78 | } // namespace android::ui |