diff --git a/ably-ios/ARTChannel.h b/ably-ios/ARTChannel.h index fd6653c20..d0c543f94 100644 --- a/ably-ios/ARTChannel.h +++ b/ably-ios/ARTChannel.h @@ -32,10 +32,8 @@ ART_ASSUME_NONNULL_BEGIN - (void)publish:(__GENERIC(NSArray, ARTMessage *) *)messages; - (void)publish:(__GENERIC(NSArray, ARTMessage *) *)messages cb:(art_nullable void (^)(ARTErrorInfo *__art_nullable error))callback; -- (NSError *__art_nullable)history:(void(^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *__art_nullable result, NSError *__art_nullable error))callback; -- (NSError *__art_nullable)history:(art_nullable ARTDataQuery *)query callback:(void(^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *__art_nullable result, NSError *__art_nullable error))callback; -- (BOOL)historyWithError:(NSError *__art_nullable *__art_nullable)errorPtr callback:(void(^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *__art_nullable result, NSError *__art_nullable error))callback; -- (BOOL)history:(art_nullable ARTDataQuery *)query error:(NSError *__art_nullable *__art_nullable)errorPtr callback:(void(^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *__art_nullable result, NSError *__art_nullable error))callback; +- (BOOL)history:(void(^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *__art_nullable result, NSError *__art_nullable error))callback error:(NSError *__art_nullable *__art_nullable)errorPtr; +- (BOOL)history:(art_nullable ARTDataQuery *)query callback:(void(^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *__art_nullable result, NSError *__art_nullable error))callback error:(NSError *__art_nullable *__art_nullable)errorPtr; @end diff --git a/ably-ios/ARTChannel.m b/ably-ios/ARTChannel.m index d1aceef56..3cb8615fa 100644 --- a/ably-ios/ARTChannel.m +++ b/ably-ios/ARTChannel.m @@ -81,23 +81,11 @@ - (ARTMessage *)encodeMessageIfNeeded:(ARTMessage *)message { return message; } -- (NSError *)history:(void (^)(ARTPaginatedResult * _Nullable, NSError * _Nullable))callback { - NSError *error = nil; - [self historyWithError:&error callback:callback]; - return error; -} - -- (NSError *)history:(ARTDataQuery *)query callback:(void (^)(ARTPaginatedResult * _Nullable, NSError * _Nullable))callback { - NSError *error = nil; - [self history:query error:&error callback:callback]; - return error; -} - -- (BOOL)historyWithError:(NSError *__autoreleasing _Nullable *)errorPtr callback:(void (^)(ARTPaginatedResult * _Nullable, NSError * _Nullable))callback { - return [self history:[[ARTDataQuery alloc] init] error:errorPtr callback:callback]; +- (BOOL)history:(void (^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *, NSError *))callback error:(NSError **)errorPtr { + return [self history:[[ARTDataQuery alloc] init] callback:callback error:errorPtr]; } -- (BOOL)history:(ARTDataQuery *)query error:(NSError **)errorPtr callback:(void (^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *, NSError *))callback { +- (BOOL)history:(ARTDataQuery *)query callback:(void (^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *, NSError *))callback error:(NSError **)errorPtr { NSAssert(false, @"-[%@ %@] should always be overriden.", self.class, NSStringFromSelector(_cmd)); return NO; } diff --git a/ably-ios/ARTRealtimeChannel.h b/ably-ios/ARTRealtimeChannel.h index e04ea533f..b41995235 100644 --- a/ably-ios/ARTRealtimeChannel.h +++ b/ably-ios/ARTRealtimeChannel.h @@ -36,10 +36,8 @@ ART_ASSUME_NONNULL_BEGIN - (void)unsubscribe:(__GENERIC(ARTEventListener, ARTMessage *) *)listener; - (void)unsubscribe:(NSString *)name listener:(__GENERIC(ARTEventListener, ARTMessage *) *)listener; -- (NSError *__art_nullable)history:(void(^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *__art_nullable result, NSError *__art_nullable error))callback; -- (NSError *__art_nullable)history:(art_nullable ARTRealtimeHistoryQuery *)query callback:(void(^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *__art_nullable result, NSError *__art_nullable error))callback; -- (BOOL)historyWithError:(NSError *__art_nullable *__art_nullable)errorPtr callback:(void(^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *__art_nullable result, NSError *__art_nullable error))callback; -- (BOOL)history:(art_nullable ARTRealtimeHistoryQuery *)query error:(NSError *__art_nullable *__art_nullable)errorPtr callback:(void(^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *__art_nullable result, NSError *__art_nullable error))callback; +- (BOOL)history:(void(^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *__art_nullable result, NSError *__art_nullable error))callback error:(NSError *__art_nullable *__art_nullable)errorPtr; +- (BOOL)history:(art_nullable ARTRealtimeHistoryQuery *)query callback:(void(^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *__art_nullable result, NSError *__art_nullable error))callback error:(NSError *__art_nullable *__art_nullable)errorPtr; ART_EMBED_INTERFACE_EVENT_EMITTER(ARTRealtimeChannelState, ARTErrorInfo *) diff --git a/ably-ios/ARTRealtimeChannel.m b/ably-ios/ARTRealtimeChannel.m index 2c8e9fa27..2109e0fba 100644 --- a/ably-ios/ARTRealtimeChannel.m +++ b/ably-ios/ARTRealtimeChannel.m @@ -495,24 +495,12 @@ - (NSString *)getClientId { return self.realtime.auth.clientId; } -- (NSError *)history:(void (^)(ARTPaginatedResult * _Nullable, NSError * _Nullable))callback { - NSError *error = nil; - [self historyWithError:&error callback:callback]; - return error; +- (BOOL)history:(void (^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *, NSError *))callback error:(NSError **)errorPtr { + return [self history:[[ARTRealtimeHistoryQuery alloc] init] callback:callback error:errorPtr]; } -- (NSError *)history:(ARTRealtimeHistoryQuery *)query callback:(void (^)(ARTPaginatedResult * _Nullable, NSError * _Nullable))callback { - NSError *error = nil; - [self history:query error:&error callback:callback]; - return error; -} - -- (BOOL)historyWithError:(NSError *__autoreleasing _Nullable *)errorPtr callback:(void (^)(ARTPaginatedResult * _Nullable, NSError * _Nullable))callback { - return [self history:[[ARTRealtimeHistoryQuery alloc] init] error:errorPtr callback:callback]; -} - -- (BOOL)history:(ARTRealtimeHistoryQuery *)query error:(NSError *__autoreleasing _Nullable *)errorPtr callback:(void (^)(ARTPaginatedResult * _Nullable, NSError * _Nullable))callback { - return [super history:query error:errorPtr callback:callback]; +- (BOOL)history:(ARTRealtimeHistoryQuery *)query callback:(void (^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *, NSError *))callback error:(NSError **)errorPtr { + return [super history:query callback:callback error:errorPtr]; } @end diff --git a/ably-ios/ARTRestChannel.m b/ably-ios/ARTRestChannel.m index e18bc1a2e..49ec7cdd1 100644 --- a/ably-ios/ARTRestChannel.m +++ b/ably-ios/ARTRestChannel.m @@ -52,7 +52,7 @@ - (ARTRestPresence *)getPresence { return _restPresence; } -- (BOOL)history:(ARTDataQuery *)query error:(NSError **)errorPtr callback:(void(^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *result, NSError *error))callback { +- (BOOL)history:(ARTDataQuery *)query callback:(void(^)(__GENERIC(ARTPaginatedResult, ARTMessage *) *result, NSError *error))callback error:(NSError **)errorPtr { if (query.limit > 1000) { if (errorPtr) { *errorPtr = [NSError errorWithDomain:ARTAblyErrorDomain diff --git a/ably-iosTests/ARTReadmeExamples.m b/ably-iosTests/ARTReadmeExamples.m index 54d31bed6..cc9f79b69 100644 --- a/ably-iosTests/ARTReadmeExamples.m +++ b/ably-iosTests/ARTReadmeExamples.m @@ -71,7 +71,7 @@ - (void)testSubscribeAndPublishingToChannel { [channel history:^(ARTPaginatedResult *messagesPage, NSError *error) { NSLog(@"%@", messagesPage.items); - }]; + } error:nil]; }]; } @@ -89,7 +89,7 @@ - (void) testQueryingTheHistory { // retrieved the next page in nextPage }]; NSLog(@"%d", messagesPage.hasNext); // true, there are more pages - }]; + } error:nil]; }]; } @@ -150,7 +150,7 @@ - (void)testRestQueryingTheHistory { // retrieved the next page in nextPage }]; NSLog(@"%d", messagesPage.hasNext); // true, there are more pages - }]; + } error:nil]; }]; } diff --git a/ably-iosTests/ARTRealtimeChannelHistoryTest.m b/ably-iosTests/ARTRealtimeChannelHistoryTest.m index cea498d1a..385eb565c 100644 --- a/ably-iosTests/ARTRealtimeChannelHistoryTest.m +++ b/ably-iosTests/ARTRealtimeChannelHistoryTest.m @@ -54,7 +54,7 @@ - (void)testHistory { XCTAssertNil(errorInfo); [channel publish:nil data:@"testString2" cb:^(ARTErrorInfo *errorInfo) { XCTAssertNil(errorInfo); - [channel history:[[ARTRealtimeHistoryQuery alloc] init] error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [channel history:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); NSArray *messages = [result items]; XCTAssertEqual(2, messages.count); @@ -64,7 +64,7 @@ - (void)testHistory { XCTAssertEqualObjects(@"testString", [m1 data]); [expectation fulfill]; - }]; + } error:nil]; }]; }]; } @@ -115,7 +115,7 @@ - (void) testHistoryBothChannels { XCTAssertNil(errorInfo); [channel2 publish:nil data:@"testString2" cb:^(ARTErrorInfo *errorInfo) { XCTAssertNil(errorInfo); - [channel1 history:[[ARTRealtimeHistoryQuery alloc] init] error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [channel1 history:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); NSArray *messages = [result items]; XCTAssertEqual(2, messages.count); @@ -125,8 +125,8 @@ - (void) testHistoryBothChannels { XCTAssertEqualObjects(@"testString", [m1 data]); [expectation1 fulfill]; - }]; - [channel2 history:[[ARTRealtimeHistoryQuery alloc] init] error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + } error:nil]; + [channel2 history:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); NSArray *messages = [result items]; XCTAssertEqual(2, messages.count); @@ -135,7 +135,7 @@ - (void) testHistoryBothChannels { XCTAssertEqualObjects(@"testString2", [m0 data]); XCTAssertEqualObjects(@"testString", [m1 data]); [expectation2 fulfill]; - }]; + } error:nil]; }]; }]; }]; @@ -154,7 +154,7 @@ - (void)testHistoryForward { XCTAssertNil(errorInfo); ARTRealtimeHistoryQuery* query = [[ARTRealtimeHistoryQuery alloc] init]; query.direction = ARTQueryDirectionForwards; - [channel history:query error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [channel history:query callback:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); NSArray *messages = [result items]; XCTAssertEqual(2, messages.count); @@ -164,7 +164,7 @@ - (void)testHistoryForward { XCTAssertEqualObjects(@"testString2", [m1 data]); [expectation fulfill]; - }]; + } error:nil]; }]; }]; }]; @@ -184,7 +184,7 @@ -(void) testHistoryForwardPagination { query.limit = 2; query.direction = ARTQueryDirectionForwards; - [channel history:query error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [channel history:query callback:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); XCTAssertTrue([result hasNext]); NSArray * items = [result items]; @@ -222,7 +222,7 @@ -(void) testHistoryForwardPagination { }]; }]; }]; - }]; + } error:nil]; }]; }]; @@ -241,7 +241,7 @@ -(void) testHistoryBackwardPagination { query.limit = 2; query.direction = ARTQueryDirectionBackwards; - [channel history:query error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [channel history:query callback:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); XCTAssertTrue([result hasNext]); NSArray * items = [result items]; @@ -290,7 +290,7 @@ -(void) testHistoryBackwardPagination { }]; }]; }]; - }]; + } error:nil]; }]; }]; [self waitForExpectationsWithTimeout:[ARTTestUtil timeout] handler:nil]; @@ -348,7 +348,7 @@ - (void)testTimeBackwards { query.end = [NSDate dateWithTimeIntervalSince1970:intervalEnd/1000]; query.direction = ARTQueryDirectionBackwards; - [channel history:query error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [channel history:query callback:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); XCTAssertFalse([result hasNext]); NSArray *items = [result items]; @@ -361,7 +361,7 @@ - (void)testTimeBackwards { XCTAssertEqualObjects(goalStr, [m data]); } [expectation fulfill]; - }]; + } error:nil]; }]; }]; }]; @@ -421,7 +421,7 @@ - (void)testTimeForwards { query.end = [NSDate dateWithTimeIntervalSince1970:intervalEnd/1000]; query.direction = ARTQueryDirectionForwards; - [channel history:query error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [channel history:query callback:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); XCTAssertFalse([result hasNext]); NSArray * items = [result items]; @@ -435,7 +435,7 @@ - (void)testTimeForwards { XCTAssertEqualObjects(goalStr, [m data]); } [expectation fulfill]; - }]; + } error:nil]; }]; }]; }]; @@ -476,7 +476,7 @@ - (void)testHistoryFromAttach { ARTRealtimeHistoryQuery *query = [[ARTRealtimeHistoryQuery alloc] init]; query.direction = ARTQueryDirectionBackwards; - [channel2 history:query error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [channel2 history:query callback:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); XCTAssertFalse([result hasNext]); NSArray * items = [result items]; @@ -488,7 +488,7 @@ - (void)testHistoryFromAttach { XCTAssertEqualObjects(goalStr, [m data]); } [expecation fulfill]; - }]; + } error:nil]; } }]; } diff --git a/ably-iosTests/ARTRealtimeCryptoTest.m b/ably-iosTests/ARTRealtimeCryptoTest.m index 6f248ae52..f6f68b41c 100644 --- a/ably-iosTests/ARTRealtimeCryptoTest.m +++ b/ably-iosTests/ARTRealtimeCryptoTest.m @@ -62,7 +62,7 @@ - (void)testSendEncodedMessage { [channel publish:nil data:stringPayload cb:^(ARTErrorInfo *errorInfo) { XCTAssertNil(errorInfo); ARTRealtimeHistoryQuery *query = [[ARTRealtimeHistoryQuery alloc] init]; - [channel history:query error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [channel history:query callback:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); XCTAssertFalse([result hasNext]); NSArray *page = [result items]; @@ -73,7 +73,7 @@ - (void)testSendEncodedMessage { XCTAssertEqualObjects([dataMessage data], dataPayload); XCTAssertEqualObjects([stringMessage data], stringPayload); [exp fulfill]; - }]; + } error:nil]; }]; }]; }]; @@ -102,7 +102,7 @@ - (void)testSendEncodedMessageOnExistingChannel { XCTAssertNil(errorInfo); [c publish:nil data:stringPayload cb:^(ARTErrorInfo *errorInfo) { XCTAssertNil(errorInfo); - [c history:[[ARTRealtimeHistoryQuery alloc] init] error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [c history:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); XCTAssertFalse([result hasNext]); NSArray * page = [result items]; @@ -115,7 +115,7 @@ - (void)testSendEncodedMessageOnExistingChannel { XCTAssertEqualObjects([stringMessage data], stringPayload); XCTAssertEqualObjects([firstMessage data], firstMessageText); [exp fulfill]; - }]; + } error:nil]; }]; }]; }]; diff --git a/ably-iosTests/ARTRealtimeMessageTest.m b/ably-iosTests/ARTRealtimeMessageTest.m index af32cf687..695106e5f 100644 --- a/ably-iosTests/ARTRealtimeMessageTest.m +++ b/ably-iosTests/ARTRealtimeMessageTest.m @@ -303,7 +303,7 @@ - (void)testConnectionIdsInMessage { ARTRealtimeChannel *c2 = [_realtime2.channels get:channelName]; [c2 publish:nil data:@"message2" cb:^(ARTErrorInfo *errorInfo) { XCTAssertNil(errorInfo); - [c1 history:[[ARTRealtimeHistoryQuery alloc] init] error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [c1 history:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); NSArray *messages = [result items]; XCTAssertEqual(2, messages.count); @@ -315,7 +315,7 @@ - (void)testConnectionIdsInMessage { XCTAssertEqualObjects(m1.connectionId, _realtime.connection.id); XCTAssertFalse([m0.connectionId isEqualToString:m1.connectionId]); [exp fulfill]; - }]; + } error:nil]; }]; }]; }]; diff --git a/ably-iosTests/ARTRestChannelHistoryTest.m b/ably-iosTests/ARTRestChannelHistoryTest.m index 36f228669..961d9a5c6 100644 --- a/ably-iosTests/ARTRestChannelHistoryTest.m +++ b/ably-iosTests/ARTRestChannelHistoryTest.m @@ -86,7 +86,7 @@ - (void)testTimeBackwards { query.end = [NSDate dateWithTimeIntervalSince1970:intervalEnd/1000]; query.direction = ARTQueryDirectionBackwards; - [channel history:query error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [channel history:query callback:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); XCTAssertFalse([result hasNext]); NSArray *page = [result items]; @@ -99,7 +99,7 @@ - (void)testTimeBackwards { XCTAssertEqualObjects(goalStr, [m data]); } [firstExpectation fulfill]; - }]; + } error:nil]; }]; }]; }]; @@ -157,7 +157,7 @@ - (void)testTimeForwards { query.end = [NSDate dateWithTimeIntervalSince1970:intervalEnd/1000]; query.direction = ARTQueryDirectionForwards; - [channel history:query error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [channel history:query callback:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); XCTAssertFalse([result hasNext]); NSArray *page = [result items]; @@ -171,7 +171,7 @@ - (void)testTimeForwards { XCTAssertEqualObjects(goalStr, [m data]); } [firstExpectation fulfill]; - }]; + } error:nil]; }]; }]; }]; @@ -196,7 +196,7 @@ - (void)testHistoryForwardPagination { query.limit = 2; query.direction = ARTQueryDirectionBackwards; - [channel history:query error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [channel history:query callback:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); XCTAssertTrue([result hasNext]); NSArray *page = [result items]; @@ -237,7 +237,7 @@ - (void)testHistoryForwardPagination { }]; }]; }]; - }]; + } error:nil]; }]; }]; [self waitForExpectationsWithTimeout:[ARTTestUtil timeout] handler:nil]; @@ -260,7 +260,7 @@ - (void)testHistoryBackwardPagination { query.limit = 2; query.direction = ARTQueryDirectionBackwards; - [channel history:query error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [channel history:query callback:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); XCTAssertTrue([result hasNext]); NSArray * page = [result items]; @@ -301,7 +301,7 @@ - (void)testHistoryBackwardPagination { }]; }]; }]; - }]; + } error:nil]; }]; }]; [self waitForExpectationsWithTimeout:[ARTTestUtil timeout] handler:nil]; @@ -323,7 +323,7 @@ - (void)testHistoryBackwardDefault { ARTDataQuery *query = [[ARTDataQuery alloc] init]; query.limit = 2; - [channel history:query error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [channel history:query callback:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); XCTAssertTrue([result hasNext]); NSArray * page = [result items]; @@ -333,7 +333,7 @@ - (void)testHistoryBackwardDefault { XCTAssertEqualObjects(@"testString4", [firstMessage data]); XCTAssertEqualObjects(@"testString3", [secondMessage data]); [firstExpectation fulfill]; - }]; + } error:nil]; }]; }]; [self waitForExpectationsWithTimeout:[ARTTestUtil timeout] handler:nil]; @@ -362,7 +362,7 @@ -(void) testHistoryTwoClients { ARTDataQuery *query = [[ARTDataQuery alloc] init]; query.limit = 2; - [channelTwo history:query error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [channelTwo history:query callback:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); XCTAssertTrue([result hasNext]); NSArray * page = [result items]; @@ -372,7 +372,7 @@ -(void) testHistoryTwoClients { XCTAssertEqualObjects(@"testString4", [firstMessage data]); XCTAssertEqualObjects(@"testString3", [secondMessage data]); [firstExpectation fulfill]; - }]; + } error:nil]; }]; }]; [self waitForExpectationsWithTimeout:[ARTTestUtil timeout] handler:nil]; @@ -388,7 +388,7 @@ - (void)testHistoryLimit { query.limit = 1001; NSError *error = nil; - BOOL valid = [channelOne history:query error:&error callback:^(ARTPaginatedResult *result, NSError *error) {}]; + BOOL valid = [channelOne history:query callback:^(ARTPaginatedResult *result, NSError *error) {} error:&error]; XCTAssertFalse(valid); XCTAssertNotNil(error); XCTAssert(error.code == ARTDataQueryErrorLimit); @@ -406,7 +406,7 @@ - (void)testHistoryLimitIgnoringError { ARTDataQuery *query = [[ARTDataQuery alloc] init]; query.limit = 1001; // Forcing an invalid query where the error is ignored and the result should be invalid (the request was canceled) - BOOL requested = [channelOne history:query error:nil callback:^(ARTPaginatedResult *result, NSError *error) {}]; + BOOL requested = [channelOne history:query callback:^(ARTPaginatedResult *result, NSError *error) {} error:nil]; XCTAssertFalse(requested); [exp fulfill]; }]; diff --git a/ably-iosTests/ARTRestChannelPublishTest.m b/ably-iosTests/ARTRestChannelPublishTest.m index 3368efe21..373318f48 100644 --- a/ably-iosTests/ARTRestChannelPublishTest.m +++ b/ably-iosTests/ARTRestChannelPublishTest.m @@ -49,7 +49,7 @@ - (void)testTypesByText { XCTAssert(!error); ARTDataQuery *query = [[ARTDataQuery alloc] init]; query.direction = ARTQueryDirectionForwards; - [channel history:query error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [channel history:query callback:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); NSArray *messages = [result items]; XCTAssertEqual(2, messages.count); @@ -58,7 +58,7 @@ - (void)testTypesByText { XCTAssertEqualObjects([m0 data], message1); XCTAssertEqualObjects([m1 data], message2); [expectation fulfill]; - }]; + } error:nil]; }]; }]; }]; @@ -80,7 +80,7 @@ -(void) testPublishArray { [channel publish:messages cb:^(ARTErrorInfo *error) { XCTAssert(!error); - [channel history:[[ARTDataQuery alloc] init] error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [channel history:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); NSArray *messages = [result items]; XCTAssertEqual(3, messages.count); @@ -91,7 +91,7 @@ -(void) testPublishArray { XCTAssertEqualObjects([m1 data], test2); XCTAssertEqualObjects([m2 data], test1); [exp fulfill]; - }]; + } error:nil]; }]; }]; [self waitForExpectationsWithTimeout:[ARTTestUtil timeout] handler:nil]; diff --git a/ably-iosTests/ARTRestCryptoTest.m b/ably-iosTests/ARTRestCryptoTest.m index c310b03a7..0e9263496 100644 --- a/ably-iosTests/ARTRestCryptoTest.m +++ b/ably-iosTests/ARTRestCryptoTest.m @@ -49,7 +49,7 @@ -(void) testSendBinary { XCTAssert(!error); [c publish:nil data:stringPayload cb:^(ARTErrorInfo *error) { XCTAssert(!error); - [c history:[[ARTDataQuery alloc] init] error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [c history:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); NSArray * page = [result items]; XCTAssertTrue(page != nil); @@ -59,7 +59,7 @@ -(void) testSendBinary { XCTAssertEqualObjects([dataMessage data], dataPayload); XCTAssertEqualObjects([stringMessage data], stringPayload); [exp fulfill]; - }]; + } error:nil]; }]; }]; }]; @@ -86,7 +86,7 @@ -(void) testSendEncodedMessage { XCTAssert(!error); [c publish:nil data:stringPayload cb:^(ARTErrorInfo *error) { XCTAssert(!error); - [c history:[[ARTDataQuery alloc] init] error:nil callback:^(ARTPaginatedResult *result, NSError *error) { + [c history:^(ARTPaginatedResult *result, NSError *error) { XCTAssert(!error); NSArray * page = [result items]; XCTAssertTrue(page != nil); @@ -96,7 +96,7 @@ -(void) testSendEncodedMessage { XCTAssertEqualObjects([dataMessage data], dataPayload); XCTAssertEqualObjects([stringMessage data], stringPayload); [exp fulfill]; - }]; + } error:nil]; }]; }]; }]; diff --git a/ably.xcodeproj/project.pbxproj b/ably.xcodeproj/project.pbxproj index cf81dba30..1b249ba9d 100644 --- a/ably.xcodeproj/project.pbxproj +++ b/ably.xcodeproj/project.pbxproj @@ -95,6 +95,7 @@ D70EAAED1BC3376200CD8B9E /* ARTRestChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = D70EAAEB1BC3376200CD8B9E /* ARTRestChannel.h */; settings = {ATTRIBUTES = (Public, ); }; }; D70EAAEE1BC3376200CD8B9E /* ARTRestChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = D70EAAEC1BC3376200CD8B9E /* ARTRestChannel.m */; }; D714A6401C75F0C5002F2CA0 /* ARTWebSocketTransport+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = D714A63F1C75F0C5002F2CA0 /* ARTWebSocketTransport+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; + D714A63E1C74D4B2002F2CA0 /* NSObject+TestSuite.swift in Sources */ = {isa = PBXBuildFile; fileRef = D714A63D1C74D4B2002F2CA0 /* NSObject+TestSuite.swift */; }; D71D30041C5F7B2F002115B0 /* RealtimeClientChannels.swift in Sources */ = {isa = PBXBuildFile; fileRef = D71D30031C5F7B2F002115B0 /* RealtimeClientChannels.swift */; }; D72304701BB72CED00F1ABDA /* RealtimeClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = D723046F1BB72CED00F1ABDA /* RealtimeClient.swift */; }; D746AE1D1BBB5207003ECEF8 /* ARTDataQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = D746AE1A1BBB5207003ECEF8 /* ARTDataQuery.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -312,6 +313,7 @@ D70EAAEB1BC3376200CD8B9E /* ARTRestChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ARTRestChannel.h; sourceTree = ""; }; D70EAAEC1BC3376200CD8B9E /* ARTRestChannel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ARTRestChannel.m; sourceTree = ""; }; D714A63F1C75F0C5002F2CA0 /* ARTWebSocketTransport+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ARTWebSocketTransport+Private.h"; sourceTree = ""; }; + D714A63D1C74D4B2002F2CA0 /* NSObject+TestSuite.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSObject+TestSuite.swift"; sourceTree = ""; }; D71D30031C5F7B2F002115B0 /* RealtimeClientChannels.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealtimeClientChannels.swift; sourceTree = ""; }; D723046F1BB72CED00F1ABDA /* RealtimeClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealtimeClient.swift; sourceTree = ""; }; D746AE1A1BBB5207003ECEF8 /* ARTDataQuery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ARTDataQuery.h; sourceTree = ""; }; @@ -456,6 +458,7 @@ 856AAC961B6E30C800B07119 /* TestUtilities.swift */, D780846C1C68B3E50083009D /* NSObject+TestSuite.h */, D780846D1C68B3E50083009D /* NSObject+TestSuite.m */, + D714A63D1C74D4B2002F2CA0 /* NSObject+TestSuite.swift */, 856AAC951B6E30C800B07119 /* ablySpec-Bridging-Header.h */, D7C1B8761BBEA81A0087B55F /* Auth.swift */, 856AAC981B6E312F00B07119 /* RestClient.swift */, @@ -1061,6 +1064,7 @@ D746AE2C1BBB625E003ECEF8 /* RestChannel.swift in Sources */, EB89D40D1C61C6EA007FA5B7 /* ARTRealtimeChannels.m in Sources */, D71D30041C5F7B2F002115B0 /* RealtimeClientChannels.swift in Sources */, + D714A63E1C74D4B2002F2CA0 /* NSObject+TestSuite.swift in Sources */, 856AAC971B6E30C800B07119 /* TestUtilities.swift in Sources */, D780846E1C68B3E50083009D /* NSObject+TestSuite.m in Sources */, 853ED7C41B7A1A3C006F1C6F /* RestClientStats.swift in Sources */, diff --git a/ablySpec/NSObject+TestSuite.h b/ablySpec/NSObject+TestSuite.h index ff7949ecb..542b89c67 100644 --- a/ablySpec/NSObject+TestSuite.h +++ b/ablySpec/NSObject+TestSuite.h @@ -14,9 +14,12 @@ ART_ASSUME_NONNULL_BEGIN -/// Get each return value generated by the identified method. +/// Get each return value generated by the identified instance method. - (void)testSuite_getReturnValueFrom:(SEL)selector callback:(void (^)(id))callback; +/// Inject a block of code to the identified instance method. +- (void)testSuite_injectIntoMethod:(SEL)selector code:(void (^)(void))block; + ART_ASSUME_NONNULL_END @end diff --git a/ablySpec/NSObject+TestSuite.m b/ablySpec/NSObject+TestSuite.m index b64dfbbe4..afe17493b 100644 --- a/ablySpec/NSObject+TestSuite.m +++ b/ablySpec/NSObject+TestSuite.m @@ -12,11 +12,17 @@ @implementation NSObject (TestSuite) - (void)testSuite_getReturnValueFrom:(SEL)selector callback:(void (^)(id))callback { - [self aspect_hookSelector:selector withOptions:0 usingBlock:^(id info) { + [self aspect_hookSelector:selector withOptions:AspectPositionAfter usingBlock:^(id info) { __autoreleasing id result; [[info originalInvocation] getReturnValue:&result]; callback([result copy]); } error:nil]; } +- (void)testSuite_injectIntoMethod:(SEL)selector code:(void (^)(void))block { + [self aspect_hookSelector:selector withOptions:AspectPositionAfter usingBlock:^(id info) { + block(); + } error:nil]; +} + @end diff --git a/ablySpec/NSObject+TestSuite.swift b/ablySpec/NSObject+TestSuite.swift new file mode 100644 index 000000000..766dbd692 --- /dev/null +++ b/ablySpec/NSObject+TestSuite.swift @@ -0,0 +1,21 @@ +// +// NSObject+TestSuite.swift +// ably +// +// Created by Ricardo Pereira on 17/02/16. +// Copyright © 2016 Ably. All rights reserved. +// + +import Aspects + +extension NSObject { + + /// Inject a block of code to the identified class method. + class func testSuite_injectIntoClassMethod(selector: Selector, code: ()->()) { + let block: @convention(block) (AspectInfo) -> Void = { _ in + code() + } + let _ = try! self.aspect_hookSelector(selector, withOptions: .PositionAfter, usingBlock: unsafeBitCast(block, AnyObject.self)) + } + +} diff --git a/ablySpec/ReadmeExamples.swift b/ablySpec/ReadmeExamples.swift index bc3ac163a..221517856 100644 --- a/ablySpec/ReadmeExamples.swift +++ b/ablySpec/ReadmeExamples.swift @@ -78,7 +78,7 @@ class ReadmeExamples : QuickSpec { let channel = client.channels.get("test") - channel.history { messagesPage, error in + try! channel.history { messagesPage, error in let messagesPage = messagesPage! print(messagesPage.items) print(messagesPage.items.first) @@ -149,7 +149,7 @@ class ReadmeExamples : QuickSpec { let client = ARTRest(options: options) let channel = client.channels.get("test") - channel.history { messagesPage, error in + try! channel.history { messagesPage, error in let messagesPage = messagesPage! print(messagesPage.items.first) print((messagesPage.items.first as? ARTMessage)?.data) // payload for the message diff --git a/ablySpec/RealtimeClientChannel.swift b/ablySpec/RealtimeClientChannel.swift index 23cf8a7a6..2a020130e 100644 --- a/ablySpec/RealtimeClientChannel.swift +++ b/ablySpec/RealtimeClientChannel.swift @@ -828,6 +828,52 @@ class RealtimeClientChannel: QuickSpec { } + // RTL10 + context("history") { + + // RTL10a + it("should support all the same params as Rest") { + let options = AblyTests.commonAppSetup() + + let rest = ARTRest(options: options) + + let realtime = ARTRealtime(options: options) + defer { realtime.close() } + + var restChannelHistoryMethodWasCalled = false + ARTRestChannel.testSuite_injectIntoClassMethod("history:callback:error:") { + restChannelHistoryMethodWasCalled = true + } + + let channelRest = rest.channels.get("test") + let channelRealtime = realtime.channels.get("test") + + let queryRealtime = ARTRealtimeHistoryQuery() + queryRealtime.start = NSDate() + queryRealtime.end = NSDate() + queryRealtime.direction = .Forwards + queryRealtime.limit = 50 + + let queryRest = queryRealtime as ARTDataQuery + + waitUntil(timeout: testTimeout) { done in + try! channelRest.history(queryRest) { _, _ in + done() + } + } + expect(restChannelHistoryMethodWasCalled).to(beTrue()) + restChannelHistoryMethodWasCalled = false + + waitUntil(timeout: testTimeout) { done in + try! channelRealtime.history(queryRealtime) { _, _ in + done() + } + } + expect(restChannelHistoryMethodWasCalled).to(beTrue()) + } + + } + } } } diff --git a/ablySpec/RestChannel.swift b/ablySpec/RestChannel.swift index 097e48380..2a0825ff2 100644 --- a/ablySpec/RestChannel.swift +++ b/ablySpec/RestChannel.swift @@ -36,7 +36,7 @@ class RestChannel: QuickSpec { channel.publish(name, data: data) { error in publishError = error - channel.history(nil) { result, _ in + try! channel.history { result, _ in publishedMessage = result?.items.first as? ARTMessage } } @@ -55,7 +55,7 @@ class RestChannel: QuickSpec { channel.publish(name, data: nil) { error in publishError = error - channel.history(nil) { result, _ in + try! channel.history { result, _ in publishedMessage = result?.items.first as? ARTMessage } } @@ -74,7 +74,7 @@ class RestChannel: QuickSpec { channel.publish(nil, data: data) { error in publishError = error - channel.history(nil) { result, _ in + try! channel.history { result, _ in publishedMessage = result?.items.first as? ARTMessage } } @@ -93,7 +93,7 @@ class RestChannel: QuickSpec { channel.publish(nil, data: nil) { error in publishError = error - channel.history(nil) { result, _ in + try! channel.history { result, _ in publishedMessage = result?.items.first as? ARTMessage } } @@ -111,7 +111,7 @@ class RestChannel: QuickSpec { channel.publish([ARTMessage(data:data, name: name)]) { error in publishError = error - channel.history(nil) { result, _ in + try! channel.history { result, _ in publishedMessage = result?.items.first as? ARTMessage } } @@ -139,7 +139,7 @@ class RestChannel: QuickSpec { channel.publish(messages) { error in publishError = error client.httpExecutor = oldExecutor - channel.history(nil) { result, _ in + try! channel.history { result, _ in if let items = result?.items as? [ARTMessage] { publishedMessages.appendContentsOf(items) } @@ -377,7 +377,7 @@ class RestChannel: QuickSpec { } var totalReceived = 0 - channel.history(nil) { result, error in + try! channel.history { result, error in expect(error).to(beNil()) guard let result = result else { XCTFail("Result is nil")