Fix build break
[chromium-blink-merge.git] / device / bluetooth / bluetooth_service_record_chromeos_unittest.cc
blobdf4bab72d021a3da9fc25c2bdd912645322a4e3c
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 <bluetooth/bluetooth.h>
7 #include <string>
9 #include "base/base_paths.h"
10 #include "base/basictypes.h"
11 #include "base/file_util.h"
12 #include "base/files/file_path.h"
13 #include "base/path_service.h"
14 #include "device/bluetooth/bluetooth_service_record_chromeos.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace {
19 static const char* kAddress = "01:02:03:0A:10:A0";
20 static const char* kCustomUuid = "01234567-89ab-cdef-0123-456789abcdef";
21 static const char* kSerialUuid = "00001101-0000-1000-8000-00805f9b34fb";
23 } // namespace
25 namespace chromeos {
27 class BluetoothServiceRecordChromeOSTest : public testing::Test {
28 public:
29 base::FilePath GetTestDataFilePath(const char* file) {
30 base::FilePath path;
31 PathService::Get(base::DIR_SOURCE_ROOT, &path);
32 path = path.AppendASCII("device");
33 path = path.AppendASCII("test");
34 path = path.AppendASCII("data");
35 path = path.AppendASCII("bluetooth");
36 path = path.AppendASCII(file);
37 return path;
41 TEST_F(BluetoothServiceRecordChromeOSTest, RfcommService) {
42 std::string xml_data;
43 file_util::ReadFileToString(GetTestDataFilePath("rfcomm.xml"), &xml_data);
45 BluetoothServiceRecordChromeOS service_record(kAddress, xml_data);
46 EXPECT_EQ(kAddress, service_record.address());
47 EXPECT_EQ("Headset Audio Gateway", service_record.name());
48 EXPECT_TRUE(service_record.SupportsRfcomm());
49 EXPECT_EQ((uint8)12, service_record.rfcomm_channel());
50 EXPECT_EQ(kCustomUuid, service_record.uuid());
53 TEST_F(BluetoothServiceRecordChromeOSTest, ShortUuid) {
54 std::string xml_data;
55 file_util::ReadFileToString(GetTestDataFilePath("short_uuid.xml"), &xml_data);
56 BluetoothServiceRecordChromeOS short_uuid_service_record(kAddress, xml_data);
57 EXPECT_EQ(kSerialUuid, short_uuid_service_record.uuid());
59 xml_data.clear();
60 file_util::ReadFileToString(
61 GetTestDataFilePath("medium_uuid.xml"), &xml_data);
62 BluetoothServiceRecordChromeOS medium_uuid_service_record(kAddress, xml_data);
63 EXPECT_EQ(kSerialUuid, medium_uuid_service_record.uuid());
66 TEST_F(BluetoothServiceRecordChromeOSTest, CleanUuid) {
67 std::string xml_data;
68 file_util::ReadFileToString(GetTestDataFilePath("uppercase_uuid.xml"),
69 &xml_data);
70 BluetoothServiceRecordChromeOS service_record(kAddress, xml_data);
71 EXPECT_EQ(kCustomUuid, service_record.uuid());
73 xml_data.clear();
74 file_util::ReadFileToString(GetTestDataFilePath("invalid_uuid.xml"),
75 &xml_data);
76 BluetoothServiceRecordChromeOS invalid_service_record(kAddress, xml_data);
77 EXPECT_EQ("", invalid_service_record.uuid());
80 TEST_F(BluetoothServiceRecordChromeOSTest, BluetoothAddress) {
81 BluetoothServiceRecordChromeOS service_record(kAddress, "");
82 bdaddr_t bluetooth_address;
83 service_record.GetBluetoothAddress(&bluetooth_address);
84 EXPECT_EQ(1, bluetooth_address.b[5]);
85 EXPECT_EQ(2, bluetooth_address.b[4]);
86 EXPECT_EQ(3, bluetooth_address.b[3]);
87 EXPECT_EQ(10, bluetooth_address.b[2]);
88 EXPECT_EQ(16, bluetooth_address.b[1]);
89 EXPECT_EQ(160, bluetooth_address.b[0]);
92 } // namespace chromeos