OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/macros.h" |
5 #include "device/bluetooth/bluetooth_uuid.h" | 6 #include "device/bluetooth/bluetooth_uuid.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
7 | 8 |
8 namespace device { | 9 namespace device { |
9 | 10 |
10 TEST(BluetoothUUIDTest, MainTest) { | 11 TEST(BluetoothUUIDTest, BluetoothUUID) { |
11 const char kValid128Bit0[] = "12345678-1234-5678-9abc-def123456789"; | 12 const char kValid128Bit0[] = "12345678-1234-5678-9abc-def123456789"; |
12 const char kValid128Bit1[] = "00001101-0000-1000-8000-00805f9b34fb"; | 13 const char kValid128Bit1[] = "00001101-0000-1000-8000-00805f9b34fb"; |
13 const char kInvalid36Char0[] = "1234567-1234-5678-9abc-def123456789"; | 14 const char kInvalid36Char0[] = "1234567-1234-5678-9abc-def123456789"; |
14 const char kInvalid36Char1[] = "0x00001101-0000-1000-8000-00805f9b34fb"; | 15 const char kInvalid36Char1[] = "0x00001101-0000-1000-8000-00805f9b34fb"; |
15 const char kInvalid4Char[] = "Z101"; | 16 const char kInvalid4Char[] = "Z101"; |
16 const char kValid16Bit[] = "0x1101"; | 17 const char kValid16Bit[] = "0x1101"; |
17 const char kValid32Bit[] = "00001101"; | 18 const char kValid32Bit[] = "00001101"; |
18 | 19 |
19 // Valid 128-bit custom UUID. | 20 // Valid 128-bit custom UUID. |
20 BluetoothUUID uuid0(kValid128Bit0); | 21 BluetoothUUID uuid0(kValid128Bit0); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 EXPECT_NE(uuid6.value(), uuid6.canonical_value()); | 67 EXPECT_NE(uuid6.value(), uuid6.canonical_value()); |
67 EXPECT_EQ("00001101", uuid6.value()); | 68 EXPECT_EQ("00001101", uuid6.value()); |
68 EXPECT_EQ(kValid128Bit1, uuid6.canonical_value()); | 69 EXPECT_EQ(kValid128Bit1, uuid6.canonical_value()); |
69 | 70 |
70 // uuid5, uuid6, and uuid1 are equivalent. | 71 // uuid5, uuid6, and uuid1 are equivalent. |
71 EXPECT_EQ(uuid5, uuid6); | 72 EXPECT_EQ(uuid5, uuid6); |
72 EXPECT_EQ(uuid1, uuid5); | 73 EXPECT_EQ(uuid1, uuid5); |
73 EXPECT_EQ(uuid1, uuid6); | 74 EXPECT_EQ(uuid1, uuid6); |
74 } | 75 } |
75 | 76 |
| 77 // Verify that UUIDs are parsed case-insensitively |
| 78 TEST(BluetoothUUIDTest, BluetoothUUID_CaseInsensitive) { |
| 79 const char k16Bit[] = "1abc"; |
| 80 const char k32Bit[] = "00001abc"; |
| 81 const char k128Bit[] = "00001abc-0000-1000-8000-00805f9b34fb"; |
| 82 |
| 83 struct TestCase { |
| 84 const std::string input_uuid; |
| 85 const std::string expected_value; |
| 86 } test_cases[] = { |
| 87 { "1abc", k16Bit }, |
| 88 { "1ABC", k16Bit }, |
| 89 { "1aBc", k16Bit }, |
| 90 { "00001abc", k32Bit }, |
| 91 { "00001ABC", k32Bit }, |
| 92 { "00001aBc", k32Bit }, |
| 93 { "00001abc-0000-1000-8000-00805f9b34fb", k128Bit }, |
| 94 { "00001ABC-0000-1000-8000-00805F9B34FB", k128Bit }, |
| 95 { "00001aBc-0000-1000-8000-00805F9b34fB", k128Bit }, |
| 96 }; |
| 97 |
| 98 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
| 99 SCOPED_TRACE("Input UUID: " + test_cases[i].input_uuid); |
| 100 BluetoothUUID uuid(test_cases[i].input_uuid); |
| 101 EXPECT_TRUE(uuid.IsValid()); |
| 102 EXPECT_EQ(test_cases[i].expected_value, uuid.value()); |
| 103 EXPECT_EQ(k128Bit, uuid.canonical_value()); |
| 104 } |
| 105 } |
| 106 |
76 } // namespace device | 107 } // namespace device |
OLD | NEW |