From fb9c473f3ce1dc5e7786cdbbda1e679aefd194b6 Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Sat, 5 Aug 2023 12:01:51 +0200 Subject: [PATCH] Add type to most array, set and dictionarry Some can not be easily typed, such as list of arguments. This help the reader understands what they can expect in a collection. --- Channel/Tests/EDOChannelPoolTest.m | 2 +- Device/Sources/EDODeviceConnector.m | 6 ++--- Device/Tests/EDODeviceConnectorTest.m | 2 +- Service/Sources/EDOHostService+Handlers.m | 2 +- Service/Sources/EDOInvocationMessage.m | 6 ++--- Service/Sources/EDOParameter.m | 2 +- .../FunctionalTests/EDOServiceUIBlockTest.m | 2 +- .../Tests/FunctionalTests/EDOServiceUITest.m | 8 +++---- Service/Tests/PerfTests/EDOServicePerfTest.m | 6 ++--- Service/Tests/TestsBundle/EDOTestDummy.h | 4 ++-- Service/Tests/TestsBundle/EDOTestDummy.m | 4 ++-- Service/Tests/UnitTests/EDOServiceTest.m | 22 +++++++++---------- 12 files changed, 33 insertions(+), 33 deletions(-) diff --git a/Channel/Tests/EDOChannelPoolTest.m b/Channel/Tests/EDOChannelPoolTest.m index 404a3f5c..62eec29a 100644 --- a/Channel/Tests/EDOChannelPoolTest.m +++ b/Channel/Tests/EDOChannelPoolTest.m @@ -56,7 +56,7 @@ - (void)testAsyncCreateChannels { for (int i = 0; i < 10; i++) { UInt16 port = i % 2 == 0 ? host1.socketPort.port : host2.socketPort.port; - NSMutableSet *set = i % 2 == 0 ? set1 : set2; + NSMutableSet *set = i % 2 == 0 ? set1 : set2; EDOHostPort *hostPort = [EDOHostPort hostPortWithLocalPort:port]; id socketChannel = [channelPool channelWithPort:hostPort error:nil]; diff --git a/Device/Sources/EDODeviceConnector.m b/Device/Sources/EDODeviceConnector.m index 4de71640..d4173c5c 100644 --- a/Device/Sources/EDODeviceConnector.m +++ b/Device/Sources/EDODeviceConnector.m @@ -35,7 +35,7 @@ @interface EDODeviceConnector () /** The detector to detect iOS device attachment/detachment events. */ @property(nonatomic) EDODeviceDetector *detector; /** The connected device info of mappings from device serial strings to auto-assigned device IDs. */ -@property(nonatomic) NSMutableDictionary *deviceInfo; +@property(nonatomic) NSMutableDictionary  *deviceInfo; @end @implementation EDODeviceConnector { @@ -69,7 +69,7 @@ + (EDODeviceConnector *)sharedConnector { // Wait for a short time to detect all connected devices when listening just starts. sleep(kDeviceDetectTime); } - __block NSArray *result; + __block NSArray *result; dispatch_sync(_syncQueue, ^{ result = [self.deviceInfo.allKeys copy]; }); @@ -153,7 +153,7 @@ - (void)handleBroadcastPacket:(NSDictionary *)packet { userInfo:userInfo]; } else if ([messageType isEqualToString:kEDOMessageTypeDetachedKey]) { NSNumber *deviceID = packet[kEDOMessageDeviceIDKey]; - NSMutableArray *keysToRemove = [[NSMutableArray alloc] init]; + NSMutableArray *keysToRemove = [[NSMutableArray alloc] init]; dispatch_sync(_syncQueue, ^{ for (NSString *serialNumberString in self.deviceInfo) { if ([self.deviceInfo[serialNumberString] isEqualToNumber:deviceID]) { diff --git a/Device/Tests/EDODeviceConnectorTest.m b/Device/Tests/EDODeviceConnectorTest.m index dc003386..b5650a7b 100644 --- a/Device/Tests/EDODeviceConnectorTest.m +++ b/Device/Tests/EDODeviceConnectorTest.m @@ -34,7 +34,7 @@ // Exposes the internal property for test purpose. @interface EDODeviceConnector () @property(nonatomic) EDODeviceDetector *detector; -@property(nonatomic) NSMutableDictionary *deviceInfo; +@property(nonatomic) NSMutableDictionary *deviceInfo; @end @interface EDODeviceConnectorTest : XCTestCase diff --git a/Service/Sources/EDOHostService+Handlers.m b/Service/Sources/EDOHostService+Handlers.m index 8560d779..1e1312e7 100644 --- a/Service/Sources/EDOHostService+Handlers.m +++ b/Service/Sources/EDOHostService+Handlers.m @@ -31,7 +31,7 @@ + (NSDictionary *)handlers { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ handlers = [[NSMutableDictionary alloc] init]; - NSArray *requestClasses = @[ + NSArray *requestClasses = @[ [EDOClassRequest class], [EDOInvocationRequest class], [EDOMethodSignatureRequest class], diff --git a/Service/Sources/EDOInvocationMessage.m b/Service/Sources/EDOInvocationMessage.m index 79875a33..868d672a 100644 --- a/Service/Sources/EDOInvocationMessage.m +++ b/Service/Sources/EDOInvocationMessage.m @@ -212,7 +212,7 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder { forKey:kEDOInvocationCoderReturnValueKey]; _exception = [aDecoder decodeObjectOfClass:[EDORemoteException class] forKey:kEDOInvocationCoderExceptionKey]; - NSSet *anyClasses = + NSSet *anyClasses = [NSSet setWithObjects:[EDOBlockObject class], [NSObject class], [EDOObject class], nil]; _outValues = [aDecoder decodeObjectOfClasses:anyClasses forKey:kEDOInvocationCoderOutValuesKey]; } @@ -515,7 +515,7 @@ - (instancetype)initWithTarget:(EDOPointerType)target - (instancetype)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self) { - NSSet *anyClasses = + NSSet *anyClasses = [NSSet setWithObjects:[EDOBlockObject class], [EDOObject class], [NSObject class], nil]; _target = [aDecoder decodeInt64ForKey:kEDOInvocationCoderTargetKey]; _selectorName = [aDecoder decodeObjectOfClass:[NSString class] @@ -542,4 +542,4 @@ - (NSString *)description { self.messageID, self.target, self.selectorName]; } -@end \ No newline at end of file +@end diff --git a/Service/Sources/EDOParameter.m b/Service/Sources/EDOParameter.m index 845b3f31..2b9df95a 100644 --- a/Service/Sources/EDOParameter.m +++ b/Service/Sources/EDOParameter.m @@ -102,7 +102,7 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder { // EDOParameter can carry any type of object as long as it's serializable, so it whitelists all // the types inheriting from NSObject. EDOObject and EDOBlockObject are NSProxy's and need to be // whitelisted as well. - NSSet *anyClasses = + NSSet *anyClasses = [NSSet setWithObjects:[EDOBlockObject class], [EDOObject class], [NSObject class], nil]; _value = [aDecoder decodeObjectOfClasses:anyClasses forKey:kEDOParameterCoderValueKey]; _valueObjCType = [aDecoder decodeObjectOfClass:[NSString class] diff --git a/Service/Tests/FunctionalTests/EDOServiceUIBlockTest.m b/Service/Tests/FunctionalTests/EDOServiceUIBlockTest.m index 5afd35f1..10556163 100644 --- a/Service/Tests/FunctionalTests/EDOServiceUIBlockTest.m +++ b/Service/Tests/FunctionalTests/EDOServiceUIBlockTest.m @@ -168,7 +168,7 @@ - (void)testBlockResolveToLocalAddress { - (void)testBlockByValueAndOutArgument { EDOTestDummy *remoteDummy = [EDOClientService rootObjectWithPort:EDOTEST_APP_SERVICE_PORT]; - NSArray *arrayReturn = [remoteDummy returnWithBlockObject:^id(EDOTestDummy *dummy) { + NSArray *arrayReturn = [remoteDummy returnWithBlockObject:^id(EDOTestDummy *dummy) { // Use NSClassFromString to fetch EDOObject to make it private here. XCTAssertEqual([dummy class], NSClassFromString(@"EDOObject")); XCTAssertEqual(dummy.value, 10); diff --git a/Service/Tests/FunctionalTests/EDOServiceUITest.m b/Service/Tests/FunctionalTests/EDOServiceUITest.m index 217affe5..c3f7ff1b 100644 --- a/Service/Tests/FunctionalTests/EDOServiceUITest.m +++ b/Service/Tests/FunctionalTests/EDOServiceUITest.m @@ -401,8 +401,8 @@ - (void)testIsKindOfClassOnlyResolvesInSameProcess { - (void)testRemoteObjectCopy { [self launchApplicationWithPort:EDOTEST_APP_SERVICE_PORT initValue:5]; EDOTestDummy *dummy = [EDOClientService rootObjectWithPort:EDOTEST_APP_SERVICE_PORT]; - NSArray *remoteArray = [dummy returnArray]; - NSArray *remoteArrayCopy; + NSArray *remoteArray = [dummy returnArray]; + NSArray *remoteArrayCopy; XCTAssertNoThrow(remoteArrayCopy = [remoteArray copy]); XCTAssertEqual(remoteArray, remoteArrayCopy); } @@ -410,8 +410,8 @@ - (void)testRemoteObjectCopy { - (void)testRemoteObjectMutableCopy { [self launchApplicationWithPort:EDOTEST_APP_SERVICE_PORT initValue:5]; EDOTestDummy *dummy = [EDOClientService rootObjectWithPort:EDOTEST_APP_SERVICE_PORT]; - NSArray *remoteArray = [dummy returnArray]; - NSMutableArray *remoteArrayCopy = [remoteArray mutableCopy]; + NSArray *remoteArray = [dummy returnArray]; + NSMutableArray *remoteArrayCopy = [remoteArray mutableCopy]; XCTAssertNotEqual(remoteArray, remoteArrayCopy); XCTAssertEqualObjects(remoteArray, remoteArrayCopy); [remoteArrayCopy addObject:@"test"]; diff --git a/Service/Tests/PerfTests/EDOServicePerfTest.m b/Service/Tests/PerfTests/EDOServicePerfTest.m index a06b088c..230b0a56 100644 --- a/Service/Tests/PerfTests/EDOServicePerfTest.m +++ b/Service/Tests/PerfTests/EDOServicePerfTest.m @@ -194,7 +194,7 @@ - (void)testIteratingReturnByValueResultLotsTimes { assertPerformBlockWithWeight:1 executions:10 block:^(EDOTestDummy *remoteDummy) { - NSArray *result = [[remoteDummy returnByValue] returnLargeArray]; + NSArray *result = [[remoteDummy returnByValue] returnLargeArray]; for (NSInteger i = 0; i < 1000; i++) { XCTAssert(((NSNumber *)result[i]).integerValue == i); } @@ -203,7 +203,7 @@ - (void)testIteratingReturnByValueResultLotsTimes { [self assertPerformBlockWithWeight:1000 executions:10 block:^(EDOTestDummy *remoteDummy) { - NSArray *result = [remoteDummy returnLargeArray]; + NSArray *result = [remoteDummy returnLargeArray]; for (NSInteger i = 0; i < 1000; i++) { XCTAssert(((NSNumber *)result[i]).integerValue == i); } @@ -212,7 +212,7 @@ - (void)testIteratingReturnByValueResultLotsTimes { } - (void)testIteratingPassByValueParameterLotsTimes { - NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:1000]; + NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:1000]; for (int i = 0; i < 1000; i++) { [array addObject:@(i)]; } diff --git a/Service/Tests/TestsBundle/EDOTestDummy.h b/Service/Tests/TestsBundle/EDOTestDummy.h index a40798bd..f8dd9ae1 100644 --- a/Service/Tests/TestsBundle/EDOTestDummy.h +++ b/Service/Tests/TestsBundle/EDOTestDummy.h @@ -123,8 +123,8 @@ typedef EDOTestDummy * (^EDOMultiTypesHandler)(EDOTestDummyStruct, int, id, EDOT - (BOOL)returnBoolWithError:(NSError **)errorOrNil; - (NSString *)returnClassNameWithObject:(id)object; - (NSInteger)returnCountWithArray:(NSArray *)value; -- (NSInteger)returnSumWithArray:(NSArray *)value; -- (NSInteger)returnSumWithArrayAndProxyCheck:(NSArray *)value; +- (NSInteger)returnSumWithArray:(NSArray *)value; +- (NSInteger)returnSumWithArrayAndProxyCheck:(NSArray *)value; - (int *)returnIntPointer; /** diff --git a/Service/Tests/TestsBundle/EDOTestDummy.m b/Service/Tests/TestsBundle/EDOTestDummy.m index dbe14a49..c461ee4f 100644 --- a/Service/Tests/TestsBundle/EDOTestDummy.m +++ b/Service/Tests/TestsBundle/EDOTestDummy.m @@ -326,7 +326,7 @@ - (NSInteger)returnCountWithArray:(NSArray *)value { return value.count; } -- (NSInteger)returnSumWithArray:(NSArray *)value { +- (NSInteger)returnSumWithArray:(NSArray *)value { NSInteger result = 0; for (NSNumber *number in value) { result += number.integerValue; @@ -334,7 +334,7 @@ - (NSInteger)returnSumWithArray:(NSArray *)value { return result; } -- (NSInteger)returnSumWithArrayAndProxyCheck:(NSArray *)value { +- (NSInteger)returnSumWithArrayAndProxyCheck:(NSArray *)value { NSAssert(!value.isProxy, @"This method is to test pass-by-value. The parameter should not be a proxy."); return [self returnSumWithArray:value]; diff --git a/Service/Tests/UnitTests/EDOServiceTest.m b/Service/Tests/UnitTests/EDOServiceTest.m index 814291eb..5cab02ee 100644 --- a/Service/Tests/UnitTests/EDOServiceTest.m +++ b/Service/Tests/UnitTests/EDOServiceTest.m @@ -693,9 +693,9 @@ - (void)testEDOEqual { - (void)testEDOAsDictKey { EDOTestDummy *dummyOnBackground = self.rootObjectOnBackground; - NSSet *returnSet = [dummyOnBackground returnSet]; - NSArray *returnArray = [dummyOnBackground returnArray]; - NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; + NSSet *returnSet = [dummyOnBackground returnSet]; + NSArray *returnArray = [dummyOnBackground returnArray]; + NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; XCTAssertNil(dictionary[returnSet]); XCTAssertNoThrow(dictionary[returnSet] = @1); @@ -707,8 +707,8 @@ - (void)testEDOAsDictKey { - (void)testEDOAsCFDictKey { EDOTestDummy *dummyOnBackground = self.rootObjectOnBackground; - NSSet *returnSet = [dummyOnBackground returnSet]; - NSArray *returnArray = [dummyOnBackground returnArray]; + NSSet *returnSet = [dummyOnBackground returnSet]; + NSArray *returnArray = [dummyOnBackground returnArray]; CFMutableDictionaryRef cfDictionary = CFDictionaryCreateMutable( NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); @@ -751,8 +751,8 @@ - (void)testFailToEnableNonNSCodingTypetoBeValueType { - (void)testEDOReturnsAsValueType { EDOTestDummy *dummyOnBackground = self.rootObjectOnBackground; - NSArray *returnArray = [[dummyOnBackground returnByValue] returnArray]; - NSArray *localArray = @[ @1, @2, @3, @4 ]; + NSArray *returnArray = [[dummyOnBackground returnByValue] returnArray]; + NSArray *localArray = @[ @1, @2, @3, @4 ]; XCTAssertEqual([returnArray class], [localArray class]); XCTAssertTrue([returnArray isEqualToArray:localArray]); } @@ -771,25 +771,25 @@ - (void)testEDOPassByValue { - (void)testEDOPassByValueWithRemoteObject { EDOTestDummy *dummyOnBackground = self.rootObjectOnBackground; - NSArray *array = [dummyOnBackground returnArray]; + NSArray *array = [dummyOnBackground returnArray]; XCTAssertEqual([dummyOnBackground returnCountWithArray:[array passByValue]], 4); } - (void)testEDOPassByValueNestedWithReturnByValue { EDOTestDummy *dummyOnBackground = self.rootObjectOnBackground; - NSArray *array = [dummyOnBackground returnArray]; + NSArray *array = [dummyOnBackground returnArray]; XCTAssertEqual([dummyOnBackground returnCountWithArray:[[array returnByValue] passByValue]], 4); } - (void)testEDOPassByValueNestedWithPassByValue { EDOTestDummy *dummyOnBackground = self.rootObjectOnBackground; - NSArray *array = [dummyOnBackground returnArray]; + NSArray *array = [dummyOnBackground returnArray]; XCTAssertEqual([dummyOnBackground returnCountWithArray:[[array passByValue] passByValue]], 4); } - (void)testEDOReturnByValueNestedWithPassByValue { EDOTestDummy *dummyOnBackground = self.rootObjectOnBackground; - NSArray *array = [dummyOnBackground returnArray]; + NSArray *array = [dummyOnBackground returnArray]; XCTAssertEqual([dummyOnBackground returnCountWithArray:[[array passByValue] returnByValue]], 4); }