OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #if defined(OS_CHROMEOS) |
5 #include <bluetooth/bluetooth.h> | 6 #include <bluetooth/bluetooth.h> |
| 7 #endif |
6 | 8 |
7 #include "chrome/browser/chromeos/bluetooth/bluetooth_utils.h" | 9 #include "device/bluetooth/bluetooth_utils.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
9 | 11 |
10 namespace chromeos { | 12 namespace device { |
11 | 13 |
| 14 #if defined(OS_CHROMEOS) |
12 TEST(BluetoothUtilsTest, str2ba) { | 15 TEST(BluetoothUtilsTest, str2ba) { |
13 bdaddr_t bluetooth_address; | 16 bdaddr_t bluetooth_address; |
14 | 17 |
15 EXPECT_TRUE(bluetooth_utils::str2ba("01:02:03:0A:10:A0", &bluetooth_address)); | 18 EXPECT_TRUE(bluetooth_utils::str2ba("01:02:03:0A:10:A0", &bluetooth_address)); |
16 EXPECT_EQ(1, bluetooth_address.b[5]); | 19 EXPECT_EQ(1, bluetooth_address.b[5]); |
17 EXPECT_EQ(2, bluetooth_address.b[4]); | 20 EXPECT_EQ(2, bluetooth_address.b[4]); |
18 EXPECT_EQ(3, bluetooth_address.b[3]); | 21 EXPECT_EQ(3, bluetooth_address.b[3]); |
19 EXPECT_EQ(10, bluetooth_address.b[2]); | 22 EXPECT_EQ(10, bluetooth_address.b[2]); |
20 EXPECT_EQ(16, bluetooth_address.b[1]); | 23 EXPECT_EQ(16, bluetooth_address.b[1]); |
21 EXPECT_EQ(160, bluetooth_address.b[0]); | 24 EXPECT_EQ(160, bluetooth_address.b[0]); |
22 | 25 |
23 EXPECT_FALSE(bluetooth_utils::str2ba("obviously wrong", &bluetooth_address)); | 26 EXPECT_FALSE(bluetooth_utils::str2ba("obviously wrong", &bluetooth_address)); |
24 EXPECT_FALSE(bluetooth_utils::str2ba("00:00", &bluetooth_address)); | 27 EXPECT_FALSE(bluetooth_utils::str2ba("00:00", &bluetooth_address)); |
25 EXPECT_FALSE(bluetooth_utils::str2ba("00:00:00:00:00:00:00", | 28 EXPECT_FALSE( |
26 &bluetooth_address)); | 29 bluetooth_utils::str2ba("00:00:00:00:00:00:00", &bluetooth_address)); |
27 EXPECT_FALSE(bluetooth_utils::str2ba("01:02:03:0A:10:A0", NULL)); | 30 EXPECT_FALSE(bluetooth_utils::str2ba("01:02:03:0A:10:A0", NULL)); |
28 } | 31 } |
| 32 #endif |
29 | 33 |
30 TEST(BluetoothUtilsTest, CanonicalUuid) { | 34 TEST(BluetoothUtilsTest, CanonicalUuid) { |
31 // Does nothing for an already canonical UUID | 35 // Does nothing for an already canonical UUID |
32 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", | 36 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", |
33 bluetooth_utils::CanonicalUuid("00001101-0000-1000-8000-00805f9b34fb")); | 37 bluetooth_utils::CanonicalUuid("00001101-0000-1000-8000-00805f9b34fb")); |
34 | 38 |
35 // Rejects misformatted | 39 // Rejects misformatted |
36 EXPECT_EQ("", bluetooth_utils::CanonicalUuid("1101a")); | 40 EXPECT_EQ("", bluetooth_utils::CanonicalUuid("1101a")); |
37 EXPECT_EQ("", bluetooth_utils::CanonicalUuid("Z101")); | 41 EXPECT_EQ("", bluetooth_utils::CanonicalUuid("Z101")); |
38 EXPECT_EQ("", bluetooth_utils::CanonicalUuid("0000-1101")); | 42 EXPECT_EQ("", bluetooth_utils::CanonicalUuid("0000-1101")); |
(...skipping 23 matching lines...) Expand all Loading... |
62 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", | 66 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", |
63 bluetooth_utils::CanonicalUuid("00001101")); | 67 bluetooth_utils::CanonicalUuid("00001101")); |
64 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", | 68 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", |
65 bluetooth_utils::CanonicalUuid("0x00001101")); | 69 bluetooth_utils::CanonicalUuid("0x00001101")); |
66 | 70 |
67 // No 0x prefix on 36 character | 71 // No 0x prefix on 36 character |
68 EXPECT_EQ("", | 72 EXPECT_EQ("", |
69 bluetooth_utils::CanonicalUuid("0x00001101-0000-1000-8000-00805f9b34fb")); | 73 bluetooth_utils::CanonicalUuid("0x00001101-0000-1000-8000-00805f9b34fb")); |
70 } | 74 } |
71 | 75 |
72 } // namespace chromeos | 76 } // namespace device |
OLD | NEW |