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

Unified Diff: device/bluetooth/bluetooth_device_unittest.cc

Issue 288903003: [Bluetooth] Standardize Bluetooth device address format to XX:XX:XX:XX:XX:XX. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ChromeOS tests too Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/bluetooth/bluetooth_device_mac.mm ('k') | device/bluetooth/bluetooth_device_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_device_unittest.cc
diff --git a/device/bluetooth/bluetooth_device_unittest.cc b/device/bluetooth/bluetooth_device_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7fb505925368ef7368e882e42b5168d93a17559d
--- /dev/null
+++ b/device/bluetooth/bluetooth_device_unittest.cc
@@ -0,0 +1,59 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "device/bluetooth/bluetooth_device.h"
+
+#include "base/macros.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace device {
+
+TEST(BluetoothDeviceTest, CanonicalizeAddressFormat_AcceptsAllValidFormats) {
+ // There are three valid separators (':', '-', and none).
+ // Case shouldn't matter.
+ const char* const kValidFormats[] = {
+ "1A:2B:3C:4D:5E:6F",
+ "1a:2B:3c:4D:5e:6F",
+ "1a:2b:3c:4d:5e:6f",
+ "1A-2B-3C-4D-5E-6F",
+ "1a-2B-3c-4D-5e-6F",
+ "1a-2b-3c-4d-5e-6f",
+ "1A2B3C4D5E6F",
+ "1a2B3c4D5e6F",
+ "1a2b3c4d5e6f",
+ };
+
+ for (size_t i = 0; i < arraysize(kValidFormats); ++i) {
+ SCOPED_TRACE(std::string("Input format: '") + kValidFormats[i] + "'");
+ EXPECT_EQ("1A:2B:3C:4D:5E:6F",
+ BluetoothDevice::CanonicalizeAddress(kValidFormats[i]));
+ }
+}
+
+TEST(BluetoothDeviceTest, CanonicalizeAddressFormat_RejectsInvalidFormats) {
+ const char* const kValidFormats[] = {
+ // Empty string.
+ "",
+ // Too short.
+ "1A:2B:3C:4D:5E",
+ // Too long.
+ "1A:2B:3C:4D:5E:6F:70",
+ // Missing a separator.
+ "1A:2B:3C:4D:5E6F",
+ // Mixed separators.
+ "1A:2B-3C:4D-5E:6F",
+ // Invalid characters.
+ "1A:2B-3C:4D-5E:6X",
+ // Separators in the wrong place.
+ "1:A2:B3:C4:D5:E6F",
+ };
+
+ for (size_t i = 0; i < arraysize(kValidFormats); ++i) {
+ SCOPED_TRACE(std::string("Input format: '") + kValidFormats[i] + "'");
+ EXPECT_EQ(std::string(),
+ BluetoothDevice::CanonicalizeAddress(kValidFormats[i]));
+ }
+}
+
+} // namespace device
« no previous file with comments | « device/bluetooth/bluetooth_device_mac.mm ('k') | device/bluetooth/bluetooth_device_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698