diff options
author | scheib <scheib@chromium.org> | 2015-10-08 17:05:57 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-09 00:06:36 +0000 |
commit | 93a67f3b1e93a74dd7f2095aed1c39f3d64e9f22 (patch) | |
tree | 0808af91e8ecf02ac918ad0187f8f9baf5347b19 /device/bluetooth | |
parent | e0b332fb5cbd5d1673d61e42ff13e67ad1b3eb40 (diff) | |
download | chromium_src-93a67f3b1e93a74dd7f2095aed1c39f3d64e9f22.zip chromium_src-93a67f3b1e93a74dd7f2095aed1c39f3d64e9f22.tar.gz chromium_src-93a67f3b1e93a74dd7f2095aed1c39f3d64e9f22.tar.bz2 |
bluetooth: Refactor BluetoothTest member names.
Rename *_attempt_count_ -> *_attempts_.
Add 'Fake' into OnFakeBluetoothDeviceConnectGattCalled.
Use 'Simulate' prefix on test fixture methods the simulate a platform action.
Review URL: https://codereview.chromium.org/1380883003
Cr-Commit-Position: refs/heads/master@{#353178}
Diffstat (limited to 'device/bluetooth')
-rw-r--r-- | device/bluetooth/bluetooth_device_unittest.cc | 68 | ||||
-rw-r--r-- | device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java | 6 | ||||
-rw-r--r-- | device/bluetooth/test/bluetooth_test.cc | 4 | ||||
-rw-r--r-- | device/bluetooth/test/bluetooth_test.h | 12 | ||||
-rw-r--r-- | device/bluetooth/test/bluetooth_test_android.cc | 17 | ||||
-rw-r--r-- | device/bluetooth/test/bluetooth_test_android.h | 10 |
6 files changed, 58 insertions, 59 deletions
diff --git a/device/bluetooth/bluetooth_device_unittest.cc b/device/bluetooth/bluetooth_device_unittest.cc index 368232d..2aa9688 100644 --- a/device/bluetooth/bluetooth_device_unittest.cc +++ b/device/bluetooth/bluetooth_device_unittest.cc @@ -122,7 +122,7 @@ TEST_F(BluetoothTest, CreateGattConnection) { ResetEventCounts(); device->CreateGattConnection(GetGattConnectionCallback(), GetConnectErrorCallback()); - CompleteGattConnection(device); + SimulateGattConnection(device); EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); ASSERT_EQ(1u, gatt_connections_.size()); @@ -144,8 +144,8 @@ TEST_F(BluetoothTest, BluetoothGattConnection) { ResetEventCounts(); device->CreateGattConnection(GetGattConnectionCallback(), GetConnectErrorCallback()); - EXPECT_EQ(1, gatt_connection_attempt_count_); - CompleteGattConnection(device); + EXPECT_EQ(1, gatt_connection_attempts_); + SimulateGattConnection(device); EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); ASSERT_EQ(1u, gatt_connections_.size()); @@ -158,7 +158,7 @@ TEST_F(BluetoothTest, BluetoothGattConnection) { GetConnectErrorCallback()); device->CreateGattConnection(GetGattConnectionCallback(), GetConnectErrorCallback()); - EXPECT_EQ(0, gatt_connection_attempt_count_); + EXPECT_EQ(0, gatt_connection_attempts_); EXPECT_EQ(2, callback_count_); EXPECT_EQ(0, error_callback_count_); ASSERT_EQ(3u, gatt_connections_.size()); @@ -177,12 +177,12 @@ TEST_F(BluetoothTest, BluetoothGattConnection) { EXPECT_FALSE(gatt_connections_[0]->IsConnected()); EXPECT_TRUE(gatt_connections_[1]->IsConnected()); EXPECT_TRUE(device->IsGattConnected()); - EXPECT_EQ(0, gatt_disconnection_attempt_count_); + EXPECT_EQ(0, gatt_disconnection_attempts_); // Delete device, connection objects should all be disconnected. - gatt_disconnection_attempt_count_ = 0; + gatt_disconnection_attempts_ = 0; DeleteDevice(device); - EXPECT_EQ(1, gatt_disconnection_attempt_count_); + EXPECT_EQ(1, gatt_disconnection_attempts_); EXPECT_FALSE(gatt_connections_[0]->IsConnected()); EXPECT_FALSE(gatt_connections_[1]->IsConnected()); @@ -205,16 +205,16 @@ TEST_F(BluetoothTest, ResetEventCounts(); device->CreateGattConnection(GetGattConnectionCallback(), GetConnectErrorCallback()); - CompleteGattConnection(device); - CompleteGattConnection(device); - EXPECT_EQ(1, gatt_connection_attempt_count_); + SimulateGattConnection(device); + SimulateGattConnection(device); + EXPECT_EQ(1, gatt_connection_attempts_); EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); EXPECT_TRUE(gatt_connections_[0]->IsConnected()); // Become disconnected: ResetEventCounts(); - CompleteGattDisconnection(device); + SimulateGattDisconnection(device); EXPECT_EQ(0, callback_count_); EXPECT_EQ(0, error_callback_count_); EXPECT_FALSE(gatt_connections_[0]->IsConnected()); @@ -231,14 +231,14 @@ TEST_F(BluetoothTest, BluetoothGattConnection_AlreadyConnected) { // Be already connected: device->CreateGattConnection(GetGattConnectionCallback(), GetConnectErrorCallback()); - CompleteGattConnection(device); + SimulateGattConnection(device); EXPECT_TRUE(gatt_connections_[0]->IsConnected()); // Then CreateGattConnection: ResetEventCounts(); device->CreateGattConnection(GetGattConnectionCallback(), GetConnectErrorCallback()); - EXPECT_EQ(0, gatt_connection_attempt_count_); + EXPECT_EQ(0, gatt_connection_attempts_); EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); EXPECT_TRUE(gatt_connections_[1]->IsConnected()); @@ -256,16 +256,16 @@ TEST_F(BluetoothTest, // Create connection: device->CreateGattConnection(GetGattConnectionCallback(), GetConnectErrorCallback()); - CompleteGattConnection(device); + SimulateGattConnection(device); // Disconnect connection: gatt_connections_[0]->Disconnect(); - CompleteGattDisconnection(device); + SimulateGattDisconnection(device); // Create 2nd connection: device->CreateGattConnection(GetGattConnectionCallback(), GetConnectErrorCallback()); - CompleteGattConnection(device); + SimulateGattConnection(device); EXPECT_FALSE(gatt_connections_[0]->IsConnected()) << "The disconnected connection shouldn't become connected when another " @@ -286,12 +286,12 @@ TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectWhenObjectsDestroyed) { GetConnectErrorCallback()); device->CreateGattConnection(GetGattConnectionCallback(), GetConnectErrorCallback()); - CompleteGattConnection(device); + SimulateGattConnection(device); // Delete all CreateGattConnection objects, observe disconnection: ResetEventCounts(); gatt_connections_.clear(); - EXPECT_EQ(1, gatt_disconnection_attempt_count_); + EXPECT_EQ(1, gatt_disconnection_attempts_); } #endif // defined(OS_ANDROID) @@ -307,19 +307,19 @@ TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectInProgress) { GetConnectErrorCallback()); device->CreateGattConnection(GetGattConnectionCallback(), GetConnectErrorCallback()); - CompleteGattConnection(device); + SimulateGattConnection(device); // Disconnect all CreateGattConnection objects & create a new connection. // But, don't yet simulate the device disconnecting: ResetEventCounts(); for (BluetoothGattConnection* connection : gatt_connections_) connection->Disconnect(); - EXPECT_EQ(1, gatt_disconnection_attempt_count_); + EXPECT_EQ(1, gatt_disconnection_attempts_); // Create a connection. device->CreateGattConnection(GetGattConnectionCallback(), GetConnectErrorCallback()); - EXPECT_EQ(0, gatt_connection_attempt_count_); // No connection attempt. + EXPECT_EQ(0, gatt_connection_attempts_); // No connection attempt. EXPECT_EQ(1, callback_count_); // Device is assumed still connected. EXPECT_EQ(0, error_callback_count_); EXPECT_FALSE(gatt_connections_.front()->IsConnected()); @@ -327,7 +327,7 @@ TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectInProgress) { // Actually disconnect: ResetEventCounts(); - CompleteGattDisconnection(device); + SimulateGattDisconnection(device); EXPECT_EQ(0, callback_count_); EXPECT_EQ(0, error_callback_count_); for (BluetoothGattConnection* connection : gatt_connections_) @@ -346,8 +346,8 @@ TEST_F(BluetoothTest, BluetoothGattConnection_SimulateDisconnect) { ResetEventCounts(); device->CreateGattConnection(GetGattConnectionCallback(), GetConnectErrorCallback()); - EXPECT_EQ(1, gatt_connection_attempt_count_); - CompleteGattDisconnection(device); + EXPECT_EQ(1, gatt_connection_attempts_); + SimulateGattDisconnection(device); EXPECT_EQ(0, callback_count_); EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_); @@ -367,14 +367,14 @@ TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_SimulateConnect) { device->CreateGattConnection(GetGattConnectionCallback(), GetConnectErrorCallback()); device->DisconnectGatt(); - EXPECT_EQ(1, gatt_connection_attempt_count_); - EXPECT_EQ(1, gatt_disconnection_attempt_count_); - CompleteGattConnection(device); + EXPECT_EQ(1, gatt_connection_attempts_); + EXPECT_EQ(1, gatt_disconnection_attempts_); + SimulateGattConnection(device); EXPECT_EQ(1, callback_count_); EXPECT_EQ(0, error_callback_count_); EXPECT_TRUE(gatt_connections_.back()->IsConnected()); ResetEventCounts(); - CompleteGattDisconnection(device); + SimulateGattDisconnection(device); EXPECT_EQ(0, callback_count_); EXPECT_EQ(0, error_callback_count_); } @@ -392,9 +392,9 @@ TEST_F(BluetoothTest, device->CreateGattConnection(GetGattConnectionCallback(), GetConnectErrorCallback()); device->DisconnectGatt(); - EXPECT_EQ(1, gatt_connection_attempt_count_); - EXPECT_EQ(1, gatt_disconnection_attempt_count_); - CompleteGattDisconnection(device); + EXPECT_EQ(1, gatt_connection_attempts_); + EXPECT_EQ(1, gatt_disconnection_attempts_); + SimulateGattDisconnection(device); EXPECT_EQ(0, callback_count_); EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_); @@ -414,9 +414,9 @@ TEST_F(BluetoothTest, BluetoothGattConnection_ErrorAfterConnection) { ResetEventCounts(); device->CreateGattConnection(GetGattConnectionCallback(), GetConnectErrorCallback()); - EXPECT_EQ(1, gatt_connection_attempt_count_); - FailGattConnection(device, BluetoothDevice::ERROR_AUTH_FAILED); - FailGattConnection(device, BluetoothDevice::ERROR_FAILED); + EXPECT_EQ(1, gatt_connection_attempts_); + SimulateGattConnectionError(device, BluetoothDevice::ERROR_AUTH_FAILED); + SimulateGattConnectionError(device, BluetoothDevice::ERROR_FAILED); EXPECT_EQ(0, callback_count_); EXPECT_EQ(1, error_callback_count_); EXPECT_EQ(BluetoothDevice::ERROR_AUTH_FAILED, last_connect_error_code_); diff --git a/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java b/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java index 5ebb63d..67ee3ef 100644 --- a/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java +++ b/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java @@ -218,7 +218,7 @@ class Fakes { "BluetoothGattWrapper doesn't support calls to connectGatt() with " + "multiple distinct callbacks."); } - nativeOnBluetoothDeviceConnectGattCalled(mAdapter.mNativeBluetoothTestAndroid); + nativeOnFakeBluetoothDeviceConnectGattCalled(mAdapter.mNativeBluetoothTestAndroid); mGattCallback = callback; return new FakeBluetoothGatt(this); } @@ -264,8 +264,8 @@ class Fakes { // --------------------------------------------------------------------------------------------- // BluetoothTestAndroid C++ methods declared for access from java: - // Binds to BluetoothAdapterAndroid::OnBluetoothDeviceConnectGattCalled. - private static native void nativeOnBluetoothDeviceConnectGattCalled( + // Binds to BluetoothAdapterAndroid::OnFakeBluetoothDeviceConnectGattCalled. + private static native void nativeOnFakeBluetoothDeviceConnectGattCalled( long nativeBluetoothTestAndroid); // Binds to BluetoothAdapterAndroid::OnFakeBluetoothGattDisconnect. diff --git a/device/bluetooth/test/bluetooth_test.cc b/device/bluetooth/test/bluetooth_test.cc index f1ed4c5..98589c2 100644 --- a/device/bluetooth/test/bluetooth_test.cc +++ b/device/bluetooth/test/bluetooth_test.cc @@ -103,8 +103,8 @@ void BluetoothTestBase::ResetEventCounts() { last_connect_error_code_ = BluetoothDevice::ERROR_UNKNOWN; callback_count_ = 0; error_callback_count_ = 0; - gatt_connection_attempt_count_ = 0; - gatt_disconnection_attempt_count_ = 0; + gatt_connection_attempts_ = 0; + gatt_disconnection_attempts_ = 0; } } // namespace device diff --git a/device/bluetooth/test/bluetooth_test.h b/device/bluetooth/test/bluetooth_test.h index e331b42..275fbbb 100644 --- a/device/bluetooth/test/bluetooth_test.h +++ b/device/bluetooth/test/bluetooth_test.h @@ -75,14 +75,14 @@ class BluetoothTestBase : public testing::Test { virtual BluetoothDevice* DiscoverLowEnergyDevice(int device_ordinal); // Simulates success of implementation details of CreateGattConnection. - virtual void CompleteGattConnection(BluetoothDevice* device) {} + virtual void SimulateGattConnection(BluetoothDevice* device) {} // Simulates failure of CreateGattConnection with the given error code. - virtual void FailGattConnection(BluetoothDevice* device, - BluetoothDevice::ConnectErrorCode) {} + virtual void SimulateGattConnectionError(BluetoothDevice* device, + BluetoothDevice::ConnectErrorCode) {} // Simulates GattConnection disconnecting. - virtual void CompleteGattDisconnection(BluetoothDevice* device) {} + virtual void SimulateGattDisconnection(BluetoothDevice* device) {} // Remove the device from the adapter and delete it. virtual void DeleteDevice(BluetoothDevice* device); @@ -115,8 +115,8 @@ class BluetoothTestBase : public testing::Test { BluetoothDevice::ERROR_UNKNOWN; int callback_count_ = 0; int error_callback_count_ = 0; - int gatt_connection_attempt_count_ = 0; - int gatt_disconnection_attempt_count_ = 0; + int gatt_connection_attempts_ = 0; + int gatt_disconnection_attempts_ = 0; base::WeakPtrFactory<BluetoothTestBase> weak_factory_; }; diff --git a/device/bluetooth/test/bluetooth_test_android.cc b/device/bluetooth/test/bluetooth_test_android.cc index 8e0951d..34dbdb6 100644 --- a/device/bluetooth/test/bluetooth_test_android.cc +++ b/device/bluetooth/test/bluetooth_test_android.cc @@ -57,7 +57,7 @@ BluetoothDevice* BluetoothTestAndroid::DiscoverLowEnergyDevice( return observer.last_device(); } -void BluetoothTestAndroid::CompleteGattConnection(BluetoothDevice* device) { +void BluetoothTestAndroid::SimulateGattConnection(BluetoothDevice* device) { BluetoothDeviceAndroid* device_android = static_cast<BluetoothDeviceAndroid*>(device); @@ -67,7 +67,7 @@ void BluetoothTestAndroid::CompleteGattConnection(BluetoothDevice* device) { true); // connected } -void BluetoothTestAndroid::FailGattConnection( +void BluetoothTestAndroid::SimulateGattConnectionError( BluetoothDevice* device, BluetoothDevice::ConnectErrorCode error) { int android_error_value = 0; @@ -96,7 +96,7 @@ void BluetoothTestAndroid::FailGattConnection( false); // connected } -void BluetoothTestAndroid::CompleteGattDisconnection(BluetoothDevice* device) { +void BluetoothTestAndroid::SimulateGattDisconnection(BluetoothDevice* device) { BluetoothDeviceAndroid* device_android = static_cast<BluetoothDeviceAndroid*>(device); @@ -106,16 +106,15 @@ void BluetoothTestAndroid::CompleteGattDisconnection(BluetoothDevice* device) { false); // disconnected } -// Records that Java FakeBluetoothDevice connectGatt was called. -void BluetoothTestAndroid::OnBluetoothDeviceConnectGattCalled(JNIEnv* env, - jobject caller) { - gatt_connection_attempt_count_++; +void BluetoothTestAndroid::OnFakeBluetoothDeviceConnectGattCalled( + JNIEnv* env, + jobject caller) { + gatt_connection_attempts_++; } -// Records that Java FakeBluetoothGatt disconnect was called. void BluetoothTestAndroid::OnFakeBluetoothGattDisconnect(JNIEnv* env, jobject caller) { - gatt_disconnection_attempt_count_++; + gatt_disconnection_attempts_++; } } // namespace device diff --git a/device/bluetooth/test/bluetooth_test_android.h b/device/bluetooth/test/bluetooth_test_android.h index f525323..910825c 100644 --- a/device/bluetooth/test/bluetooth_test_android.h +++ b/device/bluetooth/test/bluetooth_test_android.h @@ -27,13 +27,13 @@ class BluetoothTestAndroid : public BluetoothTestBase { void InitWithoutDefaultAdapter() override; void InitWithFakeAdapter() override; BluetoothDevice* DiscoverLowEnergyDevice(int device_ordinal) override; - void CompleteGattConnection(BluetoothDevice* device) override; - void FailGattConnection(BluetoothDevice* device, - BluetoothDevice::ConnectErrorCode) override; - void CompleteGattDisconnection(BluetoothDevice* device) override; + void SimulateGattConnection(BluetoothDevice* device) override; + void SimulateGattConnectionError(BluetoothDevice* device, + BluetoothDevice::ConnectErrorCode) override; + void SimulateGattDisconnection(BluetoothDevice* device) override; // Records that Java FakeBluetoothDevice connectGatt was called. - void OnBluetoothDeviceConnectGattCalled(JNIEnv* env, jobject caller); + void OnFakeBluetoothDeviceConnectGattCalled(JNIEnv* env, jobject caller); // Records that Java FakeBluetoothGatt disconnect was called. void OnFakeBluetoothGattDisconnect(JNIEnv* env, jobject caller); |