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

Side by Side Diff: components/arc/bluetooth/bluetooth_type_converters_unittest.cc

Issue 2046283003: Add unit test for ArcBluetoothBridge and TypeConverter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bt
Patch Set: Range check in type_converters Created 4 years, 4 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/arc/bluetooth/bluetooth_type_converters.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "device/bluetooth/bluetooth_gatt_service.h"
11 #include "device/bluetooth/bluetooth_uuid.h"
12 #include "mojo/public/cpp/bindings/array.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace {
16 constexpr char kAddressStr[] = "1A:2B:3C:4D:5E:6F";
17 constexpr char kInvalidAddressStr[] = "00:00:00:00:00:00";
18 constexpr uint8_t kAddressArray[] = {0x1a, 0x2b, 0x3c, 0x4d, 0x5e, 0x6f};
19 constexpr size_t kAddressSize = 6;
20 constexpr char kUuidStr[] = "12345678-1234-5678-9abc-def123456789";
21 constexpr uint8_t kUuidArray[] = {0x12, 0x34, 0x56, 0x78, 0x12, 0x34,
22 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf1,
23 0x23, 0x45, 0x67, 0x89};
24 constexpr size_t kUuidSize = 16;
25 constexpr uint8_t kFillerByte = 0x79;
26 } // namespace
27
28 namespace mojo {
29
30 TEST(BluetoothTypeConvertorTest, ConvertMojoBluetoothAddressFromString) {
31 arc::mojom::BluetoothAddressPtr addressMojo =
32 arc::mojom::BluetoothAddress::From(std::string(kAddressStr));
33 EXPECT_EQ(kAddressSize, addressMojo->address.size());
34 for (size_t i = 0; i < kAddressSize; i++) {
35 EXPECT_EQ(kAddressArray[i], addressMojo->address[i]);
36 }
37 }
38
39 TEST(BluetoothTypeConvertorTest, ConvertMojoBluetoothAddressToString) {
40 arc::mojom::BluetoothAddressPtr addressMojo =
41 arc::mojom::BluetoothAddress::New();
42 for (size_t i = 0; i < kAddressSize - 1; i++) {
43 addressMojo->address.push_back(kAddressArray[i]);
44 }
45 EXPECT_EQ(std::string(kInvalidAddressStr), addressMojo->To<std::string>());
46
47 addressMojo->address.push_back(kAddressArray[kAddressSize - 1]);
48 EXPECT_EQ(std::string(kAddressStr), addressMojo->To<std::string>());
49
50 addressMojo->address.push_back(kFillerByte);
51
52 EXPECT_EQ(std::string(kInvalidAddressStr), addressMojo->To<std::string>());
53 }
54
55 TEST(BluetoothTypeConvertorTest,
56 ConvertMojoBluetoothUUIDFromDeviceBluetoothUUID) {
57 device::BluetoothUUID uuidDevice((std::string(kUuidStr)));
58 arc::mojom::BluetoothUUIDPtr uuidMojo =
59 arc::mojom::BluetoothUUID::From(uuidDevice);
60 EXPECT_EQ(kUuidSize, uuidMojo->uuid.size());
61 for (size_t i = 0; i < kUuidSize; i++) {
62 EXPECT_EQ(kUuidArray[i], uuidMojo->uuid[i]);
63 }
64 }
65
66 TEST(BluetoothTypeConvertorTest,
67 ConvertMojoBluetoothUUIDToDeviceBluetoothUUID) {
68 arc::mojom::BluetoothUUIDPtr uuidMojo = arc::mojom::BluetoothUUID::New();
69 for (size_t i = 0; i < kUuidSize - 1; i++) {
70 uuidMojo->uuid.push_back(kUuidArray[i]);
71 }
72 EXPECT_FALSE(uuidMojo.To<device::BluetoothUUID>().IsValid());
73
74 uuidMojo->uuid.push_back(kUuidArray[kUuidSize - 1]);
75 EXPECT_TRUE(uuidMojo.To<device::BluetoothUUID>().IsValid());
76 EXPECT_EQ(std::string(kUuidStr),
77 uuidMojo.To<device::BluetoothUUID>().canonical_value());
78
79 uuidMojo->uuid.push_back(kFillerByte);
80 EXPECT_FALSE(uuidMojo.To<device::BluetoothUUID>().IsValid());
81 }
82
83 } // namespace mojo
OLDNEW
« no previous file with comments | « components/arc/bluetooth/bluetooth_type_converters.cc ('k') | components/arc/test/fake_bluetooth_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698