OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "device/usb/usb_descriptors.h" |
| 6 |
5 #include <stdint.h> | 7 #include <stdint.h> |
6 | 8 |
| 9 #include <memory> |
| 10 |
7 #include "base/bind.h" | 11 #include "base/bind.h" |
8 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
9 #include "device/usb/mock_usb_device_handle.h" | 13 #include "device/usb/mock_usb_device_handle.h" |
10 #include "device/usb/usb_descriptors.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
12 | 15 |
13 using testing::_; | 16 using testing::_; |
14 | 17 |
15 namespace device { | 18 namespace device { |
16 | 19 |
17 namespace { | 20 namespace { |
18 | 21 |
19 ACTION_P2(InvokeCallback, data, length) { | 22 ACTION_P2(InvokeCallback, data, length) { |
20 size_t transferred_length = std::min(length, arg7); | 23 size_t transferred_length = std::min(length, arg7); |
21 memcpy(arg6->data(), data, transferred_length); | 24 memcpy(arg6->data(), data, transferred_length); |
22 arg9.Run(USB_TRANSFER_COMPLETED, arg6, transferred_length); | 25 arg9.Run(USB_TRANSFER_COMPLETED, arg6, transferred_length); |
23 } | 26 } |
24 | 27 |
25 void ExpectStringDescriptors( | 28 void ExpectStringDescriptors( |
26 scoped_ptr<std::map<uint8_t, base::string16>> string_map) { | 29 std::unique_ptr<std::map<uint8_t, base::string16>> string_map) { |
27 EXPECT_EQ(3u, string_map->size()); | 30 EXPECT_EQ(3u, string_map->size()); |
28 EXPECT_EQ(base::ASCIIToUTF16("String 1"), (*string_map)[1]); | 31 EXPECT_EQ(base::ASCIIToUTF16("String 1"), (*string_map)[1]); |
29 EXPECT_EQ(base::ASCIIToUTF16("String 2"), (*string_map)[2]); | 32 EXPECT_EQ(base::ASCIIToUTF16("String 2"), (*string_map)[2]); |
30 EXPECT_EQ(base::ASCIIToUTF16("String 3"), (*string_map)[3]); | 33 EXPECT_EQ(base::ASCIIToUTF16("String 3"), (*string_map)[3]); |
31 } | 34 } |
32 | 35 |
33 class UsbDescriptorsTest : public ::testing::Test {}; | 36 class UsbDescriptorsTest : public ::testing::Test {}; |
34 | 37 |
35 TEST_F(UsbDescriptorsTest, NoInterfaceAssociations) { | 38 TEST_F(UsbDescriptorsTest, NoInterfaceAssociations) { |
36 UsbConfigDescriptor config(1, false, false, 0); | 39 UsbConfigDescriptor config(1, false, false, 0); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 TEST_F(UsbDescriptorsTest, OneByteStringDescriptor) { | 177 TEST_F(UsbDescriptorsTest, OneByteStringDescriptor) { |
175 // The string is only one byte. | 178 // The string is only one byte. |
176 static const uint8_t kBuffer[] = {0x03, 0x03, '?'}; | 179 static const uint8_t kBuffer[] = {0x03, 0x03, '?'}; |
177 base::string16 string; | 180 base::string16 string; |
178 ASSERT_TRUE(ParseUsbStringDescriptor( | 181 ASSERT_TRUE(ParseUsbStringDescriptor( |
179 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer)), &string)); | 182 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer)), &string)); |
180 EXPECT_EQ(base::string16(), string); | 183 EXPECT_EQ(base::string16(), string); |
181 } | 184 } |
182 | 185 |
183 TEST_F(UsbDescriptorsTest, ReadStringDescriptors) { | 186 TEST_F(UsbDescriptorsTest, ReadStringDescriptors) { |
184 scoped_ptr<std::map<uint8_t, base::string16>> string_map( | 187 std::unique_ptr<std::map<uint8_t, base::string16>> string_map( |
185 new std::map<uint8_t, base::string16>()); | 188 new std::map<uint8_t, base::string16>()); |
186 (*string_map)[1] = base::string16(); | 189 (*string_map)[1] = base::string16(); |
187 (*string_map)[2] = base::string16(); | 190 (*string_map)[2] = base::string16(); |
188 (*string_map)[3] = base::string16(); | 191 (*string_map)[3] = base::string16(); |
189 | 192 |
190 scoped_refptr<MockUsbDeviceHandle> device_handle( | 193 scoped_refptr<MockUsbDeviceHandle> device_handle( |
191 new MockUsbDeviceHandle(nullptr)); | 194 new MockUsbDeviceHandle(nullptr)); |
192 static const uint8_t kStringDescriptor0[] = {0x04, 0x03, 0x21, 0x43}; | 195 static const uint8_t kStringDescriptor0[] = {0x04, 0x03, 0x21, 0x43}; |
193 EXPECT_CALL(*device_handle, | 196 EXPECT_CALL(*device_handle, |
194 ControlTransfer(USB_DIRECTION_INBOUND, UsbDeviceHandle::STANDARD, | 197 ControlTransfer(USB_DIRECTION_INBOUND, UsbDeviceHandle::STANDARD, |
(...skipping 25 matching lines...) Expand all Loading... |
220 _, _, _)) | 223 _, _, _)) |
221 .WillOnce(InvokeCallback(kStringDescriptor3, sizeof(kStringDescriptor3))); | 224 .WillOnce(InvokeCallback(kStringDescriptor3, sizeof(kStringDescriptor3))); |
222 | 225 |
223 ReadUsbStringDescriptors(device_handle, std::move(string_map), | 226 ReadUsbStringDescriptors(device_handle, std::move(string_map), |
224 base::Bind(&ExpectStringDescriptors)); | 227 base::Bind(&ExpectStringDescriptors)); |
225 } | 228 } |
226 | 229 |
227 } // namespace | 230 } // namespace |
228 | 231 |
229 } // namespace device | 232 } // namespace device |
OLD | NEW |