OLD | NEW |
(Empty) | |
| 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 |
| 5 #include "device/bluetooth/bluetooth_advertisement.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 |
| 8 namespace device { |
| 9 |
| 10 namespace { |
| 11 |
| 12 TEST(BluetoothAdvertisementTest, DataMembersAreAssignedCorrectly) { |
| 13 // Sample manufacturer data. |
| 14 BluetoothAdvertisement::ManufacturerData manufacturer_data; |
| 15 std::vector<uint8_t> sample_data(5, 0); |
| 16 manufacturer_data[0] = std::vector<uint8_t>(5, 0); |
| 17 // Sample UUID List. |
| 18 const BluetoothAdvertisement::UUIDList uuids(1, "1234"); |
| 19 // Sample Service Data. |
| 20 BluetoothAdvertisement::ServiceData service_data; |
| 21 service_data["1234"] = std::vector<uint8_t>(5, 0); |
| 22 |
| 23 BluetoothAdvertisement::Data data( |
| 24 BluetoothAdvertisement::ADVERTISEMENT_TYPE_BROADCAST); |
| 25 ASSERT_EQ(data.type(), BluetoothAdvertisement::ADVERTISEMENT_TYPE_BROADCAST); |
| 26 |
| 27 // Try without assiging Service UUID. |
| 28 ASSERT_FALSE(data.service_uuids().get()); |
| 29 // Assign Service UUID. |
| 30 data.set_service_uuids( |
| 31 make_scoped_ptr(new BluetoothAdvertisement::UUIDList(uuids))); |
| 32 // Retrieve Service UUID. |
| 33 ASSERT_EQ(*data.service_uuids(), uuids); |
| 34 // Retrieve again. |
| 35 ASSERT_FALSE(data.service_uuids().get()); |
| 36 |
| 37 // Try without assigning Manufacturer Data. |
| 38 ASSERT_FALSE(data.manufacturer_data().get()); |
| 39 // Assign Manufacturer Data. |
| 40 data.set_manufacturer_data(make_scoped_ptr( |
| 41 new BluetoothAdvertisement::ManufacturerData(manufacturer_data))); |
| 42 // Retrieve Manufacturer Data. |
| 43 ASSERT_EQ(*data.manufacturer_data(), manufacturer_data); |
| 44 // Retrieve again. |
| 45 ASSERT_FALSE(data.manufacturer_data().get()); |
| 46 |
| 47 // Try without assigning Solicit UUIDs. |
| 48 ASSERT_FALSE(data.solicit_uuids().get()); |
| 49 // Assign Solicit UUIDs. |
| 50 data.set_solicit_uuids( |
| 51 make_scoped_ptr(new BluetoothAdvertisement::UUIDList(uuids))); |
| 52 // Retrieve Solicit UUIDs. |
| 53 ASSERT_EQ(*data.solicit_uuids(), uuids); |
| 54 // Retieve again. |
| 55 ASSERT_FALSE(data.solicit_uuids().get()); |
| 56 |
| 57 // Try without assigning Service Data. |
| 58 ASSERT_FALSE(data.service_data().get()); |
| 59 // Assign Service Data. |
| 60 data.set_service_data( |
| 61 make_scoped_ptr(new BluetoothAdvertisement::ServiceData(service_data))); |
| 62 // Retrieve Service Data. |
| 63 ASSERT_EQ(*data.service_data(), service_data); |
| 64 // Retrieve again. |
| 65 ASSERT_FALSE(data.service_data().get()); |
| 66 } |
| 67 |
| 68 } // namespace |
| 69 |
| 70 } // namespace device |
OLD | NEW |