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

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

Issue 1739383002: Implement read & write remote GATT characteristic value for Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: format Created 4 years, 9 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/bluetooth_gatt_characteristic.h" 5 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 #if defined(OS_ANDROID) || defined(OS_WIN) 257 #if defined(OS_ANDROID) || defined(OS_WIN)
258 // Tests GetService. 258 // Tests GetService.
259 TEST_F(BluetoothGattCharacteristicTest, GetService) { 259 TEST_F(BluetoothGattCharacteristicTest, GetService) {
260 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 260 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
261 261
262 EXPECT_EQ(service_, characteristic1_->GetService()); 262 EXPECT_EQ(service_, characteristic1_->GetService());
263 EXPECT_EQ(service_, characteristic2_->GetService()); 263 EXPECT_EQ(service_, characteristic2_->GetService());
264 } 264 }
265 #endif // defined(OS_ANDROID) || defined(OS_WIN) 265 #endif // defined(OS_ANDROID) || defined(OS_WIN)
266 266
267 #if defined(OS_ANDROID) 267 #if defined(OS_ANDROID) || defined(OS_WIN)
268 // Tests ReadRemoteCharacteristic and GetValue with empty value buffer. 268 // Tests ReadRemoteCharacteristic and GetValue with empty value buffer.
269 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_Empty) { 269 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_Empty) {
270 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 270 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
271 BluetoothGattCharacteristic::PROPERTY_READ));
271 272
272 characteristic1_->ReadRemoteCharacteristic( 273 characteristic1_->ReadRemoteCharacteristic(
273 GetReadValueCallback(Call::EXPECTED), 274 GetReadValueCallback(Call::EXPECTED),
274 GetGattErrorCallback(Call::NOT_EXPECTED)); 275 GetGattErrorCallback(Call::NOT_EXPECTED));
275 EXPECT_EQ(1, gatt_read_characteristic_attempts_); 276 EXPECT_EQ(1, gatt_read_characteristic_attempts_);
276 std::vector<uint8_t> empty_vector; 277 std::vector<uint8_t> empty_vector;
277 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 278 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
278 279
279 // Duplicate read reported from OS shouldn't cause a problem: 280 // Duplicate read reported from OS shouldn't cause a problem:
280 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 281 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
281 282
282 EXPECT_EQ(empty_vector, last_read_value_); 283 EXPECT_EQ(empty_vector, last_read_value_);
283 EXPECT_EQ(empty_vector, characteristic1_->GetValue()); 284 EXPECT_EQ(empty_vector, characteristic1_->GetValue());
284 } 285 }
285 #endif // defined(OS_ANDROID) 286 #endif // defined(OS_ANDROID) || defined(OS_WIN)
286 287
287 #if defined(OS_ANDROID) 288 #if defined(OS_ANDROID) || defined(OS_WIN)
288 // Tests WriteRemoteCharacteristic with empty value buffer. 289 // Tests WriteRemoteCharacteristic with empty value buffer.
289 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Empty) { 290 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Empty) {
290 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 291 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
292 BluetoothGattCharacteristic::PROPERTY_WRITE));
291 293
292 std::vector<uint8_t> empty_vector; 294 std::vector<uint8_t> empty_vector;
293 characteristic1_->WriteRemoteCharacteristic( 295 characteristic1_->WriteRemoteCharacteristic(
294 empty_vector, GetCallback(Call::EXPECTED), 296 empty_vector, GetCallback(Call::EXPECTED),
295 GetGattErrorCallback(Call::NOT_EXPECTED)); 297 GetGattErrorCallback(Call::NOT_EXPECTED));
296 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 298 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
297 SimulateGattCharacteristicWrite(characteristic1_); 299 SimulateGattCharacteristicWrite(characteristic1_);
298 300
299 EXPECT_EQ(empty_vector, last_write_value_); 301 EXPECT_EQ(empty_vector, last_write_value_);
300 } 302 }
301 #endif // defined(OS_ANDROID) 303 #endif // defined(OS_ANDROID) || defined(OS_WIN)
302 304
303 #if defined(OS_ANDROID) 305 #if defined(OS_ANDROID) || defined(OS_WIN)
304 // Tests ReadRemoteCharacteristic completing after Chrome objects are deleted. 306 // Tests ReadRemoteCharacteristic completing after Chrome objects are deleted.
305 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_AfterDeleted) { 307 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_AfterDeleted) {
306 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 308 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
309 BluetoothGattCharacteristic::PROPERTY_READ));
307 310
308 characteristic1_->ReadRemoteCharacteristic( 311 characteristic1_->ReadRemoteCharacteristic(
309 GetReadValueCallback(Call::NOT_EXPECTED), 312 GetReadValueCallback(Call::NOT_EXPECTED),
310 GetGattErrorCallback(Call::NOT_EXPECTED)); 313 GetGattErrorCallback(Call::NOT_EXPECTED));
311 314
312 RememberCharacteristicForSubsequentAction(characteristic1_); 315 RememberCharacteristicForSubsequentAction(characteristic1_);
313 DeleteDevice(device_); 316 DeleteDevice(device_);
314 317
315 std::vector<uint8_t> empty_vector; 318 std::vector<uint8_t> empty_vector;
316 SimulateGattCharacteristicRead(/* use remembered characteristic */ nullptr, 319 SimulateGattCharacteristicRead(/* use remembered characteristic */ nullptr,
317 empty_vector); 320 empty_vector);
318 EXPECT_TRUE("Did not crash!"); 321 EXPECT_TRUE("Did not crash!");
319 } 322 }
320 #endif // defined(OS_ANDROID) 323 #endif // defined(OS_ANDROID) || defined(OS_WIN)
321 324
322 #if defined(OS_ANDROID) 325 #if defined(OS_ANDROID) || defined(OS_WIN)
323 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted. 326 // Tests WriteRemoteCharacteristic completing after Chrome objects are deleted.
324 TEST_F(BluetoothGattCharacteristicTest, 327 TEST_F(BluetoothGattCharacteristicTest,
325 WriteRemoteCharacteristic_AfterDeleted) { 328 WriteRemoteCharacteristic_AfterDeleted) {
326 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 329 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
330 BluetoothGattCharacteristic::PROPERTY_WRITE));
327 331
328 std::vector<uint8_t> empty_vector; 332 std::vector<uint8_t> empty_vector;
329 characteristic1_->WriteRemoteCharacteristic( 333 characteristic1_->WriteRemoteCharacteristic(
330 empty_vector, GetCallback(Call::NOT_EXPECTED), 334 empty_vector, GetCallback(Call::NOT_EXPECTED),
331 GetGattErrorCallback(Call::NOT_EXPECTED)); 335 GetGattErrorCallback(Call::NOT_EXPECTED));
332 336
333 RememberCharacteristicForSubsequentAction(characteristic1_); 337 RememberCharacteristicForSubsequentAction(characteristic1_);
334 DeleteDevice(device_); 338 DeleteDevice(device_);
335 339
336 SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr); 340 SimulateGattCharacteristicWrite(/* use remembered characteristic */ nullptr);
337 EXPECT_TRUE("Did not crash!"); 341 EXPECT_TRUE("Did not crash!");
338 } 342 }
339 #endif // defined(OS_ANDROID) 343 #endif // defined(OS_ANDROID) || defined(OS_WIN)
340 344
341 #if defined(OS_ANDROID) 345 #if defined(OS_ANDROID) || defined(OS_WIN)
342 // Tests ReadRemoteCharacteristic and GetValue with non-empty value buffer. 346 // Tests ReadRemoteCharacteristic and GetValue with non-empty value buffer.
343 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic) { 347 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic) {
344 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 348 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
349 BluetoothGattCharacteristic::PROPERTY_READ));
345 350
346 characteristic1_->ReadRemoteCharacteristic( 351 characteristic1_->ReadRemoteCharacteristic(
347 GetReadValueCallback(Call::EXPECTED), 352 GetReadValueCallback(Call::EXPECTED),
348 GetGattErrorCallback(Call::NOT_EXPECTED)); 353 GetGattErrorCallback(Call::NOT_EXPECTED));
349 EXPECT_EQ(1, gatt_read_characteristic_attempts_); 354 EXPECT_EQ(1, gatt_read_characteristic_attempts_);
350 355
351 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; 356 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
352 std::vector<uint8_t> test_vector(values, values + arraysize(values)); 357 std::vector<uint8_t> test_vector(values, values + arraysize(values));
353 SimulateGattCharacteristicRead(characteristic1_, test_vector); 358 SimulateGattCharacteristicRead(characteristic1_, test_vector);
354 359
355 // Duplicate read reported from OS shouldn't cause a problem: 360 // Duplicate read reported from OS shouldn't cause a problem:
356 std::vector<uint8_t> empty_vector; 361 std::vector<uint8_t> empty_vector;
357 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 362 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
358 363
359 EXPECT_EQ(test_vector, last_read_value_); 364 EXPECT_EQ(test_vector, last_read_value_);
360 EXPECT_EQ(test_vector, characteristic1_->GetValue()); 365 EXPECT_EQ(test_vector, characteristic1_->GetValue());
361 } 366 }
362 #endif // defined(OS_ANDROID) 367 #endif // defined(OS_ANDROID) || defined(OS_WIN)
363 368
364 #if defined(OS_ANDROID) 369 #if defined(OS_ANDROID) || defined(OS_WIN)
365 // Tests WriteRemoteCharacteristic with non-empty value buffer. 370 // Tests WriteRemoteCharacteristic with non-empty value buffer.
366 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic) { 371 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic) {
367 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 372 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
373 BluetoothGattCharacteristic::PROPERTY_WRITE));
368 374
369 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; 375 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
370 std::vector<uint8_t> test_vector(values, values + arraysize(values)); 376 std::vector<uint8_t> test_vector(values, values + arraysize(values));
371 characteristic1_->WriteRemoteCharacteristic( 377 characteristic1_->WriteRemoteCharacteristic(
372 test_vector, GetCallback(Call::EXPECTED), 378 test_vector, GetCallback(Call::EXPECTED),
373 GetGattErrorCallback(Call::NOT_EXPECTED)); 379 GetGattErrorCallback(Call::NOT_EXPECTED));
374 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 380 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
375 381
376 SimulateGattCharacteristicWrite(characteristic1_); 382 SimulateGattCharacteristicWrite(characteristic1_);
377 383
378 EXPECT_EQ(test_vector, last_write_value_); 384 EXPECT_EQ(test_vector, last_write_value_);
379 } 385 }
380 #endif // defined(OS_ANDROID) 386 #endif // defined(OS_ANDROID) || defined(OS_WIN)
381 387
382 #if defined(OS_ANDROID) 388 #if defined(OS_ANDROID) || defined(OS_WIN)
383 // Tests ReadRemoteCharacteristic and GetValue multiple times. 389 // Tests ReadRemoteCharacteristic and GetValue multiple times.
384 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_Twice) { 390 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_Twice) {
385 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 391 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
392 BluetoothGattCharacteristic::PROPERTY_READ));
386 393
387 characteristic1_->ReadRemoteCharacteristic( 394 characteristic1_->ReadRemoteCharacteristic(
388 GetReadValueCallback(Call::EXPECTED), 395 GetReadValueCallback(Call::EXPECTED),
389 GetGattErrorCallback(Call::NOT_EXPECTED)); 396 GetGattErrorCallback(Call::NOT_EXPECTED));
390 EXPECT_EQ(1, gatt_read_characteristic_attempts_); 397 EXPECT_EQ(1, gatt_read_characteristic_attempts_);
391 398
392 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; 399 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
393 std::vector<uint8_t> test_vector(values, values + arraysize(values)); 400 std::vector<uint8_t> test_vector(values, values + arraysize(values));
394 SimulateGattCharacteristicRead(characteristic1_, test_vector); 401 SimulateGattCharacteristicRead(characteristic1_, test_vector);
395 EXPECT_EQ(1, callback_count_); 402 EXPECT_EQ(1, callback_count_);
396 EXPECT_EQ(0, error_callback_count_); 403 EXPECT_EQ(0, error_callback_count_);
397 EXPECT_EQ(test_vector, last_read_value_); 404 EXPECT_EQ(test_vector, last_read_value_);
398 EXPECT_EQ(test_vector, characteristic1_->GetValue()); 405 EXPECT_EQ(test_vector, characteristic1_->GetValue());
399 406
400 // Read again, with different value: 407 // Read again, with different value:
401 ResetEventCounts(); 408 ResetEventCounts();
402 characteristic1_->ReadRemoteCharacteristic( 409 characteristic1_->ReadRemoteCharacteristic(
403 GetReadValueCallback(Call::EXPECTED), 410 GetReadValueCallback(Call::EXPECTED),
404 GetGattErrorCallback(Call::NOT_EXPECTED)); 411 GetGattErrorCallback(Call::NOT_EXPECTED));
405 EXPECT_EQ(1, gatt_read_characteristic_attempts_); 412 EXPECT_EQ(1, gatt_read_characteristic_attempts_);
406 std::vector<uint8_t> empty_vector; 413 std::vector<uint8_t> empty_vector;
407 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 414 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
408 EXPECT_EQ(1, callback_count_); 415 EXPECT_EQ(1, callback_count_);
409 EXPECT_EQ(0, error_callback_count_); 416 EXPECT_EQ(0, error_callback_count_);
410 EXPECT_EQ(empty_vector, last_read_value_); 417 EXPECT_EQ(empty_vector, last_read_value_);
411 EXPECT_EQ(empty_vector, characteristic1_->GetValue()); 418 EXPECT_EQ(empty_vector, characteristic1_->GetValue());
412 } 419 }
413 #endif // defined(OS_ANDROID) 420 #endif // defined(OS_ANDROID) || defined(OS_WIN)
414 421
415 #if defined(OS_ANDROID) 422 #if defined(OS_ANDROID) || defined(OS_WIN)
416 // Tests WriteRemoteCharacteristic multiple times. 423 // Tests WriteRemoteCharacteristic multiple times.
417 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Twice) { 424 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_Twice) {
418 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 425 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
426 BluetoothGattCharacteristic::PROPERTY_WRITE));
419 427
420 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff}; 428 uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
421 std::vector<uint8_t> test_vector(values, values + arraysize(values)); 429 std::vector<uint8_t> test_vector(values, values + arraysize(values));
422 characteristic1_->WriteRemoteCharacteristic( 430 characteristic1_->WriteRemoteCharacteristic(
423 test_vector, GetCallback(Call::EXPECTED), 431 test_vector, GetCallback(Call::EXPECTED),
424 GetGattErrorCallback(Call::NOT_EXPECTED)); 432 GetGattErrorCallback(Call::NOT_EXPECTED));
425 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 433 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
426 434
427 SimulateGattCharacteristicWrite(characteristic1_); 435 SimulateGattCharacteristicWrite(characteristic1_);
428 EXPECT_EQ(1, callback_count_); 436 EXPECT_EQ(1, callback_count_);
429 EXPECT_EQ(0, error_callback_count_); 437 EXPECT_EQ(0, error_callback_count_);
430 EXPECT_EQ(test_vector, last_write_value_); 438 EXPECT_EQ(test_vector, last_write_value_);
431 439
432 // Write again, with different value: 440 // Write again, with different value:
433 ResetEventCounts(); 441 ResetEventCounts();
434 std::vector<uint8_t> empty_vector; 442 std::vector<uint8_t> empty_vector;
435 characteristic1_->WriteRemoteCharacteristic( 443 characteristic1_->WriteRemoteCharacteristic(
436 empty_vector, GetCallback(Call::EXPECTED), 444 empty_vector, GetCallback(Call::EXPECTED),
437 GetGattErrorCallback(Call::NOT_EXPECTED)); 445 GetGattErrorCallback(Call::NOT_EXPECTED));
438 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 446 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
439 SimulateGattCharacteristicWrite(characteristic1_); 447 SimulateGattCharacteristicWrite(characteristic1_);
440 EXPECT_EQ(1, callback_count_); 448 EXPECT_EQ(1, callback_count_);
441 EXPECT_EQ(0, error_callback_count_); 449 EXPECT_EQ(0, error_callback_count_);
442 EXPECT_EQ(empty_vector, last_write_value_); 450 EXPECT_EQ(empty_vector, last_write_value_);
443 } 451 }
444 #endif // defined(OS_ANDROID) 452 #endif // defined(OS_ANDROID) || defined(OS_WIN)
445 453
446 #if defined(OS_ANDROID) 454 #if defined(OS_ANDROID) || defined(OS_WIN)
447 // Tests ReadRemoteCharacteristic on two characteristics. 455 // Tests ReadRemoteCharacteristic on two characteristics.
448 TEST_F(BluetoothGattCharacteristicTest, 456 TEST_F(BluetoothGattCharacteristicTest,
449 ReadRemoteCharacteristic_MultipleCharacteristics) { 457 ReadRemoteCharacteristic_MultipleCharacteristics) {
450 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 458 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
459 BluetoothGattCharacteristic::PROPERTY_READ));
451 460
452 characteristic1_->ReadRemoteCharacteristic( 461 characteristic1_->ReadRemoteCharacteristic(
453 GetReadValueCallback(Call::EXPECTED), 462 GetReadValueCallback(Call::EXPECTED),
454 GetGattErrorCallback(Call::NOT_EXPECTED)); 463 GetGattErrorCallback(Call::NOT_EXPECTED));
455 characteristic2_->ReadRemoteCharacteristic( 464 characteristic2_->ReadRemoteCharacteristic(
456 GetReadValueCallback(Call::EXPECTED), 465 GetReadValueCallback(Call::EXPECTED),
457 GetGattErrorCallback(Call::NOT_EXPECTED)); 466 GetGattErrorCallback(Call::NOT_EXPECTED));
458 EXPECT_EQ(2, gatt_read_characteristic_attempts_); 467 EXPECT_EQ(2, gatt_read_characteristic_attempts_);
459 EXPECT_EQ(0, callback_count_); 468 EXPECT_EQ(0, callback_count_);
460 EXPECT_EQ(0, error_callback_count_); 469 EXPECT_EQ(0, error_callback_count_);
461 470
462 std::vector<uint8_t> test_vector1; 471 std::vector<uint8_t> test_vector1;
463 test_vector1.push_back(111); 472 test_vector1.push_back(111);
464 SimulateGattCharacteristicRead(characteristic1_, test_vector1); 473 SimulateGattCharacteristicRead(characteristic1_, test_vector1);
465 EXPECT_EQ(test_vector1, last_read_value_); 474 EXPECT_EQ(test_vector1, last_read_value_);
466 475
467 std::vector<uint8_t> test_vector2; 476 std::vector<uint8_t> test_vector2;
468 test_vector2.push_back(222); 477 test_vector2.push_back(222);
469 SimulateGattCharacteristicRead(characteristic2_, test_vector2); 478 SimulateGattCharacteristicRead(characteristic2_, test_vector2);
470 EXPECT_EQ(test_vector2, last_read_value_); 479 EXPECT_EQ(test_vector2, last_read_value_);
471 480
472 EXPECT_EQ(2, callback_count_); 481 EXPECT_EQ(2, callback_count_);
473 EXPECT_EQ(0, error_callback_count_); 482 EXPECT_EQ(0, error_callback_count_);
474 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); 483 EXPECT_EQ(test_vector1, characteristic1_->GetValue());
475 EXPECT_EQ(test_vector2, characteristic2_->GetValue()); 484 EXPECT_EQ(test_vector2, characteristic2_->GetValue());
476 } 485 }
477 #endif // defined(OS_ANDROID) 486 #endif // defined(OS_ANDROID) || defined(OS_WIN)
478 487
479 #if defined(OS_ANDROID) 488 #if defined(OS_ANDROID) || defined(OS_WIN)
480 // Tests WriteRemoteCharacteristic on two characteristics. 489 // Tests WriteRemoteCharacteristic on two characteristics.
481 TEST_F(BluetoothGattCharacteristicTest, 490 TEST_F(BluetoothGattCharacteristicTest,
482 WriteRemoteCharacteristic_MultipleCharacteristics) { 491 WriteRemoteCharacteristic_MultipleCharacteristics) {
483 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 492 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
493 BluetoothGattCharacteristic::PROPERTY_WRITE));
484 494
485 std::vector<uint8_t> test_vector1; 495 std::vector<uint8_t> test_vector1;
486 test_vector1.push_back(111); 496 test_vector1.push_back(111);
487 characteristic1_->WriteRemoteCharacteristic( 497 characteristic1_->WriteRemoteCharacteristic(
488 test_vector1, GetCallback(Call::EXPECTED), 498 test_vector1, GetCallback(Call::EXPECTED),
489 GetGattErrorCallback(Call::NOT_EXPECTED)); 499 GetGattErrorCallback(Call::NOT_EXPECTED));
490 EXPECT_EQ(test_vector1, last_write_value_);
491 500
492 std::vector<uint8_t> test_vector2; 501 std::vector<uint8_t> test_vector2;
493 test_vector2.push_back(222); 502 test_vector2.push_back(222);
494 characteristic2_->WriteRemoteCharacteristic( 503 characteristic2_->WriteRemoteCharacteristic(
495 test_vector2, GetCallback(Call::EXPECTED), 504 test_vector2, GetCallback(Call::EXPECTED),
496 GetGattErrorCallback(Call::NOT_EXPECTED)); 505 GetGattErrorCallback(Call::NOT_EXPECTED));
497 EXPECT_EQ(test_vector2, last_write_value_);
498 506
499 EXPECT_EQ(2, gatt_write_characteristic_attempts_); 507 EXPECT_EQ(2, gatt_write_characteristic_attempts_);
500 EXPECT_EQ(0, callback_count_); 508 EXPECT_EQ(0, callback_count_);
501 EXPECT_EQ(0, error_callback_count_); 509 EXPECT_EQ(0, error_callback_count_);
502 510
503 SimulateGattCharacteristicWrite(characteristic1_); 511 SimulateGattCharacteristicWrite(characteristic1_);
512 EXPECT_EQ(test_vector1, last_write_value_);
513
504 SimulateGattCharacteristicWrite(characteristic2_); 514 SimulateGattCharacteristicWrite(characteristic2_);
515 EXPECT_EQ(test_vector2, last_write_value_);
505 516
506 EXPECT_EQ(2, callback_count_); 517 EXPECT_EQ(2, callback_count_);
507 EXPECT_EQ(0, error_callback_count_); 518 EXPECT_EQ(0, error_callback_count_);
508 } 519 }
509 #endif // defined(OS_ANDROID) 520 #endif // defined(OS_ANDROID) || defined(OS_WIN)
510 521
511 #if defined(OS_ANDROID) 522 #if defined(OS_ANDROID) || defined(OS_WIN)
512 // Tests ReadRemoteCharacteristic asynchronous error. 523 // Tests ReadRemoteCharacteristic asynchronous error.
513 TEST_F(BluetoothGattCharacteristicTest, ReadError) { 524 TEST_F(BluetoothGattCharacteristicTest, ReadError) {
514 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 525 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
526 BluetoothGattCharacteristic::PROPERTY_READ));
515 527
516 characteristic1_->ReadRemoteCharacteristic( 528 characteristic1_->ReadRemoteCharacteristic(
517 GetReadValueCallback(Call::NOT_EXPECTED), 529 GetReadValueCallback(Call::NOT_EXPECTED),
518 GetGattErrorCallback(Call::EXPECTED)); 530 GetGattErrorCallback(Call::EXPECTED));
519 SimulateGattCharacteristicReadError( 531 SimulateGattCharacteristicReadError(
520 characteristic1_, BluetoothGattService::GATT_ERROR_INVALID_LENGTH); 532 characteristic1_, BluetoothGattService::GATT_ERROR_INVALID_LENGTH);
521 SimulateGattCharacteristicReadError(characteristic1_, 533 SimulateGattCharacteristicReadError(characteristic1_,
522 BluetoothGattService::GATT_ERROR_FAILED); 534 BluetoothGattService::GATT_ERROR_FAILED);
523 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, 535 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH,
524 last_gatt_error_code_); 536 last_gatt_error_code_);
525 } 537 }
526 #endif // defined(OS_ANDROID) 538 #endif // defined(OS_ANDROID) || defined(OS_WIN)
527 539
528 #if defined(OS_ANDROID) 540 #if defined(OS_ANDROID) || defined(OS_WIN)
529 // Tests WriteRemoteCharacteristic asynchronous error. 541 // Tests WriteRemoteCharacteristic asynchronous error.
530 TEST_F(BluetoothGattCharacteristicTest, WriteError) { 542 TEST_F(BluetoothGattCharacteristicTest, WriteError) {
531 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 543 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
544 BluetoothGattCharacteristic::PROPERTY_WRITE));
532 545
533 std::vector<uint8_t> empty_vector; 546 std::vector<uint8_t> empty_vector;
534 characteristic1_->WriteRemoteCharacteristic( 547 characteristic1_->WriteRemoteCharacteristic(
535 empty_vector, GetCallback(Call::NOT_EXPECTED), 548 empty_vector, GetCallback(Call::NOT_EXPECTED),
536 GetGattErrorCallback(Call::EXPECTED)); 549 GetGattErrorCallback(Call::EXPECTED));
537 SimulateGattCharacteristicWriteError( 550 SimulateGattCharacteristicWriteError(
538 characteristic1_, BluetoothGattService::GATT_ERROR_INVALID_LENGTH); 551 characteristic1_, BluetoothGattService::GATT_ERROR_INVALID_LENGTH);
539 SimulateGattCharacteristicWriteError(characteristic1_, 552 SimulateGattCharacteristicWriteError(characteristic1_,
540 BluetoothGattService::GATT_ERROR_FAILED); 553 BluetoothGattService::GATT_ERROR_FAILED);
541 554
542 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, 555 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH,
543 last_gatt_error_code_); 556 last_gatt_error_code_);
544 } 557 }
545 #endif // defined(OS_ANDROID) 558 #endif // defined(OS_ANDROID) || defined(OS_WIN)
546 559
547 #if defined(OS_ANDROID) 560 #if defined(OS_ANDROID)
548 // Tests ReadRemoteCharacteristic synchronous error. 561 // Tests ReadRemoteCharacteristic synchronous error.
549 TEST_F(BluetoothGattCharacteristicTest, ReadSynchronousError) { 562 TEST_F(BluetoothGattCharacteristicTest, ReadSynchronousError) {
550 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 563 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate());
551 564
552 SimulateGattCharacteristicReadWillFailSynchronouslyOnce(characteristic1_); 565 SimulateGattCharacteristicReadWillFailSynchronouslyOnce(characteristic1_);
553 characteristic1_->ReadRemoteCharacteristic( 566 characteristic1_->ReadRemoteCharacteristic(
554 GetReadValueCallback(Call::NOT_EXPECTED), 567 GetReadValueCallback(Call::NOT_EXPECTED),
555 GetGattErrorCallback(Call::EXPECTED)); 568 GetGattErrorCallback(Call::EXPECTED));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 characteristic1_->WriteRemoteCharacteristic( 606 characteristic1_->WriteRemoteCharacteristic(
594 empty_vector, GetCallback(Call::EXPECTED), 607 empty_vector, GetCallback(Call::EXPECTED),
595 GetGattErrorCallback(Call::NOT_EXPECTED)); 608 GetGattErrorCallback(Call::NOT_EXPECTED));
596 EXPECT_EQ(1, gatt_write_characteristic_attempts_); 609 EXPECT_EQ(1, gatt_write_characteristic_attempts_);
597 SimulateGattCharacteristicWrite(characteristic1_); 610 SimulateGattCharacteristicWrite(characteristic1_);
598 EXPECT_EQ(1, callback_count_); 611 EXPECT_EQ(1, callback_count_);
599 EXPECT_EQ(0, error_callback_count_); 612 EXPECT_EQ(0, error_callback_count_);
600 } 613 }
601 #endif // defined(OS_ANDROID) 614 #endif // defined(OS_ANDROID)
602 615
603 #if defined(OS_ANDROID) 616 #if defined(OS_ANDROID) || defined(OS_WIN)
604 // Tests ReadRemoteCharacteristic error with a pending read operation. 617 // Tests ReadRemoteCharacteristic error with a pending read operation.
605 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_ReadPending) { 618 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_ReadPending) {
606 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 619 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
620 BluetoothGattCharacteristic::PROPERTY_READ));
607 621
608 characteristic1_->ReadRemoteCharacteristic( 622 characteristic1_->ReadRemoteCharacteristic(
609 GetReadValueCallback(Call::EXPECTED), 623 GetReadValueCallback(Call::EXPECTED),
610 GetGattErrorCallback(Call::NOT_EXPECTED)); 624 GetGattErrorCallback(Call::NOT_EXPECTED));
611 characteristic1_->ReadRemoteCharacteristic( 625 characteristic1_->ReadRemoteCharacteristic(
612 GetReadValueCallback(Call::NOT_EXPECTED), 626 GetReadValueCallback(Call::NOT_EXPECTED),
613 GetGattErrorCallback(Call::EXPECTED)); 627 GetGattErrorCallback(Call::EXPECTED));
614 628
615 base::RunLoop().RunUntilIdle(); 629 base::RunLoop().RunUntilIdle();
616 630
617 EXPECT_EQ(0, callback_count_); 631 EXPECT_EQ(0, callback_count_);
618 EXPECT_EQ(1, error_callback_count_); 632 EXPECT_EQ(1, error_callback_count_);
619 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, 633 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS,
620 last_gatt_error_code_); 634 last_gatt_error_code_);
621 635
622 // Initial read should still succeed: 636 // Initial read should still succeed:
623 ResetEventCounts(); 637 ResetEventCounts();
624 std::vector<uint8_t> empty_vector; 638 std::vector<uint8_t> empty_vector;
625 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 639 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
626 EXPECT_EQ(1, callback_count_); 640 EXPECT_EQ(1, callback_count_);
627 EXPECT_EQ(0, error_callback_count_); 641 EXPECT_EQ(0, error_callback_count_);
628 } 642 }
629 #endif // defined(OS_ANDROID) 643 #endif // defined(OS_ANDROID) || defined(OS_WIN)
630 644
631 #if defined(OS_ANDROID) 645 #if defined(OS_ANDROID) || defined(OS_WIN)
632 // Tests WriteRemoteCharacteristic error with a pending write operation. 646 // Tests WriteRemoteCharacteristic error with a pending write operation.
633 TEST_F(BluetoothGattCharacteristicTest, 647 TEST_F(BluetoothGattCharacteristicTest,
634 WriteRemoteCharacteristic_WritePending) { 648 WriteRemoteCharacteristic_WritePending) {
635 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 649 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
650 BluetoothGattCharacteristic::PROPERTY_WRITE));
636 651
637 std::vector<uint8_t> empty_vector; 652 std::vector<uint8_t> empty_vector;
638 characteristic1_->WriteRemoteCharacteristic( 653 characteristic1_->WriteRemoteCharacteristic(
639 empty_vector, GetCallback(Call::EXPECTED), 654 empty_vector, GetCallback(Call::EXPECTED),
640 GetGattErrorCallback(Call::NOT_EXPECTED)); 655 GetGattErrorCallback(Call::NOT_EXPECTED));
641 characteristic1_->WriteRemoteCharacteristic( 656 characteristic1_->WriteRemoteCharacteristic(
642 empty_vector, GetCallback(Call::NOT_EXPECTED), 657 empty_vector, GetCallback(Call::NOT_EXPECTED),
643 GetGattErrorCallback(Call::EXPECTED)); 658 GetGattErrorCallback(Call::EXPECTED));
644 659
645 base::RunLoop().RunUntilIdle(); 660 base::RunLoop().RunUntilIdle();
646 661
647 EXPECT_EQ(0, callback_count_); 662 EXPECT_EQ(0, callback_count_);
648 EXPECT_EQ(1, error_callback_count_); 663 EXPECT_EQ(1, error_callback_count_);
649 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, 664 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS,
650 last_gatt_error_code_); 665 last_gatt_error_code_);
651 666
652 // Initial write should still succeed: 667 // Initial write should still succeed:
653 ResetEventCounts(); 668 ResetEventCounts();
654 SimulateGattCharacteristicWrite(characteristic1_); 669 SimulateGattCharacteristicWrite(characteristic1_);
655 EXPECT_EQ(1, callback_count_); 670 EXPECT_EQ(1, callback_count_);
656 EXPECT_EQ(0, error_callback_count_); 671 EXPECT_EQ(0, error_callback_count_);
657 } 672 }
658 #endif // defined(OS_ANDROID) 673 #endif // defined(OS_ANDROID) || defined(OS_WIN)
659 674
660 #if defined(OS_ANDROID) 675 #if defined(OS_ANDROID) || defined(OS_WIN)
661 // Tests ReadRemoteCharacteristic error with a pending write operation. 676 // Tests ReadRemoteCharacteristic error with a pending write operation.
662 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_WritePending) { 677 TEST_F(BluetoothGattCharacteristicTest, ReadRemoteCharacteristic_WritePending) {
663 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 678 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
679 BluetoothGattCharacteristic::PROPERTY_READ |
680 BluetoothGattCharacteristic::PROPERTY_WRITE));
664 681
665 std::vector<uint8_t> empty_vector; 682 std::vector<uint8_t> empty_vector;
666 characteristic1_->WriteRemoteCharacteristic( 683 characteristic1_->WriteRemoteCharacteristic(
667 empty_vector, GetCallback(Call::EXPECTED), 684 empty_vector, GetCallback(Call::EXPECTED),
668 GetGattErrorCallback(Call::NOT_EXPECTED)); 685 GetGattErrorCallback(Call::NOT_EXPECTED));
669 characteristic1_->ReadRemoteCharacteristic( 686 characteristic1_->ReadRemoteCharacteristic(
670 GetReadValueCallback(Call::NOT_EXPECTED), 687 GetReadValueCallback(Call::NOT_EXPECTED),
671 GetGattErrorCallback(Call::EXPECTED)); 688 GetGattErrorCallback(Call::EXPECTED));
672 689
673 base::RunLoop().RunUntilIdle(); 690 base::RunLoop().RunUntilIdle();
674 691
675 EXPECT_EQ(0, callback_count_); 692 EXPECT_EQ(0, callback_count_);
676 EXPECT_EQ(1, error_callback_count_); 693 EXPECT_EQ(1, error_callback_count_);
677 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, 694 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS,
678 last_gatt_error_code_); 695 last_gatt_error_code_);
679 696
680 // Initial write should still succeed: 697 // Initial write should still succeed:
681 ResetEventCounts(); 698 ResetEventCounts();
682 SimulateGattCharacteristicWrite(characteristic1_); 699 SimulateGattCharacteristicWrite(characteristic1_);
683 EXPECT_EQ(1, callback_count_); 700 EXPECT_EQ(1, callback_count_);
684 EXPECT_EQ(0, error_callback_count_); 701 EXPECT_EQ(0, error_callback_count_);
685 } 702 }
686 #endif // defined(OS_ANDROID) 703 #endif // defined(OS_ANDROID) || defined(OS_WIN)
687 704
688 #if defined(OS_ANDROID) 705 #if defined(OS_ANDROID) || defined(OS_WIN)
689 // Tests WriteRemoteCharacteristic error with a pending Read operation. 706 // Tests WriteRemoteCharacteristic error with a pending Read operation.
690 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_ReadPending) { 707 TEST_F(BluetoothGattCharacteristicTest, WriteRemoteCharacteristic_ReadPending) {
691 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); 708 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
709 BluetoothGattCharacteristic::PROPERTY_READ |
710 BluetoothGattCharacteristic::PROPERTY_WRITE));
692 711
693 std::vector<uint8_t> empty_vector; 712 std::vector<uint8_t> empty_vector;
694 characteristic1_->ReadRemoteCharacteristic( 713 characteristic1_->ReadRemoteCharacteristic(
695 GetReadValueCallback(Call::EXPECTED), 714 GetReadValueCallback(Call::EXPECTED),
696 GetGattErrorCallback(Call::NOT_EXPECTED)); 715 GetGattErrorCallback(Call::NOT_EXPECTED));
697 characteristic1_->WriteRemoteCharacteristic( 716 characteristic1_->WriteRemoteCharacteristic(
698 empty_vector, GetCallback(Call::NOT_EXPECTED), 717 empty_vector, GetCallback(Call::NOT_EXPECTED),
699 GetGattErrorCallback(Call::EXPECTED)); 718 GetGattErrorCallback(Call::EXPECTED));
700 base::RunLoop().RunUntilIdle(); 719 base::RunLoop().RunUntilIdle();
701 720
702 EXPECT_EQ(0, callback_count_); 721 EXPECT_EQ(0, callback_count_);
703 EXPECT_EQ(1, error_callback_count_); 722 EXPECT_EQ(1, error_callback_count_);
704 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS, 723 EXPECT_EQ(BluetoothGattService::GATT_ERROR_IN_PROGRESS,
705 last_gatt_error_code_); 724 last_gatt_error_code_);
706 725
707 // Initial read should still succeed: 726 // Initial read should still succeed:
708 ResetEventCounts(); 727 ResetEventCounts();
709 SimulateGattCharacteristicRead(characteristic1_, empty_vector); 728 SimulateGattCharacteristicRead(characteristic1_, empty_vector);
710 EXPECT_EQ(1, callback_count_); 729 EXPECT_EQ(1, callback_count_);
711 EXPECT_EQ(0, error_callback_count_); 730 EXPECT_EQ(0, error_callback_count_);
712 } 731 }
713 #endif // defined(OS_ANDROID) 732 #endif // defined(OS_ANDROID) || defined(OS_WIN)
714 733
715 #if defined(OS_ANDROID) 734 #if defined(OS_ANDROID)
716 // StartNotifySession fails if characteristic doesn't have Notify or Indicate 735 // StartNotifySession fails if characteristic doesn't have Notify or Indicate
717 // property. 736 // property.
718 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoNotifyOrIndicate) { 737 TEST_F(BluetoothGattCharacteristicTest, StartNotifySession_NoNotifyOrIndicate) {
719 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate( 738 ASSERT_NO_FATAL_FAILURE(StartNotifyBoilerplate(
720 /* properties: NOTIFY */ 0x10, 739 /* properties: NOTIFY */ 0x10,
721 /* expected_config_descriptor_value: NOTIFY */ 1, 740 /* expected_config_descriptor_value: NOTIFY */ 1,
722 StartNotifySetupError::CHARACTERISTIC_PROPERTIES)); 741 StartNotifySetupError::CHARACTERISTIC_PROPERTIES));
723 742
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 966
948 // Characteristic 1 has descriptor uuids 1 and 2 (we don't know the order). 967 // Characteristic 1 has descriptor uuids 1 and 2 (we don't know the order).
949 EXPECT_TRUE(c1_uuid1 == uuid1 || c1_uuid2 == uuid1); 968 EXPECT_TRUE(c1_uuid1 == uuid1 || c1_uuid2 == uuid1);
950 EXPECT_TRUE(c1_uuid1 == uuid2 || c1_uuid2 == uuid2); 969 EXPECT_TRUE(c1_uuid1 == uuid2 || c1_uuid2 == uuid2);
951 // ... but not uuid 3 970 // ... but not uuid 3
952 EXPECT_FALSE(c1_uuid1 == uuid3 || c1_uuid2 == uuid3); 971 EXPECT_FALSE(c1_uuid1 == uuid3 || c1_uuid2 == uuid3);
953 } 972 }
954 #endif // defined(OS_ANDROID) || defined(OS_WIN) 973 #endif // defined(OS_ANDROID) || defined(OS_WIN)
955 974
956 } // namespace device 975 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698