blob: 46d5f34a848d9f3c97f848e448390d2a52e4644d [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00005#include "base/basictypes.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +00006#include "device/bluetooth/bluetooth_utils.h"
7#include "testing/gtest/include/gtest/gtest.h"
8
9namespace device {
10
Torne (Richard Coles)58218062012-11-14 11:43:16 +000011TEST(BluetoothUtilsTest, CanonicalUuid) {
12 // Does nothing for an already canonical UUID
13 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
14 bluetooth_utils::CanonicalUuid("00001101-0000-1000-8000-00805f9b34fb"));
15
16 // Rejects misformatted
17 EXPECT_EQ("", bluetooth_utils::CanonicalUuid("1101a"));
18 EXPECT_EQ("", bluetooth_utils::CanonicalUuid("Z101"));
19 EXPECT_EQ("", bluetooth_utils::CanonicalUuid("0000-1101"));
20 EXPECT_EQ("", bluetooth_utils::CanonicalUuid("0000Z101"));
21 EXPECT_EQ("",
22 bluetooth_utils::CanonicalUuid("0001101-0000-1000-8000-00805f9b34fb"));
23 EXPECT_EQ("",
24 bluetooth_utils::CanonicalUuid("Z0001101-0000-1000-8000-00805f9b34fb"));
25 EXPECT_EQ("",
26 bluetooth_utils::CanonicalUuid("00001101 0000-1000-8000-00805f9b34fb"));
27 EXPECT_EQ("",
28 bluetooth_utils::CanonicalUuid("00001101-0000:1000-8000-00805f9b34fb"));
29 EXPECT_EQ("",
30 bluetooth_utils::CanonicalUuid("00001101-0000-1000;8000-00805f9b34fb"));
31 EXPECT_EQ("",
32 bluetooth_utils::CanonicalUuid("00001101-0000-1000-8000000805f9b34fb"));
33
34 // Lower case
35 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
36 bluetooth_utils::CanonicalUuid("00001101-0000-1000-8000-00805F9B34FB"));
37
38 // Short to full
39 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
40 bluetooth_utils::CanonicalUuid("1101"));
41 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
42 bluetooth_utils::CanonicalUuid("0x1101"));
43 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
44 bluetooth_utils::CanonicalUuid("00001101"));
45 EXPECT_EQ("00001101-0000-1000-8000-00805f9b34fb",
46 bluetooth_utils::CanonicalUuid("0x00001101"));
47
48 // No 0x prefix on 36 character
49 EXPECT_EQ("",
50 bluetooth_utils::CanonicalUuid("0x00001101-0000-1000-8000-00805f9b34fb"));
51}
52
53} // namespace device