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

Side by Side Diff: ui/display/edid_parser_unittest.cc

Issue 215233002: Update ui/display to use primitive types as defined in stdint.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 8 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/display/edid_parser.cc ('k') | ui/display/x11/edid_parser_x11.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/display/edid_parser.h" 5 #include "ui/display/edid_parser.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace ui { 10 namespace ui {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 "\xB3\x00\xD1\xC0\xD1\x00\x28\x3C\x80\xA0\x70\xB0\x23\x40\x30\x20" 90 "\xB3\x00\xD1\xC0\xD1\x00\x28\x3C\x80\xA0\x70\xB0\x23\x40\x30\x20"
91 "\x36\x00\x07\x44\x21\x00\x00\x1A\x00\x00\x00\xFD\x00\x30\x55\x1E" 91 "\x36\x00\x07\x44\x21\x00\x00\x1A\x00\x00\x00\xFD\x00\x30\x55\x1E"
92 "\x5E\x15\x00\x0A\x20\x20\x20\x20\x20\x20\x00\x00\x00\xFC\x00\x48" 92 "\x5E\x15\x00\x0A\x20\x20\x20\x20\x20\x20\x00\x00\x00\xFC\x00\x48"
93 "\x50\x20\x4C\x50\x32\x34\x36\x35\x0A\x20\x20\x20\x00\x00\x00\xFF" 93 "\x50\x20\x4C\x50\x32\x34\x36\x35\x0A\x20\x20\x20\x00\x00\x00\xFF"
94 "\x00\x43\x4E\x4B\x38\x30\x32\x30\x34\x48\x4D\x0A\x20\x20\x00\x45"; 94 "\x00\x43\x4E\x4B\x38\x30\x32\x30\x34\x48\x4D\x0A\x20\x20\x00\x45";
95 95
96 } // namespace 96 } // namespace
97 97
98 TEST(EDIDParserTest, ParseOverscanFlag) { 98 TEST(EDIDParserTest, ParseOverscanFlag) {
99 bool flag = false; 99 bool flag = false;
100 std::vector<uint8> edid( 100 std::vector<uint8_t> edid(
101 kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay)); 101 kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay));
102 EXPECT_FALSE(ParseOutputOverscanFlag(edid, &flag)); 102 EXPECT_FALSE(ParseOutputOverscanFlag(edid, &flag));
103 103
104 flag = false; 104 flag = false;
105 edid.assign(kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay)); 105 edid.assign(kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay));
106 EXPECT_FALSE(ParseOutputOverscanFlag(edid, &flag)); 106 EXPECT_FALSE(ParseOutputOverscanFlag(edid, &flag));
107 107
108 flag = false; 108 flag = false;
109 edid.assign(kOverscanDisplay, kOverscanDisplay + charsize(kOverscanDisplay)); 109 edid.assign(kOverscanDisplay, kOverscanDisplay + charsize(kOverscanDisplay));
110 EXPECT_TRUE(ParseOutputOverscanFlag(edid, &flag)); 110 EXPECT_TRUE(ParseOutputOverscanFlag(edid, &flag));
111 EXPECT_TRUE(flag); 111 EXPECT_TRUE(flag);
112 112
113 flag = false; 113 flag = false;
114 edid.assign( 114 edid.assign(
115 kMisdetectedDisplay, kMisdetectedDisplay + charsize(kMisdetectedDisplay)); 115 kMisdetectedDisplay, kMisdetectedDisplay + charsize(kMisdetectedDisplay));
116 EXPECT_FALSE(ParseOutputOverscanFlag(edid, &flag)); 116 EXPECT_FALSE(ParseOutputOverscanFlag(edid, &flag));
117 117
118 flag = false; 118 flag = false;
119 // Copy |kOverscanDisplay| and set flags to false in it. The overscan flags 119 // Copy |kOverscanDisplay| and set flags to false in it. The overscan flags
120 // are embedded at byte 150 in this specific example. Fix here too when the 120 // are embedded at byte 150 in this specific example. Fix here too when the
121 // contents of kOverscanDisplay is altered. 121 // contents of kOverscanDisplay is altered.
122 edid.assign(kOverscanDisplay, kOverscanDisplay + charsize(kOverscanDisplay)); 122 edid.assign(kOverscanDisplay, kOverscanDisplay + charsize(kOverscanDisplay));
123 edid[150] = '\0'; 123 edid[150] = '\0';
124 EXPECT_TRUE(ParseOutputOverscanFlag(edid, &flag)); 124 EXPECT_TRUE(ParseOutputOverscanFlag(edid, &flag));
125 EXPECT_FALSE(flag); 125 EXPECT_FALSE(flag);
126 } 126 }
127 127
128 TEST(EDIDParserTest, ParseBrokenOverscanData) { 128 TEST(EDIDParserTest, ParseBrokenOverscanData) {
129 // Do not fill valid data here because it anyway fails to parse the data. 129 // Do not fill valid data here because it anyway fails to parse the data.
130 std::vector<uint8> data; 130 std::vector<uint8_t> data;
131 bool flag = false; 131 bool flag = false;
132 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag)); 132 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag));
133 data.assign(126, '\0'); 133 data.assign(126, '\0');
134 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag)); 134 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag));
135 135
136 // extending data because ParseOutputOverscanFlag() will access the data. 136 // extending data because ParseOutputOverscanFlag() will access the data.
137 data.assign(128, '\0'); 137 data.assign(128, '\0');
138 // The number of CEA extensions is stored at byte 126. 138 // The number of CEA extensions is stored at byte 126.
139 data[126] = '\x01'; 139 data[126] = '\x01';
140 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag)); 140 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag));
141 141
142 data.assign(150, '\0'); 142 data.assign(150, '\0');
143 data[126] = '\x01'; 143 data[126] = '\x01';
144 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag)); 144 EXPECT_FALSE(ParseOutputOverscanFlag(data, &flag));
145 } 145 }
146 146
147 TEST(EDIDParserTest, ParseEDID) { 147 TEST(EDIDParserTest, ParseEDID) {
148 uint16 manufacturer_id = 0; 148 uint16_t manufacturer_id = 0;
149 std::string human_readable_name; 149 std::string human_readable_name;
150 std::vector<uint8> edid( 150 std::vector<uint8_t> edid(
151 kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay)); 151 kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay));
152 EXPECT_TRUE(ParseOutputDeviceData( 152 EXPECT_TRUE(ParseOutputDeviceData(
153 edid, &manufacturer_id, &human_readable_name)); 153 edid, &manufacturer_id, &human_readable_name));
154 EXPECT_EQ(0x22f0u, manufacturer_id); 154 EXPECT_EQ(0x22f0u, manufacturer_id);
155 EXPECT_EQ("HP ZR30w", human_readable_name); 155 EXPECT_EQ("HP ZR30w", human_readable_name);
156 156
157 manufacturer_id = 0; 157 manufacturer_id = 0;
158 human_readable_name.clear(); 158 human_readable_name.clear();
159 edid.assign(kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay)); 159 edid.assign(kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay));
160 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, NULL)); 160 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, NULL));
161 EXPECT_EQ(0x4ca3u, manufacturer_id); 161 EXPECT_EQ(0x4ca3u, manufacturer_id);
162 EXPECT_EQ("", human_readable_name); 162 EXPECT_EQ("", human_readable_name);
163 163
164 // Internal display doesn't have name. 164 // Internal display doesn't have name.
165 EXPECT_TRUE(ParseOutputDeviceData(edid, NULL, &human_readable_name)); 165 EXPECT_TRUE(ParseOutputDeviceData(edid, NULL, &human_readable_name));
166 EXPECT_TRUE(human_readable_name.empty()); 166 EXPECT_TRUE(human_readable_name.empty());
167 167
168 manufacturer_id = 0; 168 manufacturer_id = 0;
169 human_readable_name.clear(); 169 human_readable_name.clear();
170 edid.assign(kOverscanDisplay, kOverscanDisplay + charsize(kOverscanDisplay)); 170 edid.assign(kOverscanDisplay, kOverscanDisplay + charsize(kOverscanDisplay));
171 EXPECT_TRUE(ParseOutputDeviceData( 171 EXPECT_TRUE(ParseOutputDeviceData(
172 edid, &manufacturer_id, &human_readable_name)); 172 edid, &manufacturer_id, &human_readable_name));
173 EXPECT_EQ(0x4c2du, manufacturer_id); 173 EXPECT_EQ(0x4c2du, manufacturer_id);
174 EXPECT_EQ("SAMSUNG", human_readable_name); 174 EXPECT_EQ("SAMSUNG", human_readable_name);
175 } 175 }
176 176
177 TEST(EDIDParserTest, ParseBrokenEDID) { 177 TEST(EDIDParserTest, ParseBrokenEDID) {
178 uint16 manufacturer_id = 0; 178 uint16_t manufacturer_id = 0;
179 std::string human_readable_name; 179 std::string human_readable_name;
180 std::vector<uint8> edid; 180 std::vector<uint8_t> edid;
181 181
182 // length == 0 182 // length == 0
183 EXPECT_FALSE(ParseOutputDeviceData( 183 EXPECT_FALSE(ParseOutputDeviceData(
184 edid, &manufacturer_id, &human_readable_name)); 184 edid, &manufacturer_id, &human_readable_name));
185 185
186 // name is broken. Copying kNormalDisplay and substitute its name data by 186 // name is broken. Copying kNormalDisplay and substitute its name data by
187 // some control code. 187 // some control code.
188 edid.assign(kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay)); 188 edid.assign(kNormalDisplay, kNormalDisplay + charsize(kNormalDisplay));
189 189
190 // display's name data is embedded in byte 95-107 in this specific example. 190 // display's name data is embedded in byte 95-107 in this specific example.
191 // Fix here too when the contents of kNormalDisplay is altered. 191 // Fix here too when the contents of kNormalDisplay is altered.
192 edid[97] = '\x1b'; 192 edid[97] = '\x1b';
193 EXPECT_FALSE(ParseOutputDeviceData( 193 EXPECT_FALSE(ParseOutputDeviceData(
194 edid, &manufacturer_id, &human_readable_name)); 194 edid, &manufacturer_id, &human_readable_name));
195 195
196 // If |human_readable_name| isn't specified, it skips parsing the name. 196 // If |human_readable_name| isn't specified, it skips parsing the name.
197 manufacturer_id = 0; 197 manufacturer_id = 0;
198 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, NULL)); 198 EXPECT_TRUE(ParseOutputDeviceData(edid, &manufacturer_id, NULL));
199 EXPECT_EQ(0x22f0u, manufacturer_id); 199 EXPECT_EQ(0x22f0u, manufacturer_id);
200 } 200 }
201 201
202 TEST(EDIDParserTest, GetDisplayId) { 202 TEST(EDIDParserTest, GetDisplayId) {
203 // EDID of kLP2565A and B are slightly different but actually the same device. 203 // EDID of kLP2565A and B are slightly different but actually the same device.
204 int64 id1 = -1; 204 int64_t id1 = -1;
205 int64 id2 = -1; 205 int64_t id2 = -1;
206 std::vector<uint8> edid(kLP2565A, kLP2565A + charsize(kLP2565A)); 206 std::vector<uint8_t> edid(kLP2565A, kLP2565A + charsize(kLP2565A));
207 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id1)); 207 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id1));
208 edid.assign(kLP2565B, kLP2565B + charsize(kLP2565B)); 208 edid.assign(kLP2565B, kLP2565B + charsize(kLP2565B));
209 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id2)); 209 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id2));
210 EXPECT_EQ(id1, id2); 210 EXPECT_EQ(id1, id2);
211 EXPECT_NE(-1, id1); 211 EXPECT_NE(-1, id1);
212 } 212 }
213 213
214 TEST(EDIDParserTest, GetDisplayIdFromInternal) { 214 TEST(EDIDParserTest, GetDisplayIdFromInternal) {
215 int64 id = -1; 215 int64_t id = -1;
216 std::vector<uint8> edid( 216 std::vector<uint8_t> edid(
217 kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay)); 217 kInternalDisplay, kInternalDisplay + charsize(kInternalDisplay));
218 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id)); 218 EXPECT_TRUE(GetDisplayIdFromEDID(edid, 0, &id));
219 EXPECT_NE(-1, id); 219 EXPECT_NE(-1, id);
220 } 220 }
221 221
222 TEST(EDIDParserTest, GetDisplayIdFailure) { 222 TEST(EDIDParserTest, GetDisplayIdFailure) {
223 int64 id = -1; 223 int64_t id = -1;
224 std::vector<uint8> edid; 224 std::vector<uint8_t> edid;
225 EXPECT_FALSE(GetDisplayIdFromEDID(edid, 0, &id)); 225 EXPECT_FALSE(GetDisplayIdFromEDID(edid, 0, &id));
226 EXPECT_EQ(-1, id); 226 EXPECT_EQ(-1, id);
227 } 227 }
228 228
229 } // namespace ui 229 } // namespace ui
OLDNEW
« no previous file with comments | « ui/display/edid_parser.cc ('k') | ui/display/x11/edid_parser_x11.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698