ChildAccountService[Java] delegates everything to native side.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_low_energy_win_unittest.cc
blob3e9116e3cbe91b279ad70ade3600b55827a684e5
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/strings/sys_string_conversions.h"
6 #include "device/bluetooth/bluetooth_low_energy_win.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace {
11 const char kValidDeviceInstanceId[] =
12 "BTHLE\\DEV_BC6A29AB5FB0\\8&31038925&0&BC6A29AB5FB0";
14 const char kInvalidDeviceInstanceId[] =
15 "BTHLE\\BC6A29AB5FB0_DEV_\\8&31038925&0&BC6A29AB5FB0";
17 } // namespace
19 namespace device {
21 class BluetoothLowEnergyWinTest : public testing::Test {};
23 TEST_F(BluetoothLowEnergyWinTest, ExtractValidBluetoothAddress) {
24 BLUETOOTH_ADDRESS btha;
25 std::string error;
26 bool success =
27 device::win::ExtractBluetoothAddressFromDeviceInstanceIdForTesting(
28 kValidDeviceInstanceId, &btha, &error);
30 EXPECT_TRUE(success);
31 EXPECT_TRUE(error.empty());
32 EXPECT_EQ(0xbc, btha.rgBytes[5]);
33 EXPECT_EQ(0x6a, btha.rgBytes[4]);
34 EXPECT_EQ(0x29, btha.rgBytes[3]);
35 EXPECT_EQ(0xab, btha.rgBytes[2]);
36 EXPECT_EQ(0x5f, btha.rgBytes[1]);
37 EXPECT_EQ(0xb0, btha.rgBytes[0]);
40 TEST_F(BluetoothLowEnergyWinTest, ExtractInvalidBluetoothAddress) {
41 BLUETOOTH_ADDRESS btha;
42 std::string error;
43 bool success =
44 device::win::ExtractBluetoothAddressFromDeviceInstanceIdForTesting(
45 kInvalidDeviceInstanceId, &btha, &error);
47 EXPECT_FALSE(success);
48 EXPECT_FALSE(error.empty());
51 TEST_F(BluetoothLowEnergyWinTest, DeviceRegistryPropertyValueAsString) {
52 std::string test_value = "String used for round trip test.";
53 std::wstring wide_value = base::SysUTF8ToWide(test_value);
54 size_t buffer_size = (wide_value.size() + 1) * sizeof(wchar_t);
55 scoped_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]);
56 memcpy(buffer.get(), wide_value.c_str(), buffer_size);
57 scoped_ptr<device::win::DeviceRegistryPropertyValue> value =
58 device::win::DeviceRegistryPropertyValue::Create(
59 REG_SZ, buffer.Pass(), buffer_size).Pass();
60 EXPECT_EQ(test_value, value->AsString());
63 TEST_F(BluetoothLowEnergyWinTest, DeviceRegistryPropertyValueAsDWORD) {
64 DWORD test_value = 5u;
65 size_t buffer_size = sizeof(DWORD);
66 scoped_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]);
67 memcpy(buffer.get(), &test_value, buffer_size);
68 scoped_ptr<device::win::DeviceRegistryPropertyValue> value =
69 device::win::DeviceRegistryPropertyValue::Create(
70 REG_DWORD, buffer.Pass(), buffer_size).Pass();
71 EXPECT_EQ(test_value, value->AsDWORD());
74 TEST_F(BluetoothLowEnergyWinTest, DevicePropertyValueAsUint32) {
75 uint32_t test_value = 5u;
76 size_t buffer_size = sizeof(uint32_t);
77 scoped_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]);
78 memcpy(buffer.get(), &test_value, buffer_size);
79 scoped_ptr<device::win::DevicePropertyValue> value(
80 new device::win::DevicePropertyValue(
81 DEVPROP_TYPE_UINT32, buffer.Pass(), buffer_size));
82 EXPECT_EQ(test_value, value->AsUint32());
85 } // namespace device