ortuno | 945c90d | 2015-09-01 01:47:08 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
thakis | 08c9d69b0 | 2016-04-11 04:37:25 | [diff] [blame] | 5 | #include "device/bluetooth/bluetooth_advertisement.h" |
| 6 | |
avi | 176e269 | 2015-12-22 19:26:52 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
thakis | 08c9d69b0 | 2016-04-11 04:37:25 | [diff] [blame] | 9 | #include <memory> |
| 10 | |
| 11 | #include "base/memory/ptr_util.h" |
ortuno | 945c90d | 2015-09-01 01:47:08 | [diff] [blame] | 12 | #include "testing/gtest/include/gtest/gtest.h" |
| 13 | |
| 14 | namespace device { |
| 15 | |
| 16 | namespace { |
| 17 | |
| 18 | TEST(BluetoothAdvertisementTest, DataMembersAreAssignedCorrectly) { |
| 19 | // Sample manufacturer data. |
| 20 | BluetoothAdvertisement::ManufacturerData manufacturer_data; |
| 21 | std::vector<uint8_t> sample_data(5, 0); |
| 22 | manufacturer_data[0] = std::vector<uint8_t>(5, 0); |
| 23 | // Sample UUID List. |
| 24 | const BluetoothAdvertisement::UUIDList uuids(1, "1234"); |
| 25 | // Sample Service Data. |
| 26 | BluetoothAdvertisement::ServiceData service_data; |
| 27 | service_data["1234"] = std::vector<uint8_t>(5, 0); |
| 28 | |
| 29 | BluetoothAdvertisement::Data data( |
| 30 | BluetoothAdvertisement::ADVERTISEMENT_TYPE_BROADCAST); |
| 31 | ASSERT_EQ(data.type(), BluetoothAdvertisement::ADVERTISEMENT_TYPE_BROADCAST); |
| 32 | |
| 33 | // Try without assiging Service UUID. |
| 34 | ASSERT_FALSE(data.service_uuids().get()); |
| 35 | // Assign Service UUID. |
| 36 | data.set_service_uuids( |
Jeremy Roman | 9857376d | 2017-08-29 20:04:26 | [diff] [blame] | 37 | std::make_unique<BluetoothAdvertisement::UUIDList>(uuids)); |
ortuno | 945c90d | 2015-09-01 01:47:08 | [diff] [blame] | 38 | // Retrieve Service UUID. |
| 39 | ASSERT_EQ(*data.service_uuids(), uuids); |
| 40 | // Retrieve again. |
| 41 | ASSERT_FALSE(data.service_uuids().get()); |
| 42 | |
| 43 | // Try without assigning Manufacturer Data. |
| 44 | ASSERT_FALSE(data.manufacturer_data().get()); |
| 45 | // Assign Manufacturer Data. |
ricea | 0c937aa | 2016-08-25 05:24:04 | [diff] [blame] | 46 | data.set_manufacturer_data( |
Jeremy Roman | 9857376d | 2017-08-29 20:04:26 | [diff] [blame] | 47 | std::make_unique<BluetoothAdvertisement::ManufacturerData>( |
ricea | 0c937aa | 2016-08-25 05:24:04 | [diff] [blame] | 48 | manufacturer_data)); |
ortuno | 945c90d | 2015-09-01 01:47:08 | [diff] [blame] | 49 | // Retrieve Manufacturer Data. |
| 50 | ASSERT_EQ(*data.manufacturer_data(), manufacturer_data); |
| 51 | // Retrieve again. |
| 52 | ASSERT_FALSE(data.manufacturer_data().get()); |
| 53 | |
| 54 | // Try without assigning Solicit UUIDs. |
| 55 | ASSERT_FALSE(data.solicit_uuids().get()); |
| 56 | // Assign Solicit UUIDs. |
| 57 | data.set_solicit_uuids( |
Jeremy Roman | 9857376d | 2017-08-29 20:04:26 | [diff] [blame] | 58 | std::make_unique<BluetoothAdvertisement::UUIDList>(uuids)); |
ortuno | 945c90d | 2015-09-01 01:47:08 | [diff] [blame] | 59 | // Retrieve Solicit UUIDs. |
| 60 | ASSERT_EQ(*data.solicit_uuids(), uuids); |
| 61 | // Retieve again. |
| 62 | ASSERT_FALSE(data.solicit_uuids().get()); |
| 63 | |
| 64 | // Try without assigning Service Data. |
| 65 | ASSERT_FALSE(data.service_data().get()); |
| 66 | // Assign Service Data. |
| 67 | data.set_service_data( |
Jeremy Roman | 9857376d | 2017-08-29 20:04:26 | [diff] [blame] | 68 | std::make_unique<BluetoothAdvertisement::ServiceData>(service_data)); |
ortuno | 945c90d | 2015-09-01 01:47:08 | [diff] [blame] | 69 | // Retrieve Service Data. |
| 70 | ASSERT_EQ(*data.service_data(), service_data); |
| 71 | // Retrieve again. |
| 72 | ASSERT_FALSE(data.service_data().get()); |
| 73 | } |
| 74 | |
| 75 | } // namespace |
| 76 | |
| 77 | } // namespace device |