• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "device/bluetooth/bluetooth_device.h"
6 
7 #include "base/macros.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 
10 namespace device {
11 
TEST(BluetoothDeviceTest,CanonicalizeAddressFormat_AcceptsAllValidFormats)12 TEST(BluetoothDeviceTest, CanonicalizeAddressFormat_AcceptsAllValidFormats) {
13   // There are three valid separators (':', '-', and none).
14   // Case shouldn't matter.
15   const char* const kValidFormats[] = {
16     "1A:2B:3C:4D:5E:6F",
17     "1a:2B:3c:4D:5e:6F",
18     "1a:2b:3c:4d:5e:6f",
19     "1A-2B-3C-4D-5E-6F",
20     "1a-2B-3c-4D-5e-6F",
21     "1a-2b-3c-4d-5e-6f",
22     "1A2B3C4D5E6F",
23     "1a2B3c4D5e6F",
24     "1a2b3c4d5e6f",
25   };
26 
27   for (size_t i = 0; i < arraysize(kValidFormats); ++i) {
28     SCOPED_TRACE(std::string("Input format: '") + kValidFormats[i] + "'");
29     EXPECT_EQ("1A:2B:3C:4D:5E:6F",
30               BluetoothDevice::CanonicalizeAddress(kValidFormats[i]));
31   }
32 }
33 
TEST(BluetoothDeviceTest,CanonicalizeAddressFormat_RejectsInvalidFormats)34 TEST(BluetoothDeviceTest, CanonicalizeAddressFormat_RejectsInvalidFormats) {
35   const char* const kValidFormats[] = {
36     // Empty string.
37     "",
38     // Too short.
39     "1A:2B:3C:4D:5E",
40     // Too long.
41     "1A:2B:3C:4D:5E:6F:70",
42     // Missing a separator.
43     "1A:2B:3C:4D:5E6F",
44     // Mixed separators.
45     "1A:2B-3C:4D-5E:6F",
46     // Invalid characters.
47     "1A:2B-3C:4D-5E:6X",
48     // Separators in the wrong place.
49     "1:A2:B3:C4:D5:E6F",
50   };
51 
52   for (size_t i = 0; i < arraysize(kValidFormats); ++i) {
53     SCOPED_TRACE(std::string("Input format: '") + kValidFormats[i] + "'");
54     EXPECT_EQ(std::string(),
55               BluetoothDevice::CanonicalizeAddress(kValidFormats[i]));
56   }
57 }
58 
59 }  // namespace device
60