OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "base/strings/sys_string_conversions.h" |
5 #include "device/bluetooth/bluetooth_low_energy_win.h" | 6 #include "device/bluetooth/bluetooth_low_energy_win.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
7 | 8 |
8 namespace { | 9 namespace { |
9 | 10 |
10 const char kValidDeviceInstanceId[] = | 11 const char kValidDeviceInstanceId[] = |
11 "BTHLE\\DEV_BC6A29AB5FB0\\8&31038925&0&BC6A29AB5FB0"; | 12 "BTHLE\\DEV_BC6A29AB5FB0\\8&31038925&0&BC6A29AB5FB0"; |
12 | 13 |
13 const char kInvalidDeviceInstanceId[] = | 14 const char kInvalidDeviceInstanceId[] = |
14 "BTHLE\\BC6A29AB5FB0_DEV_\\8&31038925&0&BC6A29AB5FB0"; | 15 "BTHLE\\BC6A29AB5FB0_DEV_\\8&31038925&0&BC6A29AB5FB0"; |
(...skipping 25 matching lines...) Expand all Loading... |
40 BLUETOOTH_ADDRESS btha; | 41 BLUETOOTH_ADDRESS btha; |
41 std::string error; | 42 std::string error; |
42 bool success = | 43 bool success = |
43 device::win::ExtractBluetoothAddressFromDeviceInstanceIdForTesting( | 44 device::win::ExtractBluetoothAddressFromDeviceInstanceIdForTesting( |
44 kInvalidDeviceInstanceId, &btha, &error); | 45 kInvalidDeviceInstanceId, &btha, &error); |
45 | 46 |
46 EXPECT_FALSE(success); | 47 EXPECT_FALSE(success); |
47 EXPECT_FALSE(error.empty()); | 48 EXPECT_FALSE(error.empty()); |
48 } | 49 } |
49 | 50 |
| 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()); |
| 61 } |
| 62 |
| 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()); |
| 72 } |
| 73 |
50 } // namespace device | 74 } // namespace device |
OLD | NEW |