diff options
author | scheib <scheib@chromium.org> | 2015-06-30 15:26:58 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-30 22:27:37 +0000 |
commit | 545d7fd0b4de41af907c1ad01f72b492f01f9d3c (patch) | |
tree | e1987c48ae5f716297d071920c4f37a848e465de /device/bluetooth/bluetooth_adapter_unittest.cc | |
parent | b24a7e02ef7d7e1551cd1cadb96a50bdfa3fe283 (diff) | |
download | chromium_src-545d7fd0b4de41af907c1ad01f72b492f01f9d3c.zip chromium_src-545d7fd0b4de41af907c1ad01f72b492f01f9d3c.tar.gz chromium_src-545d7fd0b4de41af907c1ad01f72b492f01f9d3c.tar.bz2 |
bluetooth: android: Refactor tests, wrappers, and fakes.
Refactoring to simplify follow up patch
"Initial Low Energy Discovery Sessions"
https://codereview.chromium.org/1150833002
Android wrapper and fake classes are refactored to be inner classes
because many more wrapper and fake classes are being implemented.
Testing code is refactored to be run in cross platform files
(e.g. bluetooth_adapter_unittest.cc), with a test fixture
BluetoothTest that is be subclassed to enable tests
on multiple platforms.
Tests implemented for Android will be done in this new style,
encapsulating Android specific details so that the tests may
be used on other platforms as well. E.g. the anticipated
Mac OSX support can us these tests instead of creating additional
platform specific tests. The larger test suites of ChromeOS
may some day be refactored to this style as well, adding coverage
for all platforms.
BUG=488575
Review URL: https://codereview.chromium.org/1216473005
Cr-Commit-Position: refs/heads/master@{#336894}
Diffstat (limited to 'device/bluetooth/bluetooth_adapter_unittest.cc')
-rw-r--r-- | device/bluetooth/bluetooth_adapter_unittest.cc | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/device/bluetooth/bluetooth_adapter_unittest.cc b/device/bluetooth/bluetooth_adapter_unittest.cc index 15a09e1..2805a6f 100644 --- a/device/bluetooth/bluetooth_adapter_unittest.cc +++ b/device/bluetooth/bluetooth_adapter_unittest.cc @@ -4,12 +4,17 @@ #include "base/bind.h" #include "base/memory/ref_counted.h" +#include "base/run_loop.h" #include "device/bluetooth/bluetooth_adapter.h" #include "device/bluetooth/bluetooth_device.h" #include "device/bluetooth/bluetooth_discovery_session.h" +#include "device/bluetooth/test/bluetooth_test.h" #include "testing/gtest/include/gtest/gtest.h" -using device::BluetoothAdapter; +#if defined(OS_ANDROID) +#include "device/bluetooth/test/bluetooth_test_android.h" +#endif + using device::BluetoothDevice; namespace device { @@ -394,4 +399,49 @@ TEST(BluetoothAdapterTest, GetMergedDiscoveryFilterAllFields) { adapter->CleanupSessions(); } +// TODO(scheib): Enable BluetoothTest fixture tests on all platforms. +#if defined(OS_ANDROID) +TEST_F(BluetoothTest, ConstructDefaultAdapter) { + InitWithDefaultAdapter(); + if (!adapter_->IsPresent()) { + LOG(WARNING) << "Bluetooth adapter not present; skipping unit test."; + return; + } + EXPECT_GT(adapter_->GetAddress().length(), 0u); + EXPECT_GT(adapter_->GetName().length(), 0u); + EXPECT_TRUE(adapter_->IsPresent()); + // Don't know on test machines if adapter will be powered or not, but + // the call should be safe to make and consistent. + EXPECT_EQ(adapter_->IsPowered(), adapter_->IsPowered()); + EXPECT_FALSE(adapter_->IsDiscoverable()); + EXPECT_FALSE(adapter_->IsDiscovering()); +} +#endif // defined(OS_ANDROID) + +// TODO(scheib): Enable BluetoothTest fixture tests on all platforms. +#if defined(OS_ANDROID) +TEST_F(BluetoothTest, ConstructWithoutDefaultAdapter) { + InitWithoutDefaultAdapter(); + EXPECT_EQ(adapter_->GetAddress(), ""); + EXPECT_EQ(adapter_->GetName(), ""); + EXPECT_FALSE(adapter_->IsPresent()); + EXPECT_FALSE(adapter_->IsPowered()); + EXPECT_FALSE(adapter_->IsDiscoverable()); + EXPECT_FALSE(adapter_->IsDiscovering()); +} +#endif // defined(OS_ANDROID) + +// TODO(scheib): Enable BluetoothTest fixture tests on all platforms. +#if defined(OS_ANDROID) +TEST_F(BluetoothTest, ConstructFakeAdapter) { + InitWithFakeAdapter(); + EXPECT_EQ(adapter_->GetAddress(), "A1:B2:C3:D4:E5:F6"); + EXPECT_EQ(adapter_->GetName(), "FakeBluetoothAdapter"); + EXPECT_TRUE(adapter_->IsPresent()); + EXPECT_TRUE(adapter_->IsPowered()); + EXPECT_FALSE(adapter_->IsDiscoverable()); + EXPECT_FALSE(adapter_->IsDiscovering()); +} +#endif // defined(OS_ANDROID) + } // namespace device |