Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1462)

Unified Diff: components/arc/bluetooth/bluetooth_struct_traits_unittest.cc

Issue 2256003002: components/arc: implement multi advertising (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@plumb-incoming-connections
Patch Set: lhchavez@ nits Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/arc/bluetooth/bluetooth_struct_traits_unittest.cc
diff --git a/components/arc/bluetooth/bluetooth_struct_traits_unittest.cc b/components/arc/bluetooth/bluetooth_struct_traits_unittest.cc
index 7d152417fe84dbddb5a5757b015898022e2a369d..a155b0ae359ce494e16f3519cef0efebc52badfb 100644
--- a/components/arc/bluetooth/bluetooth_struct_traits_unittest.cc
+++ b/components/arc/bluetooth/bluetooth_struct_traits_unittest.cc
@@ -16,6 +16,13 @@ constexpr uint8_t kUuidArray[] = {0x12, 0x34, 0x56, 0x78, 0x12, 0x34,
0x23, 0x45, 0x67, 0x89};
constexpr size_t kUuidSize = 16;
+constexpr char kUuid16Str[] = "1234";
+constexpr uint16_t kUuid16 = 0x1234;
+constexpr uint8_t kServiceData[] = {0x11, 0x22, 0x33, 0x44, 0x55};
+constexpr size_t kServiceDataSize = 5;
rickyz (no longer on Chrome) 2016/09/14 20:47:27 nit: Would prefer arraysize from base/macros.h ins
+constexpr uint8_t kManufacturerData[] = {0x00, 0xe0};
+constexpr size_t kManufacturerDataSize = 2;
+
template <typename MojoType, typename UserType>
mojo::StructPtr<MojoType> ConvertToMojo(UserType& input) {
mojo::Array<uint8_t> data = MojoType::Serialize(&input);
@@ -59,4 +66,87 @@ TEST(BluetoothStructTraitsTest, DeserializeBluetoothUUID) {
// array<uint8, 16>.
}
+TEST(BluetoothStructTraitsTest, DeserializeBluetoothAdvertisement) {
+ arc::mojom::BluetoothAdvertisementPtr advertisement_mojo =
+ arc::mojom::BluetoothAdvertisement::New();
+ mojo::Array<arc::mojom::BluetoothAdvertisingDataPtr> adv_data;
+
+ // Create service UUIDs.
+ arc::mojom::BluetoothAdvertisingDataPtr data =
+ arc::mojom::BluetoothAdvertisingData::New();
+ std::vector<device::BluetoothUUID> service_uuids;
+ service_uuids.push_back((device::BluetoothUUID(kUuidStr)));
+ data->set_service_uuids(service_uuids);
+ adv_data.push_back(std::move(data));
+
+ // Create service data.
+ data = arc::mojom::BluetoothAdvertisingData::New();
+ arc::mojom::BluetoothServiceDataPtr service_data =
+ arc::mojom::BluetoothServiceData::New();
+ service_data->uuid_16bit = kUuid16;
+ service_data->data = mojo::Array<uint8_t>::From(
+ std::vector<uint8_t>(kServiceData, kServiceData + kServiceDataSize));
rickyz (no longer on Chrome) 2016/09/14 20:47:26 nit: Can use (std::begin(kData), std::end(kData))
+ data->set_service_data(std::move(service_data));
+ adv_data.push_back(std::move(data));
+
+ // Create manufacturer data.
+ data = arc::mojom::BluetoothAdvertisingData::New();
+ data->set_manufacturer_data(std::vector<uint8_t>(
+ kManufacturerData, kManufacturerData + kManufacturerDataSize));
+ adv_data.push_back(std::move(data));
+
+ advertisement_mojo->type =
+ arc::mojom::BluetoothAdvertisementType::ADV_TYPE_CONNECTABLE;
+ advertisement_mojo->data = std::move(adv_data);
+
+ std::unique_ptr<device::BluetoothAdvertisement::Data> advertisement;
+ EXPECT_TRUE(ConvertFromMojo(std::move(advertisement_mojo), &advertisement));
+
+ EXPECT_EQ(advertisement->type(),
+ device::BluetoothAdvertisement::ADVERTISEMENT_TYPE_PERIPHERAL);
+
+ std::unique_ptr<device::BluetoothAdvertisement::UUIDList> converted_uuids =
+ advertisement->service_uuids();
+ EXPECT_EQ(converted_uuids->size(), 1U);
+ EXPECT_EQ(*converted_uuids->begin(), kUuidStr);
+
+ std::unique_ptr<device::BluetoothAdvertisement::ServiceData>
+ converted_service = advertisement->service_data();
+ EXPECT_EQ(converted_service->size(), 1U);
+ EXPECT_EQ(converted_service->begin()->first, kUuid16Str);
+ for (size_t i = 0; i < kServiceDataSize; i++) {
+ EXPECT_EQ(kServiceData[i], converted_service->begin()->second[i]);
+ }
+
+ std::unique_ptr<device::BluetoothAdvertisement::ManufacturerData>
+ converted_manufacturer = advertisement->manufacturer_data();
+ EXPECT_EQ(converted_manufacturer->size(), 1U);
+ uint16_t cic = converted_manufacturer->begin()->first;
+ EXPECT_EQ(cic & 0xff, kManufacturerData[0]);
+ EXPECT_EQ((cic >> 8) & 0xff, kManufacturerData[1]);
+ EXPECT_EQ(
+ converted_manufacturer->begin()->second.size(),
+ static_cast<unsigned long>(kManufacturerDataSize - sizeof(uint16_t)));
+}
+
+TEST(BluetoothStructTraitsTest, DeserializeBluetoothAdvertisementFailure) {
+ arc::mojom::BluetoothAdvertisementPtr advertisement_mojo =
+ arc::mojom::BluetoothAdvertisement::New();
+ mojo::Array<arc::mojom::BluetoothAdvertisingDataPtr> adv_data;
+
+ // Create empty manufacturer data. Manufacturer data must include the CIC
+ // which is 2 bytes long.
+ arc::mojom::BluetoothAdvertisingDataPtr data =
+ arc::mojom::BluetoothAdvertisingData::New();
+ data->set_manufacturer_data((mojo::Array<uint8_t>()));
+ adv_data.push_back(std::move(data));
+
+ advertisement_mojo->type =
+ arc::mojom::BluetoothAdvertisementType::ADV_TYPE_CONNECTABLE;
+ advertisement_mojo->data = std::move(adv_data);
+
+ std::unique_ptr<device::BluetoothAdvertisement::Data> advertisement;
+ EXPECT_FALSE(ConvertFromMojo(std::move(advertisement_mojo), &advertisement));
+}
+
} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698