OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 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. | |
4 | |
5 #include "base/x11/edid_parser_x11.h" | |
6 | |
7 #include "base/memory/scoped_ptr.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 #include <X11/extensions/Xrandr.h> | |
11 | |
12 namespace base { | |
13 | |
14 namespace { | |
15 | |
16 // Returns the number of characters in the string literal but doesn't count its | |
17 // terminator NULL byte. | |
18 #define charsize(str) (arraysize(str) - 1) | |
19 | |
20 // Sample EDID data extracted from real devices. | |
21 const unsigned char kNormalDisplay[] = | |
22 "\x00\xff\xff\xff\xff\xff\xff\x00\x22\xf0\x6c\x28\x01\x01\x01\x01" | |
23 "\x02\x16\x01\x04\xb5\x40\x28\x78\xe2\x8d\x85\xad\x4f\x35\xb1\x25" | |
24 "\x0e\x50\x54\x00\x00\x00\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" | |
25 "\x01\x01\x01\x01\x01\x01\xe2\x68\x00\xa0\xa0\x40\x2e\x60\x30\x20" | |
26 "\x36\x00\x81\x90\x21\x00\x00\x1a\xbc\x1b\x00\xa0\x50\x20\x17\x30" | |
27 "\x30\x20\x36\x00\x81\x90\x21\x00\x00\x1a\x00\x00\x00\xfc\x00\x48" | |
28 "\x50\x20\x5a\x52\x33\x30\x77\x0a\x20\x20\x20\x20\x00\x00\x00\xff" | |
29 "\x00\x43\x4e\x34\x32\x30\x32\x31\x33\x37\x51\x0a\x20\x20\x00\x71"; | |
30 | |
31 const unsigned char kInternalDisplay[] = | |
32 "\x00\xff\xff\xff\xff\xff\xff\x00\x4c\xa3\x42\x31\x00\x00\x00\x00" | |
33 "\x00\x15\x01\x03\x80\x1a\x10\x78\x0a\xd3\xe5\x95\x5c\x60\x90\x27" | |
34 "\x19\x50\x54\x00\x00\x00\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" | |
35 "\x01\x01\x01\x01\x01\x01\x9e\x1b\x00\xa0\x50\x20\x12\x30\x10\x30" | |
36 "\x13\x00\x05\xa3\x10\x00\x00\x19\x00\x00\x00\x0f\x00\x00\x00\x00" | |
37 "\x00\x00\x00\x00\x00\x23\x87\x02\x64\x00\x00\x00\x00\xfe\x00\x53" | |
38 "\x41\x4d\x53\x55\x4e\x47\x0a\x20\x20\x20\x20\x20\x00\x00\x00\xfe" | |
39 "\x00\x31\x32\x31\x41\x54\x31\x31\x2d\x38\x30\x31\x0a\x20\x00\x45"; | |
40 | |
41 const unsigned char kOverscanDisplay[] = | |
42 "\x00\xff\xff\xff\xff\xff\xff\x00\x4c\x2d\xfe\x08\x00\x00\x00\x00" | |
43 "\x29\x15\x01\x03\x80\x10\x09\x78\x0a\xee\x91\xa3\x54\x4c\x99\x26" | |
44 "\x0f\x50\x54\xbd\xef\x80\x71\x4f\x81\xc0\x81\x00\x81\x80\x95\x00" | |
45 "\xa9\xc0\xb3\x00\x01\x01\x02\x3a\x80\x18\x71\x38\x2d\x40\x58\x2c" | |
46 "\x45\x00\xa0\x5a\x00\x00\x00\x1e\x66\x21\x56\xaa\x51\x00\x1e\x30" | |
47 "\x46\x8f\x33\x00\xa0\x5a\x00\x00\x00\x1e\x00\x00\x00\xfd\x00\x18" | |
48 "\x4b\x0f\x51\x17\x00\x0a\x20\x20\x20\x20\x20\x20\x00\x00\x00\xfc" | |
49 "\x00\x53\x41\x4d\x53\x55\x4e\x47\x0a\x20\x20\x20\x20\x20\x01\x1d" | |
50 "\x02\x03\x1f\xf1\x47\x90\x04\x05\x03\x20\x22\x07\x23\x09\x07\x07" | |
51 "\x83\x01\x00\x00\xe2\x00\x0f\x67\x03\x0c\x00\x20\x00\xb8\x2d\x01" | |
52 "\x1d\x80\x18\x71\x1c\x16\x20\x58\x2c\x25\x00\xa0\x5a\x00\x00\x00" | |
53 "\x9e\x01\x1d\x00\x72\x51\xd0\x1e\x20\x6e\x28\x55\x00\xa0\x5a\x00" | |
54 "\x00\x00\x1e\x8c\x0a\xd0\x8a\x20\xe0\x2d\x10\x10\x3e\x96\x00\xa0" | |
55 "\x5a\x00\x00\x00\x18\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\x00" | |
57 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc6"; | |
58 | |
59 const unsigned char kLP2565A[] = | |
60 "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00\x22\xF0\x76\x26\x01\x01\x01\x01" | |
61 "\x02\x12\x01\x03\x80\x34\x21\x78\xEE\xEF\x95\xA3\x54\x4C\x9B\x26" | |
62 "\x0F\x50\x54\xA5\x6B\x80\x81\x40\x81\x80\x81\x99\x71\x00\xA9\x00" | |
63 "\xA9\x40\xB3\x00\xD1\x00\x28\x3C\x80\xA0\x70\xB0\x23\x40\x30\x20" | |
64 "\x36\x00\x07\x44\x21\x00\x00\x1A\x00\x00\x00\xFD\x00\x30\x55\x1E" | |
65 "\x5E\x11\x00\x0A\x20\x20\x20\x20\x20\x20\x00\x00\x00\xFC\x00\x48" | |
66 "\x50\x20\x4C\x50\x32\x34\x36\x35\x0A\x20\x20\x20\x00\x00\x00\xFF" | |
67 "\x00\x43\x4E\x4B\x38\x30\x32\x30\x34\x48\x4D\x0A\x20\x20\x00\xA4"; | |
68 | |
69 const unsigned char kLP2565B[] = | |
70 "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00\x22\xF0\x75\x26\x01\x01\x01\x01" | |
71 "\x02\x12\x01\x03\x6E\x34\x21\x78\xEE\xEF\x95\xA3\x54\x4C\x9B\x26" | |
72 "\x0F\x50\x54\xA5\x6B\x80\x81\x40\x71\x00\xA9\x00\xA9\x40\xA9\x4F" | |
73 "\xB3\x00\xD1\xC0\xD1\x00\x28\x3C\x80\xA0\x70\xB0\x23\x40\x30\x20" | |
74 "\x36\x00\x07\x44\x21\x00\x00\x1A\x00\x00\x00\xFD\x00\x30\x55\x1E" | |
75 "\x5E\x15\x00\x0A\x20\x20\x20\x20\x20\x20\x00\x00\x00\xFC\x00\x48" | |
76 "\x50\x20\x4C\x50\x32\x34\x36\x35\x0A\x20\x20\x20\x00\x00\x00\xFF" | |
77 "\x00\x43\x4E\x4B\x38\x30\x32\x30\x34\x48\x4D\x0A\x20\x20\x00\x45"; | |
78 | |
79 } // namespace | |
80 | |
81 TEST(EdidParserX11Test, ParseEDID) { | |
82 uint16 manufacturer_id = 0; | |
83 std::string human_readable_name; | |
84 EXPECT_TRUE(ParseOutputDeviceData( | |
85 kNormalDisplay, charsize(kNormalDisplay), | |
86 &manufacturer_id, &human_readable_name)); | |
87 EXPECT_EQ(0x22f0u, manufacturer_id); | |
88 EXPECT_EQ("HP ZR30w", human_readable_name); | |
89 | |
90 manufacturer_id = 0; | |
91 human_readable_name.clear(); | |
92 EXPECT_TRUE(ParseOutputDeviceData( | |
93 kInternalDisplay, charsize(kInternalDisplay), | |
94 &manufacturer_id, NULL)); | |
95 EXPECT_EQ(0x4ca3u, manufacturer_id); | |
96 EXPECT_EQ("", human_readable_name); | |
97 | |
98 // Internal display doesn't have name. | |
99 EXPECT_TRUE(ParseOutputDeviceData( | |
100 kInternalDisplay, charsize(kInternalDisplay), | |
101 NULL, &human_readable_name)); | |
102 EXPECT_TRUE(human_readable_name.empty()); | |
103 | |
104 manufacturer_id = 0; | |
105 human_readable_name.clear(); | |
106 EXPECT_TRUE(ParseOutputDeviceData( | |
107 kOverscanDisplay, charsize(kOverscanDisplay), | |
108 &manufacturer_id, &human_readable_name)); | |
109 EXPECT_EQ(0x4c2du, manufacturer_id); | |
110 EXPECT_EQ("SAMSUNG", human_readable_name); | |
111 } | |
112 | |
113 TEST(EdidParserX11Test, ParseBrokenEDID) { | |
114 uint16 manufacturer_id = 0; | |
115 std::string human_readable_name; | |
116 | |
117 // length == 0 | |
118 EXPECT_FALSE(ParseOutputDeviceData( | |
119 kNormalDisplay, 0, | |
120 &manufacturer_id, &human_readable_name)); | |
121 | |
122 // name is broken. Copying kNormalDisplay and substitute its name data by | |
123 // some control code. | |
124 std::string display_data( | |
125 reinterpret_cast<const char*>(kNormalDisplay), charsize(kNormalDisplay)); | |
126 | |
127 // display's name data is embedded in byte 95-107 in this specific example. | |
128 // Fix here too when the contents of kNormalDisplay is altered. | |
129 display_data[97] = '\x1b'; | |
130 EXPECT_FALSE(ParseOutputDeviceData( | |
131 reinterpret_cast<const unsigned char*>(display_data.data()), | |
132 display_data.size(), | |
133 &manufacturer_id, &human_readable_name)); | |
134 | |
135 // If |human_readable_name| isn't specified, it skips parsing the name. | |
136 manufacturer_id = 0; | |
137 EXPECT_TRUE(ParseOutputDeviceData( | |
138 reinterpret_cast<const unsigned char*>(display_data.data()), | |
139 display_data.size(), | |
140 &manufacturer_id, NULL)); | |
141 EXPECT_EQ(0x22f0u, manufacturer_id); | |
142 } | |
143 | |
144 TEST(EdidParserX11Test, GetDisplayId) { | |
145 // EDID of kLP2565A and B are slightly different but actually the same device. | |
146 int64 id1 = -1; | |
147 int64 id2 = -1; | |
148 EXPECT_TRUE(GetDisplayIdFromEDID(kLP2565A, charsize(kLP2565A), 0, &id1)); | |
149 EXPECT_TRUE(GetDisplayIdFromEDID(kLP2565B, charsize(kLP2565B), 0, &id2)); | |
150 EXPECT_EQ(id1, id2); | |
151 EXPECT_NE(-1, id1); | |
152 } | |
153 | |
154 TEST(EdidParserX11Test, GetDisplayIdFromInternal) { | |
155 int64 id = -1; | |
156 EXPECT_TRUE(GetDisplayIdFromEDID( | |
157 kInternalDisplay, charsize(kInternalDisplay), 0, &id)); | |
158 EXPECT_NE(-1, id); | |
159 } | |
160 | |
161 TEST(EdidParserX11Test, GetDisplayIdFailure) { | |
162 int64 id = -1; | |
163 EXPECT_FALSE(GetDisplayIdFromEDID(NULL, 0, 0, &id)); | |
164 EXPECT_EQ(-1, id); | |
165 } | |
166 | |
167 } // namespace base | |
OLD | NEW |