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

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

Issue 2074563002: bluetooth: mac: write characteristic implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@read_characteristicscan_servicescan_cleanup
Patch Set: Fix for comments 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 <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 309
310 // Duplicate read reported from OS shouldn't cause a problem: 310 // Duplicate read reported from OS shouldn't cause a problem:
311 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 311 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
312 312
313 EXPECT_EQ(1, gatt_read_characteristic_attempts_); 313 EXPECT_EQ(1, gatt_read_characteristic_attempts_);
314 EXPECT_EQ(empty_vector, last_read_value_); 314 EXPECT_EQ(empty_vector, last_read_value_);
315 EXPECT_EQ(empty_vector, characteristic1_->GetValue()); 315 EXPECT_EQ(empty_vector, characteristic1_->GetValue());
316 } 316 }
317 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 317 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
318 318
319 #if defined(OS_ANDROID) || defined(OS_WIN) 319 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
320 // Tests WriteRemoteCharacteristic with empty value buffer. 320 // Tests WriteRemoteCharacteristic with empty value buffer.
321 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic_Empty) { 321 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic_Empty) {
322 if (!PlatformSupportsLowEnergy()) {
323 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
324 return;
325 }
322 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 326 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
323 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 327 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
324 328
325 std::vector<uint8_t> empty_vector; 329 std::vector<uint8_t> empty_vector;
326 characteristic1_->WriteRemoteCharacteristic( 330 characteristic1_->WriteRemoteCharacteristic(
327 empty_vector, GetCallback(Call::EXPECTED), 331 empty_vector, GetCallback(Call::EXPECTED),
328 GetGattErrorCallback(Call::NOT_EXPECTED)); 332 GetGattErrorCallback(Call::NOT_EXPECTED));
329 SimulateGattCharacteristicWrite(characteristic1_); 333 SimulateGattCharacteristicWrite(characteristic1_);
330 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 334 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
331 335
332 // Duplicate write reported from OS shouldn't cause a problem: 336 // Duplicate write reported from OS shouldn't cause a problem:
333 SimulateGattCharacteristicWrite(characteristic1_); 337 SimulateGattCharacteristicWrite(characteristic1_);
334 338
335 EXPECT_EQ(empty_vector, last_write_value_); 339 EXPECT_EQ(empty_vector, last_write_value_);
336 } 340 }
337 #endif // defined(OS_ANDROID) || defined(OS_WIN) 341 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
338 342
339 #if defined(OS_ANDROID) || defined(OS_WIN) 343 #if defined(OS_ANDROID) || defined(OS_WIN)
340 // Tests ReadRemoteCharacteristic completing after Chrome objects are deleted. 344 // Tests ReadRemoteCharacteristic completing after Chrome objects are deleted.
341 // This test is not relevant for macOS. This can never happen if CBPeripheral 345 // This test is not relevant for macOS. This can never happen if CBPeripheral
342 // delegate is set to nil. 346 // delegate is set to nil.
343 TEST_F(BluetoothRemoteGattCharacteristicTest, 347 TEST_F(BluetoothRemoteGattCharacteristicTest,
344 ReadRemoteCharacteristic_AfterDeleted) { 348 ReadRemoteCharacteristic_AfterDeleted) {
345 if (!PlatformSupportsLowEnergy()) { 349 if (!PlatformSupportsLowEnergy()) {
346 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 350 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
347 return; 351 return;
(...skipping 14 matching lines...) Expand all
362 EXPECT_TRUE("Did not crash!"); 366 EXPECT_TRUE("Did not crash!");
363 } 367 }
364 #endif // defined(OS_ANDROID) || defined(OS_WIN) 368 #endif // defined(OS_ANDROID) || defined(OS_WIN)
365 369
366 #if defined(OS_ANDROID) || defined(OS_WIN) 370 #if defined(OS_ANDROID) || defined(OS_WIN)
367 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted. 371 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted.
368 // This test is not relevant for macOS. This can never happen if CBPeripheral 372 // This test is not relevant for macOS. This can never happen if CBPeripheral
369 // delegate is set to nil. 373 // delegate is set to nil.
370 TEST_F(BluetoothRemoteGattCharacteristicTest, 374 TEST_F(BluetoothRemoteGattCharacteristicTest,
371 WriteRemoteCharacteristic_AfterDeleted) { 375 WriteRemoteCharacteristic_AfterDeleted) {
376 if (!PlatformSupportsLowEnergy()) {
377 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
378 return;
379 }
372 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 380 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
373 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 381 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
374 382
375 std::vector<uint8_t> empty_vector; 383 std::vector<uint8_t> empty_vector;
376 characteristic1_->WriteRemoteCharacteristic( 384 characteristic1_->WriteRemoteCharacteristic(
377 empty_vector, GetCallback(Call::NOT_EXPECTED), 385 empty_vector, GetCallback(Call::NOT_EXPECTED),
378 GetGattErrorCallback(Call::NOT_EXPECTED)); 386 GetGattErrorCallback(Call::NOT_EXPECTED));
379 387
380 RememberCharacteristicForSubsequentAction(characteristic1_); 388 RememberCharacteristicForSubsequentAction(characteristic1_);
381 DeleteDevice(device_); // TODO(576906) delete only the characteristic. 389 DeleteDevice(device_); // TODO(576906) delete only the characteristic.
(...skipping 24 matching lines...) Expand all
406 // Duplicate read reported from OS shouldn't cause a problem: 414 // Duplicate read reported from OS shouldn't cause a problem:
407 std::vector<uint8_t> empty_vector; 415 std::vector<uint8_t> empty_vector;
408 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 416 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
409 417
410 EXPECT_EQ(1, gatt_read_characteristic_attempts_); 418 EXPECT_EQ(1, gatt_read_characteristic_attempts_);
411 EXPECT_EQ(test_vector, last_read_value_); 419 EXPECT_EQ(test_vector, last_read_value_);
412 EXPECT_EQ(test_vector, characteristic1_->GetValue()); 420 EXPECT_EQ(test_vector, characteristic1_->GetValue());
413 } 421 }
414 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 422 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
415 423
416 #if defined(OS_ANDROID) || defined(OS_WIN) 424 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
417 // Tests WriteRemoteCharacteristic with non-empty value buffer. 425 // Tests WriteRemoteCharacteristic with non-empty value buffer.
418 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic) { 426 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic) {
427 if (!PlatformSupportsLowEnergy()) {
428 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
429 return;
430 }
419 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 431 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
420 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 432 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
421 433
422 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; 434 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
423 std::vector<uint8_t> test_vector(values, values + arraysize(values)); 435 std::vector<uint8_t> test_vector(values, values + arraysize(values));
424 characteristic1_->WriteRemoteCharacteristic( 436 characteristic1_->WriteRemoteCharacteristic(
425 test_vector, GetCallback(Call::EXPECTED), 437 test_vector, GetCallback(Call::EXPECTED),
426 GetGattErrorCallback(Call::NOT_EXPECTED)); 438 GetGattErrorCallback(Call::NOT_EXPECTED));
427 439
428 SimulateGattCharacteristicWrite(characteristic1_); 440 SimulateGattCharacteristicWrite(characteristic1_);
429 441
430 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 442 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
431 EXPECT_EQ(test_vector, last_write_value_); 443 EXPECT_EQ(test_vector, last_write_value_);
432 } 444 }
433 #endif // defined(OS_ANDROID) || defined(OS_WIN) 445 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
434 446
435 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 447 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
436 // Tests ReadRemoteCharacteristic and GetValue multiple times. 448 // Tests ReadRemoteCharacteristic and GetValue multiple times.
437 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic_Twice) { 449 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic_Twice) {
438 if (!PlatformSupportsLowEnergy()) { 450 if (!PlatformSupportsLowEnergy()) {
439 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 451 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
440 return; 452 return;
441 } 453 }
442 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 454 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
443 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); 455 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
(...skipping 19 matching lines...) Expand all
463 std::vector<uint8_t> empty_vector; 475 std::vector<uint8_t> empty_vector;
464 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 476 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
465 EXPECT_EQ(1, gatt_read_characteristic_attempts_); 477 EXPECT_EQ(1, gatt_read_characteristic_attempts_);
466 EXPECT_EQ(1, callback_count_); 478 EXPECT_EQ(1, callback_count_);
467 EXPECT_EQ(0, error_callback_count_); 479 EXPECT_EQ(0, error_callback_count_);
468 EXPECT_EQ(empty_vector, last_read_value_); 480 EXPECT_EQ(empty_vector, last_read_value_);
469 EXPECT_EQ(empty_vector, characteristic1_->GetValue()); 481 EXPECT_EQ(empty_vector, characteristic1_->GetValue());
470 } 482 }
471 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 483 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
472 484
473 #if defined(OS_ANDROID) || defined(OS_WIN) 485 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
474 // Tests WriteRemoteCharacteristic multiple times. 486 // Tests WriteRemoteCharacteristic multiple times.
475 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic_Twice) { 487 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic_Twice) {
488 if (!PlatformSupportsLowEnergy()) {
489 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
490 return;
491 }
476 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 492 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
477 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 493 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
478 494
479 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; 495 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
480 std::vector<uint8_t> test_vector(values, values + arraysize(values)); 496 std::vector<uint8_t> test_vector(values, values + arraysize(values));
481 characteristic1_->WriteRemoteCharacteristic( 497 characteristic1_->WriteRemoteCharacteristic(
482 test_vector, GetCallback(Call::EXPECTED), 498 test_vector, GetCallback(Call::EXPECTED),
483 GetGattErrorCallback(Call::NOT_EXPECTED)); 499 GetGattErrorCallback(Call::NOT_EXPECTED));
484 500
485 SimulateGattCharacteristicWrite(characteristic1_); 501 SimulateGattCharacteristicWrite(characteristic1_);
486 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 502 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
487 EXPECT_EQ(1, callback_count_); 503 EXPECT_EQ(1, callback_count_);
488 EXPECT_EQ(0, error_callback_count_); 504 EXPECT_EQ(0, error_callback_count_);
489 EXPECT_EQ(test_vector, last_write_value_); 505 EXPECT_EQ(test_vector, last_write_value_);
490 506
491 // Write again, with different value: 507 // Write again, with different value:
492 ResetEventCounts(); 508 ResetEventCounts();
493 std::vector<uint8_t> empty_vector; 509 std::vector<uint8_t> empty_vector;
494 characteristic1_->WriteRemoteCharacteristic( 510 characteristic1_->WriteRemoteCharacteristic(
495 empty_vector, GetCallback(Call::EXPECTED), 511 empty_vector, GetCallback(Call::EXPECTED),
496 GetGattErrorCallback(Call::NOT_EXPECTED)); 512 GetGattErrorCallback(Call::NOT_EXPECTED));
497 513
498 SimulateGattCharacteristicWrite(characteristic1_); 514 SimulateGattCharacteristicWrite(characteristic1_);
499 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 515 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
500 EXPECT_EQ(1, callback_count_); 516 EXPECT_EQ(1, callback_count_);
501 EXPECT_EQ(0, error_callback_count_); 517 EXPECT_EQ(0, error_callback_count_);
502 EXPECT_EQ(empty_vector, last_write_value_); 518 EXPECT_EQ(empty_vector, last_write_value_);
503 } 519 }
504 #endif // defined(OS_ANDROID) || defined(OS_WIN) 520 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
505 521
506 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 522 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
507 // Tests ReadRemoteCharacteristic on two characteristics. 523 // Tests ReadRemoteCharacteristic on two characteristics.
508 TEST_F(BluetoothRemoteGattCharacteristicTest, 524 TEST_F(BluetoothRemoteGattCharacteristicTest,
509 ReadRemoteCharacteristic_MultipleCharacteristics) { 525 ReadRemoteCharacteristic_MultipleCharacteristics) {
510 if (!PlatformSupportsLowEnergy()) { 526 if (!PlatformSupportsLowEnergy()) {
511 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 527 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
512 return; 528 return;
513 } 529 }
514 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 530 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
(...skipping 19 matching lines...) Expand all
534 EXPECT_EQ(test_vector2, last_read_value_); 550 EXPECT_EQ(test_vector2, last_read_value_);
535 551
536 EXPECT_EQ(2, gatt_read_characteristic_attempts_); 552 EXPECT_EQ(2, gatt_read_characteristic_attempts_);
537 EXPECT_EQ(2, callback_count_); 553 EXPECT_EQ(2, callback_count_);
538 EXPECT_EQ(0, error_callback_count_); 554 EXPECT_EQ(0, error_callback_count_);
539 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); 555 EXPECT_EQ(test_vector1, characteristic1_->GetValue());
540 EXPECT_EQ(test_vector2, characteristic2_->GetValue()); 556 EXPECT_EQ(test_vector2, characteristic2_->GetValue());
541 } 557 }
542 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 558 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
543 559
544 #if defined(OS_ANDROID) || defined(OS_WIN) 560 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
545 // Tests WriteRemoteCharacteristic on two characteristics. 561 // Tests WriteRemoteCharacteristic on two characteristics.
546 TEST_F(BluetoothRemoteGattCharacteristicTest, 562 TEST_F(BluetoothRemoteGattCharacteristicTest,
547 WriteRemoteCharacteristic_MultipleCharacteristics) { 563 WriteRemoteCharacteristic_MultipleCharacteristics) {
564 if (!PlatformSupportsLowEnergy()) {
565 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
566 return;
567 }
548 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 568 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
549 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 569 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
550 570
551 std::vector<uint8_t> test_vector1; 571 std::vector<uint8_t> test_vector1;
552 test_vector1.push_back(111); 572 test_vector1.push_back(111);
553 characteristic1_->WriteRemoteCharacteristic( 573 characteristic1_->WriteRemoteCharacteristic(
554 test_vector1, GetCallback(Call::EXPECTED), 574 test_vector1, GetCallback(Call::EXPECTED),
555 GetGattErrorCallback(Call::NOT_EXPECTED)); 575 GetGattErrorCallback(Call::NOT_EXPECTED));
556 #ifdef OS_ANDROID 576 #if defined(OS_ANDROID) || defined(OS_MACOSX)
557 EXPECT_EQ(test_vector1, last_write_value_); 577 EXPECT_EQ(test_vector1, last_write_value_);
558 #endif 578 #endif
559 579
560 std::vector<uint8_t> test_vector2; 580 std::vector<uint8_t> test_vector2;
561 test_vector2.push_back(222); 581 test_vector2.push_back(222);
562 characteristic2_->WriteRemoteCharacteristic( 582 characteristic2_->WriteRemoteCharacteristic(
563 test_vector2, GetCallback(Call::EXPECTED), 583 test_vector2, GetCallback(Call::EXPECTED),
564 GetGattErrorCallback(Call::NOT_EXPECTED)); 584 GetGattErrorCallback(Call::NOT_EXPECTED));
565 #ifdef OS_ANDROID 585 #if defined(OS_ANDROID) || defined(OS_MACOSX)
566 EXPECT_EQ(test_vector2, last_write_value_); 586 EXPECT_EQ(test_vector2, last_write_value_);
567 #endif 587 #endif
568 588
569 EXPECT_EQ(0, callback_count_); 589 EXPECT_EQ(0, callback_count_);
570 EXPECT_EQ(0, error_callback_count_); 590 EXPECT_EQ(0, error_callback_count_);
571 591
572 SimulateGattCharacteristicWrite(characteristic1_); 592 SimulateGattCharacteristicWrite(characteristic1_);
573 #ifndef OS_ANDROID 593 #if !(defined(OS_ANDROID) || defined(OS_MACOSX))
574 EXPECT_EQ(test_vector1, last_write_value_); 594 EXPECT_EQ(test_vector1, last_write_value_);
575 #endif 595 #endif
576 596
577 SimulateGattCharacteristicWrite(characteristic2_); 597 SimulateGattCharacteristicWrite(characteristic2_);
578 #ifndef OS_ANDROID 598 #if !(defined(OS_ANDROID) || defined(OS_MACOSX))
579 EXPECT_EQ(test_vector2, last_write_value_); 599 EXPECT_EQ(test_vector2, last_write_value_);
580 #endif 600 #endif
581 601
582 EXPECT_EQ(2, gatt_write_characteristic_attempts_); 602 EXPECT_EQ(2, gatt_write_characteristic_attempts_);
583 EXPECT_EQ(2, callback_count_); 603 EXPECT_EQ(2, callback_count_);
584 EXPECT_EQ(0, error_callback_count_); 604 EXPECT_EQ(0, error_callback_count_);
585 605
586 // TODO(591740): Remove if define for OS_ANDROID in this test. 606 // TODO(591740): Remove if define for OS_ANDROID in this test.
587 } 607 }
588 #endif // defined(OS_ANDROID) || defined(OS_WIN) 608 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
589 609
590 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 610 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
591 // Tests ReadRemoteCharacteristic asynchronous error. 611 // Tests ReadRemoteCharacteristic asynchronous error.
592 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadError) { 612 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadError) {
593 if (!PlatformSupportsLowEnergy()) { 613 if (!PlatformSupportsLowEnergy()) {
594 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 614 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
595 return; 615 return;
596 } 616 }
597 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 617 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
598 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); 618 BluetoothRemoteGattCharacteristic::PROPERTY_READ));
599 619
600 TestBluetoothAdapterObserver observer(adapter_); 620 TestBluetoothAdapterObserver observer(adapter_);
601 621
602 characteristic1_->ReadRemoteCharacteristic( 622 characteristic1_->ReadRemoteCharacteristic(
603 GetReadValueCallback(Call::NOT_EXPECTED), 623 GetReadValueCallback(Call::NOT_EXPECTED),
604 GetGattErrorCallback(Call::EXPECTED)); 624 GetGattErrorCallback(Call::EXPECTED));
605 SimulateGattCharacteristicReadError( 625 SimulateGattCharacteristicReadError(
606 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH); 626 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH);
607 SimulateGattCharacteristicReadError( 627 SimulateGattCharacteristicReadError(
608 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED); 628 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED);
609 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH, 629 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH,
610 last_gatt_error_code_); 630 last_gatt_error_code_);
611 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count()); 631 EXPECT_EQ(0, observer.gatt_characteristic_value_changed_count());
612 } 632 }
613 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 633 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
614 634
615 #if defined(OS_ANDROID) || defined(OS_WIN) 635 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
616 // Tests WriteRemoteCharacteristic asynchronous error. 636 // Tests WriteRemoteCharacteristic asynchronous error.
617 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteError) { 637 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteError) {
638 if (!PlatformSupportsLowEnergy()) {
639 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
640 return;
641 }
618 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 642 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
619 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 643 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
620 644
621 std::vector<uint8_t> empty_vector; 645 std::vector<uint8_t> empty_vector;
622 characteristic1_->WriteRemoteCharacteristic( 646 characteristic1_->WriteRemoteCharacteristic(
623 empty_vector, GetCallback(Call::NOT_EXPECTED), 647 empty_vector, GetCallback(Call::NOT_EXPECTED),
624 GetGattErrorCallback(Call::EXPECTED)); 648 GetGattErrorCallback(Call::EXPECTED));
625 SimulateGattCharacteristicWriteError( 649 SimulateGattCharacteristicWriteError(
626 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH); 650 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH);
627 SimulateGattCharacteristicWriteError( 651 SimulateGattCharacteristicWriteError(
628 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED); 652 characteristic1_, BluetoothRemoteGattService::GATT_ERROR_FAILED);
629 653
630 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH, 654 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_INVALID_LENGTH,
631 last_gatt_error_code_); 655 last_gatt_error_code_);
632 } 656 }
633 #endif // defined(OS_ANDROID) || defined(OS_WIN) 657 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
634 658
635 #if defined(OS_ANDROID) 659 #if defined(OS_ANDROID)
636 // Tests ReadRemoteCharacteristic synchronous error. 660 // Tests ReadRemoteCharacteristic synchronous error.
637 // Test not relevant for macOS since characteristic read cannot generate 661 // Test not relevant for macOS since characteristic read cannot generate
638 // synchronous error. 662 // synchronous error.
639 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadSynchronousError) { 663 TEST_F(BluetoothRemoteGattCharacteristicTest, ReadSynchronousError) {
640 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 664 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
641 665
642 SimulateGattCharacteristicReadWillFailSynchronouslyOnce(characteristic1_); 666 SimulateGattCharacteristicReadWillFailSynchronouslyOnce(characteristic1_);
643 characteristic1_->ReadRemoteCharacteristic( 667 characteristic1_->ReadRemoteCharacteristic(
(...skipping 14 matching lines...) Expand all
658 EXPECT_EQ(1, gatt_read_characteristic_attempts_); 682 EXPECT_EQ(1, gatt_read_characteristic_attempts_);
659 std::vector<uint8_t> empty_vector; 683 std::vector<uint8_t> empty_vector;
660 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 684 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
661 EXPECT_EQ(1, callback_count_); 685 EXPECT_EQ(1, callback_count_);
662 EXPECT_EQ(0, error_callback_count_); 686 EXPECT_EQ(0, error_callback_count_);
663 } 687 }
664 #endif // defined(OS_ANDROID) 688 #endif // defined(OS_ANDROID)
665 689
666 #if defined(OS_ANDROID) 690 #if defined(OS_ANDROID)
667 // Tests WriteRemoteCharacteristic synchronous error. 691 // Tests WriteRemoteCharacteristic synchronous error.
668 TEST_F(BluetoothRemoteGattCharacteristicTest, WriteSynchronousError) { 692 // This test doesn't apply to macOS synchronous API does exist.
693 synchronously when writing to a characteristic
ortuno 2016/06/23 19:21:16 Fix comment :)
694 .TEST_F(BluetoothRemoteGattCharacteristicTest, WriteSynchronousError) {
669 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 695 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
670 696
671 SimulateGattCharacteristicWriteWillFailSynchronouslyOnce(characteristic1_); 697 SimulateGattCharacteristicWriteWillFailSynchronouslyOnce(characteristic1_);
672 std::vector<uint8_t> empty_vector; 698 std::vector<uint8_t> empty_vector;
673 characteristic1_->WriteRemoteCharacteristic( 699 characteristic1_->WriteRemoteCharacteristic(
674 empty_vector, GetCallback(Call::NOT_EXPECTED), 700 empty_vector, GetCallback(Call::NOT_EXPECTED),
675 GetGattErrorCallback(Call::EXPECTED)); 701 GetGattErrorCallback(Call::EXPECTED));
676 EXPECT_EQ(0, gatt_write_characteristic_attempts_); 702 EXPECT_EQ(0, gatt_write_characteristic_attempts_);
677 base::RunLoop().RunUntilIdle(); 703 base::RunLoop().RunUntilIdle();
678 EXPECT_EQ(0, callback_count_); 704 EXPECT_EQ(0, callback_count_);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 745
720 // Initial read should still succeed: 746 // Initial read should still succeed:
721 ResetEventCounts(); 747 ResetEventCounts();
722 std::vector<uint8_t> empty_vector; 748 std::vector<uint8_t> empty_vector;
723 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 749 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
724 EXPECT_EQ(1, callback_count_); 750 EXPECT_EQ(1, callback_count_);
725 EXPECT_EQ(0, error_callback_count_); 751 EXPECT_EQ(0, error_callback_count_);
726 } 752 }
727 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) 753 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
728 754
729 #if defined(OS_ANDROID) || defined(OS_WIN) 755 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
730 // Tests WriteRemoteCharacteristic error with a pending write operation. 756 // Tests WriteRemoteCharacteristic error with a pending write operation.
731 TEST_F(BluetoothRemoteGattCharacteristicTest, 757 TEST_F(BluetoothRemoteGattCharacteristicTest,
732 WriteRemoteCharacteristic_WritePending) { 758 WriteRemoteCharacteristic_WritePending) {
759 if (!PlatformSupportsLowEnergy()) {
760 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
761 return;
762 }
733 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 763 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
734 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 764 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
735 765
736 std::vector<uint8_t> empty_vector; 766 std::vector<uint8_t> empty_vector;
737 characteristic1_->WriteRemoteCharacteristic( 767 characteristic1_->WriteRemoteCharacteristic(
738 empty_vector, GetCallback(Call::EXPECTED), 768 empty_vector, GetCallback(Call::EXPECTED),
739 GetGattErrorCallback(Call::NOT_EXPECTED)); 769 GetGattErrorCallback(Call::NOT_EXPECTED));
740 characteristic1_->WriteRemoteCharacteristic( 770 characteristic1_->WriteRemoteCharacteristic(
741 empty_vector, GetCallback(Call::NOT_EXPECTED), 771 empty_vector, GetCallback(Call::NOT_EXPECTED),
742 GetGattErrorCallback(Call::EXPECTED)); 772 GetGattErrorCallback(Call::EXPECTED));
743 773
744 base::RunLoop().RunUntilIdle(); 774 base::RunLoop().RunUntilIdle();
745 775
746 EXPECT_EQ(0, callback_count_); 776 EXPECT_EQ(0, callback_count_);
747 EXPECT_EQ(1, error_callback_count_); 777 EXPECT_EQ(1, error_callback_count_);
748 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS, 778 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS,
749 last_gatt_error_code_); 779 last_gatt_error_code_);
750 780
751 // Initial write should still succeed: 781 // Initial write should still succeed:
752 ResetEventCounts(); 782 ResetEventCounts();
753 SimulateGattCharacteristicWrite(characteristic1_); 783 SimulateGattCharacteristicWrite(characteristic1_);
754 EXPECT_EQ(1, callback_count_); 784 EXPECT_EQ(1, callback_count_);
755 EXPECT_EQ(0, error_callback_count_); 785 EXPECT_EQ(0, error_callback_count_);
756 } 786 }
757 #endif // defined(OS_ANDROID) || defined(OS_WIN) 787 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
758 788
759 #if defined(OS_ANDROID) || defined(OS_WIN) 789 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
760 // Tests ReadRemoteCharacteristic error with a pending write operation. 790 // Tests ReadRemoteCharacteristic error with a pending write operation.
761 TEST_F(BluetoothRemoteGattCharacteristicTest, 791 TEST_F(BluetoothRemoteGattCharacteristicTest,
762 ReadRemoteCharacteristic_WritePending) { 792 ReadRemoteCharacteristic_WritePending) {
793 if (!PlatformSupportsLowEnergy()) {
794 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
795 return;
796 }
763 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 797 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
764 BluetoothRemoteGattCharacteristic::PROPERTY_READ | 798 BluetoothRemoteGattCharacteristic::PROPERTY_READ |
765 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 799 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
766 800
767 std::vector<uint8_t> empty_vector; 801 std::vector<uint8_t> empty_vector;
768 characteristic1_->WriteRemoteCharacteristic( 802 characteristic1_->WriteRemoteCharacteristic(
769 empty_vector, GetCallback(Call::EXPECTED), 803 empty_vector, GetCallback(Call::EXPECTED),
770 GetGattErrorCallback(Call::NOT_EXPECTED)); 804 GetGattErrorCallback(Call::NOT_EXPECTED));
771 characteristic1_->ReadRemoteCharacteristic( 805 characteristic1_->ReadRemoteCharacteristic(
772 GetReadValueCallback(Call::NOT_EXPECTED), 806 GetReadValueCallback(Call::NOT_EXPECTED),
773 GetGattErrorCallback(Call::EXPECTED)); 807 GetGattErrorCallback(Call::EXPECTED));
774 808
775 base::RunLoop().RunUntilIdle(); 809 base::RunLoop().RunUntilIdle();
776 810
777 EXPECT_EQ(0, callback_count_); 811 EXPECT_EQ(0, callback_count_);
778 EXPECT_EQ(1, error_callback_count_); 812 EXPECT_EQ(1, error_callback_count_);
779 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS, 813 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS,
780 last_gatt_error_code_); 814 last_gatt_error_code_);
781 815
782 // Initial write should still succeed: 816 // Initial write should still succeed:
783 ResetEventCounts(); 817 ResetEventCounts();
784 SimulateGattCharacteristicWrite(characteristic1_); 818 SimulateGattCharacteristicWrite(characteristic1_);
785 EXPECT_EQ(1, callback_count_); 819 EXPECT_EQ(1, callback_count_);
786 EXPECT_EQ(0, error_callback_count_); 820 EXPECT_EQ(0, error_callback_count_);
787 } 821 }
788 #endif // defined(OS_ANDROID) || defined(OS_WIN) 822 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
789 823
790 #if defined(OS_ANDROID) || defined(OS_WIN) 824 #if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
791 // Tests WriteRemoteCharacteristic error with a pending Read operation. 825 // Tests WriteRemoteCharacteristic error with a pending Read operation.
792 TEST_F(BluetoothRemoteGattCharacteristicTest, 826 TEST_F(BluetoothRemoteGattCharacteristicTest,
793 WriteRemoteCharacteristic_ReadPending) { 827 WriteRemoteCharacteristic_ReadPending) {
828 if (!PlatformSupportsLowEnergy()) {
829 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
830 return;
831 }
794 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( 832 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
795 BluetoothRemoteGattCharacteristic::PROPERTY_READ | 833 BluetoothRemoteGattCharacteristic::PROPERTY_READ |
796 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 834 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
797 835
798 std::vector<uint8_t> empty_vector; 836 std::vector<uint8_t> empty_vector;
799 characteristic1_->ReadRemoteCharacteristic( 837 characteristic1_->ReadRemoteCharacteristic(
800 GetReadValueCallback(Call::EXPECTED), 838 GetReadValueCallback(Call::EXPECTED),
801 GetGattErrorCallback(Call::NOT_EXPECTED)); 839 GetGattErrorCallback(Call::NOT_EXPECTED));
802 characteristic1_->WriteRemoteCharacteristic( 840 characteristic1_->WriteRemoteCharacteristic(
803 empty_vector, GetCallback(Call::NOT_EXPECTED), 841 empty_vector, GetCallback(Call::NOT_EXPECTED),
804 GetGattErrorCallback(Call::EXPECTED)); 842 GetGattErrorCallback(Call::EXPECTED));
805 base::RunLoop().RunUntilIdle(); 843 base::RunLoop().RunUntilIdle();
806 844
807 EXPECT_EQ(0, callback_count_); 845 EXPECT_EQ(0, callback_count_);
808 EXPECT_EQ(1, error_callback_count_); 846 EXPECT_EQ(1, error_callback_count_);
809 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS, 847 EXPECT_EQ(BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS,
810 last_gatt_error_code_); 848 last_gatt_error_code_);
811 849
812 // Initial read should still succeed: 850 // Initial read should still succeed:
813 ResetEventCounts(); 851 ResetEventCounts();
814 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 852 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
815 EXPECT_EQ(1, callback_count_); 853 EXPECT_EQ(1, callback_count_);
816 EXPECT_EQ(0, error_callback_count_); 854 EXPECT_EQ(0, error_callback_count_);
817 } 855 }
818 #endif // defined(OS_ANDROID) || defined(OS_WIN) 856 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN)
819 857
820 #if defined(OS_ANDROID) || defined(OS_WIN) 858 #if defined(OS_ANDROID) || defined(OS_WIN)
821 // StartNotifySession fails if characteristic doesn't have Notify or Indicate 859 // StartNotifySession fails if characteristic doesn't have Notify or Indicate
822 // property. 860 // property.
823 TEST_F(BluetoothRemoteGattCharacteristicTest, 861 TEST_F(BluetoothRemoteGattCharacteristicTest,
824 StartNotifySession_NoNotifyOrIndicate) { 862 StartNotifySession_NoNotifyOrIndicate) {
825 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 863 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
826 /* properties: NOTIFY */ 0x10, 864 /* properties: NOTIFY */ 0x10,
827 /* expected_config_descriptor_value: NOTIFY */ 1, 865 /* expected_config_descriptor_value: NOTIFY */ 1,
828 StartNotifySetupError::CHARACTERISTIC_PROPERTIES)); 866 StartNotifySetupError::CHARACTERISTIC_PROPERTIES));
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size()); 1315 EXPECT_EQ(1u, characteristic1_->GetDescriptorsByUUID(id2).size());
1278 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size()); 1316 EXPECT_EQ(2u, characteristic2_->GetDescriptorsByUUID(id3).size());
1279 1317
1280 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size()); 1318 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id1).size());
1281 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size()); 1319 EXPECT_EQ(0u, characteristic2_->GetDescriptorsByUUID(id2).size());
1282 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size()); 1320 EXPECT_EQ(0u, characteristic1_->GetDescriptorsByUUID(id3).size());
1283 } 1321 }
1284 #endif // defined(OS_ANDROID) || defined(OS_WIN) 1322 #endif // defined(OS_ANDROID) || defined(OS_WIN)
1285 1323
1286 } // namespace device 1324 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_remote_gatt_characteristic_mac.mm ('k') | device/bluetooth/bluetooth_remote_gatt_service_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698