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

Side by Side Diff: device/bluetooth/test/bluetooth_test_android.cc

Issue 1256313002: bluetooth: android: Implement & test CreateGattConnection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split tests up into smaller tests Created 5 years, 2 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
« no previous file with comments | « device/bluetooth/test/bluetooth_test_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/test/bluetooth_test_android.h" 5 #include "device/bluetooth/test/bluetooth_test_android.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "device/bluetooth/android/wrappers.h" 8 #include "device/bluetooth/android/wrappers.h"
9 #include "device/bluetooth/bluetooth_adapter_android.h" 9 #include "device/bluetooth/bluetooth_adapter_android.h"
10 #include "device/bluetooth/bluetooth_device_android.h"
10 #include "jni/Fakes_jni.h" 11 #include "jni/Fakes_jni.h"
11 12
12 using base::android::AttachCurrentThread; 13 using base::android::AttachCurrentThread;
13 using base::android::ScopedJavaLocalRef; 14 using base::android::ScopedJavaLocalRef;
14 15
15 namespace device { 16 namespace device {
16 17
17 BluetoothTestAndroid::BluetoothTestAndroid() { 18 BluetoothTestAndroid::BluetoothTestAndroid() {
18 } 19 }
19 20
(...skipping 13 matching lines...) Expand all
33 adapter_ = 34 adapter_ =
34 BluetoothAdapterAndroid::Create( 35 BluetoothAdapterAndroid::Create(
35 BluetoothAdapterWrapper_CreateWithDefaultAdapter().obj()).get(); 36 BluetoothAdapterWrapper_CreateWithDefaultAdapter().obj()).get();
36 } 37 }
37 38
38 void BluetoothTestAndroid::InitWithoutDefaultAdapter() { 39 void BluetoothTestAndroid::InitWithoutDefaultAdapter() {
39 adapter_ = BluetoothAdapterAndroid::Create(NULL).get(); 40 adapter_ = BluetoothAdapterAndroid::Create(NULL).get();
40 } 41 }
41 42
42 void BluetoothTestAndroid::InitWithFakeAdapter() { 43 void BluetoothTestAndroid::InitWithFakeAdapter() {
43 j_fake_bluetooth_adapter_.Reset( 44 j_fake_bluetooth_adapter_.Reset(Java_FakeBluetoothAdapter_create(
44 Java_FakeBluetoothAdapter_create(AttachCurrentThread())); 45 AttachCurrentThread(), reinterpret_cast<intptr_t>(this)));
45 46
46 adapter_ = 47 adapter_ =
47 BluetoothAdapterAndroid::Create(j_fake_bluetooth_adapter_.obj()).get(); 48 BluetoothAdapterAndroid::Create(j_fake_bluetooth_adapter_.obj()).get();
48 } 49 }
49 50
50 void BluetoothTestAndroid::DiscoverLowEnergyDevice(int device_ordinal) { 51 void BluetoothTestAndroid::DiscoverLowEnergyDevice(int device_ordinal) {
51 Java_FakeBluetoothAdapter_discoverLowEnergyDevice( 52 Java_FakeBluetoothAdapter_discoverLowEnergyDevice(
52 AttachCurrentThread(), j_fake_bluetooth_adapter_.obj(), device_ordinal); 53 AttachCurrentThread(), j_fake_bluetooth_adapter_.obj(), device_ordinal);
53 } 54 }
54 55
56 void BluetoothTestAndroid::CompleteGattConnection(BluetoothDevice* device) {
57 BluetoothDeviceAndroid* device_android =
58 static_cast<BluetoothDeviceAndroid*>(device);
59
60 Java_FakeBluetoothDevice_connectionStateChange(
61 AttachCurrentThread(), device_android->GetJavaObject().obj(),
62 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS
63 true); // connected
64 }
65
66 void BluetoothTestAndroid::FailGattConnection(
67 BluetoothDevice* device,
68 BluetoothDevice::ConnectErrorCode error) {
69 int android_error_value = 0;
70 switch (error) { // Constants are from android.bluetooth.BluetoothGatt.
71 case BluetoothDevice::ERROR_FAILED:
72 android_error_value = 0x00000101; // GATT_FAILURE
73 break;
74 case BluetoothDevice::ERROR_AUTH_FAILED:
75 android_error_value = 0x00000005; // GATT_INSUFFICIENT_AUTHENTICATION
76 break;
77 case BluetoothDevice::ERROR_UNKNOWN:
78 case BluetoothDevice::ERROR_INPROGRESS:
79 case BluetoothDevice::ERROR_AUTH_CANCELED:
80 case BluetoothDevice::ERROR_AUTH_REJECTED:
81 case BluetoothDevice::ERROR_AUTH_TIMEOUT:
82 case BluetoothDevice::ERROR_UNSUPPORTED_DEVICE:
83 NOTREACHED() << "No translation for error code: " << error;
84 }
85
86 BluetoothDeviceAndroid* device_android =
87 static_cast<BluetoothDeviceAndroid*>(device);
88
89 Java_FakeBluetoothDevice_connectionStateChange(
90 AttachCurrentThread(), device_android->GetJavaObject().obj(),
91 android_error_value,
92 false); // connected
93 }
94
95 void BluetoothTestAndroid::CompleteGattDisconnection(BluetoothDevice* device) {
96 BluetoothDeviceAndroid* device_android =
97 static_cast<BluetoothDeviceAndroid*>(device);
98
99 Java_FakeBluetoothDevice_connectionStateChange(
100 AttachCurrentThread(), device_android->GetJavaObject().obj(),
101 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS
102 false); // disconnected
103 }
104
105 // Records that Java FakeBluetoothDevice connectGatt was called.
106 void BluetoothTestAndroid::OnBluetoothDeviceConnectGattCalled(JNIEnv* env,
107 jobject caller) {
108 gatt_connection_attempt_count_++;
109 }
110
111 // Records that Java FakeBluetoothGatt disconnect was called.
112 void BluetoothTestAndroid::OnFakeBluetoothGattDisconnect(JNIEnv* env,
113 jobject caller) {
114 gatt_disconnection_attempt_count_++;
115 }
116
55 } // namespace device 117 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/test/bluetooth_test_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698