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

Side by Side Diff: device/bluetooth/test/bluetooth_test.h

Issue 1246913006: Bringing 4 more BluetoothTest.* unit tests to Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scheibtest
Patch Set: CBUUID dyanamically used now Created 5 years, 4 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 #ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ 5 #ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_
6 #define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ 6 #define DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "device/bluetooth/bluetooth_adapter.h" 10 #include "device/bluetooth/bluetooth_adapter.h"
11 #include "device/bluetooth/bluetooth_discovery_session.h" 11 #include "device/bluetooth/bluetooth_discovery_session.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace device { 14 namespace device {
15 15
16 class BluetoothAdapter; 16 class BluetoothAdapter;
17 17
18 // A test fixture for Bluetooth that abstracts platform specifics for creating 18 // A test fixture for Bluetooth that abstracts platform specifics for creating
19 // and controlling fake low level objects. 19 // and controlling fake low level objects.
20 // 20 //
21 // Subclasses on each platform implement this, and are then typedef-ed to 21 // Subclasses on each platform implement this, and are then typedef-ed to
22 // BluetoothTest. 22 // BluetoothTest.
23 class BluetoothTestBase : public testing::Test { 23 class BluetoothTestBase : public testing::Test {
24 public: 24 public:
25 static const std::string kTestAdapterName; 25 static const std::string kTestAdapterName;
26 static const std::string kTestAdapterAddress; 26 static const std::string kTestAdapterAddress;
27 27
28 static const std::string kTestDeviceName;
29 static const std::string kTestDeviceNameEmpty;
30
31 static const std::string kTestDeviceAddress1;
32 static const std::string kTestDeviceAddress2;
33
34 static const std::string kTestUUIDGenericAccess;
35 static const std::string kTestUUIDGenericAttribute;
36 static const std::string kTestUUIDImmediateAlert;
37 static const std::string kTestUUIDLinkLoss;
38
28 BluetoothTestBase(); 39 BluetoothTestBase();
29 ~BluetoothTestBase() override; 40 ~BluetoothTestBase() override;
30 41
42 // Check if Low Energy is available. On Mac, we require OS X >= 10.10.
43 virtual bool PlatformSupportsLowEnergy() = 0;
44
31 // Initializes the BluetoothAdapter |adapter_| with the system adapter. 45 // Initializes the BluetoothAdapter |adapter_| with the system adapter.
32 virtual void InitWithDefaultAdapter(){}; 46 virtual void InitWithDefaultAdapter(){};
33 47
34 // Initializes the BluetoothAdapter |adapter_| with the system adapter forced 48 // Initializes the BluetoothAdapter |adapter_| with the system adapter forced
35 // to be ignored as if it did not exist. This enables tests for when an 49 // to be ignored as if it did not exist. This enables tests for when an
36 // adapter is not present on the system. 50 // adapter is not present on the system.
37 virtual void InitWithoutDefaultAdapter(){}; 51 virtual void InitWithoutDefaultAdapter(){};
38 52
39 // Initializes the BluetoothAdapter |adapter_| with a fake adapter that can be 53 // Initializes the BluetoothAdapter |adapter_| with a fake adapter that can be
40 // controlled by this test fixture. 54 // controlled by this test fixture.
41 virtual void InitWithFakeAdapter(){}; 55 virtual void InitWithFakeAdapter(){};
42 56
43 // Create a fake Low Energy device and discover it. 57 // Create a fake Low Energy device and discover it.
44 // |device_ordinal| selects between multiple fake device data sets to produce. 58 // |device_ordinal| selects between multiple fake device data sets to produce:
45 // 1: AA:00:00:00:00:01 with simple default values. 59 // 1: kTestDeviceName with advertised UUIDs kTestUUIDGenericAccess,
46 // 2: AA:00:00:00:00:01 with different advertised Service UUIDs vs 1. 60 // kTestUUIDGenericAttribute and address kTestDeviceAddress1.
47 // 3: AA:00:00:00:00:01 with empty name, empty UUIDs. 61 // 2: kTestDeviceName with advertised UUIDs kTestUUIDImmediateAlert,
48 // 4: BB:00:00:00:00:02 with empty name, empty UUIDs. 62 // kTestUUIDLinkLoss and address kTestDeviceAddress1.
63 // 3: kTestDeviceNameEmpty with no advertised UUIDs and address
64 // kTestDeviceAddress1.
65 // 4: kTestDeviceNameEmpty with no advertised UUIDs and address
66 // kTestDeviceAddress2.
49 virtual void DiscoverLowEnergyDevice(int device_ordinal){}; 67 virtual void DiscoverLowEnergyDevice(int device_ordinal){};
50 68
51 // Callbacks that increment |callback_count_|, |error_callback_count_|: 69 // Callbacks that increment |callback_count_|, |error_callback_count_|:
52 void Callback(); 70 void Callback();
53 void DiscoverySessionCallback(scoped_ptr<BluetoothDiscoverySession>); 71 void DiscoverySessionCallback(scoped_ptr<BluetoothDiscoverySession>);
54 void ErrorCallback(); 72 void ErrorCallback();
55 73
56 // Accessors to get callbacks bound to this fixture: 74 // Accessors to get callbacks bound to this fixture:
57 base::Closure GetCallback(); 75 base::Closure GetCallback();
58 BluetoothAdapter::DiscoverySessionCallback GetDiscoverySessionCallback(); 76 BluetoothAdapter::DiscoverySessionCallback GetDiscoverySessionCallback();
59 BluetoothAdapter::ErrorCallback GetErrorCallback(); 77 BluetoothAdapter::ErrorCallback GetErrorCallback();
60 78
61 // A Message loop is required by some implementations that will PostTasks and 79 // A Message loop is required by some implementations that will PostTasks and
62 // by base::RunLoop().RunUntilIdle() use in this fixuture. 80 // by base::RunLoop().RunUntilIdle() use in this fixuture.
63 base::MessageLoop message_loop_; 81 base::MessageLoop message_loop_;
64 82
65 scoped_refptr<BluetoothAdapter> adapter_; 83 scoped_refptr<BluetoothAdapter> adapter_;
66 ScopedVector<BluetoothDiscoverySession> discovery_sessions_; 84 ScopedVector<BluetoothDiscoverySession> discovery_sessions_;
67 int callback_count_ = 0; 85 int callback_count_ = 0;
68 int error_callback_count_ = 0; 86 int error_callback_count_ = 0;
69 bool run_message_loop_to_wait_for_callbacks_ = true; 87 bool run_message_loop_to_wait_for_callbacks_ = true;
70 }; 88 };
71 89
72 } // namespace device 90 } // namespace device
73 91
74 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_ 92 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_TEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698