Remove NSLog from apple platform implementation

PiperOrigin-RevId: 762444541
This commit is contained in:
Guogang Li
2025-05-23 09:02:30 -07:00
committed by Copybara-Service
parent acaf963c40
commit 3d9371afe1
6 changed files with 35 additions and 40 deletions
@@ -70,7 +70,7 @@ NS_ASSUME_NONNULL_BEGIN
* [centralPeer socketWithPairingCharacteristic:shouldAddPairingCharacteristics
* completion:^(GNSSocket *mySocket, NSError *error) {
* if (error) {
* NSLog(@"Error to get the socket %@", error);
* GTMLoggerInfo(@"Error to get the socket %@", error);
* return;
* }
* mySocket.delegate = mySocketDelegate;
@@ -26,7 +26,7 @@ typedef void (^GNSProgressHandler)(float progress);
* (when used with GNSPeripheralServiceManager) or when the socket is created (when used with
* GNSCentralPeer).
*/
@protocol GNSSocketDelegate<NSObject>
@protocol GNSSocketDelegate <NSObject>
/**
* Called when the socket is ready to send or receive data.
@@ -69,16 +69,16 @@ typedef void (^GNSProgressHandler)(float progress);
*
* * To receive data:
* - (void)socket:(GNSSocket *)socket didReceiveData:(NSData *)data {
* NSLog(@"Data received from central %@", data);
* GTMLoggerInfo(@"Data received from central %@", data);
* ...
* }
*
* * To send data:
* GNSErrorHandler completionHandler = ^(NSError *error) {
* if (error) {
* NSLog(@"Failed to send data")
* GTMLoggerInfo(@"Failed to send data")
* } else {
* NSLog(@"data has been sent");
* GTMLoggerInfo(@"data has been sent");
* }
* }
* [socket sendData:dataToSend
@@ -89,10 +89,10 @@ typedef void (^GNSProgressHandler)(float progress);
*
* * Once the socket is disconnected (by -[GNSSocket disconnect] or by the peer):
* - (void)socket:(GNSSocket *)socket didDisconnectWithError:(NSError *)error {
* NSLog(@"Socket disconnected, by peer");
* GTMLoggerInfo(@"Socket disconnected, by peer");
* ...
* }
*/
*/
@interface GNSSocket : NSObject
/**
@@ -47,15 +47,15 @@ typedef NS_ENUM(UInt8, GNSWeaveControlCommand) {
* - (void)didReceivedData:(NSData *)data {
* GNSWeavePacket *packet = [GNSWeavePacket parseData:data error:nil];
* if ([packet visitWithHandler:self context:nil]) {
* NSLog(@"This class can handle this packet.");
* GTMLoggerInfo(@"This class can handle this packet.");
* } else {
* NSLog(@"Unexpected packet received.");
* GTMLoggerInfo(@"Unexpected packet received.");
* }
* }
*
* - (void)handleConnectionRequestPacket:(GNSWeaveConnectionRequestPacket *)packet
* context:(nullable id)context {
* NSLog(@"Connection request packet received.");
* GTMLoggerInfo(@"Connection request packet received.");
* ...
* }
* @end
@@ -19,6 +19,7 @@
#import "internal/platform/implementation/apple/Mediums/ble/Sockets/Source/Shared/GNSSocket+Private.h"
#import "internal/platform/implementation/apple/Mediums/ble/Sockets/Source/Shared/GNSUtils.h"
#import "internal/platform/implementation/apple/Mediums/ble/Sockets/Source/Shared/GNSWeavePacket.h"
#import "GoogleToolboxForMac/GTMLogger.h"
#import "third_party/objective_c/ocmock/v3/Source/OCMock/OCMock.h"
@interface GNSPeripheralServiceManagerTest : XCTestCase {
@@ -39,21 +40,21 @@
- (void)setUp {
_mocksToVerify = [NSMutableArray array];
_serviceUUID = [CBUUID UUIDWithString:@"3C672799-2B3F-4D93-9E57-29D5C5B01092"];;
_serviceUUID = [CBUUID UUIDWithString:@"3C672799-2B3F-4D93-9E57-29D5C5B01092"];
_peripheralManagerMock = OCMStrictClassMock([GNSPeripheralManager class]);
_cbPeripheralManagerMock = OCMStrictClassMock([CBPeripheralManager class]);
_socketDelegateMock = OCMStrictProtocolMock(@protocol(GNSSocketDelegate));
_centralMaximumUpdateValueLength = 100;
_packetSize = 100;
OCMStub([_peripheralManagerMock cbPeripheralManager]).andReturn(_cbPeripheralManagerMock);
_peripheralServiceManager = [[GNSPeripheralServiceManager alloc]
initWithBleServiceUUID:_serviceUUID
addPairingCharacteristic:NO
shouldAcceptSocketHandler:^BOOL(GNSSocket *socket) {
_receivedSocket = socket;
socket.delegate = _socketDelegateMock;
return self->_shouldAcceptSocket;
}];
_peripheralServiceManager =
[[GNSPeripheralServiceManager alloc] initWithBleServiceUUID:_serviceUUID
addPairingCharacteristic:NO
shouldAcceptSocketHandler:^BOOL(GNSSocket *socket) {
_receivedSocket = socket;
socket.delegate = _socketDelegateMock;
return self->_shouldAcceptSocket;
}];
XCTAssertEqualObjects(_peripheralServiceManager.serviceUUID, _serviceUUID);
[_peripheralServiceManager addedToPeripheralManager:_peripheralManagerMock
bleServiceAddedCompletion:nil];
@@ -76,13 +77,13 @@
}
- (void)testServiceManagerAdded {
GNSPeripheralServiceManager *peripheralServiceManager = [[GNSPeripheralServiceManager alloc]
initWithBleServiceUUID:_serviceUUID
addPairingCharacteristic:NO
shouldAcceptSocketHandler:^BOOL(GNSSocket *socket) {
_receivedSocket = socket;
return _shouldAcceptSocket;
}];
GNSPeripheralServiceManager *peripheralServiceManager =
[[GNSPeripheralServiceManager alloc] initWithBleServiceUUID:_serviceUUID
addPairingCharacteristic:NO
shouldAcceptSocketHandler:^BOOL(GNSSocket *socket) {
_receivedSocket = socket;
return _shouldAcceptSocket;
}];
__block BOOL completionCalled = NO;
[peripheralServiceManager addedToPeripheralManager:_peripheralManagerMock
bleServiceAddedCompletion:^(NSError *error) {
@@ -288,8 +289,7 @@
[self checkOpenSocketWithShouldAccept:shouldAccept central:nil];
}
- (void)checkOpenSocketWithShouldAccept:(BOOL)shouldAccept
central:(CBCentral *)central {
- (void)checkOpenSocketWithShouldAccept:(BOOL)shouldAccept central:(CBCentral *)central {
CBMutableCharacteristic *characteristic;
NSMutableData *data = [NSMutableData data];
_shouldAcceptSocket = shouldAccept;
@@ -307,9 +307,7 @@
XCTAssertNotNil(characteristic);
CBATTRequest *request = OCMStrictClassMock([CBATTRequest class]);
OCMStub([request value]).andReturn(data);
[self setupRequest:request
withCharacteristic:characteristic
central:central];
[self setupRequest:request withCharacteristic:characteristic central:central];
__block GNSUpdateValueHandler updateValueHandler = nil;
// Nothing is sent when the socket is refused in the Weave protocol.
if (!shouldAccept) {
@@ -333,8 +331,8 @@
GNSWeaveConnectionConfirmPacket *connectionConfirm =
[[GNSWeaveConnectionConfirmPacket alloc] initWithVersion:1 packetSize:_packetSize data:nil];
[expectedData appendData:[connectionConfirm serialize]];
OCMExpect(
[_peripheralManagerMock updateOutgoingCharacteristic:expectedData onSocket:_receivedSocket])
OCMExpect([_peripheralManagerMock updateOutgoingCharacteristic:expectedData
onSocket:_receivedSocket])
.andReturn(YES);
XCTAssertNotNil(_receivedSocket);
XCTAssertFalse(_receivedSocket.isConnected);
@@ -363,8 +361,7 @@
error.code == GNSErrorNewInviteToConnectReceived;
}]]);
OCMExpect([_peripheralManagerMock socketDidDisconnect:firstSocket]);
[self checkOpenSocketWithShouldAccept:YES
central:firstSocket.peerAsCentral];
[self checkOpenSocketWithShouldAccept:YES central:firstSocket.peerAsCentral];
XCTAssertNotEqual(firstSocket, _receivedSocket);
XCTAssertFalse(firstSocket.isConnected);
}
@@ -521,7 +518,7 @@
XCTAssertNotNil(packet);
XCTAssertTrue([packet isKindOfClass:[GNSWeaveDataPacket class]]);
GNSWeaveDataPacket *dataPacket = (GNSWeaveDataPacket *)packet;
NSLog(@"packetCounter = %d", dataPacket.packetCounter);
GTMLoggerInfo(@"packetCounter = %d", dataPacket.packetCounter);
XCTAssertEqual(dataPacket.packetCounter, sendPacketCounter);
sendPacketCounter = (sendPacketCounter + 1) % kGNSMaxPacketCounterValue;
if (i == 0) {
@@ -13,12 +13,13 @@
// limitations under the License.
#import "internal/platform/implementation/apple/Mediums/GNCLeaks.h"
#import "GoogleToolboxForMac/GTMLogger.h"
void GNCVerifyDealloc(id object, NSTimeInterval timeInterval) {
#if DEBUG
__weak id weakObj = object;
NSCAssert(weakObj != nil, @"Pointer to %@ is already nil", weakObj);
NSLog(@"Verifying deallocation of %@", NSStringFromClass([weakObj class]));
GTMLoggerInfo(@"Verifying deallocation of %@", NSStringFromClass([weakObj class]));
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeInterval * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{
NSCAssert(weakObj == nil, @"%@ not deallocated.", weakObj);
@@ -91,7 +91,6 @@ ExceptionOr<ByteArray> BleInputStream::Read(std::int64_t size) {
[condition_ unlock];
if (dataToReturn) {
NSLog(@"[NEARBY] Input stream: Received data of size: %lu", (unsigned long)dataToReturn.length);
return ExceptionOr<ByteArray>(ByteArrayFromNSData(dataToReturn));
} else {
return ExceptionOr<ByteArray>{Exception::kIo};
@@ -115,8 +114,6 @@ BleOutputStream::~BleOutputStream() {
Exception BleOutputStream::Write(const ByteArray &data) {
[condition_ lock];
NSLog(@"[NEARBY] Sending data of size: %lu", NSDataFromByteArray(data).length);
if (!connection_) {
[condition_ unlock];
return {Exception::kIo};