| OLD | NEW |
| 1 // Copyright (c) 2013 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 "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 "776179"; | 35 "776179"; |
| 36 const device::BluetoothUUID kTestVideoSdpUuid("1112"); | 36 const device::BluetoothUUID kTestVideoSdpUuid("1112"); |
| 37 | 37 |
| 38 } // namespace | 38 } // namespace |
| 39 | 39 |
| 40 namespace device { | 40 namespace device { |
| 41 | 41 |
| 42 class BluetoothDeviceWinTest : public testing::Test { | 42 class BluetoothDeviceWinTest : public testing::Test { |
| 43 public: | 43 public: |
| 44 BluetoothDeviceWinTest() { | 44 BluetoothDeviceWinTest() { |
| 45 BluetoothTaskManagerWin::DeviceState device_state; | 45 scoped_refptr<base::SequencedTaskRunner> ui_task_runner( |
| 46 device_state.name = kDeviceName; | 46 new base::TestSimpleTaskRunner()); |
| 47 device_state.address = kDeviceAddress; | 47 scoped_refptr<BluetoothSocketThread> socket_thread( |
| 48 BluetoothSocketThread::Get()); |
| 48 | 49 |
| 49 // Add device with audio/video services. | 50 // Add device with audio/video services. |
| 51 device_state_.reset(new BluetoothTaskManagerWin::DeviceState()); |
| 52 device_state_->name = kDeviceName; |
| 53 device_state_->address = kDeviceAddress; |
| 54 |
| 50 BluetoothTaskManagerWin::ServiceRecordState* audio_state = | 55 BluetoothTaskManagerWin::ServiceRecordState* audio_state = |
| 51 new BluetoothTaskManagerWin::ServiceRecordState(); | 56 new BluetoothTaskManagerWin::ServiceRecordState(); |
| 52 audio_state->name = kTestAudioSdpName; | 57 audio_state->name = kTestAudioSdpName; |
| 53 base::HexStringToBytes(kTestAudioSdpBytes, &audio_state->sdp_bytes); | 58 base::HexStringToBytes(kTestAudioSdpBytes, &audio_state->sdp_bytes); |
| 54 device_state.service_record_states.push_back(audio_state); | 59 device_state_->service_record_states.push_back(audio_state); |
| 55 | 60 |
| 56 BluetoothTaskManagerWin::ServiceRecordState* video_state = | 61 BluetoothTaskManagerWin::ServiceRecordState* video_state = |
| 57 new BluetoothTaskManagerWin::ServiceRecordState(); | 62 new BluetoothTaskManagerWin::ServiceRecordState(); |
| 58 video_state->name = kTestVideoSdpName; | 63 video_state->name = kTestVideoSdpName; |
| 59 base::HexStringToBytes(kTestVideoSdpBytes, &video_state->sdp_bytes); | 64 base::HexStringToBytes(kTestVideoSdpBytes, &video_state->sdp_bytes); |
| 60 device_state.service_record_states.push_back(video_state); | 65 device_state_->service_record_states.push_back(video_state); |
| 61 | 66 |
| 62 scoped_refptr<base::SequencedTaskRunner> ui_task_runner( | 67 device_.reset(new BluetoothDeviceWin(*device_state_, |
| 63 new base::TestSimpleTaskRunner()); | |
| 64 scoped_refptr<BluetoothSocketThread> socket_thread( | |
| 65 BluetoothSocketThread::Get()); | |
| 66 device_.reset(new BluetoothDeviceWin(device_state, | |
| 67 ui_task_runner, | 68 ui_task_runner, |
| 68 socket_thread, | 69 socket_thread, |
| 69 NULL, | 70 NULL, |
| 70 net::NetLog::Source())); | 71 net::NetLog::Source())); |
| 71 | 72 |
| 72 // Add empty device. | 73 // Add empty device. |
| 73 device_state.service_record_states.clear(); | 74 empty_device_state_.reset(new BluetoothTaskManagerWin::DeviceState()); |
| 74 empty_device_.reset(new BluetoothDeviceWin(device_state, | 75 empty_device_state_->name = kDeviceName; |
| 76 empty_device_state_->address = kDeviceAddress; |
| 77 empty_device_.reset(new BluetoothDeviceWin(*empty_device_state_, |
| 75 ui_task_runner, | 78 ui_task_runner, |
| 76 socket_thread, | 79 socket_thread, |
| 77 NULL, | 80 NULL, |
| 78 net::NetLog::Source())); | 81 net::NetLog::Source())); |
| 79 } | 82 } |
| 80 | 83 |
| 81 protected: | 84 protected: |
| 82 scoped_ptr<BluetoothDevice> device_; | 85 scoped_ptr<BluetoothDeviceWin> device_; |
| 83 scoped_ptr<BluetoothDevice> empty_device_; | 86 scoped_ptr<BluetoothTaskManagerWin::DeviceState> device_state_; |
| 87 scoped_ptr<BluetoothDeviceWin> empty_device_; |
| 88 scoped_ptr<BluetoothTaskManagerWin::DeviceState> empty_device_state_; |
| 84 }; | 89 }; |
| 85 | 90 |
| 86 TEST_F(BluetoothDeviceWinTest, GetUUIDs) { | 91 TEST_F(BluetoothDeviceWinTest, GetUUIDs) { |
| 87 BluetoothDevice::UUIDList uuids = device_->GetUUIDs(); | 92 BluetoothDevice::UUIDList uuids = device_->GetUUIDs(); |
| 88 | 93 |
| 89 EXPECT_EQ(2, uuids.size()); | 94 EXPECT_EQ(2, uuids.size()); |
| 90 EXPECT_EQ(kTestAudioSdpUuid, uuids[0]); | 95 EXPECT_EQ(kTestAudioSdpUuid, uuids[0]); |
| 91 EXPECT_EQ(kTestVideoSdpUuid, uuids[1]); | 96 EXPECT_EQ(kTestVideoSdpUuid, uuids[1]); |
| 92 | 97 |
| 93 uuids = empty_device_->GetUUIDs(); | 98 uuids = empty_device_->GetUUIDs(); |
| 94 EXPECT_EQ(0, uuids.size()); | 99 EXPECT_EQ(0, uuids.size()); |
| 95 } | 100 } |
| 96 | 101 |
| 102 TEST_F(BluetoothDeviceWinTest, IsEqual) { |
| 103 EXPECT_TRUE(device_->IsEqual(*device_state_)); |
| 104 EXPECT_FALSE(device_->IsEqual(*empty_device_state_)); |
| 105 EXPECT_FALSE(empty_device_->IsEqual(*device_state_)); |
| 106 EXPECT_TRUE(empty_device_->IsEqual(*empty_device_state_)); |
| 107 } |
| 108 |
| 97 } // namespace device | 109 } // namespace device |
| OLD | NEW |