diff --git a/internal/platform/implementation/apple/BUILD b/internal/platform/implementation/apple/BUILD index 42a56f8d..a5b816c9 100644 --- a/internal/platform/implementation/apple/BUILD +++ b/internal/platform/implementation/apple/BUILD @@ -126,7 +126,6 @@ objc_library( "ble_server_socket.mm", "ble_socket.mm", "ble_utils.mm", - "bluetooth_adapter_v2.mm", "utils.mm", ], hdrs = [ @@ -140,12 +139,12 @@ objc_library( "ble_server_socket.h", "ble_socket.h", "ble_utils.h", - "bluetooth_adapter_v2.h", "utils.h", ], # Prevent Objective-C++ headers from being pulled into swift. aspect_hints = ["//tools/build_defs/swift:no_module"], deps = [ + ":bluetooth_adapter_v2", ":comm", "//internal/platform:base", "//internal/platform:cancellation_flag", @@ -165,6 +164,24 @@ objc_library( ], ) +objc_library( + name = "bluetooth_adapter_v2", + srcs = [ + "bluetooth_adapter_v2.mm", + ], + hdrs = [ + "bluetooth_adapter_v2.h", + ], + # Prevent Objective-C++ headers from being pulled into swift. + aspect_hints = ["//tools/build_defs/swift:no_module"], + deps = [ + "//internal/platform:mac_address", + "//internal/platform/implementation:comm", + "//third_party/apple_frameworks:Foundation", + "@com_google_absl//absl/strings", + ], +) + objc_library( name = "Shared", srcs = [ diff --git a/internal/platform/implementation/apple/Tests/BUILD b/internal/platform/implementation/apple/Tests/BUILD index bb164140..fe7598b7 100644 --- a/internal/platform/implementation/apple/Tests/BUILD +++ b/internal/platform/implementation/apple/Tests/BUILD @@ -54,11 +54,26 @@ objc_library( ], ) +objc_library( + name = "BluetoothAdapterV2TestLibrary", + testonly = True, + srcs = ["bluetooth_adapter_v2_test.mm"], + tags = ["nozapfhahn"], + deps = [ + "//internal/platform:mac_address", + "//internal/platform/implementation:comm", + "//internal/platform/implementation/apple:bluetooth_adapter_v2", + "//third_party/apple_frameworks:XCTest", + "@com_google_googletest//:gtest", + ], +) + ios_unit_test( name = "PlatformTest", minimum_os_version = IOS_MINIMUM_OS, runner = IOS_LATEST_TEST_RUNNER, deps = [ + ":BluetoothAdapterV2TestLibrary", ":PlatformTestsLibrary", ], ) diff --git a/internal/platform/implementation/apple/Tests/bluetooth_adapter_v2_test.mm b/internal/platform/implementation/apple/Tests/bluetooth_adapter_v2_test.mm new file mode 100644 index 00000000..598ab7fc --- /dev/null +++ b/internal/platform/implementation/apple/Tests/bluetooth_adapter_v2_test.mm @@ -0,0 +1,76 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "internal/platform/implementation/apple/bluetooth_adapter_v2.h" + +#import + +#include "gtest/gtest.h" +#include "internal/platform/implementation/bluetooth_adapter.h" +#include "internal/platform/mac_address.h" + +@interface GNCBluetoothAdapterV2Test : XCTestCase +@end + +@implementation GNCBluetoothAdapterV2Test { + nearby::apple::BluetoothAdapter _adapter; +} + +- (void)testSetStatus { + // Always returns the current IsEnabled() state. + XCTAssertTrue(_adapter.SetStatus(nearby::api::BluetoothAdapter::Status::kEnabled)); +} + +- (void)testIsEnabled { + // Currently hardcoded to return true. + XCTAssertTrue(_adapter.IsEnabled()); +} + +- (void)testGetScanMode { + // Currently hardcoded to return kUnknown. + XCTAssertEqual(_adapter.GetScanMode(), nearby::api::BluetoothAdapter::ScanMode::kUnknown); +} + +- (void)testSetScanMode { + // Currently hardcoded to return false. + XCTAssertFalse(_adapter.SetScanMode(nearby::api::BluetoothAdapter::ScanMode::kConnectable)); +} + +- (void)testGetName { + // Currently hardcoded to return "". + XCTAssertEqual(_adapter.GetName(), ""); +} + +- (void)testSetName { + // Currently hardcoded to return false. + XCTAssertFalse(_adapter.SetName("TestName")); +} + +- (void)testSetNameWithPersist { + // Currently hardcoded to return false. + XCTAssertFalse(_adapter.SetName("TestName", true)); +} + +- (void)testGetMacAddress { + // Currently hardcoded to return "". + XCTAssertEqual(_adapter.GetMacAddress(), ""); +} + +- (void)testGetAddress { + // Currently hardcoded to return an empty MacAddress. + nearby::MacAddress emptyAddress; + XCTAssertEqual(_adapter.GetAddress(), emptyAddress); +} + +@end