OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/run_loop.h" | 5 #include "base/run_loop.h" |
6 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | 6 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
7 #include "device/bluetooth/bluetooth_remote_gatt_service.h" | 7 #include "device/bluetooth/bluetooth_remote_gatt_service.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 #if defined(OS_ANDROID) | 10 #if defined(OS_ANDROID) |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 773 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
774 return; | 774 return; |
775 } | 775 } |
776 ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); | 776 ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
777 | 777 |
778 descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::EXPECTED), | 778 descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::EXPECTED), |
779 GetGattErrorCallback(Call::NOT_EXPECTED)); | 779 GetGattErrorCallback(Call::NOT_EXPECTED)); |
780 EXPECT_EQ(1, gatt_read_descriptor_attempts_); | 780 EXPECT_EQ(1, gatt_read_descriptor_attempts_); |
781 | 781 |
782 std::string test_string = "Hello"; | 782 std::string test_string = "Hello"; |
783 SimulateGattDescriptorReadNSString(descriptor1_, test_string); | 783 SimulateGattDescriptorReadNSStringMac(descriptor1_, test_string); |
784 base::RunLoop().RunUntilIdle(); | 784 base::RunLoop().RunUntilIdle(); |
785 | 785 |
786 std::vector<uint8_t> test_vector(test_string.begin(), test_string.end()); | 786 std::vector<uint8_t> test_vector(test_string.begin(), test_string.end()); |
787 EXPECT_EQ(test_vector, last_read_value_); | 787 EXPECT_EQ(test_vector, last_read_value_); |
788 EXPECT_EQ(test_vector, descriptor1_->GetValue()); | 788 EXPECT_EQ(test_vector, descriptor1_->GetValue()); |
789 } | 789 } |
790 | 790 |
791 // Tests NSNumber for descriptor value for macOS. | 791 // Tests NSNumber for descriptor value for macOS. |
792 // https://developer.apple.com/reference/corebluetooth/cbdescriptor | 792 // https://developer.apple.com/reference/corebluetooth/cbdescriptor |
793 TEST_F(BluetoothRemoteGattDescriptorTest, ReadRemoteDescriptor_NSNumber) { | 793 TEST_F(BluetoothRemoteGattDescriptorTest, ReadRemoteDescriptor_NSNumber) { |
794 if (!PlatformSupportsLowEnergy()) { | 794 if (!PlatformSupportsLowEnergy()) { |
795 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 795 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
796 return; | 796 return; |
797 } | 797 } |
798 ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); | 798 ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate()); |
799 | 799 |
800 descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::EXPECTED), | 800 descriptor1_->ReadRemoteDescriptor(GetReadValueCallback(Call::EXPECTED), |
801 GetGattErrorCallback(Call::NOT_EXPECTED)); | 801 GetGattErrorCallback(Call::NOT_EXPECTED)); |
802 EXPECT_EQ(1, gatt_read_descriptor_attempts_); | 802 EXPECT_EQ(1, gatt_read_descriptor_attempts_); |
803 | 803 |
804 const short test_number = 0x1234; | 804 const short test_number = 0x1234; |
805 SimulateGattDescriptorReadNSNumber(descriptor1_, test_number); | 805 SimulateGattDescriptorReadNSNumberMac(descriptor1_, test_number); |
806 base::RunLoop().RunUntilIdle(); | 806 base::RunLoop().RunUntilIdle(); |
807 | 807 |
808 uint8_t values[] = {0x34, 0x12}; | 808 uint8_t values[] = {0x34, 0x12}; |
809 std::vector<uint8_t> test_vector(values, values + arraysize(values)); | 809 std::vector<uint8_t> test_vector(values, values + arraysize(values)); |
810 EXPECT_EQ(test_vector, last_read_value_); | 810 EXPECT_EQ(test_vector, last_read_value_); |
811 EXPECT_EQ(test_vector, descriptor1_->GetValue()); | 811 EXPECT_EQ(test_vector, descriptor1_->GetValue()); |
812 } | 812 } |
813 #endif // defined(OS_MACOSX) | 813 #endif // defined(OS_MACOSX) |
814 | 814 |
815 } // namespace device | 815 } // namespace device |
OLD | NEW |