OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #if defined(OS_CHROMEOS) |
| 6 #include <bluetooth/bluetooth.h> |
| 7 #endif |
| 8 |
| 9 #include "device/bluetooth/bluetooth_utils.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace bluetooth { |
| 13 |
| 14 #if defined(OS_CHROMEOS) |
| 15 TEST(BluetoothUtilsTest, str2ba) { |
| 16 bdaddr_t bluetooth_address; |
| 17 |
| 18 EXPECT_TRUE(utils::str2ba("01:02:03:0A:10:A0", &bluetooth_address)); |
| 19 EXPECT_EQ(1, bluetooth_address.b[5]); |
| 20 EXPECT_EQ(2, bluetooth_address.b[4]); |
| 21 EXPECT_EQ(3, bluetooth_address.b[3]); |
| 22 EXPECT_EQ(10, bluetooth_address.b[2]); |
| 23 EXPECT_EQ(16, bluetooth_address.b[1]); |
| 24 EXPECT_EQ(160, bluetooth_address.b[0]); |
| 25 |
| 26 EXPECT_FALSE(utils::str2ba("obviously wrong", &bluetooth_address)); |
| 27 EXPECT_FALSE(utils::str2ba("00:00", &bluetooth_address)); |
| 28 EXPECT_FALSE(utils::str2ba("00:00:00:00:00:00:00", &bluetooth_address)); |
| 29 EXPECT_FALSE(utils::str2ba("01:02:03:0A:10:A0", NULL)); |
| 30 } |
| 31 #endif |
| 32 |
| 33 TEST(BluetoothUtilsTest, CanonicalUuid) { |
| 34 // Does nothing for an already canonical UUID |
| 35 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", |
| 36 utils::CanonicalUuid("00001101-0000-1000-8000-00805f9b34fb")); |
| 37 |
| 38 // Rejects misformatted |
| 39 EXPECT_EQ("", utils::CanonicalUuid("1101a")); |
| 40 EXPECT_EQ("", utils::CanonicalUuid("Z101")); |
| 41 EXPECT_EQ("", utils::CanonicalUuid("0000-1101")); |
| 42 EXPECT_EQ("", utils::CanonicalUuid("0000Z101")); |
| 43 EXPECT_EQ("", utils::CanonicalUuid("0001101-0000-1000-8000-00805f9b34fb")); |
| 44 EXPECT_EQ("", utils::CanonicalUuid("Z0001101-0000-1000-8000-00805f9b34fb")); |
| 45 EXPECT_EQ("", utils::CanonicalUuid("00001101 0000-1000-8000-00805f9b34fb")); |
| 46 EXPECT_EQ("", utils::CanonicalUuid("00001101-0000:1000-8000-00805f9b34fb")); |
| 47 EXPECT_EQ("", utils::CanonicalUuid("00001101-0000-1000;8000-00805f9b34fb")); |
| 48 EXPECT_EQ("", utils::CanonicalUuid("00001101-0000-1000-8000000805f9b34fb")); |
| 49 |
| 50 // Lower case |
| 51 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", |
| 52 utils::CanonicalUuid("00001101-0000-1000-8000-00805F9B34FB")); |
| 53 |
| 54 // Short to full |
| 55 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", |
| 56 utils::CanonicalUuid("1101")); |
| 57 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", |
| 58 utils::CanonicalUuid("0x1101")); |
| 59 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", |
| 60 utils::CanonicalUuid("00001101")); |
| 61 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb", |
| 62 utils::CanonicalUuid("0x00001101")); |
| 63 |
| 64 // No 0x prefix on 36 character |
| 65 EXPECT_EQ("", utils::CanonicalUuid("0x00001101-0000-1000-8000-00805f9b34fb")); |
| 66 } |
| 67 |
| 68 } // namespace bluetooth |
OLD | NEW |