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

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

Issue 224893002: device/bluetooth: Rename device::bluetooth_utils::UUID to device::BluetoothUUID (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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
« no previous file with comments | « device/bluetooth/bluetooth_utils.cc ('k') | device/bluetooth/bluetooth_uuid.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/basictypes.h"
6 #include "device/bluetooth/bluetooth_utils.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace device {
10 namespace bluetooth_utils {
11
12 TEST(BluetoothUtilsTest, CanonicalUuid) {
13 // Does nothing for an already canonical UUID
14 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
15 CanonicalUuid("00001101-0000-1000-8000-00805f9b34fb"));
16
17 // Rejects misformatted
18 EXPECT_EQ("", CanonicalUuid("1101a"));
19 EXPECT_EQ("", CanonicalUuid("Z101"));
20 EXPECT_EQ("", CanonicalUuid("0000-1101"));
21 EXPECT_EQ("", CanonicalUuid("0000Z101"));
22 EXPECT_EQ("", CanonicalUuid("0001101-0000-1000-8000-00805f9b34fb"));
23 EXPECT_EQ("", CanonicalUuid("Z0001101-0000-1000-8000-00805f9b34fb"));
24 EXPECT_EQ("", CanonicalUuid("00001101 0000-1000-8000-00805f9b34fb"));
25 EXPECT_EQ("", CanonicalUuid("00001101-0000:1000-8000-00805f9b34fb"));
26 EXPECT_EQ("", CanonicalUuid("00001101-0000-1000;8000-00805f9b34fb"));
27 EXPECT_EQ("", CanonicalUuid("00001101-0000-1000-8000000805f9b34fb"));
28
29 // Lower case
30 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
31 CanonicalUuid("00001101-0000-1000-8000-00805F9B34FB"));
32
33 // Short to full
34 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
35 CanonicalUuid("1101"));
36 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
37 CanonicalUuid("0x1101"));
38 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
39 CanonicalUuid("00001101"));
40 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
41 CanonicalUuid("0x00001101"));
42
43 // No 0x prefix on 36 character
44 EXPECT_EQ("", CanonicalUuid("0x00001101-0000-1000-8000-00805f9b34fb"));
45 }
46
47 TEST(BluetoothUtilsTest, UUID) {
48 const char kValid128Bit0[] = "12345678-1234-5678-9abc-def123456789";
49 const char kValid128Bit1[] = "00001101-0000-1000-8000-00805f9b34fb";
50 const char kInvalid36Char[] = "1234567-1234-5678-9abc-def123456789";
51 const char kInvalid4Char[] = "Z101";
52 const char kValid16Bit[] = "0x1101";
53 const char kValid32Bit[] = "00001101";
54
55 // Valid 128-bit custom UUID.
56 UUID uuid0(kValid128Bit0);
57 EXPECT_TRUE(uuid0.IsValid());
58 EXPECT_EQ(UUID::kFormat128Bit, uuid0.format());
59 EXPECT_EQ(uuid0.value(), uuid0.canonical_value());
60
61 // Valid 128-bit UUID.
62 UUID uuid1(kValid128Bit1);
63 EXPECT_TRUE(uuid1.IsValid());
64 EXPECT_EQ(UUID::kFormat128Bit, uuid1.format());
65 EXPECT_EQ(uuid1.value(), uuid1.canonical_value());
66
67 EXPECT_NE(uuid0, uuid1);
68
69 // Invalid 128-bit UUID.
70 UUID uuid2(kInvalid36Char);
71 EXPECT_FALSE(uuid2.IsValid());
72 EXPECT_EQ(UUID::kFormatInvalid, uuid2.format());
73 EXPECT_TRUE(uuid2.value().empty());
74 EXPECT_TRUE(uuid2.canonical_value().empty());
75
76 // Invalid 16-bit UUID.
77 UUID uuid3(kInvalid4Char);
78 EXPECT_FALSE(uuid3.IsValid());
79 EXPECT_EQ(UUID::kFormatInvalid, uuid3.format());
80 EXPECT_TRUE(uuid3.value().empty());
81 EXPECT_TRUE(uuid3.canonical_value().empty());
82
83 // Valid 16-bit UUID.
84 UUID uuid4(kValid16Bit);
85 EXPECT_TRUE(uuid4.IsValid());
86 EXPECT_EQ(UUID::kFormat16Bit, uuid4.format());
87 EXPECT_NE(uuid4.value(), uuid4.canonical_value());
88 EXPECT_EQ("1101", uuid4.value());
89 EXPECT_EQ(kValid128Bit1, uuid4.canonical_value());
90
91 // Valid 32-bit UUID.
92 UUID uuid5(kValid32Bit);
93 EXPECT_TRUE(uuid5.IsValid());
94 EXPECT_EQ(UUID::kFormat32Bit, uuid5.format());
95 EXPECT_NE(uuid5.value(), uuid5.canonical_value());
96 EXPECT_EQ("00001101", uuid5.value());
97 EXPECT_EQ(kValid128Bit1, uuid5.canonical_value());
98
99 // uuid4, uuid5, and uuid1 are equivalent.
100 EXPECT_EQ(uuid4, uuid5);
101 EXPECT_EQ(uuid1, uuid4);
102 EXPECT_EQ(uuid1, uuid5);
103 }
104
105 } // namespace bluetooth_utils
106 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_utils.cc ('k') | device/bluetooth/bluetooth_uuid.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698