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

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

Issue 2394683007: Reland "components/arc: implement multi advertising" (Closed)
Patch Set: Created 4 years, 2 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..94adbbb734fcec269ca99865719cf36f560cc6ce 100644
--- a/components/arc/bluetooth/bluetooth_struct_traits_unittest.cc
+++ b/components/arc/bluetooth/bluetooth_struct_traits_unittest.cc
@@ -4,6 +4,7 @@
#include "components/arc/bluetooth/bluetooth_struct_traits.h"
+#include "base/macros.h"
#include "device/bluetooth/bluetooth_uuid.h"
#include "mojo/public/cpp/bindings/array.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -16,6 +17,11 @@ 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 uint8_t kManufacturerData[] = {0x00, 0xe0};
+
template <typename MojoType, typename UserType>
mojo::StructPtr<MojoType> ConvertToMojo(UserType& input) {
mojo::Array<uint8_t> data = MojoType::Serialize(&input);
@@ -49,6 +55,8 @@ TEST(BluetoothStructTraitsTest, DeserializeBluetoothUUID) {
for (size_t i = 0; i < kUuidSize; i++) {
uuid_mojo->uuid.push_back(kUuidArray[i]);
}
+ uuid_mojo->uuid =
+ std::vector<uint8_t>(std::begin(kUuidArray), std::end(kUuidArray));
device::BluetoothUUID uuid_device;
EXPECT_TRUE(ConvertFromMojo(std::move(uuid_mojo), &uuid_device));
EXPECT_EQ(std::string(kUuidStr), uuid_device.canonical_value());
@@ -59,4 +67,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 =
+ std::vector<uint8_t>(std::begin(kServiceData), std::end(kServiceData));
+ 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>(
+ std::begin(kManufacturerData), std::end(kManufacturerData)));
+ 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 < arraysize(kServiceData); 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>(arraysize(kManufacturerData) -
+ 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