blob: 91131711d5fb576e08d4375195b3804df56b2377 [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) {
80 auto edid = parseEdid(asDisplayIdentificationData(kInternalEdid));
81 ASSERT_TRUE(edid);
82 EXPECT_EQ(0x4ca3u, edid->manufacturerId);
83 EXPECT_STREQ("SEC", edid->pnpId.data());
84 // ASCII text should be used as fallback if display name and serial number are missing.
85 EXPECT_EQ("121AT11-801", edid->displayName);
86
87 edid = parseEdid(asDisplayIdentificationData(kExternalEdid));
88 ASSERT_TRUE(edid);
89 EXPECT_EQ(0x22f0u, edid->manufacturerId);
90 EXPECT_STREQ("HWP", edid->pnpId.data());
91 EXPECT_EQ("HP ZR30w", edid->displayName);
92
93 edid = parseEdid(asDisplayIdentificationData(kExternalEedid));
94 ASSERT_TRUE(edid);
95 EXPECT_EQ(0x4c2du, edid->manufacturerId);
96 EXPECT_STREQ("SAM", edid->pnpId.data());
97 EXPECT_EQ("SAMSUNG", edid->displayName);
98}
99
100TEST(DisplayIdentificationTest, parseInvalidEdid) {
101 EXPECT_FALSE(isEdid({}));
102 EXPECT_FALSE(parseEdid({}));
103
104 // Display name must be printable.
105 auto data = asDisplayIdentificationData(kExternalEdid);
106 data[97] = '\x1b';
107 auto edid = parseEdid(data);
108 ASSERT_TRUE(edid);
109 // Serial number should be used as fallback if display name is invalid.
110 EXPECT_EQ("CN4202137Q", edid->displayName);
111
112 // Parsing should succeed even if EDID is truncated.
113 data.pop_back();
114 edid = parseEdid(data);
115 ASSERT_TRUE(edid);
116 EXPECT_EQ("CN4202137Q", edid->displayName);
117}
118
119TEST(DisplayIdentificationTest, getPnpId) {
120 EXPECT_FALSE(getPnpId(0));
121 EXPECT_FALSE(getPnpId(static_cast<uint16_t>(-1)));
122
123 EXPECT_STREQ("SEC", getPnpId(0x4ca3u).value_or(PnpId{}).data());
124 EXPECT_STREQ("HWP", getPnpId(0x22f0u).value_or(PnpId{}).data());
125 EXPECT_STREQ("SAM", getPnpId(0x4c2du).value_or(PnpId{}).data());
126}
127
128TEST(DisplayIdentificationTest, generateDisplayId) {
129 const auto primaryId = generateDisplayId(0, asDisplayIdentificationData(kInternalEdid));
130 ASSERT_TRUE(primaryId);
131
132 const auto secondaryId = generateDisplayId(1, asDisplayIdentificationData(kExternalEdid));
133 ASSERT_TRUE(secondaryId);
134
135 const auto tertiaryId = generateDisplayId(2, asDisplayIdentificationData(kExternalEedid));
136 ASSERT_TRUE(tertiaryId);
137
138 // Display IDs should be unique.
139 EXPECT_NE(primaryId, secondaryId);
140 EXPECT_NE(primaryId, tertiaryId);
141 EXPECT_NE(secondaryId, tertiaryId);
142}
143
144} // namespace android