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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
| 8 #include <utility> |
| 9 |
8 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
9 #include "device/bluetooth/bluetooth_low_energy_win.h" | 11 #include "device/bluetooth/bluetooth_low_energy_win.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
11 | 13 |
12 namespace { | 14 namespace { |
13 | 15 |
14 const char kValidDeviceInstanceId[] = | 16 const char kValidDeviceInstanceId[] = |
15 "BTHLE\\DEV_BC6A29AB5FB0\\8&31038925&0&BC6A29AB5FB0"; | 17 "BTHLE\\DEV_BC6A29AB5FB0\\8&31038925&0&BC6A29AB5FB0"; |
16 | 18 |
17 const char kInvalidDeviceInstanceId[] = | 19 const char kInvalidDeviceInstanceId[] = |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 } | 54 } |
53 | 55 |
54 TEST_F(BluetoothLowEnergyWinTest, DeviceRegistryPropertyValueAsString) { | 56 TEST_F(BluetoothLowEnergyWinTest, DeviceRegistryPropertyValueAsString) { |
55 std::string test_value = "String used for round trip test."; | 57 std::string test_value = "String used for round trip test."; |
56 std::wstring wide_value = base::SysUTF8ToWide(test_value); | 58 std::wstring wide_value = base::SysUTF8ToWide(test_value); |
57 size_t buffer_size = (wide_value.size() + 1) * sizeof(wchar_t); | 59 size_t buffer_size = (wide_value.size() + 1) * sizeof(wchar_t); |
58 scoped_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); | 60 scoped_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); |
59 memcpy(buffer.get(), wide_value.c_str(), buffer_size); | 61 memcpy(buffer.get(), wide_value.c_str(), buffer_size); |
60 scoped_ptr<device::win::DeviceRegistryPropertyValue> value = | 62 scoped_ptr<device::win::DeviceRegistryPropertyValue> value = |
61 device::win::DeviceRegistryPropertyValue::Create( | 63 device::win::DeviceRegistryPropertyValue::Create( |
62 REG_SZ, buffer.Pass(), buffer_size).Pass(); | 64 REG_SZ, std::move(buffer), buffer_size); |
63 EXPECT_EQ(test_value, value->AsString()); | 65 EXPECT_EQ(test_value, value->AsString()); |
64 } | 66 } |
65 | 67 |
66 TEST_F(BluetoothLowEnergyWinTest, DeviceRegistryPropertyValueAsDWORD) { | 68 TEST_F(BluetoothLowEnergyWinTest, DeviceRegistryPropertyValueAsDWORD) { |
67 DWORD test_value = 5u; | 69 DWORD test_value = 5u; |
68 size_t buffer_size = sizeof(DWORD); | 70 size_t buffer_size = sizeof(DWORD); |
69 scoped_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); | 71 scoped_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); |
70 memcpy(buffer.get(), &test_value, buffer_size); | 72 memcpy(buffer.get(), &test_value, buffer_size); |
71 scoped_ptr<device::win::DeviceRegistryPropertyValue> value = | 73 scoped_ptr<device::win::DeviceRegistryPropertyValue> value = |
72 device::win::DeviceRegistryPropertyValue::Create( | 74 device::win::DeviceRegistryPropertyValue::Create( |
73 REG_DWORD, buffer.Pass(), buffer_size).Pass(); | 75 REG_DWORD, std::move(buffer), buffer_size); |
74 EXPECT_EQ(test_value, value->AsDWORD()); | 76 EXPECT_EQ(test_value, value->AsDWORD()); |
75 } | 77 } |
76 | 78 |
77 TEST_F(BluetoothLowEnergyWinTest, DevicePropertyValueAsUint32) { | 79 TEST_F(BluetoothLowEnergyWinTest, DevicePropertyValueAsUint32) { |
78 uint32_t test_value = 5u; | 80 uint32_t test_value = 5u; |
79 size_t buffer_size = sizeof(uint32_t); | 81 size_t buffer_size = sizeof(uint32_t); |
80 scoped_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); | 82 scoped_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); |
81 memcpy(buffer.get(), &test_value, buffer_size); | 83 memcpy(buffer.get(), &test_value, buffer_size); |
82 scoped_ptr<device::win::DevicePropertyValue> value( | 84 scoped_ptr<device::win::DevicePropertyValue> value( |
83 new device::win::DevicePropertyValue( | 85 new device::win::DevicePropertyValue(DEVPROP_TYPE_UINT32, |
84 DEVPROP_TYPE_UINT32, buffer.Pass(), buffer_size)); | 86 std::move(buffer), buffer_size)); |
85 EXPECT_EQ(test_value, value->AsUint32()); | 87 EXPECT_EQ(test_value, value->AsUint32()); |
86 } | 88 } |
87 | 89 |
88 } // namespace device | 90 } // namespace device |
OLD | NEW |