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

Side by Side Diff: device/bluetooth/bluetooth_utils_unittest.cc

Issue 11075006: Moved bluetooth adapter files to device/bluetooth/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #include <bluetooth/bluetooth.h>
6
7 #include "device/bluetooth/bluetooth_utils.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace bluetooth {
11
12 TEST(BluetoothUtilsTest, str2ba) {
13 bdaddr_t bluetooth_address;
14
15 EXPECT_TRUE(utils::str2ba("01:02:03:0A:10:A0", &bluetooth_address));
16 EXPECT_EQ(1, bluetooth_address.b[5]);
17 EXPECT_EQ(2, bluetooth_address.b[4]);
18 EXPECT_EQ(3, bluetooth_address.b[3]);
19 EXPECT_EQ(10, bluetooth_address.b[2]);
20 EXPECT_EQ(16, bluetooth_address.b[1]);
21 EXPECT_EQ(160, bluetooth_address.b[0]);
22
23 EXPECT_FALSE(utils::str2ba("obviously wrong", &bluetooth_address));
24 EXPECT_FALSE(utils::str2ba("00:00", &bluetooth_address));
25 EXPECT_FALSE(utils::str2ba("00:00:00:00:00:00:00", &bluetooth_address));
26 EXPECT_FALSE(utils::str2ba("01:02:03:0A:10:A0", NULL));
27 }
28
29 TEST(BluetoothUtilsTest, CanonicalUuid) {
30 // Does nothing for an already canonical UUID
31 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
32 utils::CanonicalUuid("00001101-0000-1000-8000-00805f9b34fb"));
33
34 // Rejects misformatted
35 EXPECT_EQ("", utils::CanonicalUuid("1101a"));
36 EXPECT_EQ("", utils::CanonicalUuid("Z101"));
37 EXPECT_EQ("", utils::CanonicalUuid("0000-1101"));
38 EXPECT_EQ("", utils::CanonicalUuid("0000Z101"));
39 EXPECT_EQ("", utils::CanonicalUuid("0001101-0000-1000-8000-00805f9b34fb"));
40 EXPECT_EQ("", utils::CanonicalUuid("Z0001101-0000-1000-8000-00805f9b34fb"));
41 EXPECT_EQ("", utils::CanonicalUuid("00001101 0000-1000-8000-00805f9b34fb"));
42 EXPECT_EQ("", utils::CanonicalUuid("00001101-0000:1000-8000-00805f9b34fb"));
43 EXPECT_EQ("", utils::CanonicalUuid("00001101-0000-1000;8000-00805f9b34fb"));
44 EXPECT_EQ("", utils::CanonicalUuid("00001101-0000-1000-8000000805f9b34fb"));
45
46 // Lower case
47 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
48 utils::CanonicalUuid("00001101-0000-1000-8000-00805F9B34FB"));
49
50 // Short to full
51 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
52 utils::CanonicalUuid("1101"));
53 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
54 utils::CanonicalUuid("0x1101"));
55 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
56 utils::CanonicalUuid("00001101"));
57 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
58 utils::CanonicalUuid("0x00001101"));
59
60 // No 0x prefix on 36 character
61 EXPECT_EQ("", utils::CanonicalUuid("0x00001101-0000-1000-8000-00805f9b34fb"));
62 }
63
64 } // namespace bluetooth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698