Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: device/bluetooth/bluetooth_device_win_unittest.cc

Issue 424093004: Improve processing of Bluetooth device discovery on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address code review feedback (nits and memory leak). Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/bluetooth/bluetooth_device_win.cc ('k') | device/bluetooth/bluetooth_low_energy_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_device_win.cc ('k') | device/bluetooth/bluetooth_low_energy_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698