Add a stub __cxa_demangle to disable LLVM's demangler.
[chromium-blink-merge.git] / ui / display / util / edid_parser_unittest.cc
blob2e77cacf678d16d0e45ab6f182d5dc3b56f54983
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/display/util/edid_parser.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/geometry/size.h"
11 namespace ui {
13 namespace {
15 // Returns the number of characters in the string literal but doesn't count its
16 // terminator NULL byte.
17 #define charsize(str) (arraysize(str) - 1)
19 // Sample EDID data extracted from real devices.
20 const unsigned char kNormalDisplay[] =
21 "\x00\xff\xff\xff\xff\xff\xff\x00\x22\xf0\x6c\x28\x01\x01\x01\x01"
22 "\x02\x16\x01\x04\xb5\x40\x28\x78\xe2\x8d\x85\xad\x4f\x35\xb1\x25"
23 "\x0e\x50\x54\x00\x00\x00\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
24 "\x01\x01\x01\x01\x01\x01\xe2\x68\x00\xa0\xa0\x40\x2e\x60\x30\x20"
25 "\x36\x00\x81\x90\x21\x00\x00\x1a\xbc\x1b\x00\xa0\x50\x20\x17\x30"
26 "\x30\x20\x36\x00\x81\x90\x21\x00\x00\x1a\x00\x00\x00\xfc\x00\x48"
27 "\x50\x20\x5a\x52\x33\x30\x77\x0a\x20\x20\x20\x20\x00\x00\x00\xff"
28 "\x00\x43\x4e\x34\x32\x30\x32\x31\x33\x37\x51\x0a\x20\x20\x00\x71";
30 const unsigned char kInternalDisplay[] =
31 "\x00\xff\xff\xff\xff\xff\xff\x00\x4c\xa3\x42\x31\x00\x00\x00\x00"
32 "\x00\x15\x01\x03\x80\x1a\x10\x78\x0a\xd3\xe5\x95\x5c\x60\x90\x27"
33 "\x19\x50\x54\x00\x00\x00\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
34 "\x01\x01\x01\x01\x01\x01\x9e\x1b\x00\xa0\x50\x20\x12\x30\x10\x30"
35 "\x13\x00\x05\xa3\x10\x00\x00\x19\x00\x00\x00\x0f\x00\x00\x00\x00"
36 "\x00\x00\x00\x00\x00\x23\x87\x02\x64\x00\x00\x00\x00\xfe\x00\x53"
37 "\x41\x4d\x53\x55\x4e\x47\x0a\x20\x20\x20\x20\x20\x00\x00\x00\xfe"
38 "\x00\x31\x32\x31\x41\x54\x31\x31\x2d\x38\x30\x31\x0a\x20\x00\x45";
40 const unsigned char kOverscanDisplay[] =
41 "\x00\xff\xff\xff\xff\xff\xff\x00\x4c\x2d\xfe\x08\x00\x00\x00\x00"
42 "\x29\x15\x01\x03\x80\x10\x09\x78\x0a\xee\x91\xa3\x54\x4c\x99\x26"
43 "\x0f\x50\x54\xbd\xef\x80\x71\x4f\x81\xc0\x81\x00\x81\x80\x95\x00"
44 "\xa9\xc0\xb3\x00\x01\x01\x02\x3a\x80\x18\x71\x38\x2d\x40\x58\x2c"
45 "\x45\x00\xa0\x5a\x00\x00\x00\x1e\x66\x21\x56\xaa\x51\x00\x1e\x30"
46 "\x46\x8f\x33\x00\xa0\x5a\x00\x00\x00\x1e\x00\x00\x00\xfd\x00\x18"
47 "\x4b\x0f\x51\x17\x00\x0a\x20\x20\x20\x20\x20\x20\x00\x00\x00\xfc"
48 "\x00\x53\x41\x4d\x53\x55\x4e\x47\x0a\x20\x20\x20\x20\x20\x01\x1d"
49 "\x02\x03\x1f\xf1\x47\x90\x04\x05\x03\x20\x22\x07\x23\x09\x07\x07"
50 "\x83\x01\x00\x00\xe2\x00\x0f\x67\x03\x0c\x00\x20\x00\xb8\x2d\x01"
51 "\x1d\x80\x18\x71\x1c\x16\x20\x58\x2c\x25\x00\xa0\x5a\x00\x00\x00"
52 "\x9e\x01\x1d\x00\x72\x51\xd0\x1e\x20\x6e\x28\x55\x00\xa0\x5a\x00"
53 "\x00\x00\x1e\x8c\x0a\xd0\x8a\x20\xe0\x2d\x10\x10\x3e\x96\x00\xa0"
54 "\x5a\x00\x00\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
55 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
56 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc6";
58 // The EDID info misdetecting overscan once. see crbug.com/226318
59 const unsigned char kMisdetectedDisplay[] =
60 "\x00\xff\xff\xff\xff\xff\xff\x00\x10\xac\x64\x40\x4c\x30\x30\x32"
61 "\x0c\x15\x01\x03\x80\x40\x28\x78\xea\x8d\x85\xad\x4f\x35\xb1\x25"
62 "\x0e\x50\x54\xa5\x4b\x00\x71\x4f\x81\x00\x81\x80\xd1\x00\xa9\x40"
63 "\x01\x01\x01\x01\x01\x01\x28\x3c\x80\xa0\x70\xb0\x23\x40\x30\x20"
64 "\x36\x00\x81\x91\x21\x00\x00\x1a\x00\x00\x00\xff\x00\x50\x48\x35"
65 "\x4e\x59\x31\x33\x4e\x32\x30\x30\x4c\x0a\x00\x00\x00\xfc\x00\x44"
66 "\x45\x4c\x4c\x20\x55\x33\x30\x31\x31\x0a\x20\x20\x00\x00\x00\xfd"
67 "\x00\x31\x56\x1d\x5e\x12\x00\x0a\x20\x20\x20\x20\x20\x20\x01\x38"
68 "\x02\x03\x29\xf1\x50\x90\x05\x04\x03\x02\x07\x16\x01\x06\x11\x12"
69 "\x15\x13\x14\x1f\x20\x23\x0d\x7f\x07\x83\x0f\x00\x00\x67\x03\x0c"
70 "\x00\x10\x00\x38\x2d\xe3\x05\x03\x01\x02\x3a\x80\x18\x71\x38\x2d"
71 "\x40\x58\x2c\x45\x00\x81\x91\x21\x00\x00\x1e\x01\x1d\x80\x18\x71"
72 "\x1c\x16\x20\x58\x2c\x25\x00\x81\x91\x21\x00\x00\x9e\x01\x1d\x00"
73 "\x72\x51\xd0\x1e\x20\x6e\x28\x55\x00\x81\x91\x21\x00\x00\x1e\x8c"
74 "\x0a\xd0\x8a\x20\xe0\x2d\x10\x10\x3e\x96\x00\x81\x91\x21\x00\x00"
75 "\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x94";
77 const unsigned char kLP2565A[] =
78 "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00\x22\xF0\x76\x26\x01\x01\x01\x01"
79 "\x02\x12\x01\x03\x80\x34\x21\x78\xEE\xEF\x95\xA3\x54\x4C\x9B\x26"
80 "\x0F\x50\x54\xA5\x6B\x80\x81\x40\x81\x80\x81\x99\x71\x00\xA9\x00"
81 "\xA9\x40\xB3\x00\xD1\x00\x28\x3C\x80\xA0\x70\xB0\x23\x40\x30\x20"
82 "\x36\x00\x07\x44\x21\x00\x00\x1A\x00\x00\x00\xFD\x00\x30\x55\x1E"
83 "\x5E\x11\x00\x0A\x20\x20\x20\x20\x20\x20\x00\x00\x00\xFC\x00\x48"
84 "\x50\x20\x4C\x50\x32\x34\x36\x35\x0A\x20\x20\x20\x00\x00\x00\xFF"
85 "\x00\x43\x4E\x4B\x38\x30\x32\x30\x34\x48\x4D\x0A\x20\x20\x00\xA4";
87 const unsigned char kLP2565B[] =
88 "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00\x22\xF0\x75\x26\x01\x01\x01\x01"
89 "\x02\x12\x01\x03\x6E\x34\x21\x78\xEE\xEF\x95\xA3\x54\x4C\x9B\x26"
90 "\x0F\x50\x54\xA5\x6B\x80\x81\x40\x71\x00\xA9\x00\xA9\x40\xA9\x4F"
91 "\xB3\x00\xD1\xC0\xD1\x00\x28\x3C\x80\xA0\x70\xB0\x23\x40\x30\x20"
92 "\x36\x00\x07\x44\x21\x00\x00\x1A\x00\x00\x00\xFD\x00\x30\x55\x1E"
93 "\x5E\x15\x00\x0A\x20\x20\x20\x20\x20\x20\x00\x00\x00\xFC\x00\x48"
94 "\x50\x20\x4C\x50\x32\x34\x36\x35\x0A\x20\x20\x20\x00\x00\x00\xFF"
95 "\x00\x43\x4E\x4B\x38\x30\x32\x30\x34\x48\x4D\x0A\x20\x20\x00\x45";
97 void Reset(gfx::Size* pixel, gfx::Size* size) {
98 pixel->SetSize(0, 0);
99 size->SetSize(0, 0);
102 } // namespace
104 TEST(EDIDParserTest, ParseOverscanFlag) {
105 bool flag = false;
106 std::vector<uint8_t> edid(
107 kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay));
108 EXPECT_FALSE(ParseOutputOverscanFlag(edid, &flag));
110 flag = false;
111 edid.assign(kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay));
112 EXPECT_FALSE(ParseOutputOverscanFlag(edid, &flag));
114 flag = false;
115 edid.assign(kOverscanDisplay, kOverscanDisplay + charsize(kOverscanDisplay));
116 EXPECT_TRUE(ParseOutputOverscanFlag(edid, &flag));
117 EXPECT_TRUE(flag);
119 flag = false;
120 edid.assign(
121 kMisdetectedDisplay, kMisdetectedDisplay + charsize(kMisdetectedDisplay));
122 EXPECT_FALSE(ParseOutputOverscanFlag(edid, &flag));
124 flag = false;
125 // Copy |kOverscanDisplay| and set flags to false in it. The overscan flags
126 // are embedded at byte 150 in this specific example. Fix here too when the
127 // contents of kOverscanDisplay is altered.
128 edid.assign(kOverscanDisplay, kOverscanDisplay + charsize(kOverscanDisplay));
129 edid[150] = '\0';
130 EXPECT_TRUE(ParseOutputOverscanFlag(edid, &flag));
131 EXPECT_FALSE(flag);
134 TEST(EDIDParserTest, ParseBrokenOverscanData) {
135 // Do not fill valid data here because it anyway fails to parse the data.
136 std::vector<uint8_t> data;
137 bool flag = false;
138 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag));
139 data.assign(126, '\0');
140 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag));
142 // extending data because ParseOutputOverscanFlag() will access the data.
143 data.assign(128, '\0');
144 // The number of CEA extensions is stored at byte 126.
145 data[126] = '\x01';
146 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag));
148 data.assign(150, '\0');
149 data[126] = '\x01';
150 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag));
153 TEST(EDIDParserTest, ParseEDID) {
154 uint16_t manufacturer_id = 0;
155 uint16_t product_code = 0;
156 std::string human_readable_name;
157 std::vector<uint8_t> edid(
158 kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay));
159 gfx::Size pixel;
160 gfx::Size size;
161 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, &product_code,
162 &human_readable_name, &pixel, &size));
163 EXPECT_EQ(0x22f0u, manufacturer_id);
164 EXPECT_EQ(0x286cu, product_code);
165 EXPECT_EQ("HP ZR30w", human_readable_name);
166 EXPECT_EQ("2560x1600", pixel.ToString());
167 EXPECT_EQ("641x400", size.ToString());
169 manufacturer_id = 0;
170 product_code = 0;
171 human_readable_name.clear();
172 Reset(&pixel, &size);
173 edid.assign(kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay));
175 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, &product_code,
176 nullptr, &pixel, &size));
177 EXPECT_EQ(0x4ca3u, manufacturer_id);
178 EXPECT_EQ(0x3142u, product_code);
179 EXPECT_EQ("", human_readable_name);
180 EXPECT_EQ("1280x800", pixel.ToString());
181 EXPECT_EQ("261x163", size.ToString());
183 // Internal display doesn't have name.
184 EXPECT_TRUE(ParseOutputDeviceData(edid, nullptr, nullptr,
185 &human_readable_name, &pixel, &size));
186 EXPECT_TRUE(human_readable_name.empty());
188 manufacturer_id = 0;
189 product_code = 0;
190 human_readable_name.clear();
191 Reset(&pixel, &size);
192 edid.assign(kOverscanDisplay, kOverscanDisplay + charsize(kOverscanDisplay));
193 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, &product_code,
194 &human_readable_name, &pixel, &size));
195 EXPECT_EQ(0x4c2du, manufacturer_id);
196 EXPECT_EQ(0x08feu, product_code);
197 EXPECT_EQ("SAMSUNG", human_readable_name);
198 EXPECT_EQ("1920x1080", pixel.ToString());
199 EXPECT_EQ("160x90", size.ToString());
202 TEST(EDIDParserTest, ParseBrokenEDID) {
203 uint16_t manufacturer_id = 0;
204 uint16_t product_code = 0;
205 std::string human_readable_name;
206 std::vector<uint8_t> edid;
208 gfx::Size dummy;
210 // length == 0
211 EXPECT_FALSE(ParseOutputDeviceData(edid, &manufacturer_id, &product_code,
212 &human_readable_name, &dummy, &dummy));
214 // name is broken. Copying kNormalDisplay and substitute its name data by
215 // some control code.
216 edid.assign(kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay));
218 // display's name data is embedded in byte 95-107 in this specific example.
219 // Fix here too when the contents of kNormalDisplay is altered.
220 edid[97] = '\x1b';
221 EXPECT_FALSE(ParseOutputDeviceData(edid, &manufacturer_id, nullptr,
222 &human_readable_name, &dummy, &dummy));
224 // If |human_readable_name| isn't specified, it skips parsing the name.
225 manufacturer_id = 0;
226 product_code = 0;
227 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, &product_code,
228 nullptr, &dummy, &dummy));
229 EXPECT_EQ(0x22f0u, manufacturer_id);
230 EXPECT_EQ(0x286cu, product_code);
233 TEST(EDIDParserTest, GetDisplayId) {
234 // EDID of kLP2565A and B are slightly different but actually the same device.
235 int64_t id1 = -1;
236 int64_t id2 = -1;
237 int64_t product_id1 = -1;
238 int64_t product_id2 = -1;
239 std::vector<uint8_t> edid(kLP2565A, kLP2565A + charsize(kLP2565A));
240 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id1, &product_id1));
241 edid.assign(kLP2565B, kLP2565B + charsize(kLP2565B));
242 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id2, &product_id2));
243 EXPECT_EQ(id1, id2);
244 // The product code in the two EDIDs varies.
245 EXPECT_NE(product_id1, product_id2);
246 EXPECT_EQ(0x22f02676, product_id1);
247 EXPECT_EQ(0x22f02675, product_id2);
248 EXPECT_NE(-1, id1);
249 EXPECT_NE(-1, product_id1);
252 TEST(EDIDParserTest, GetDisplayIdFromInternal) {
253 int64_t id = -1;
254 int64_t product_id = -1;
255 std::vector<uint8_t> edid(
256 kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay));
257 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id, &product_id));
258 EXPECT_NE(-1, id);
259 EXPECT_NE(-1, product_id);
262 TEST(EDIDParserTest, GetDisplayIdFailure) {
263 int64_t id = -1;
264 int64_t product_id = -1;
265 std::vector<uint8_t> edid;
266 EXPECT_FALSE(GetDisplayIdFromEDID(edid, 0, &id, &product_id));
267 EXPECT_EQ(-1, id);
268 EXPECT_EQ(-1, product_id);
271 } // namespace ui