OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/arc/bluetooth/bluetooth_type_converters.h" | 5 #include "components/arc/bluetooth/bluetooth_type_converters.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 size_t depth) { | 56 size_t depth) { |
57 if (depth > 0u) { | 57 if (depth > 0u) { |
58 std::unique_ptr<bluez::BluetoothServiceAttributeValueBlueZ::Sequence> | 58 std::unique_ptr<bluez::BluetoothServiceAttributeValueBlueZ::Sequence> |
59 sequence(new bluez::BluetoothServiceAttributeValueBlueZ::Sequence()); | 59 sequence(new bluez::BluetoothServiceAttributeValueBlueZ::Sequence()); |
60 sequence->push_back(CreateDeepBlueZSequenceAttribute(depth - 1)); | 60 sequence->push_back(CreateDeepBlueZSequenceAttribute(depth - 1)); |
61 | 61 |
62 return bluez::BluetoothServiceAttributeValueBlueZ(std::move(sequence)); | 62 return bluez::BluetoothServiceAttributeValueBlueZ(std::move(sequence)); |
63 } else { | 63 } else { |
64 return bluez::BluetoothServiceAttributeValueBlueZ( | 64 return bluez::BluetoothServiceAttributeValueBlueZ( |
65 bluez::BluetoothServiceAttributeValueBlueZ::UINT, sizeof(uint16_t), | 65 bluez::BluetoothServiceAttributeValueBlueZ::UINT, sizeof(uint16_t), |
66 base::WrapUnique(new base::FundamentalValue(3))); | 66 base::WrapUnique(new base::Value(3))); |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 size_t GetDepthOfBlueZAttribute( | 70 size_t GetDepthOfBlueZAttribute( |
71 const bluez::BluetoothServiceAttributeValueBlueZ& attribute) { | 71 const bluez::BluetoothServiceAttributeValueBlueZ& attribute) { |
72 size_t depth = 1; | 72 size_t depth = 1; |
73 if (attribute.type() == | 73 if (attribute.type() == |
74 bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE) { | 74 bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE) { |
75 for (const auto& value : attribute.sequence()) | 75 for (const auto& value : attribute.sequence()) |
76 depth = std::max(depth, GetDepthOfBlueZAttribute(value) + 1); | 76 depth = std::max(depth, GetDepthOfBlueZAttribute(value) + 1); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 nulltypeAttributeMojo->type); | 322 nulltypeAttributeMojo->type); |
323 EXPECT_EQ(0u, nulltypeAttributeMojo->type_size); | 323 EXPECT_EQ(0u, nulltypeAttributeMojo->type_size); |
324 EXPECT_TRUE(nulltypeAttributeMojo->value.Get(0, &actualValue)); | 324 EXPECT_TRUE(nulltypeAttributeMojo->value.Get(0, &actualValue)); |
325 EXPECT_EQ(base::Value::Type::NONE, actualValue->GetType()); | 325 EXPECT_EQ(base::Value::Type::NONE, actualValue->GetType()); |
326 | 326 |
327 // Check integer types (INT, UINT). | 327 // Check integer types (INT, UINT). |
328 uint16_t valueUint16 = 10; | 328 uint16_t valueUint16 = 10; |
329 int valueUint16AsInt; | 329 int valueUint16AsInt; |
330 auto uintAttributeBlueZ = bluez::BluetoothServiceAttributeValueBlueZ( | 330 auto uintAttributeBlueZ = bluez::BluetoothServiceAttributeValueBlueZ( |
331 bluez::BluetoothServiceAttributeValueBlueZ::UINT, sizeof(valueUint16), | 331 bluez::BluetoothServiceAttributeValueBlueZ::UINT, sizeof(valueUint16), |
332 base::MakeUnique<base::FundamentalValue>(static_cast<int>(valueUint16))); | 332 base::MakeUnique<base::Value>(static_cast<int>(valueUint16))); |
333 | 333 |
334 auto uintAttributeMojo = | 334 auto uintAttributeMojo = |
335 ConvertTo<arc::mojom::BluetoothSdpAttributePtr>(uintAttributeBlueZ); | 335 ConvertTo<arc::mojom::BluetoothSdpAttributePtr>(uintAttributeBlueZ); |
336 | 336 |
337 EXPECT_EQ(bluez::BluetoothServiceAttributeValueBlueZ::UINT, | 337 EXPECT_EQ(bluez::BluetoothServiceAttributeValueBlueZ::UINT, |
338 uintAttributeMojo->type); | 338 uintAttributeMojo->type); |
339 EXPECT_EQ(sizeof(valueUint16), uintAttributeMojo->type_size); | 339 EXPECT_EQ(sizeof(valueUint16), uintAttributeMojo->type_size); |
340 EXPECT_TRUE(uintAttributeMojo->value.GetInteger(0, &valueUint16AsInt)); | 340 EXPECT_TRUE(uintAttributeMojo->value.GetInteger(0, &valueUint16AsInt)); |
341 EXPECT_EQ(valueUint16, static_cast<uint16_t>(valueUint16AsInt)); | 341 EXPECT_EQ(valueUint16, static_cast<uint16_t>(valueUint16AsInt)); |
342 | 342 |
343 // Check bool type. | 343 // Check bool type. |
344 bool valueBool = false; | 344 bool valueBool = false; |
345 bool actualBool = true; | 345 bool actualBool = true; |
346 auto boolAttributeBlueZ = bluez::BluetoothServiceAttributeValueBlueZ( | 346 auto boolAttributeBlueZ = bluez::BluetoothServiceAttributeValueBlueZ( |
347 bluez::BluetoothServiceAttributeValueBlueZ::BOOL, sizeof(bool), | 347 bluez::BluetoothServiceAttributeValueBlueZ::BOOL, sizeof(bool), |
348 base::MakeUnique<base::FundamentalValue>(valueBool)); | 348 base::MakeUnique<base::Value>(valueBool)); |
349 | 349 |
350 auto boolAttributeMojo = | 350 auto boolAttributeMojo = |
351 ConvertTo<arc::mojom::BluetoothSdpAttributePtr>(boolAttributeBlueZ); | 351 ConvertTo<arc::mojom::BluetoothSdpAttributePtr>(boolAttributeBlueZ); |
352 | 352 |
353 EXPECT_EQ(bluez::BluetoothServiceAttributeValueBlueZ::BOOL, | 353 EXPECT_EQ(bluez::BluetoothServiceAttributeValueBlueZ::BOOL, |
354 boolAttributeMojo->type); | 354 boolAttributeMojo->type); |
355 EXPECT_EQ(static_cast<uint32_t>(sizeof(valueBool)), | 355 EXPECT_EQ(static_cast<uint32_t>(sizeof(valueBool)), |
356 boolAttributeMojo->type_size); | 356 boolAttributeMojo->type_size); |
357 EXPECT_TRUE(boolAttributeMojo->value.GetBoolean(0, &actualBool)); | 357 EXPECT_TRUE(boolAttributeMojo->value.GetBoolean(0, &actualBool)); |
358 EXPECT_FALSE(valueBool); | 358 EXPECT_FALSE(valueBool); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 std::string l2capUUID("00000100-0000-1000-8000-00805f9b34fb"); | 396 std::string l2capUUID("00000100-0000-1000-8000-00805f9b34fb"); |
397 uint16_t l2capChannel = 3; | 397 uint16_t l2capChannel = 3; |
398 | 398 |
399 std::unique_ptr<bluez::BluetoothServiceAttributeValueBlueZ::Sequence> | 399 std::unique_ptr<bluez::BluetoothServiceAttributeValueBlueZ::Sequence> |
400 sequence(new bluez::BluetoothServiceAttributeValueBlueZ::Sequence()); | 400 sequence(new bluez::BluetoothServiceAttributeValueBlueZ::Sequence()); |
401 sequence->push_back(bluez::BluetoothServiceAttributeValueBlueZ( | 401 sequence->push_back(bluez::BluetoothServiceAttributeValueBlueZ( |
402 bluez::BluetoothServiceAttributeValueBlueZ::UUID, sizeof(uint16_t), | 402 bluez::BluetoothServiceAttributeValueBlueZ::UUID, sizeof(uint16_t), |
403 base::MakeUnique<base::StringValue>(l2capUUID))); | 403 base::MakeUnique<base::StringValue>(l2capUUID))); |
404 sequence->push_back(bluez::BluetoothServiceAttributeValueBlueZ( | 404 sequence->push_back(bluez::BluetoothServiceAttributeValueBlueZ( |
405 bluez::BluetoothServiceAttributeValueBlueZ::UINT, sizeof(uint16_t), | 405 bluez::BluetoothServiceAttributeValueBlueZ::UINT, sizeof(uint16_t), |
406 base::MakeUnique<base::FundamentalValue>(l2capChannel))); | 406 base::MakeUnique<base::Value>(l2capChannel))); |
407 | 407 |
408 auto sequenceBlueZ = | 408 auto sequenceBlueZ = |
409 bluez::BluetoothServiceAttributeValueBlueZ(std::move(sequence)); | 409 bluez::BluetoothServiceAttributeValueBlueZ(std::move(sequence)); |
410 | 410 |
411 ASSERT_EQ(2u, sequenceBlueZ.sequence().size()); | 411 ASSERT_EQ(2u, sequenceBlueZ.sequence().size()); |
412 | 412 |
413 auto sequenceMojo = | 413 auto sequenceMojo = |
414 ConvertTo<arc::mojom::BluetoothSdpAttributePtr>(sequenceBlueZ); | 414 ConvertTo<arc::mojom::BluetoothSdpAttributePtr>(sequenceBlueZ); |
415 | 415 |
416 EXPECT_EQ(bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE, | 416 EXPECT_EQ(bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE, |
(...skipping 27 matching lines...) Expand all Loading... |
444 auto sequenceMojo = | 444 auto sequenceMojo = |
445 ConvertTo<arc::mojom::BluetoothSdpAttributePtr>(sequenceBlueZ); | 445 ConvertTo<arc::mojom::BluetoothSdpAttributePtr>(sequenceBlueZ); |
446 | 446 |
447 EXPECT_EQ(bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE, | 447 EXPECT_EQ(bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE, |
448 sequenceMojo->type); | 448 sequenceMojo->type); |
449 EXPECT_EQ((uint32_t)1, sequenceMojo->type_size); | 449 EXPECT_EQ((uint32_t)1, sequenceMojo->type_size); |
450 EXPECT_EQ(arc::kBluetoothSDPMaxDepth, GetDepthOfMojoAttribute(sequenceMojo)); | 450 EXPECT_EQ(arc::kBluetoothSDPMaxDepth, GetDepthOfMojoAttribute(sequenceMojo)); |
451 } | 451 } |
452 | 452 |
453 } // namespace mojo | 453 } // namespace mojo |
OLD | NEW |