blob: 8ddee7e7402801b89072fac8eb76852f60c5788d [file] [log] [blame]
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +02001/*
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
21namespace android::ui {
22
23TEST(DisplayIdTest, createPhysicalIdFromEdid) {
24 constexpr uint8_t port = 1;
25 constexpr uint16_t manufacturerId = 13;
26 constexpr uint32_t modelHash = 42;
Alan Ding5be08652024-05-24 01:48:07 +000027 PhysicalDisplayId id = PhysicalDisplayId::fromEdid(port, manufacturerId, modelHash);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020028 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 Laskowskif1833852021-03-23 15:06:50 -070035
36 EXPECT_EQ(id, DisplayId::fromValue(id.value));
37 EXPECT_EQ(id, DisplayId::fromValue<PhysicalDisplayId>(id.value));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020038}
39
40TEST(DisplayIdTest, createPhysicalIdFromPort) {
41 constexpr uint8_t port = 3;
Alan Ding5be08652024-05-24 01:48:07 +000042 PhysicalDisplayId id = PhysicalDisplayId::fromPort(port);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020043 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 Laskowskif1833852021-03-23 15:06:50 -070049
50 EXPECT_EQ(id, DisplayId::fromValue(id.value));
51 EXPECT_EQ(id, DisplayId::fromValue<PhysicalDisplayId>(id.value));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020052}
53
54TEST(DisplayIdTest, createGpuVirtualId) {
Alan Ding5be08652024-05-24 01:48:07 +000055 GpuVirtualDisplayId id(42);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020056 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 Laskowskif1833852021-03-23 15:06:50 -070061
62 EXPECT_EQ(id, DisplayId::fromValue(id.value));
63 EXPECT_EQ(id, DisplayId::fromValue<GpuVirtualDisplayId>(id.value));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020064}
65
66TEST(DisplayIdTest, createHalVirtualId) {
Alan Ding5be08652024-05-24 01:48:07 +000067 HalVirtualDisplayId id(42);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020068 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 Laskowskif1833852021-03-23 15:06:50 -070073
74 EXPECT_EQ(id, DisplayId::fromValue(id.value));
75 EXPECT_EQ(id, DisplayId::fromValue<HalVirtualDisplayId>(id.value));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020076}
77
78} // namespace android::ui