mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
[NC Apple coverage] add initial unit tests for BluetoothAdapterV2.
PiperOrigin-RevId: 807650119
This commit is contained in:
committed by
Copybara-Service
parent
c52edc9bae
commit
21f7e51635
@@ -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 = [
|
||||
|
||||
@@ -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",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -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 <XCTest/XCTest.h>
|
||||
|
||||
#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
|
||||
Reference in New Issue
Block a user