Add JSON check in tools/perf presubmit script.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_utils_unittest.cc
blob07c63b5c001ec00f401ad2c2ea95413e57405acb
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.
5 #include "base/basictypes.h"
6 #include "device/bluetooth/bluetooth_utils.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace device {
10 namespace bluetooth_utils {
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"));
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"));
29 // Lower case
30 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
31 CanonicalUuid("00001101-0000-1000-8000-00805F9B34FB"));
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"));
43 // No 0x prefix on 36 character
44 EXPECT_EQ("", CanonicalUuid("0x00001101-0000-1000-8000-00805f9b34fb"));
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";
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());
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());
67 EXPECT_NE(uuid0, uuid1);
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());
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());
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());
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());
99 // uuid4, uuid5, and uuid1 are equivalent.
100 EXPECT_EQ(uuid4, uuid5);
101 EXPECT_EQ(uuid1, uuid4);
102 EXPECT_EQ(uuid1, uuid5);
105 } // namespace bluetooth_utils
106 } // namespace device