| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/base_paths.h" |
| 8 #include "base/basictypes.h" |
| 7 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 10 #include "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h" | 12 #include "device/bluetooth/bluetooth_service_record.h" |
| 11 #include "chrome/common/chrome_paths.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 static const char* kAddress = "01:02:03:04:05:06"; | 17 static const char* kAddress = "01:02:03:04:05:06"; |
| 17 static const char* kCustomUuid = "01234567-89ab-cdef-0123-456789abcdef"; | 18 static const char* kCustomUuid = "01234567-89ab-cdef-0123-456789abcdef"; |
| 18 static const char* kSerialUuid = "00001101-0000-1000-8000-00805f9b34fb"; | 19 static const char* kSerialUuid = "00001101-0000-1000-8000-00805f9b34fb"; |
| 19 | 20 |
| 20 } // namespace | 21 } // namespace |
| 21 | 22 |
| 22 namespace chromeos { | 23 namespace device { |
| 23 | 24 |
| 24 class BluetoothServiceRecordTest : public testing::Test { | 25 class BluetoothServiceRecordTest : public testing::Test { |
| 25 public: | 26 public: |
| 26 FilePath GetTestDataFilePath(const char* file) { | 27 FilePath GetTestDataFilePath(const char* file) { |
| 27 FilePath path; | 28 FilePath path; |
| 28 PathService::Get(chrome::DIR_TEST_DATA, &path); | 29 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 29 path = path.AppendASCII("chromeos"); | 30 path = path.AppendASCII("device"); |
| 31 path = path.AppendASCII("test"); |
| 32 path = path.AppendASCII("data"); |
| 30 path = path.AppendASCII("bluetooth"); | 33 path = path.AppendASCII("bluetooth"); |
| 31 path = path.AppendASCII(file); | 34 path = path.AppendASCII(file); |
| 32 return path; | 35 return path; |
| 33 } | 36 } |
| 34 }; | 37 }; |
| 35 | 38 |
| 36 TEST_F(BluetoothServiceRecordTest, RfcommService) { | 39 TEST_F(BluetoothServiceRecordTest, RfcommService) { |
| 37 std::string xml_data; | 40 std::string xml_data; |
| 38 file_util::ReadFileToString(GetTestDataFilePath("rfcomm.xml"), &xml_data); | 41 file_util::ReadFileToString(GetTestDataFilePath("rfcomm.xml"), &xml_data); |
| 39 | 42 |
| 40 BluetoothServiceRecord service_record(kAddress, xml_data); | 43 BluetoothServiceRecord service_record(kAddress, xml_data); |
| 41 EXPECT_EQ(kAddress, service_record.address()); | 44 EXPECT_EQ(kAddress, service_record.address()); |
| 42 EXPECT_EQ("Headset Audio Gateway", service_record.name()); | 45 EXPECT_EQ("Headset Audio Gateway", service_record.name()); |
| 43 EXPECT_TRUE(service_record.SupportsRfcomm()); | 46 EXPECT_TRUE(service_record.SupportsRfcomm()); |
| 44 EXPECT_EQ((uint8_t)12, service_record.rfcomm_channel()); | 47 EXPECT_EQ((uint8)12, service_record.rfcomm_channel()); |
| 45 EXPECT_EQ(kCustomUuid, service_record.uuid()); | 48 EXPECT_EQ(kCustomUuid, service_record.uuid()); |
| 46 } | 49 } |
| 47 | 50 |
| 48 TEST_F(BluetoothServiceRecordTest, ShortUuid) { | 51 TEST_F(BluetoothServiceRecordTest, ShortUuid) { |
| 49 std::string xml_data; | 52 std::string xml_data; |
| 50 file_util::ReadFileToString(GetTestDataFilePath("short_uuid.xml"), &xml_data); | 53 file_util::ReadFileToString(GetTestDataFilePath("short_uuid.xml"), &xml_data); |
| 51 BluetoothServiceRecord short_uuid_service_record(kAddress, xml_data); | 54 BluetoothServiceRecord short_uuid_service_record(kAddress, xml_data); |
| 52 EXPECT_EQ(kSerialUuid, short_uuid_service_record.uuid()); | 55 EXPECT_EQ(kSerialUuid, short_uuid_service_record.uuid()); |
| 53 | 56 |
| 54 xml_data.clear(); | 57 xml_data.clear(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 65 BluetoothServiceRecord service_record(kAddress, xml_data); | 68 BluetoothServiceRecord service_record(kAddress, xml_data); |
| 66 EXPECT_EQ(kCustomUuid, service_record.uuid()); | 69 EXPECT_EQ(kCustomUuid, service_record.uuid()); |
| 67 | 70 |
| 68 xml_data.clear(); | 71 xml_data.clear(); |
| 69 file_util::ReadFileToString(GetTestDataFilePath("invalid_uuid.xml"), | 72 file_util::ReadFileToString(GetTestDataFilePath("invalid_uuid.xml"), |
| 70 &xml_data); | 73 &xml_data); |
| 71 BluetoothServiceRecord invalid_service_record(kAddress, xml_data); | 74 BluetoothServiceRecord invalid_service_record(kAddress, xml_data); |
| 72 EXPECT_EQ("", invalid_service_record.uuid()); | 75 EXPECT_EQ("", invalid_service_record.uuid()); |
| 73 } | 76 } |
| 74 | 77 |
| 75 } // namespace chromeos | 78 } // namespace device |
| OLD | NEW |