| 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/mojo/device_impl.h" | 5 #include "device/usb/mojo/device_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 continuation.Run(); | 81 continuation.Run(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void ExpectResultAndThen(bool expected_result, | 84 void ExpectResultAndThen(bool expected_result, |
| 85 const base::Closure& continuation, | 85 const base::Closure& continuation, |
| 86 bool actual_result) { | 86 bool actual_result) { |
| 87 EXPECT_EQ(expected_result, actual_result); | 87 EXPECT_EQ(expected_result, actual_result); |
| 88 continuation.Run(); | 88 continuation.Run(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void ExpectTransferInAndThen(TransferStatus expected_status, | 91 void ExpectTransferInAndThen( |
| 92 const std::vector<uint8_t>& expected_bytes, | 92 TransferStatus expected_status, |
| 93 const base::Closure& continuation, | 93 const std::vector<uint8_t>& expected_bytes, |
| 94 TransferStatus actual_status, | 94 const base::Closure& continuation, |
| 95 mojo::Array<uint8_t> actual_bytes) { | 95 TransferStatus actual_status, |
| 96 const base::Optional<std::vector<uint8_t>>& actual_bytes) { |
| 96 EXPECT_EQ(expected_status, actual_status); | 97 EXPECT_EQ(expected_status, actual_status); |
| 97 ASSERT_EQ(expected_bytes.size(), actual_bytes.size()); | 98 ASSERT_TRUE(actual_bytes); |
| 98 for (size_t i = 0; i < actual_bytes.size(); ++i) { | 99 ASSERT_EQ(expected_bytes.size(), actual_bytes->size()); |
| 99 EXPECT_EQ(expected_bytes[i], actual_bytes[i]) | 100 for (size_t i = 0; i < actual_bytes->size(); ++i) { |
| 101 EXPECT_EQ(expected_bytes[i], (*actual_bytes)[i]) |
| 100 << "Contents differ at index: " << i; | 102 << "Contents differ at index: " << i; |
| 101 } | 103 } |
| 102 continuation.Run(); | 104 continuation.Run(); |
| 103 } | 105 } |
| 104 | 106 |
| 105 void ExpectPacketsOutAndThen(const std::vector<uint32_t>& expected_packets, | 107 void ExpectPacketsOutAndThen(const std::vector<uint32_t>& expected_packets, |
| 106 const base::Closure& continuation, | 108 const base::Closure& continuation, |
| 107 mojo::Array<IsochronousPacketPtr> actual_packets) { | 109 std::vector<IsochronousPacketPtr> actual_packets) { |
| 108 ASSERT_EQ(expected_packets.size(), actual_packets.size()); | 110 ASSERT_EQ(expected_packets.size(), actual_packets.size()); |
| 109 for (size_t i = 0; i < expected_packets.size(); ++i) { | 111 for (size_t i = 0; i < expected_packets.size(); ++i) { |
| 110 EXPECT_EQ(expected_packets[i], actual_packets[i]->transferred_length) | 112 EXPECT_EQ(expected_packets[i], actual_packets[i]->transferred_length) |
| 111 << "Packet lengths differ at index: " << i; | 113 << "Packet lengths differ at index: " << i; |
| 112 EXPECT_EQ(TransferStatus::COMPLETED, actual_packets[i]->status) | 114 EXPECT_EQ(TransferStatus::COMPLETED, actual_packets[i]->status) |
| 113 << "Packet at index " << i << " not completed."; | 115 << "Packet at index " << i << " not completed."; |
| 114 } | 116 } |
| 115 continuation.Run(); | 117 continuation.Run(); |
| 116 } | 118 } |
| 117 | 119 |
| 118 void ExpectPacketsInAndThen(const std::vector<uint8_t>& expected_bytes, | 120 void ExpectPacketsInAndThen( |
| 119 const std::vector<uint32_t>& expected_packets, | 121 const std::vector<uint8_t>& expected_bytes, |
| 120 const base::Closure& continuation, | 122 const std::vector<uint32_t>& expected_packets, |
| 121 mojo::Array<uint8_t> actual_bytes, | 123 const base::Closure& continuation, |
| 122 mojo::Array<IsochronousPacketPtr> actual_packets) { | 124 const base::Optional<std::vector<uint8_t>>& actual_bytes, |
| 125 std::vector<IsochronousPacketPtr> actual_packets) { |
| 123 ASSERT_EQ(expected_packets.size(), actual_packets.size()); | 126 ASSERT_EQ(expected_packets.size(), actual_packets.size()); |
| 124 for (size_t i = 0; i < expected_packets.size(); ++i) { | 127 for (size_t i = 0; i < expected_packets.size(); ++i) { |
| 125 EXPECT_EQ(expected_packets[i], actual_packets[i]->transferred_length) | 128 EXPECT_EQ(expected_packets[i], actual_packets[i]->transferred_length) |
| 126 << "Packet lengths differ at index: " << i; | 129 << "Packet lengths differ at index: " << i; |
| 127 EXPECT_EQ(TransferStatus::COMPLETED, actual_packets[i]->status) | 130 EXPECT_EQ(TransferStatus::COMPLETED, actual_packets[i]->status) |
| 128 << "Packet at index " << i << " not completed."; | 131 << "Packet at index " << i << " not completed."; |
| 129 } | 132 } |
| 130 ASSERT_EQ(expected_bytes.size(), actual_bytes.size()); | 133 ASSERT_TRUE(actual_bytes); |
| 131 for (size_t i = 0; i < expected_bytes.size(); ++i) { | 134 ASSERT_EQ(expected_bytes.size(), actual_bytes->size()); |
| 132 EXPECT_EQ(expected_bytes[i], actual_bytes[i]) | 135 for (size_t i = 0; i < actual_bytes->size(); ++i) { |
| 136 EXPECT_EQ(expected_bytes[i], (*actual_bytes)[i]) |
| 133 << "Contents differ at index: " << i; | 137 << "Contents differ at index: " << i; |
| 134 } | 138 } |
| 135 continuation.Run(); | 139 continuation.Run(); |
| 136 } | 140 } |
| 137 | 141 |
| 138 void ExpectTransferStatusAndThen(TransferStatus expected_status, | 142 void ExpectTransferStatusAndThen(TransferStatus expected_status, |
| 139 const base::Closure& continuation, | 143 const base::Closure& continuation, |
| 140 TransferStatus actual_status) { | 144 TransferStatus actual_status) { |
| 141 EXPECT_EQ(expected_status, actual_status); | 145 EXPECT_EQ(expected_status, actual_status); |
| 142 continuation.Run(); | 146 continuation.Run(); |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 | 767 |
| 764 { | 768 { |
| 765 auto params = ControlTransferParams::New(); | 769 auto params = ControlTransferParams::New(); |
| 766 params->type = ControlTransferType::STANDARD; | 770 params->type = ControlTransferType::STANDARD; |
| 767 params->recipient = ControlTransferRecipient::INTERFACE; | 771 params->recipient = ControlTransferRecipient::INTERFACE; |
| 768 params->request = 5; | 772 params->request = 5; |
| 769 params->value = 6; | 773 params->value = 6; |
| 770 params->index = 7; | 774 params->index = 7; |
| 771 base::RunLoop loop; | 775 base::RunLoop loop; |
| 772 device->ControlTransferOut( | 776 device->ControlTransferOut( |
| 773 std::move(params), mojo::Array<uint8_t>::From(fake_data), 0, | 777 std::move(params), fake_data, 0, |
| 774 base::Bind(&ExpectTransferStatusAndThen, TransferStatus::COMPLETED, | 778 base::Bind(&ExpectTransferStatusAndThen, TransferStatus::COMPLETED, |
| 775 loop.QuitClosure())); | 779 loop.QuitClosure())); |
| 776 loop.Run(); | 780 loop.Run(); |
| 777 } | 781 } |
| 778 | 782 |
| 779 EXPECT_CALL(mock_handle(), Close()); | 783 EXPECT_CALL(mock_handle(), Close()); |
| 780 } | 784 } |
| 781 | 785 |
| 782 TEST_F(USBDeviceImplTest, GenericTransfer) { | 786 TEST_F(USBDeviceImplTest, GenericTransfer) { |
| 783 DevicePtr device = GetMockDeviceProxy(); | 787 DevicePtr device = GetMockDeviceProxy(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 802 AddMockConfig(ConfigBuilder(1).AddInterface(7, 0, 1, 2, 3)); | 806 AddMockConfig(ConfigBuilder(1).AddInterface(7, 0, 1, 2, 3)); |
| 803 AddMockOutboundData(fake_outbound_data); | 807 AddMockOutboundData(fake_outbound_data); |
| 804 AddMockInboundData(fake_inbound_data); | 808 AddMockInboundData(fake_inbound_data); |
| 805 | 809 |
| 806 EXPECT_CALL(mock_handle(), GenericTransfer(USB_DIRECTION_OUTBOUND, 0x01, _, | 810 EXPECT_CALL(mock_handle(), GenericTransfer(USB_DIRECTION_OUTBOUND, 0x01, _, |
| 807 fake_outbound_data.size(), 0, _)); | 811 fake_outbound_data.size(), 0, _)); |
| 808 | 812 |
| 809 { | 813 { |
| 810 base::RunLoop loop; | 814 base::RunLoop loop; |
| 811 device->GenericTransferOut( | 815 device->GenericTransferOut( |
| 812 1, mojo::Array<uint8_t>::From(fake_outbound_data), 0, | 816 1, fake_outbound_data, 0, |
| 813 base::Bind(&ExpectTransferStatusAndThen, TransferStatus::COMPLETED, | 817 base::Bind(&ExpectTransferStatusAndThen, TransferStatus::COMPLETED, |
| 814 loop.QuitClosure())); | 818 loop.QuitClosure())); |
| 815 loop.Run(); | 819 loop.Run(); |
| 816 } | 820 } |
| 817 | 821 |
| 818 EXPECT_CALL(mock_handle(), GenericTransfer(USB_DIRECTION_INBOUND, 0x81, _, | 822 EXPECT_CALL(mock_handle(), GenericTransfer(USB_DIRECTION_INBOUND, 0x81, _, |
| 819 fake_inbound_data.size(), 0, _)); | 823 fake_inbound_data.size(), 0, _)); |
| 820 | 824 |
| 821 { | 825 { |
| 822 base::RunLoop loop; | 826 base::RunLoop loop; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 AddMockConfig(ConfigBuilder(1).AddInterface(7, 0, 1, 2, 3)); | 869 AddMockConfig(ConfigBuilder(1).AddInterface(7, 0, 1, 2, 3)); |
| 866 AddMockOutboundPackets(fake_outbound_data, fake_packets); | 870 AddMockOutboundPackets(fake_outbound_data, fake_packets); |
| 867 AddMockInboundPackets(fake_inbound_data, fake_packets); | 871 AddMockInboundPackets(fake_inbound_data, fake_packets); |
| 868 | 872 |
| 869 EXPECT_CALL(mock_handle(), | 873 EXPECT_CALL(mock_handle(), |
| 870 IsochronousTransferOut(0x01, _, fake_packet_lengths, 0, _)); | 874 IsochronousTransferOut(0x01, _, fake_packet_lengths, 0, _)); |
| 871 | 875 |
| 872 { | 876 { |
| 873 base::RunLoop loop; | 877 base::RunLoop loop; |
| 874 device->IsochronousTransferOut( | 878 device->IsochronousTransferOut( |
| 875 1, mojo::Array<uint8_t>::From(fake_outbound_data), | 879 1, fake_outbound_data, fake_packet_lengths, 0, |
| 876 mojo::Array<uint32_t>::From(fake_packet_lengths), 0, | |
| 877 base::Bind(&ExpectPacketsOutAndThen, expected_transferred_lengths, | 880 base::Bind(&ExpectPacketsOutAndThen, expected_transferred_lengths, |
| 878 loop.QuitClosure())); | 881 loop.QuitClosure())); |
| 879 loop.Run(); | 882 loop.Run(); |
| 880 } | 883 } |
| 881 | 884 |
| 882 EXPECT_CALL(mock_handle(), | 885 EXPECT_CALL(mock_handle(), |
| 883 IsochronousTransferIn(0x81, fake_packet_lengths, 0, _)); | 886 IsochronousTransferIn(0x81, fake_packet_lengths, 0, _)); |
| 884 | 887 |
| 885 { | 888 { |
| 886 base::RunLoop loop; | 889 base::RunLoop loop; |
| 887 device->IsochronousTransferIn( | 890 device->IsochronousTransferIn( |
| 888 1, mojo::Array<uint32_t>::From(fake_packet_lengths), 0, | 891 1, fake_packet_lengths, 0, |
| 889 base::Bind(&ExpectPacketsInAndThen, fake_inbound_data, | 892 base::Bind(&ExpectPacketsInAndThen, fake_inbound_data, |
| 890 expected_transferred_lengths, loop.QuitClosure())); | 893 expected_transferred_lengths, loop.QuitClosure())); |
| 891 loop.Run(); | 894 loop.Run(); |
| 892 } | 895 } |
| 893 | 896 |
| 894 EXPECT_CALL(mock_handle(), Close()); | 897 EXPECT_CALL(mock_handle(), Close()); |
| 895 } | 898 } |
| 896 | 899 |
| 897 } // namespace usb | 900 } // namespace usb |
| 898 } // namespace device | 901 } // namespace device |
| OLD | NEW |