Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(974)

Side by Side Diff: ui/base/x/x11_util_unittest.cc

Issue 11725005: Checks the possibility of overscans from EDID extension data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/x/x11_util.cc ('k') | ui/ui_unittests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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/basictypes.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/base/x/x11_util.h"
9
10 namespace ui {
11
12 namespace {
13
14 // Sample EDID data extracted from real devices.
15 const unsigned char kNormalDisplay[] =
16 "\x00\xff\xff\xff\xff\xff\xff\x00\x22\xf0\x6c\x28\x01\x01\x01\x01"
17 "\x02\x16\x01\x04\xb5\x40\x28\x78\xe2\x8d\x85\xad\x4f\x35\xb1\x25"
18 "\x0e\x50\x54\x00\x00\x00\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
19 "\x01\x01\x01\x01\x01\x01\xe2\x68\x00\xa0\xa0\x40\x2e\x60\x30\x20"
20 "\x36\x00\x81\x90\x21\x00\x00\x1a\xbc\x1b\x00\xa0\x50\x20\x17\x30"
21 "\x30\x20\x36\x00\x81\x90\x21\x00\x00\x1a\x00\x00\x00\xfc\x00\x48"
22 "\x50\x20\x5a\x52\x33\x30\x77\x0a\x20\x20\x20\x20\x00\x00\x00\xff"
23 "\x00\x43\x4e\x34\x32\x30\x32\x31\x33\x37\x51\x0a\x20\x20\x00\x71";
24
25 const unsigned char kInternalDisplay[] =
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
35 const unsigned char kOverscanDisplay[] =
36 "\x00\xff\xff\xff\xff\xff\xff\x00\x4c\x2d\xfe\x08\x00\x00\x00\x00"
37 "\x29\x15\x01\x03\x80\x10\x09\x78\x0a\xee\x91\xa3\x54\x4c\x99\x26"
38 "\x0f\x50\x54\xbd\xef\x80\x71\x4f\x81\xc0\x81\x00\x81\x80\x95\x00"
39 "\xa9\xc0\xb3\x00\x01\x01\x02\x3a\x80\x18\x71\x38\x2d\x40\x58\x2c"
40 "\x45\x00\xa0\x5a\x00\x00\x00\x1e\x66\x21\x56\xaa\x51\x00\x1e\x30"
41 "\x46\x8f\x33\x00\xa0\x5a\x00\x00\x00\x1e\x00\x00\x00\xfd\x00\x18"
42 "\x4b\x0f\x51\x17\x00\x0a\x20\x20\x20\x20\x20\x20\x00\x00\x00\xfc"
43 "\x00\x53\x41\x4d\x53\x55\x4e\x47\x0a\x20\x20\x20\x20\x20\x01\x1d"
44 "\x02\x03\x1f\xf1\x47\x90\x04\x05\x03\x20\x22\x07\x23\x09\x07\x07"
45 "\x83\x01\x00\x00\xe2\x00\x0f\x67\x03\x0c\x00\x20\x00\xb8\x2d\x01"
46 "\x1d\x80\x18\x71\x1c\x16\x20\x58\x2c\x25\x00\xa0\x5a\x00\x00\x00"
47 "\x9e\x01\x1d\x00\x72\x51\xd0\x1e\x20\x6e\x28\x55\x00\xa0\x5a\x00"
48 "\x00\x00\x1e\x8c\x0a\xd0\x8a\x20\xe0\x2d\x10\x10\x3e\x96\x00\xa0"
49 "\x5a\x00\x00\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
50 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
51 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc6";
52
53 }
54
55 TEST(X11UtilTest, ParseEDID) {
56 uint16 manufacturer_id = 0;
57 uint32 serial_number = 0;
58 std::string human_readable_name;
59 EXPECT_TRUE(ParseOutputDeviceData(
60 kNormalDisplay, arraysize(kNormalDisplay),
61 &manufacturer_id, &serial_number, &human_readable_name));
62 EXPECT_EQ(0x22f0u, manufacturer_id);
63 EXPECT_EQ(0x01010101u, serial_number);
64 EXPECT_EQ("HP ZR30w", human_readable_name);
65
66 manufacturer_id = 0;
67 serial_number = 0;
68 human_readable_name.clear();
69 EXPECT_TRUE(ParseOutputDeviceData(
70 kInternalDisplay, arraysize(kInternalDisplay),
71 &manufacturer_id, &serial_number, NULL));
72 EXPECT_EQ(0x4ca3u, manufacturer_id);
73 EXPECT_EQ(0x00000000u, serial_number);
74 EXPECT_EQ("", human_readable_name);
75
76 // Internal display doesn't have name.
77 EXPECT_FALSE(ParseOutputDeviceData(
78 kInternalDisplay, arraysize(kInternalDisplay),
79 NULL, NULL, &human_readable_name));
80
81 manufacturer_id = 0;
82 serial_number = 0;
83 human_readable_name.clear();
84 EXPECT_TRUE(ParseOutputDeviceData(
85 kOverscanDisplay, arraysize(kOverscanDisplay),
86 &manufacturer_id, &serial_number, &human_readable_name));
87 EXPECT_EQ(0x4c2du, manufacturer_id);
88 EXPECT_EQ(0x00000000u, serial_number);
89 EXPECT_EQ("SAMSUNG", human_readable_name);
90 }
91
92 TEST(X11UtilTest, ParseBrokenEDID) {
93 uint16 manufacturer_id = 0;
94 uint32 serial_number = 0;
95 std::string human_readable_name;
96
97 // length == 0
98 EXPECT_FALSE(ParseOutputDeviceData(
99 kNormalDisplay, 0,
100 &manufacturer_id, &serial_number, &human_readable_name));
101
102 // name is broken. Copying kNormalDisplay and substitute its name data by
103 // some control code.
104 std::string display_data(
105 reinterpret_cast<const char*>(kNormalDisplay), arraysize(kNormalDisplay));
106
107 // display's name data is embedded in byte 95-107 in this specific example.
108 // Fix here too when the contents of kNormalDisplay is altered.
109 display_data[97] = '\x1b';
110 EXPECT_FALSE(ParseOutputDeviceData(
111 reinterpret_cast<const unsigned char*>(display_data.data()),
112 display_data.size(),
113 &manufacturer_id, &serial_number, &human_readable_name));
114
115 // If |human_readable_name| isn't specified, it skips parsing the name.
116 manufacturer_id = 0;
117 serial_number = 0;
118 EXPECT_TRUE(ParseOutputDeviceData(
119 reinterpret_cast<const unsigned char*>(display_data.data()),
120 display_data.size(),
121 &manufacturer_id, &serial_number, NULL));
122 EXPECT_EQ(0x22f0u, manufacturer_id);
123 EXPECT_EQ(0x01010101u, serial_number);
124 }
125
126 TEST(X11UtilTest, ParseOverscanFlag) {
127 bool flag = false;
128 EXPECT_FALSE(ParseOutputOverscanFlag(
129 kNormalDisplay, arraysize(kNormalDisplay), &flag));
130
131 flag = false;
132 EXPECT_FALSE(ParseOutputOverscanFlag(
133 kInternalDisplay, arraysize(kInternalDisplay), &flag));
134
135 flag = false;
136 EXPECT_TRUE(ParseOutputOverscanFlag(
137 kOverscanDisplay, arraysize(kOverscanDisplay), &flag));
138 EXPECT_TRUE(flag);
139
140 flag = false;
141 // Copy |kOverscanDisplay| and set flags to false in it. The overscan flags
142 // are embedded at byte 150 in this specific example. Fix here too when the
143 // contents of kOverscanDisplay is altered.
144 std::string display_data(reinterpret_cast<const char*>(kOverscanDisplay),
145 arraysize(kOverscanDisplay));
146 display_data[150] = '\0';
147 EXPECT_TRUE(ParseOutputOverscanFlag(
148 reinterpret_cast<const unsigned char*>(display_data.data()),
149 display_data.size(), &flag));
150 EXPECT_FALSE(flag);
151 }
152
153 TEST(X11UtilTest, ParseBrokenOverscanData) {
154 // Do not fill valid data here because it anyway fails to parse the data.
155 scoped_array<unsigned char> data(new unsigned char[126]);
156 bool flag = false;
157 EXPECT_FALSE(ParseOutputOverscanFlag(data.get(), 0, &flag));
158 EXPECT_FALSE(ParseOutputOverscanFlag(data.get(), 126, &flag));
159
160 // extending data because ParseOutputOverscanFlag() will access the data.
161 data.reset(new unsigned char[150]);
162 // The number of CEA extensions is stored at byte 126.
163 data[126] = '\x01';
164 EXPECT_FALSE(ParseOutputOverscanFlag(data.get(), 128, &flag));
165 EXPECT_FALSE(ParseOutputOverscanFlag(data.get(), 150, &flag));
166 }
167
168 }
OLDNEW
« no previous file with comments | « ui/base/x/x11_util.cc ('k') | ui/ui_unittests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698