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

Side by Side Diff: device/bluetooth/test/bluetooth_test_mac.mm

Issue 2074563002: bluetooth: mac: write characteristic implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@read_characteristicscan_servicescan_cleanup
Patch Set: Merge from top of tree Created 4 years, 5 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
OLDNEW
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/bluetooth/test/bluetooth_test_mac.h" 5 #include "device/bluetooth/test/bluetooth_test_mac.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 302
303 void BluetoothTestMac::SimulateGattCharacteristicReadError( 303 void BluetoothTestMac::SimulateGattCharacteristicReadError(
304 BluetoothRemoteGattCharacteristic* characteristic, 304 BluetoothRemoteGattCharacteristic* characteristic,
305 BluetoothRemoteGattService::GattErrorCode error_code) { 305 BluetoothRemoteGattService::GattErrorCode error_code) {
306 MockCBCharacteristic* characteristic_mock = 306 MockCBCharacteristic* characteristic_mock =
307 GetCBMockCharacteristic(characteristic); 307 GetCBMockCharacteristic(characteristic);
308 NSError* error = BluetoothDeviceMac::GetNSErrorFromGattErrorCode(error_code); 308 NSError* error = BluetoothDeviceMac::GetNSErrorFromGattErrorCode(error_code);
309 [characteristic_mock simulateReadWithValue:nil error:error]; 309 [characteristic_mock simulateReadWithValue:nil error:error];
310 } 310 }
311 311
312 void BluetoothTestMac::SimulateGattCharacteristicWrite(
313 BluetoothRemoteGattCharacteristic* characteristic) {
314 MockCBCharacteristic* characteristic_mock =
315 GetCBMockCharacteristic(characteristic);
316 [characteristic_mock simulateWriteWithError:nil];
317 }
318
319 void BluetoothTestMac::SimulateGattCharacteristicWriteError(
320 BluetoothRemoteGattCharacteristic* characteristic,
321 BluetoothRemoteGattService::GattErrorCode error_code) {
322 MockCBCharacteristic* characteristic_mock =
323 GetCBMockCharacteristic(characteristic);
324 NSError* error = BluetoothDeviceMac::GetNSErrorFromGattErrorCode(error_code);
325 [characteristic_mock simulateWriteWithError:error];
326 }
327
312 void BluetoothTestMac::SimulateGattCharacteristicRemoved( 328 void BluetoothTestMac::SimulateGattCharacteristicRemoved(
313 BluetoothRemoteGattService* service, 329 BluetoothRemoteGattService* service,
314 BluetoothRemoteGattCharacteristic* characteristic) { 330 BluetoothRemoteGattCharacteristic* characteristic) {
315 MockCBPeripheral* peripheral_mock = GetMockCBPeripheral(service); 331 MockCBPeripheral* peripheral_mock = GetMockCBPeripheral(service);
316 BluetoothRemoteGattServiceMac* mac_gatt_service = 332 BluetoothRemoteGattServiceMac* mac_gatt_service =
317 static_cast<BluetoothRemoteGattServiceMac*>(service); 333 static_cast<BluetoothRemoteGattServiceMac*>(service);
318 CBService* cb_service = mac_gatt_service->GetService(); 334 CBService* cb_service = mac_gatt_service->GetService();
319 MockCBService* service_mock = ObjCCast<MockCBService>(cb_service); 335 MockCBService* service_mock = ObjCCast<MockCBService>(cb_service);
320 BluetoothRemoteGattCharacteristicMac* characteristic_mac = 336 BluetoothRemoteGattCharacteristicMac* characteristic_mac =
321 static_cast<BluetoothRemoteGattCharacteristicMac*>(characteristic); 337 static_cast<BluetoothRemoteGattCharacteristicMac*>(characteristic);
(...skipping 14 matching lines...) Expand all
336 } 352 }
337 353
338 void BluetoothTestMac::OnFakeBluetoothServiceDiscovery() { 354 void BluetoothTestMac::OnFakeBluetoothServiceDiscovery() {
339 gatt_discovery_attempts_++; 355 gatt_discovery_attempts_++;
340 } 356 }
341 357
342 void BluetoothTest::OnFakeBluetoothCharacteristicReadValue() { 358 void BluetoothTest::OnFakeBluetoothCharacteristicReadValue() {
343 gatt_read_characteristic_attempts_++; 359 gatt_read_characteristic_attempts_++;
344 } 360 }
345 361
362 void BluetoothTest::OnFakeBluetoothCharacteristicWriteValue(
363 std::vector<uint8_t> value) {
364 last_write_value_ = value;
365 gatt_write_characteristic_attempts_++;
366 }
367
346 MockCBPeripheral* BluetoothTestMac::GetMockCBPeripheral( 368 MockCBPeripheral* BluetoothTestMac::GetMockCBPeripheral(
347 BluetoothRemoteGattService* service) const { 369 BluetoothRemoteGattService* service) const {
348 BluetoothDevice* device = service->GetDevice(); 370 BluetoothDevice* device = service->GetDevice();
349 BluetoothLowEnergyDeviceMac* device_mac = 371 BluetoothLowEnergyDeviceMac* device_mac =
350 static_cast<BluetoothLowEnergyDeviceMac*>(device); 372 static_cast<BluetoothLowEnergyDeviceMac*>(device);
351 CBPeripheral* cb_peripheral = device_mac->GetPeripheral(); 373 CBPeripheral* cb_peripheral = device_mac->GetPeripheral();
352 return ObjCCast<MockCBPeripheral>(cb_peripheral); 374 return ObjCCast<MockCBPeripheral>(cb_peripheral);
353 } 375 }
354 376
355 MockCBCharacteristic* BluetoothTest::GetCBMockCharacteristic( 377 MockCBCharacteristic* BluetoothTest::GetCBMockCharacteristic(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); 413 // crypto::SHA256HashString(input_str, raw, sizeof(raw));
392 // if (base::HexEncode(raw, sizeof(raw)) == target) { 414 // if (base::HexEncode(raw, sizeof(raw)) == target) {
393 // return input_str; 415 // return input_str;
394 // } 416 // }
395 // ++input[0]; 417 // ++input[0];
396 // } 418 // }
397 // return ""; 419 // return "";
398 // } 420 // }
399 421
400 } // namespace device 422 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/test/bluetooth_test_mac.h ('k') | device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698