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

Unified Diff: device/bluetooth/bluetooth_service_record_mac_unittest.mm

Issue 12539004: Implemented BluetoothServiceRecordMac with unittest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluetooth_service_record_mac_unittest.mm
diff --git a/device/bluetooth/bluetooth_service_record_mac_unittest.mm b/device/bluetooth/bluetooth_service_record_mac_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..7429b3df5549de50eb4237b9024b7bb1c3913c69
--- /dev/null
+++ b/device/bluetooth/bluetooth_service_record_mac_unittest.mm
@@ -0,0 +1,153 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import <IOBluetooth/objc/IOBluetoothSDPDataElement.h>
+#import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h>
+#import <IOBluetooth/objc/IOBluetoothSDPUUID.h>
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/string_number_conversions.h"
+#include "base/strings/sys_string_conversions.h"
+#include "device/bluetooth/bluetooth_service_record_mac.h"
Mark Mentovai 2013/03/11 22:38:48 The test corresponding to this header is allowed t
youngki 2013/03/12 04:15:12 Done.
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+const BluetoothSDPServiceAttributeID kServiceClassIDAttributeId = 0x0001;
+const BluetoothSDPServiceAttributeID kProtocolDescriptorListAttributeId
+ = 0x0004;
Mark Mentovai 2013/03/11 22:38:48 I think it’s more usual to see the = at the end of
youngki 2013/03/12 04:15:12 Done.
+const BluetoothSDPServiceAttributeID kServiceNameAttributeId = 0x0100;
+
+const uint8 kRfcommChannel = 0x0c;
+const char kServiceName[] = "Headset Audio Gateway";
+
+const char kRfcommUuid[] = "0123456789abcdef0123456789abcdef";
Mark Mentovai 2013/03/11 22:38:48 kRfcommUuid, kUpperCaseUuid, kShortUuid, and kMedi
youngki 2013/03/12 04:15:12 Done.
+const int kRfcommUuidSize = sizeof(kRfcommUuid) / 2;
Mark Mentovai 2013/03/11 22:38:48 These are size_t, not int. But I don’t think you n
youngki 2013/03/12 04:15:12 Done.
+const char kUpperCaseUuid[] = "0123456789ABCDEF0123456789ABCDEF";
+const int kUpperCaseUuidSize = sizeof(kUpperCaseUuid) / 2;
+
+const char kExpectedRfcommUuid[] = "01234567-89ab-cdef-0123-456789abcdef";
+
+const char kShortUuid[] = "1101";
+const int kShortUuidSize = sizeof(kShortUuid) / 2;
+const char kMediumUuid[] = "00001101";
+const int kMediumUuidSize = sizeof(kMediumUuid) / 2;
+
+const char kExpectedSerialUuid[] = "00001101-0000-1000-8000-00805f9b34fb";
+
Mark Mentovai 2013/03/11 22:38:48 Extra blank line?
youngki 2013/03/12 04:15:12 Done.
+
+const int kMaxUuidSize = 16;
+
+}
Mark Mentovai 2013/03/11 22:38:48 } // namespace
youngki 2013/03/12 04:15:12 Done.
+
+namespace device {
+
+class BluetoothServiceRecordMacTest : public testing::Test {
+ public:
+
+ IOBluetoothSDPUUID* ConvertUuid(const char* uuid_hex_char, int uuid_size) {
+ std::vector<uint8> uuid_bytes_vector;
+ uint8 uuid_buffer[kMaxUuidSize];
+ base::HexStringToBytes(uuid_hex_char, &uuid_bytes_vector);
+ std::copy(uuid_bytes_vector.begin(),
+ uuid_bytes_vector.end(),
+ uuid_buffer);
+ return [IOBluetoothSDPUUID uuidWithBytes: uuid_buffer length: uuid_size];
Mark Mentovai 2013/03/11 22:38:48 No space after the : for an argument in an Objecti
youngki 2013/03/12 04:15:12 Done.
+ }
+
+ IOBluetoothSDPDataElement* GetServiceClassId(IOBluetoothSDPUUID* uuid) {
+ IOBluetoothSDPDataElement* uuid_element =
+ [IOBluetoothSDPDataElement withElementValue: uuid];
+ return [IOBluetoothSDPDataElement
+ withElementValue: [NSArray arrayWithObject: uuid_element]];
+ }
+
+ IOBluetoothSDPDataElement* GetProtocolDescriptorList(bool supports_rfcomm) {
+ NSMutableArray* protocol_descriptor_list_sequence = [NSMutableArray array];
+
+ const uint8 l2cap_uuid_bytes[] = { 0x01, 0x00 };
+
+ IOBluetoothSDPUUID* l2cap_uuid =
+ [IOBluetoothSDPUUID uuidWithBytes: l2cap_uuid_bytes length: 2];
+ [protocol_descriptor_list_sequence
+ addObject: [NSArray arrayWithObject: l2cap_uuid]];
+
+ if (supports_rfcomm) {
+ const uint8 rfcomm_uuid_bytes[] = { 0x00, 0x03 };
+ IOBluetoothSDPUUID* rfcomm_uuid =
+ [IOBluetoothSDPUUID uuidWithBytes: rfcomm_uuid_bytes length: 2];
+ NSNumber* rfcomm_channel =
+ [NSNumber numberWithUnsignedChar: kRfcommChannel];
+ [protocol_descriptor_list_sequence
+ addObject:
+ [NSArray arrayWithObjects: rfcomm_uuid, rfcomm_channel, nil]];
+ }
+
+ return [IOBluetoothSDPDataElement
+ withElementValue: protocol_descriptor_list_sequence];
+ }
+
+ IOBluetoothSDPDataElement* GetServiceName(const std::string& service_name) {
+ return [IOBluetoothSDPDataElement
+ withElementValue: base::SysUTF8ToNSString(service_name)];
+ }
+
+ IOBluetoothSDPServiceRecord* GetServiceRecord(
+ IOBluetoothSDPUUID* uuid, bool supports_rfcomm) {
+ NSMutableDictionary* service_attrs = [NSMutableDictionary dictionary];
+
+ if (uuid != nil) {
+ [service_attrs setObject: GetServiceClassId(uuid)
+ forKey: [NSNumber numberWithInt: kServiceClassIDAttributeId]];
+ }
+ [service_attrs setObject: GetProtocolDescriptorList(supports_rfcomm)
+ forKey: [NSNumber numberWithInt: kProtocolDescriptorListAttributeId]];
+ [service_attrs setObject: GetServiceName(kServiceName)
+ forKey: [NSNumber numberWithInt: kServiceNameAttributeId]];
+
+ return [IOBluetoothSDPServiceRecord withServiceDictionary: service_attrs
+ device: nil];
+ }
+};
+
+TEST_F(BluetoothServiceRecordMacTest, RfcommService) {
+ IOBluetoothSDPUUID* rfcomm_uuid = ConvertUuid(kRfcommUuid, kRfcommUuidSize);
+
+ BluetoothServiceRecordMac record(GetServiceRecord(rfcomm_uuid, true));
+ EXPECT_EQ(kServiceName, record.name());
+ EXPECT_TRUE(record.SupportsRfcomm());
+ EXPECT_EQ(kRfcommChannel, record.rfcomm_channel());
+ EXPECT_EQ(kExpectedRfcommUuid, record.uuid());
+}
+
+TEST_F(BluetoothServiceRecordMacTest, ShortUuid) {
+ IOBluetoothSDPUUID* short_uuid = ConvertUuid(kShortUuid, kShortUuidSize);
+
+ BluetoothServiceRecordMac record(GetServiceRecord(short_uuid, false));
+ EXPECT_EQ(kExpectedSerialUuid, record.uuid());
+}
+
+TEST_F(BluetoothServiceRecordMacTest, MediumUuid) {
+ IOBluetoothSDPUUID* medium_uuid = ConvertUuid(kMediumUuid, kMediumUuidSize);
+
+ BluetoothServiceRecordMac record(GetServiceRecord(medium_uuid, false));
+ EXPECT_EQ(kExpectedSerialUuid, record.uuid());
+}
+
+TEST_F(BluetoothServiceRecordMacTest, UpperCaseUuid) {
+ IOBluetoothSDPUUID* upper_case_uuid =
+ ConvertUuid(kUpperCaseUuid, kUpperCaseUuidSize);
+
+ BluetoothServiceRecordMac record(GetServiceRecord(upper_case_uuid, false));
+ EXPECT_EQ(kExpectedRfcommUuid, record.uuid());
+}
+
+TEST_F(BluetoothServiceRecordMacTest, InvalidUuid) {
+ BluetoothServiceRecordMac record(GetServiceRecord(nil, false));
+ EXPECT_EQ("", record.uuid());
+}
+
+} // namespace device

Powered by Google App Engine
This is Rietveld 408576698