OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/basictypes.h" | 5 #include "chromeos/display/output_util.h" |
| 6 |
6 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/base/x/x11_util.h" | |
9 | 9 |
10 namespace ui { | 10 namespace chromeos { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 // Returns the number of characters in the string literal but doesn't count its | 14 // Returns the number of characters in the string literal but doesn't count its |
15 // terminator NULL byte. | 15 // terminator NULL byte. |
16 #define charsize(str) (arraysize(str) - 1) | 16 #define charsize(str) (arraysize(str) - 1) |
17 | 17 |
18 // Sample EDID data extracted from real devices. | 18 // Sample EDID data extracted from real devices. |
19 const unsigned char kNormalDisplay[] = | 19 const unsigned char kNormalDisplay[] = |
20 "\x00\xff\xff\xff\xff\xff\xff\x00\x22\xf0\x6c\x28\x01\x01\x01\x01" | 20 "\x00\xff\xff\xff\xff\xff\xff\x00\x22\xf0\x6c\x28\x01\x01\x01\x01" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 "\x15\x13\x14\x1f\x20\x23\x0d\x7f\x07\x83\x0f\x00\x00\x67\x03\x0c" | 68 "\x15\x13\x14\x1f\x20\x23\x0d\x7f\x07\x83\x0f\x00\x00\x67\x03\x0c" |
69 "\x00\x10\x00\x38\x2d\xe3\x05\x03\x01\x02\x3a\x80\x18\x71\x38\x2d" | 69 "\x00\x10\x00\x38\x2d\xe3\x05\x03\x01\x02\x3a\x80\x18\x71\x38\x2d" |
70 "\x40\x58\x2c\x45\x00\x81\x91\x21\x00\x00\x1e\x01\x1d\x80\x18\x71" | 70 "\x40\x58\x2c\x45\x00\x81\x91\x21\x00\x00\x1e\x01\x1d\x80\x18\x71" |
71 "\x1c\x16\x20\x58\x2c\x25\x00\x81\x91\x21\x00\x00\x9e\x01\x1d\x00" | 71 "\x1c\x16\x20\x58\x2c\x25\x00\x81\x91\x21\x00\x00\x9e\x01\x1d\x00" |
72 "\x72\x51\xd0\x1e\x20\x6e\x28\x55\x00\x81\x91\x21\x00\x00\x1e\x8c" | 72 "\x72\x51\xd0\x1e\x20\x6e\x28\x55\x00\x81\x91\x21\x00\x00\x1e\x8c" |
73 "\x0a\xd0\x8a\x20\xe0\x2d\x10\x10\x3e\x96\x00\x81\x91\x21\x00\x00" | 73 "\x0a\xd0\x8a\x20\xe0\x2d\x10\x10\x3e\x96\x00\x81\x91\x21\x00\x00" |
74 "\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x94"; | 74 "\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x94"; |
75 | 75 |
76 } | 76 } |
77 | 77 |
78 TEST(X11UtilTest, ParseEDID) { | 78 TEST(OutputUtilTest, ParseEDID) { |
79 uint16 manufacturer_id = 0; | 79 uint16 manufacturer_id = 0; |
80 uint16 product_code = 0; | 80 uint16 product_code = 0; |
81 std::string human_readable_name; | 81 std::string human_readable_name; |
82 EXPECT_TRUE(ParseOutputDeviceData( | 82 EXPECT_TRUE(ParseOutputDeviceData( |
83 kNormalDisplay, charsize(kNormalDisplay), | 83 kNormalDisplay, charsize(kNormalDisplay), |
84 &manufacturer_id, &product_code, &human_readable_name)); | 84 &manufacturer_id, &product_code, &human_readable_name)); |
85 EXPECT_EQ(0x22f0u, manufacturer_id); | 85 EXPECT_EQ(0x22f0u, manufacturer_id); |
86 EXPECT_EQ(0x286cu, product_code); | 86 EXPECT_EQ(0x286cu, product_code); |
87 EXPECT_EQ("HP ZR30w", human_readable_name); | 87 EXPECT_EQ("HP ZR30w", human_readable_name); |
88 | 88 |
(...skipping 16 matching lines...) Expand all Loading... |
105 product_code = 0; | 105 product_code = 0; |
106 human_readable_name.clear(); | 106 human_readable_name.clear(); |
107 EXPECT_TRUE(ParseOutputDeviceData( | 107 EXPECT_TRUE(ParseOutputDeviceData( |
108 kOverscanDisplay, charsize(kOverscanDisplay), | 108 kOverscanDisplay, charsize(kOverscanDisplay), |
109 &manufacturer_id, &product_code, &human_readable_name)); | 109 &manufacturer_id, &product_code, &human_readable_name)); |
110 EXPECT_EQ(0x4c2du, manufacturer_id); | 110 EXPECT_EQ(0x4c2du, manufacturer_id); |
111 EXPECT_EQ(0x08feu, product_code); | 111 EXPECT_EQ(0x08feu, product_code); |
112 EXPECT_EQ("SAMSUNG", human_readable_name); | 112 EXPECT_EQ("SAMSUNG", human_readable_name); |
113 } | 113 } |
114 | 114 |
115 TEST(X11UtilTest, ParseBrokenEDID) { | 115 TEST(OutputUtilTest, ParseBrokenEDID) { |
116 uint16 manufacturer_id = 0; | 116 uint16 manufacturer_id = 0; |
117 uint16 product_code = 0; | 117 uint16 product_code = 0; |
118 std::string human_readable_name; | 118 std::string human_readable_name; |
119 | 119 |
120 // length == 0 | 120 // length == 0 |
121 EXPECT_FALSE(ParseOutputDeviceData( | 121 EXPECT_FALSE(ParseOutputDeviceData( |
122 kNormalDisplay, 0, | 122 kNormalDisplay, 0, |
123 &manufacturer_id, &product_code, &human_readable_name)); | 123 &manufacturer_id, &product_code, &human_readable_name)); |
124 | 124 |
125 // name is broken. Copying kNormalDisplay and substitute its name data by | 125 // name is broken. Copying kNormalDisplay and substitute its name data by |
(...skipping 13 matching lines...) Expand all Loading... |
139 manufacturer_id = 0; | 139 manufacturer_id = 0; |
140 product_code = 0; | 140 product_code = 0; |
141 EXPECT_TRUE(ParseOutputDeviceData( | 141 EXPECT_TRUE(ParseOutputDeviceData( |
142 reinterpret_cast<const unsigned char*>(display_data.data()), | 142 reinterpret_cast<const unsigned char*>(display_data.data()), |
143 display_data.size(), | 143 display_data.size(), |
144 &manufacturer_id, &product_code, NULL)); | 144 &manufacturer_id, &product_code, NULL)); |
145 EXPECT_EQ(0x22f0u, manufacturer_id); | 145 EXPECT_EQ(0x22f0u, manufacturer_id); |
146 EXPECT_EQ(0x286cu, product_code); | 146 EXPECT_EQ(0x286cu, product_code); |
147 } | 147 } |
148 | 148 |
149 TEST(X11UtilTest, ParseOverscanFlag) { | 149 TEST(OutputUtilTest, ParseOverscanFlag) { |
150 bool flag = false; | 150 bool flag = false; |
151 EXPECT_FALSE(ParseOutputOverscanFlag( | 151 EXPECT_FALSE(ParseOutputOverscanFlag( |
152 kNormalDisplay, charsize(kNormalDisplay), &flag)); | 152 kNormalDisplay, charsize(kNormalDisplay), &flag)); |
153 | 153 |
154 flag = false; | 154 flag = false; |
155 EXPECT_FALSE(ParseOutputOverscanFlag( | 155 EXPECT_FALSE(ParseOutputOverscanFlag( |
156 kInternalDisplay, charsize(kInternalDisplay), &flag)); | 156 kInternalDisplay, charsize(kInternalDisplay), &flag)); |
157 | 157 |
158 flag = false; | 158 flag = false; |
159 EXPECT_TRUE(ParseOutputOverscanFlag( | 159 EXPECT_TRUE(ParseOutputOverscanFlag( |
(...skipping 10 matching lines...) Expand all Loading... |
170 // contents of kOverscanDisplay is altered. | 170 // contents of kOverscanDisplay is altered. |
171 std::string display_data(reinterpret_cast<const char*>(kOverscanDisplay), | 171 std::string display_data(reinterpret_cast<const char*>(kOverscanDisplay), |
172 charsize(kOverscanDisplay)); | 172 charsize(kOverscanDisplay)); |
173 display_data[150] = '\0'; | 173 display_data[150] = '\0'; |
174 EXPECT_TRUE(ParseOutputOverscanFlag( | 174 EXPECT_TRUE(ParseOutputOverscanFlag( |
175 reinterpret_cast<const unsigned char*>(display_data.data()), | 175 reinterpret_cast<const unsigned char*>(display_data.data()), |
176 display_data.size(), &flag)); | 176 display_data.size(), &flag)); |
177 EXPECT_FALSE(flag); | 177 EXPECT_FALSE(flag); |
178 } | 178 } |
179 | 179 |
180 TEST(X11UtilTest, ParseBrokenOverscanData) { | 180 TEST(OutputUtilTest, ParseBrokenOverscanData) { |
181 // Do not fill valid data here because it anyway fails to parse the data. | 181 // Do not fill valid data here because it anyway fails to parse the data. |
182 scoped_ptr<unsigned char[]> data(new unsigned char[126]); | 182 scoped_ptr<unsigned char[]> data(new unsigned char[126]); |
183 bool flag = false; | 183 bool flag = false; |
184 EXPECT_FALSE(ParseOutputOverscanFlag(data.get(), 0, &flag)); | 184 EXPECT_FALSE(ParseOutputOverscanFlag(data.get(), 0, &flag)); |
185 EXPECT_FALSE(ParseOutputOverscanFlag(data.get(), 126, &flag)); | 185 EXPECT_FALSE(ParseOutputOverscanFlag(data.get(), 126, &flag)); |
186 | 186 |
187 // extending data because ParseOutputOverscanFlag() will access the data. | 187 // extending data because ParseOutputOverscanFlag() will access the data. |
188 data.reset(new unsigned char[150]); | 188 data.reset(new unsigned char[150]); |
189 // The number of CEA extensions is stored at byte 126. | 189 // The number of CEA extensions is stored at byte 126. |
190 data[126] = '\x01'; | 190 data[126] = '\x01'; |
191 EXPECT_FALSE(ParseOutputOverscanFlag(data.get(), 128, &flag)); | 191 EXPECT_FALSE(ParseOutputOverscanFlag(data.get(), 128, &flag)); |
192 EXPECT_FALSE(ParseOutputOverscanFlag(data.get(), 150, &flag)); | 192 EXPECT_FALSE(ParseOutputOverscanFlag(data.get(), 150, &flag)); |
193 } | 193 } |
194 | 194 |
| 195 TEST(OutputUtilTest, IsInternalOutputName) { |
| 196 EXPECT_TRUE(IsInternalOutputName("LVDS")); |
| 197 EXPECT_TRUE(IsInternalOutputName("eDP")); |
| 198 EXPECT_TRUE(IsInternalOutputName("LVDSxx")); |
| 199 EXPECT_TRUE(IsInternalOutputName("eDPzz")); |
| 200 |
| 201 EXPECT_FALSE(IsInternalOutputName("xyz")); |
| 202 EXPECT_FALSE(IsInternalOutputName("abcLVDS")); |
| 203 EXPECT_FALSE(IsInternalOutputName("cdeeDP")); |
| 204 EXPECT_FALSE(IsInternalOutputName("LVD")); |
| 205 EXPECT_FALSE(IsInternalOutputName("eD")); |
195 } | 206 } |
| 207 |
| 208 } // namespace chromeos |
OLD | NEW |