Loading framework/tests/bumble/src/android/bluetooth/GattClientTest.java +58 −37 Original line number Diff line number Diff line Loading @@ -177,6 +177,16 @@ public class GattClientTest { return gatt; } private void disconnectAndWaitDisconnection( BluetoothGatt gatt, BluetoothGattCallback callback) { gatt.disconnect(); verify(callback, timeout(1000)) .onConnectionStateChange(any(), anyInt(), eq(BluetoothProfile.STATE_DISCONNECTED)); gatt.close(); gatt = null; } @Test @Ignore("b/307981748: requestMTU should return a direct error") public void requestMtu_notConnected_isFalse() { Loading @@ -195,11 +205,16 @@ public class GattClientTest { @Test @Ignore("b/307981748: requestMTU should return a direct error or a error on the callback") public void requestMtu_invalidParamer_isFalse() { BluetoothGatt gatt = connectGattAndWaitConnection(mock(BluetoothGattCallback.class)); BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class); BluetoothGatt gatt = connectGattAndWaitConnection(gattCallback); try { assertThat(gatt.requestMtu(1024)).isTrue(); // verify(gattCallback, timeout(5000).atLeast(1)).onMtuChanged(eq(gatt), eq(ANDROID_MTU), // eq(BluetoothGatt.GATT_FAILURE)); // verify(gattCallback, timeout(5000).atLeast(1)).onMtuChanged(eq(gatt), // eq(ANDROID_MTU), eq(BluetoothGatt.GATT_FAILURE)); } finally { disconnectAndWaitDisconnection(gatt, gattCallback); } } @Test Loading @@ -207,13 +222,14 @@ public class GattClientTest { BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class); BluetoothGatt gatt = connectGattAndWaitConnection(gattCallback); try { assertThat(gatt.requestMtu(MTU_REQUESTED)).isTrue(); // Check that only the ANDROID_MTU is returned, not the MTU_REQUESTED verify(gattCallback, timeout(5000).atLeast(1)) verify(gattCallback, timeout(5000)) .onMtuChanged(eq(gatt), eq(ANDROID_MTU), eq(BluetoothGatt.GATT_SUCCESS)); // TODO(b/308031848): remove atLeast(1): // The callback should be called exactly once. // When running this test along to other, we may see this being called more than once } finally { disconnectAndWaitDisconnection(gatt, gattCallback); } } @Test Loading @@ -221,20 +237,18 @@ public class GattClientTest { BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class); BluetoothGatt gatt = connectGattAndWaitConnection(gattCallback); try { assertThat(gatt.requestMtu(MTU_REQUESTED)).isTrue(); // Check that only the ANDROID_MTU is returned, not the MTU_REQUESTED verify(gattCallback, timeout(5000).atLeast(1)) verify(gattCallback, timeout(5000)) .onMtuChanged(eq(gatt), eq(ANDROID_MTU), eq(BluetoothGatt.GATT_SUCCESS)); // TODO(b/308031848): remove atLeast(1): // The callback should be called exactly once. // When running this test along to other, we may see this being called more than once assertThat(gatt.requestMtu(ANOTHER_MTU_REQUESTED)).isTrue(); verify(gattCallback, timeout(5000).atLeast(2)) verify(gattCallback, timeout(5000).times(2)) .onMtuChanged(eq(gatt), eq(ANDROID_MTU), eq(BluetoothGatt.GATT_SUCCESS)); // TODO(b/308031848): change atLeast(2) with times(2): // The callback should be called exactly twice. // When running this test along to other, we may see this being called more than once } finally { disconnectAndWaitDisconnection(gatt, gattCallback); } } @Test Loading @@ -242,18 +256,25 @@ public class GattClientTest { BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class); BluetoothGatt gatt = connectGattAndWaitConnection(gattCallback); try { assertThat(gatt.requestMtu(MTU_REQUESTED)).isTrue(); verify(gattCallback, timeout(5000)) .onMtuChanged(eq(gatt), eq(ANDROID_MTU), eq(BluetoothGatt.GATT_SUCCESS)); BluetoothGattCallback gattCallback2 = mock(BluetoothGattCallback.class); BluetoothGatt gatt2 = connectGattAndWaitConnection(gattCallback2); try { // first callback because there is already a connected device verify(gattCallback2, timeout(9000)) .onMtuChanged(eq(gatt2), eq(ANDROID_MTU), eq(BluetoothGatt.GATT_SUCCESS)); assertThat(gatt2.requestMtu(ANOTHER_MTU_REQUESTED)).isTrue(); verify(gattCallback2, timeout(9000).atLeast(1)) verify(gattCallback2, timeout(9000).times(2)) .onMtuChanged(eq(gatt2), eq(ANDROID_MTU), eq(BluetoothGatt.GATT_SUCCESS)); // TODO(b/308031848): remove atLeast(1): // The callback should be called exactly once. // When running this test along to other, we may see this being called more than once } finally { disconnectAndWaitDisconnection(gatt2, gattCallback2); } } finally { disconnectAndWaitDisconnection(gatt, gattCallback); } } } Loading
framework/tests/bumble/src/android/bluetooth/GattClientTest.java +58 −37 Original line number Diff line number Diff line Loading @@ -177,6 +177,16 @@ public class GattClientTest { return gatt; } private void disconnectAndWaitDisconnection( BluetoothGatt gatt, BluetoothGattCallback callback) { gatt.disconnect(); verify(callback, timeout(1000)) .onConnectionStateChange(any(), anyInt(), eq(BluetoothProfile.STATE_DISCONNECTED)); gatt.close(); gatt = null; } @Test @Ignore("b/307981748: requestMTU should return a direct error") public void requestMtu_notConnected_isFalse() { Loading @@ -195,11 +205,16 @@ public class GattClientTest { @Test @Ignore("b/307981748: requestMTU should return a direct error or a error on the callback") public void requestMtu_invalidParamer_isFalse() { BluetoothGatt gatt = connectGattAndWaitConnection(mock(BluetoothGattCallback.class)); BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class); BluetoothGatt gatt = connectGattAndWaitConnection(gattCallback); try { assertThat(gatt.requestMtu(1024)).isTrue(); // verify(gattCallback, timeout(5000).atLeast(1)).onMtuChanged(eq(gatt), eq(ANDROID_MTU), // eq(BluetoothGatt.GATT_FAILURE)); // verify(gattCallback, timeout(5000).atLeast(1)).onMtuChanged(eq(gatt), // eq(ANDROID_MTU), eq(BluetoothGatt.GATT_FAILURE)); } finally { disconnectAndWaitDisconnection(gatt, gattCallback); } } @Test Loading @@ -207,13 +222,14 @@ public class GattClientTest { BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class); BluetoothGatt gatt = connectGattAndWaitConnection(gattCallback); try { assertThat(gatt.requestMtu(MTU_REQUESTED)).isTrue(); // Check that only the ANDROID_MTU is returned, not the MTU_REQUESTED verify(gattCallback, timeout(5000).atLeast(1)) verify(gattCallback, timeout(5000)) .onMtuChanged(eq(gatt), eq(ANDROID_MTU), eq(BluetoothGatt.GATT_SUCCESS)); // TODO(b/308031848): remove atLeast(1): // The callback should be called exactly once. // When running this test along to other, we may see this being called more than once } finally { disconnectAndWaitDisconnection(gatt, gattCallback); } } @Test Loading @@ -221,20 +237,18 @@ public class GattClientTest { BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class); BluetoothGatt gatt = connectGattAndWaitConnection(gattCallback); try { assertThat(gatt.requestMtu(MTU_REQUESTED)).isTrue(); // Check that only the ANDROID_MTU is returned, not the MTU_REQUESTED verify(gattCallback, timeout(5000).atLeast(1)) verify(gattCallback, timeout(5000)) .onMtuChanged(eq(gatt), eq(ANDROID_MTU), eq(BluetoothGatt.GATT_SUCCESS)); // TODO(b/308031848): remove atLeast(1): // The callback should be called exactly once. // When running this test along to other, we may see this being called more than once assertThat(gatt.requestMtu(ANOTHER_MTU_REQUESTED)).isTrue(); verify(gattCallback, timeout(5000).atLeast(2)) verify(gattCallback, timeout(5000).times(2)) .onMtuChanged(eq(gatt), eq(ANDROID_MTU), eq(BluetoothGatt.GATT_SUCCESS)); // TODO(b/308031848): change atLeast(2) with times(2): // The callback should be called exactly twice. // When running this test along to other, we may see this being called more than once } finally { disconnectAndWaitDisconnection(gatt, gattCallback); } } @Test Loading @@ -242,18 +256,25 @@ public class GattClientTest { BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class); BluetoothGatt gatt = connectGattAndWaitConnection(gattCallback); try { assertThat(gatt.requestMtu(MTU_REQUESTED)).isTrue(); verify(gattCallback, timeout(5000)) .onMtuChanged(eq(gatt), eq(ANDROID_MTU), eq(BluetoothGatt.GATT_SUCCESS)); BluetoothGattCallback gattCallback2 = mock(BluetoothGattCallback.class); BluetoothGatt gatt2 = connectGattAndWaitConnection(gattCallback2); try { // first callback because there is already a connected device verify(gattCallback2, timeout(9000)) .onMtuChanged(eq(gatt2), eq(ANDROID_MTU), eq(BluetoothGatt.GATT_SUCCESS)); assertThat(gatt2.requestMtu(ANOTHER_MTU_REQUESTED)).isTrue(); verify(gattCallback2, timeout(9000).atLeast(1)) verify(gattCallback2, timeout(9000).times(2)) .onMtuChanged(eq(gatt2), eq(ANDROID_MTU), eq(BluetoothGatt.GATT_SUCCESS)); // TODO(b/308031848): remove atLeast(1): // The callback should be called exactly once. // When running this test along to other, we may see this being called more than once } finally { disconnectAndWaitDisconnection(gatt2, gattCallback2); } } finally { disconnectAndWaitDisconnection(gatt, gattCallback); } } }