blob: 83287dafed1a1a64a5d377000447942147dda335 [file] [log] [blame]
ortuno945c90d2015-09-01 01:47:081// 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
thakis08c9d69b02016-04-11 04:37:255#include "device/bluetooth/bluetooth_advertisement.h"
6
avi176e2692015-12-22 19:26:527#include <stdint.h>
8
thakis08c9d69b02016-04-11 04:37:259#include <memory>
10
11#include "base/memory/ptr_util.h"
ortuno945c90d2015-09-01 01:47:0812#include "testing/gtest/include/gtest/gtest.h"
13
14namespace device {
15
16namespace {
17
18TEST(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 Roman9857376d2017-08-29 20:04:2637 std::make_unique<BluetoothAdvertisement::UUIDList>(uuids));
ortuno945c90d2015-09-01 01:47:0838 // 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.
ricea0c937aa2016-08-25 05:24:0446 data.set_manufacturer_data(
Jeremy Roman9857376d2017-08-29 20:04:2647 std::make_unique<BluetoothAdvertisement::ManufacturerData>(
ricea0c937aa2016-08-25 05:24:0448 manufacturer_data));
ortuno945c90d2015-09-01 01:47:0849 // 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 Roman9857376d2017-08-29 20:04:2658 std::make_unique<BluetoothAdvertisement::UUIDList>(uuids));
ortuno945c90d2015-09-01 01:47:0859 // 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 Roman9857376d2017-08-29 20:04:2668 std::make_unique<BluetoothAdvertisement::ServiceData>(service_data));
ortuno945c90d2015-09-01 01:47:0869 // 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