| 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_NULL, actualValue->GetType()); | 325 EXPECT_EQ(base::Value::TYPE_NULL, 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>( | 332 base::MakeUnique<base::Value>( |
| 333 base::FundamentalValue(static_cast<int>(valueUint16)))); | 333 base::Value(static_cast<int>(valueUint16)))); |
| 334 | 334 |
| 335 auto uintAttributeMojo = | 335 auto uintAttributeMojo = |
| 336 ConvertTo<arc::mojom::BluetoothSdpAttributePtr>(uintAttributeBlueZ); | 336 ConvertTo<arc::mojom::BluetoothSdpAttributePtr>(uintAttributeBlueZ); |
| 337 | 337 |
| 338 EXPECT_EQ(bluez::BluetoothServiceAttributeValueBlueZ::UINT, | 338 EXPECT_EQ(bluez::BluetoothServiceAttributeValueBlueZ::UINT, |
| 339 uintAttributeMojo->type); | 339 uintAttributeMojo->type); |
| 340 EXPECT_EQ(sizeof(valueUint16), uintAttributeMojo->type_size); | 340 EXPECT_EQ(sizeof(valueUint16), uintAttributeMojo->type_size); |
| 341 EXPECT_TRUE(uintAttributeMojo->value.GetInteger(0, &valueUint16AsInt)); | 341 EXPECT_TRUE(uintAttributeMojo->value.GetInteger(0, &valueUint16AsInt)); |
| 342 EXPECT_EQ(valueUint16, static_cast<uint16_t>(valueUint16AsInt)); | 342 EXPECT_EQ(valueUint16, static_cast<uint16_t>(valueUint16AsInt)); |
| 343 | 343 |
| 344 // Check bool type. | 344 // Check bool type. |
| 345 bool valueBool = false; | 345 bool valueBool = false; |
| 346 bool actualBool = true; | 346 bool actualBool = true; |
| 347 auto boolAttributeBlueZ = bluez::BluetoothServiceAttributeValueBlueZ( | 347 auto boolAttributeBlueZ = bluez::BluetoothServiceAttributeValueBlueZ( |
| 348 bluez::BluetoothServiceAttributeValueBlueZ::BOOL, sizeof(bool), | 348 bluez::BluetoothServiceAttributeValueBlueZ::BOOL, sizeof(bool), |
| 349 base::MakeUnique<base::FundamentalValue>( | 349 base::MakeUnique<base::Value>( |
| 350 base::FundamentalValue(valueBool))); | 350 base::Value(valueBool))); |
| 351 | 351 |
| 352 auto boolAttributeMojo = | 352 auto boolAttributeMojo = |
| 353 ConvertTo<arc::mojom::BluetoothSdpAttributePtr>(boolAttributeBlueZ); | 353 ConvertTo<arc::mojom::BluetoothSdpAttributePtr>(boolAttributeBlueZ); |
| 354 | 354 |
| 355 EXPECT_EQ(bluez::BluetoothServiceAttributeValueBlueZ::BOOL, | 355 EXPECT_EQ(bluez::BluetoothServiceAttributeValueBlueZ::BOOL, |
| 356 boolAttributeMojo->type); | 356 boolAttributeMojo->type); |
| 357 EXPECT_EQ(static_cast<uint32_t>(sizeof(valueBool)), | 357 EXPECT_EQ(static_cast<uint32_t>(sizeof(valueBool)), |
| 358 boolAttributeMojo->type_size); | 358 boolAttributeMojo->type_size); |
| 359 EXPECT_TRUE(boolAttributeMojo->value.GetBoolean(0, &actualBool)); | 359 EXPECT_TRUE(boolAttributeMojo->value.GetBoolean(0, &actualBool)); |
| 360 EXPECT_FALSE(valueBool); | 360 EXPECT_FALSE(valueBool); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 std::string l2capUUID("00000100-0000-1000-8000-00805f9b34fb"); | 398 std::string l2capUUID("00000100-0000-1000-8000-00805f9b34fb"); |
| 399 uint16_t l2capChannel = 3; | 399 uint16_t l2capChannel = 3; |
| 400 | 400 |
| 401 std::unique_ptr<bluez::BluetoothServiceAttributeValueBlueZ::Sequence> | 401 std::unique_ptr<bluez::BluetoothServiceAttributeValueBlueZ::Sequence> |
| 402 sequence(new bluez::BluetoothServiceAttributeValueBlueZ::Sequence()); | 402 sequence(new bluez::BluetoothServiceAttributeValueBlueZ::Sequence()); |
| 403 sequence->push_back(bluez::BluetoothServiceAttributeValueBlueZ( | 403 sequence->push_back(bluez::BluetoothServiceAttributeValueBlueZ( |
| 404 bluez::BluetoothServiceAttributeValueBlueZ::UUID, sizeof(uint16_t), | 404 bluez::BluetoothServiceAttributeValueBlueZ::UUID, sizeof(uint16_t), |
| 405 base::MakeUnique<base::StringValue>(base::StringValue(l2capUUID)))); | 405 base::MakeUnique<base::StringValue>(base::StringValue(l2capUUID)))); |
| 406 sequence->push_back(bluez::BluetoothServiceAttributeValueBlueZ( | 406 sequence->push_back(bluez::BluetoothServiceAttributeValueBlueZ( |
| 407 bluez::BluetoothServiceAttributeValueBlueZ::UINT, sizeof(uint16_t), | 407 bluez::BluetoothServiceAttributeValueBlueZ::UINT, sizeof(uint16_t), |
| 408 base::MakeUnique<base::FundamentalValue>( | 408 base::MakeUnique<base::Value>( |
| 409 base::FundamentalValue(l2capChannel)))); | 409 base::Value(l2capChannel)))); |
| 410 | 410 |
| 411 auto sequenceBlueZ = | 411 auto sequenceBlueZ = |
| 412 bluez::BluetoothServiceAttributeValueBlueZ(std::move(sequence)); | 412 bluez::BluetoothServiceAttributeValueBlueZ(std::move(sequence)); |
| 413 | 413 |
| 414 ASSERT_EQ(2u, sequenceBlueZ.sequence().size()); | 414 ASSERT_EQ(2u, sequenceBlueZ.sequence().size()); |
| 415 | 415 |
| 416 auto sequenceMojo = | 416 auto sequenceMojo = |
| 417 ConvertTo<arc::mojom::BluetoothSdpAttributePtr>(sequenceBlueZ); | 417 ConvertTo<arc::mojom::BluetoothSdpAttributePtr>(sequenceBlueZ); |
| 418 | 418 |
| 419 EXPECT_EQ(bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE, | 419 EXPECT_EQ(bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 447 auto sequenceMojo = | 447 auto sequenceMojo = |
| 448 ConvertTo<arc::mojom::BluetoothSdpAttributePtr>(sequenceBlueZ); | 448 ConvertTo<arc::mojom::BluetoothSdpAttributePtr>(sequenceBlueZ); |
| 449 | 449 |
| 450 EXPECT_EQ(bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE, | 450 EXPECT_EQ(bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE, |
| 451 sequenceMojo->type); | 451 sequenceMojo->type); |
| 452 EXPECT_EQ((uint32_t)1, sequenceMojo->type_size); | 452 EXPECT_EQ((uint32_t)1, sequenceMojo->type_size); |
| 453 EXPECT_EQ(arc::kBluetoothSDPMaxDepth, GetDepthOfMojoAttribute(sequenceMojo)); | 453 EXPECT_EQ(arc::kBluetoothSDPMaxDepth, GetDepthOfMojoAttribute(sequenceMojo)); |
| 454 } | 454 } |
| 455 | 455 |
| 456 } // namespace mojo | 456 } // namespace mojo |
| OLD | NEW |