blob: 4f1c99e417f5478220efa1e8661611b133e0e500 [file] [log] [blame]
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -07001/*
2 * Copyright (C) 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#include <gmock/gmock.h>
18#include <gtest/gtest.h>
19
20#include "DisplayHardware/DisplayIdentification.h"
21
22namespace android {
23namespace {
24
25const unsigned char kInternalEdid[] =
26 "\x00\xff\xff\xff\xff\xff\xff\x00\x4c\xa3\x42\x31\x00\x00\x00\x00"
27 "\x00\x15\x01\x03\x80\x1a\x10\x78\x0a\xd3\xe5\x95\x5c\x60\x90\x27"
28 "\x19\x50\x54\x00\x00\x00\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
29 "\x01\x01\x01\x01\x01\x01\x9e\x1b\x00\xa0\x50\x20\x12\x30\x10\x30"
30 "\x13\x00\x05\xa3\x10\x00\x00\x19\x00\x00\x00\x0f\x00\x00\x00\x00"
31 "\x00\x00\x00\x00\x00\x23\x87\x02\x64\x00\x00\x00\x00\xfe\x00\x53"
32 "\x41\x4d\x53\x55\x4e\x47\x0a\x20\x20\x20\x20\x20\x00\x00\x00\xfe"
33 "\x00\x31\x32\x31\x41\x54\x31\x31\x2d\x38\x30\x31\x0a\x20\x00\x45";
34
35const unsigned char kExternalEdid[] =
36 "\x00\xff\xff\xff\xff\xff\xff\x00\x22\xf0\x6c\x28\x01\x01\x01\x01"
37 "\x02\x16\x01\x04\xb5\x40\x28\x78\xe2\x8d\x85\xad\x4f\x35\xb1\x25"
38 "\x0e\x50\x54\x00\x00\x00\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
39 "\x01\x01\x01\x01\x01\x01\xe2\x68\x00\xa0\xa0\x40\x2e\x60\x30\x20"
40 "\x36\x00\x81\x90\x21\x00\x00\x1a\xbc\x1b\x00\xa0\x50\x20\x17\x30"
41 "\x30\x20\x36\x00\x81\x90\x21\x00\x00\x1a\x00\x00\x00\xfc\x00\x48"
42 "\x50\x20\x5a\x52\x33\x30\x77\x0a\x20\x20\x20\x20\x00\x00\x00\xff"
43 "\x00\x43\x4e\x34\x32\x30\x32\x31\x33\x37\x51\x0a\x20\x20\x00\x71";
44
45// Extended EDID with timing extension.
46const unsigned char kExternalEedid[] =
47 "\x00\xff\xff\xff\xff\xff\xff\x00\x4c\x2d\xfe\x08\x00\x00\x00\x00"
48 "\x29\x15\x01\x03\x80\x10\x09\x78\x0a\xee\x91\xa3\x54\x4c\x99\x26"
49 "\x0f\x50\x54\xbd\xef\x80\x71\x4f\x81\xc0\x81\x00\x81\x80\x95\x00"
50 "\xa9\xc0\xb3\x00\x01\x01\x02\x3a\x80\x18\x71\x38\x2d\x40\x58\x2c"
51 "\x45\x00\xa0\x5a\x00\x00\x00\x1e\x66\x21\x56\xaa\x51\x00\x1e\x30"
52 "\x46\x8f\x33\x00\xa0\x5a\x00\x00\x00\x1e\x00\x00\x00\xfd\x00\x18"
53 "\x4b\x0f\x51\x17\x00\x0a\x20\x20\x20\x20\x20\x20\x00\x00\x00\xfc"
54 "\x00\x53\x41\x4d\x53\x55\x4e\x47\x0a\x20\x20\x20\x20\x20\x01\x1d"
55 "\x02\x03\x1f\xf1\x47\x90\x04\x05\x03\x20\x22\x07\x23\x09\x07\x07"
56 "\x83\x01\x00\x00\xe2\x00\x0f\x67\x03\x0c\x00\x20\x00\xb8\x2d\x01"
57 "\x1d\x80\x18\x71\x1c\x16\x20\x58\x2c\x25\x00\xa0\x5a\x00\x00\x00"
58 "\x9e\x01\x1d\x00\x72\x51\xd0\x1e\x20\x6e\x28\x55\x00\xa0\x5a\x00"
59 "\x00\x00\x1e\x8c\x0a\xd0\x8a\x20\xe0\x2d\x10\x10\x3e\x96\x00\xa0"
60 "\x5a\x00\x00\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
61 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
62 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc6";
63
64template <size_t N>
65DisplayIdentificationData asDisplayIdentificationData(const unsigned char (&bytes)[N]) {
66 return DisplayIdentificationData(bytes, bytes + N - 1);
67}
68
69} // namespace
70
71TEST(DisplayIdentificationTest, isEdid) {
72 EXPECT_FALSE(isEdid({}));
73
74 EXPECT_TRUE(isEdid(asDisplayIdentificationData(kInternalEdid)));
75 EXPECT_TRUE(isEdid(asDisplayIdentificationData(kExternalEdid)));
76 EXPECT_TRUE(isEdid(asDisplayIdentificationData(kExternalEedid)));
77}
78
79TEST(DisplayIdentificationTest, parseEdid) {
Lloyd Pique438e9e72018-09-04 18:06:08 -070080 auto data = asDisplayIdentificationData(kInternalEdid);
81 auto edid = parseEdid(data);
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -070082 ASSERT_TRUE(edid);
83 EXPECT_EQ(0x4ca3u, edid->manufacturerId);
84 EXPECT_STREQ("SEC", edid->pnpId.data());
85 // ASCII text should be used as fallback if display name and serial number are missing.
86 EXPECT_EQ("121AT11-801", edid->displayName);
87
Lloyd Pique438e9e72018-09-04 18:06:08 -070088 data = asDisplayIdentificationData(kExternalEdid);
89 edid = parseEdid(data);
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -070090 ASSERT_TRUE(edid);
91 EXPECT_EQ(0x22f0u, edid->manufacturerId);
92 EXPECT_STREQ("HWP", edid->pnpId.data());
93 EXPECT_EQ("HP ZR30w", edid->displayName);
94
Lloyd Pique438e9e72018-09-04 18:06:08 -070095 data = asDisplayIdentificationData(kExternalEedid);
96 edid = parseEdid(data);
Dominik Laskowskie9ef7c42018-03-12 19:34:30 -070097 ASSERT_TRUE(edid);
98 EXPECT_EQ(0x4c2du, edid->manufacturerId);
99 EXPECT_STREQ("SAM", edid->pnpId.data());
100 EXPECT_EQ("SAMSUNG", edid->displayName);
101}
102
103TEST(DisplayIdentificationTest, parseInvalidEdid) {
104 EXPECT_FALSE(isEdid({}));
105 EXPECT_FALSE(parseEdid({}));
106
107 // Display name must be printable.
108 auto data = asDisplayIdentificationData(kExternalEdid);
109 data[97] = '\x1b';
110 auto edid = parseEdid(data);
111 ASSERT_TRUE(edid);
112 // Serial number should be used as fallback if display name is invalid.
113 EXPECT_EQ("CN4202137Q", edid->displayName);
114
115 // Parsing should succeed even if EDID is truncated.
116 data.pop_back();
117 edid = parseEdid(data);
118 ASSERT_TRUE(edid);
119 EXPECT_EQ("CN4202137Q", edid->displayName);
120}
121
122TEST(DisplayIdentificationTest, getPnpId) {
123 EXPECT_FALSE(getPnpId(0));
124 EXPECT_FALSE(getPnpId(static_cast<uint16_t>(-1)));
125
126 EXPECT_STREQ("SEC", getPnpId(0x4ca3u).value_or(PnpId{}).data());
127 EXPECT_STREQ("HWP", getPnpId(0x22f0u).value_or(PnpId{}).data());
128 EXPECT_STREQ("SAM", getPnpId(0x4c2du).value_or(PnpId{}).data());
129}
130
131TEST(DisplayIdentificationTest, generateDisplayId) {
132 const auto primaryId = generateDisplayId(0, asDisplayIdentificationData(kInternalEdid));
133 ASSERT_TRUE(primaryId);
134
135 const auto secondaryId = generateDisplayId(1, asDisplayIdentificationData(kExternalEdid));
136 ASSERT_TRUE(secondaryId);
137
138 const auto tertiaryId = generateDisplayId(2, asDisplayIdentificationData(kExternalEedid));
139 ASSERT_TRUE(tertiaryId);
140
141 // Display IDs should be unique.
142 EXPECT_NE(primaryId, secondaryId);
143 EXPECT_NE(primaryId, tertiaryId);
144 EXPECT_NE(secondaryId, tertiaryId);
145}
146
147} // namespace android