OLD | NEW |
---|---|
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 Loading... | |
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 EXPECT_EQ(1, gatt_read_characteristic_attempts_); |
456 GetReadValueCallback(Call::EXPECTED), | |
457 GetGattErrorCallback(Call::NOT_EXPECTED)); | |
458 EXPECT_EQ(2, gatt_read_characteristic_attempts_); | |
459 EXPECT_EQ(0, callback_count_); | 465 EXPECT_EQ(0, callback_count_); |
460 EXPECT_EQ(0, error_callback_count_); | 466 EXPECT_EQ(0, error_callback_count_); |
461 | 467 |
462 std::vector<uint8_t> test_vector1; | 468 std::vector<uint8_t> test_vector1; |
463 test_vector1.push_back(111); | 469 test_vector1.push_back(111); |
464 SimulateGattCharacteristicRead(characteristic1_, test_vector1); | 470 SimulateGattCharacteristicRead(characteristic1_, test_vector1); |
465 EXPECT_EQ(test_vector1, last_read_value_); | 471 EXPECT_EQ(test_vector1, last_read_value_); |
466 | 472 |
473 characteristic2_->ReadRemoteCharacteristic( | |
scheib
2016/03/02 05:59:05
This changes the test meaning, in that two read ch
gogerald1
2016/03/02 23:56:29
Done.
| |
474 GetReadValueCallback(Call::EXPECTED), | |
475 GetGattErrorCallback(Call::NOT_EXPECTED)); | |
476 EXPECT_EQ(2, gatt_read_characteristic_attempts_); | |
477 EXPECT_EQ(1, callback_count_); | |
478 EXPECT_EQ(0, error_callback_count_); | |
479 | |
467 std::vector<uint8_t> test_vector2; | 480 std::vector<uint8_t> test_vector2; |
468 test_vector2.push_back(222); | 481 test_vector2.push_back(222); |
469 SimulateGattCharacteristicRead(characteristic2_, test_vector2); | 482 SimulateGattCharacteristicRead(characteristic2_, test_vector2); |
470 EXPECT_EQ(test_vector2, last_read_value_); | 483 EXPECT_EQ(test_vector2, last_read_value_); |
471 | 484 |
472 EXPECT_EQ(2, callback_count_); | 485 EXPECT_EQ(2, callback_count_); |
473 EXPECT_EQ(0, error_callback_count_); | 486 EXPECT_EQ(0, error_callback_count_); |
474 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); | 487 EXPECT_EQ(test_vector1, characteristic1_->GetValue()); |
475 EXPECT_EQ(test_vector2, characteristic2_->GetValue()); | 488 EXPECT_EQ(test_vector2, characteristic2_->GetValue()); |
476 } | 489 } |
477 #endif // defined(OS_ANDROID) | 490 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
478 | 491 |
479 #if defined(OS_ANDROID) | 492 #if defined(OS_ANDROID) || defined(OS_WIN) |
480 // Tests WriteRemoteCharacteristic on two characteristics. | 493 // Tests WriteRemoteCharacteristic on two characteristics. |
481 TEST_F(BluetoothGattCharacteristicTest, | 494 TEST_F(BluetoothGattCharacteristicTest, |
482 WriteRemoteCharacteristic_MultipleCharacteristics) { | 495 WriteRemoteCharacteristic_MultipleCharacteristics) { |
483 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 496 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
497 BluetoothGattCharacteristic::PROPERTY_WRITE)); | |
484 | 498 |
485 std::vector<uint8_t> test_vector1; | 499 std::vector<uint8_t> test_vector1; |
486 test_vector1.push_back(111); | 500 test_vector1.push_back(111); |
487 characteristic1_->WriteRemoteCharacteristic( | 501 characteristic1_->WriteRemoteCharacteristic( |
488 test_vector1, GetCallback(Call::EXPECTED), | 502 test_vector1, GetCallback(Call::EXPECTED), |
489 GetGattErrorCallback(Call::NOT_EXPECTED)); | 503 GetGattErrorCallback(Call::NOT_EXPECTED)); |
504 EXPECT_EQ(1, gatt_write_characteristic_attempts_); | |
505 EXPECT_EQ(0, callback_count_); | |
506 EXPECT_EQ(0, error_callback_count_); | |
507 SimulateGattCharacteristicWrite(characteristic1_); | |
scheib
2016/03/02 05:59:05
Similar to above, this changes the test logic -- e
gogerald1
2016/03/02 23:56:29
Done.
| |
490 EXPECT_EQ(test_vector1, last_write_value_); | 508 EXPECT_EQ(test_vector1, last_write_value_); |
491 | 509 |
492 std::vector<uint8_t> test_vector2; | 510 std::vector<uint8_t> test_vector2; |
493 test_vector2.push_back(222); | 511 test_vector2.push_back(222); |
494 characteristic2_->WriteRemoteCharacteristic( | 512 characteristic2_->WriteRemoteCharacteristic( |
495 test_vector2, GetCallback(Call::EXPECTED), | 513 test_vector2, GetCallback(Call::EXPECTED), |
496 GetGattErrorCallback(Call::NOT_EXPECTED)); | 514 GetGattErrorCallback(Call::NOT_EXPECTED)); |
515 EXPECT_EQ(2, gatt_write_characteristic_attempts_); | |
516 EXPECT_EQ(1, callback_count_); | |
517 EXPECT_EQ(0, error_callback_count_); | |
518 SimulateGattCharacteristicWrite(characteristic2_); | |
497 EXPECT_EQ(test_vector2, last_write_value_); | 519 EXPECT_EQ(test_vector2, last_write_value_); |
498 | 520 |
499 EXPECT_EQ(2, gatt_write_characteristic_attempts_); | |
500 EXPECT_EQ(0, callback_count_); | |
501 EXPECT_EQ(0, error_callback_count_); | |
502 | |
503 SimulateGattCharacteristicWrite(characteristic1_); | |
504 SimulateGattCharacteristicWrite(characteristic2_); | |
505 | |
506 EXPECT_EQ(2, callback_count_); | 521 EXPECT_EQ(2, callback_count_); |
507 EXPECT_EQ(0, error_callback_count_); | 522 EXPECT_EQ(0, error_callback_count_); |
508 } | 523 } |
509 #endif // defined(OS_ANDROID) | 524 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
510 | 525 |
511 #if defined(OS_ANDROID) | 526 #if defined(OS_ANDROID) || defined(OS_WIN) |
512 // Tests ReadRemoteCharacteristic asynchronous error. | 527 // Tests ReadRemoteCharacteristic asynchronous error. |
513 TEST_F(BluetoothGattCharacteristicTest, ReadError) { | 528 TEST_F(BluetoothGattCharacteristicTest, ReadError) { |
514 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 529 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
530 BluetoothGattCharacteristic::PROPERTY_READ)); | |
515 | 531 |
516 characteristic1_->ReadRemoteCharacteristic( | 532 characteristic1_->ReadRemoteCharacteristic( |
517 GetReadValueCallback(Call::NOT_EXPECTED), | 533 GetReadValueCallback(Call::NOT_EXPECTED), |
518 GetGattErrorCallback(Call::EXPECTED)); | 534 GetGattErrorCallback(Call::EXPECTED)); |
519 SimulateGattCharacteristicReadError( | 535 SimulateGattCharacteristicReadError( |
520 characteristic1_, BluetoothGattService::GATT_ERROR_INVALID_LENGTH); | 536 characteristic1_, BluetoothGattService::GATT_ERROR_INVALID_LENGTH); |
521 SimulateGattCharacteristicReadError(characteristic1_, | 537 SimulateGattCharacteristicReadError(characteristic1_, |
522 BluetoothGattService::GATT_ERROR_FAILED); | 538 BluetoothGattService::GATT_ERROR_FAILED); |
523 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, | 539 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, |
524 last_gatt_error_code_); | 540 last_gatt_error_code_); |
525 } | 541 } |
526 #endif // defined(OS_ANDROID) | 542 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
527 | 543 |
528 #if defined(OS_ANDROID) | 544 #if defined(OS_ANDROID) || defined(OS_WIN) |
529 // Tests WriteRemoteCharacteristic asynchronous error. | 545 // Tests WriteRemoteCharacteristic asynchronous error. |
530 TEST_F(BluetoothGattCharacteristicTest, WriteError) { | 546 TEST_F(BluetoothGattCharacteristicTest, WriteError) { |
531 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 547 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate( |
548 BluetoothGattCharacteristic::PROPERTY_WRITE)); | |
532 | 549 |
533 std::vector<uint8_t> empty_vector; | 550 std::vector<uint8_t> empty_vector; |
534 characteristic1_->WriteRemoteCharacteristic( | 551 characteristic1_->WriteRemoteCharacteristic( |
535 empty_vector, GetCallback(Call::NOT_EXPECTED), | 552 empty_vector, GetCallback(Call::NOT_EXPECTED), |
536 GetGattErrorCallback(Call::EXPECTED)); | 553 GetGattErrorCallback(Call::EXPECTED)); |
537 SimulateGattCharacteristicWriteError( | 554 SimulateGattCharacteristicWriteError( |
538 characteristic1_, BluetoothGattService::GATT_ERROR_INVALID_LENGTH); | 555 characteristic1_, BluetoothGattService::GATT_ERROR_INVALID_LENGTH); |
539 SimulateGattCharacteristicWriteError(characteristic1_, | 556 SimulateGattCharacteristicWriteError(characteristic1_, |
540 BluetoothGattService::GATT_ERROR_FAILED); | 557 BluetoothGattService::GATT_ERROR_FAILED); |
541 | 558 |
542 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, | 559 EXPECT_EQ(BluetoothGattService::GATT_ERROR_INVALID_LENGTH, |
543 last_gatt_error_code_); | 560 last_gatt_error_code_); |
544 } | 561 } |
545 #endif // defined(OS_ANDROID) | 562 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
546 | 563 |
547 #if defined(OS_ANDROID) | 564 #if defined(OS_ANDROID) |
548 // Tests ReadRemoteCharacteristic synchronous error. | 565 // Tests ReadRemoteCharacteristic synchronous error. |
549 TEST_F(BluetoothGattCharacteristicTest, ReadSynchronousError) { | 566 TEST_F(BluetoothGattCharacteristicTest, ReadSynchronousError) { |
550 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); | 567 ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate()); |
551 | 568 |
552 SimulateGattCharacteristicReadWillFailSynchronouslyOnce(characteristic1_); | 569 SimulateGattCharacteristicReadWillFailSynchronouslyOnce(characteristic1_); |
553 characteristic1_->ReadRemoteCharacteristic( | 570 characteristic1_->ReadRemoteCharacteristic( |
554 GetReadValueCallback(Call::NOT_EXPECTED), | 571 GetReadValueCallback(Call::NOT_EXPECTED), |
555 GetGattErrorCallback(Call::EXPECTED)); | 572 GetGattErrorCallback(Call::EXPECTED)); |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
947 | 964 |
948 // Characteristic 1 has descriptor uuids 1 and 2 (we don't know the order). | 965 // Characteristic 1 has descriptor uuids 1 and 2 (we don't know the order). |
949 EXPECT_TRUE(c1_uuid1 == uuid1 || c1_uuid2 == uuid1); | 966 EXPECT_TRUE(c1_uuid1 == uuid1 || c1_uuid2 == uuid1); |
950 EXPECT_TRUE(c1_uuid1 == uuid2 || c1_uuid2 == uuid2); | 967 EXPECT_TRUE(c1_uuid1 == uuid2 || c1_uuid2 == uuid2); |
951 // ... but not uuid 3 | 968 // ... but not uuid 3 |
952 EXPECT_FALSE(c1_uuid1 == uuid3 || c1_uuid2 == uuid3); | 969 EXPECT_FALSE(c1_uuid1 == uuid3 || c1_uuid2 == uuid3); |
953 } | 970 } |
954 #endif // defined(OS_ANDROID) || defined(OS_WIN) | 971 #endif // defined(OS_ANDROID) || defined(OS_WIN) |
955 | 972 |
956 } // namespace device | 973 } // namespace device |
OLD | NEW |