diff --git a/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m b/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m index 2ef6a6e4ab9..72ceed0c318 100644 --- a/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m +++ b/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m @@ -31,9 +31,12 @@ * */ +#include + #import #import +#import #import #import #import @@ -69,7 +72,7 @@ } - (void)testLargeUnaryRPC { - __weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyUnary"]; + __weak XCTestExpectation *expectation = [self expectationWithDescription:@"LargeUnary"]; RMTSimpleRequest *request = [[[[[[RMTSimpleRequestBuilder alloc] init] setResponseType:RMTPayloadTypeCompressable] @@ -95,7 +98,7 @@ } - (void)testClientStreamingRPC { - __weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyUnary"]; + __weak XCTestExpectation *expectation = [self expectationWithDescription:@"ClientStreaming"]; id request1 = [[[[RMTStreamingInputCallRequestBuilder alloc] init] setPayloadBuilder:[[[RMTPayloadBuilder alloc] init] @@ -130,4 +133,60 @@ [self waitForExpectationsWithTimeout:4. handler:nil]; } +- (void)testServerStreamingRPC { + __weak XCTestExpectation *expectation = [self expectationWithDescription:@"ServerStreaming"]; + NSArray *expectedSizes = @[@31415, @9, @2653, @58979]; + __block int index = 0; + id request = [[[[[[[RMTStreamingOutputCallRequestBuilder alloc] init] + addResponseParameters:[[[[RMTResponseParametersBuilder alloc] init] + setSize:31415] build]] + addResponseParameters:[[[[RMTResponseParametersBuilder alloc] init] + setSize:9] build]] + addResponseParameters:[[[[RMTResponseParametersBuilder alloc] init] + setSize:2653] build]] + addResponseParameters:[[[[RMTResponseParametersBuilder alloc] init] + setSize:58979] build]] + build]; + [_service streamingOutputCallWithRequest:request handler:^(BOOL done, RMTStreamingOutputCallResponse *response, NSError *error){ + XCTAssertNil(error, @"Finished with unexpected error: %@", error); + id expectedResponseBuilder = [[RMTStreamingOutputCallResponseBuilder alloc] init]; + id expectedPayload = [[[[[RMTPayloadBuilder alloc] init] + setType:RMTPayloadTypeCompressable] + setBody:[NSMutableData dataWithLength:[expectedSizes[index] unsignedIntegerValue]]] + build]; + expectedResponseBuilder = [expectedResponseBuilder setPayload:expectedPayload]; + id expectedResponse = [expectedResponseBuilder build]; + XCTAssertEqualObjects(response, expectedResponse); + + [expectation fulfill]; + index += 1; + }]; + + [self waitForExpectationsWithTimeout:4 handler:nil]; +} + +- (void)testEmptyStreamRPC { + __weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyStream"]; + [_service fullDuplexCallWithRequestsWriter:[GRXWriter emptyWriter] + handler:^(bool done, RMTStreamingOutputCallResponse *response, NSError *error) { + XCTAssertNil(error, @"Finished with unexpected error: %@", error); + XCTAssert(done, @"Unexpected response: %@", response); + [expectation fulfill]; + }]; + [self waitForExpectationsWithTimeout:4 handler:nil]; +} + +- (void)testCancelAfterBeginRPC { + __weak XCTestExpectation *expectation = [self expectationWithDescription:@"CancelAfterBegin"]; + // TODO(mlumish): change to writing that blocks instead of writing + ProtoRPC *call = [_service RPCToStreamingInputCallWithRequestsWriter:[GRXWriter emptyWriter] + handler:^(RMTStreamingInputCallResponse *response, NSError *error) { + XCTAssertEqual([error code], GRPC_STATUS_CANCELLED); + [expectation fulfill]; + }]; + [call start]; + [call cancel]; + [self waitForExpectationsWithTimeout:1 handler:nil]; +} + @end