From 9d96aa6e4c90f6a7772e1b633759a18403e22e07 Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Tue, 21 Apr 2015 15:53:45 -0700 Subject: [PATCH] Implements empty_unary, large_unary, and client_streaming integration tests. As defined in the spec. --- .../Sample/SampleTests/RemoteProtoTests.m | 87 ++++++++++++++----- 1 file changed, 65 insertions(+), 22 deletions(-) diff --git a/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m b/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m index 6c5de812770..f7a7aaec3ee 100644 --- a/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m +++ b/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m @@ -34,6 +34,7 @@ #import #import +#import #import #import @@ -48,40 +49,82 @@ _service = [[RMTTestService alloc] initWithHost:@"grpc-test.sandbox.google.com"]; } -- (void)testEmptyRPC { - __weak XCTestExpectation *noRPCError = [self expectationWithDescription:@"RPC succeeded."]; - __weak XCTestExpectation *responded = [self expectationWithDescription:@"Response received."]; +// Tests as described here: https://github.com/grpc/grpc/blob/master/doc/interop-test-descriptions.md - [_service emptyCallWithRequest:[RMTEmpty defaultInstance] - handler:^(RMTEmpty *response, NSError *error) { +- (void)testEmptyUnaryRPC { + __weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyUnary"]; + + RMTEmpty *request = [RMTEmpty defaultInstance]; + + [_service emptyCallWithRequest:request handler:^(RMTEmpty *response, NSError *error) { XCTAssertNil(error, @"Finished with unexpected error: %@", error); - [noRPCError fulfill]; - XCTAssertNotNil(response, @"nil response received."); - [responded fulfill]; + + id expectedResponse = [RMTEmpty defaultInstance]; + XCTAssertEqualObjects(response, expectedResponse); + + [expectation fulfill]; }]; [self waitForExpectationsWithTimeout:2. handler:nil]; } -- (void)testSimpleProtoRPC { - __weak XCTestExpectation *noRPCError = [self expectationWithDescription:@"RPC succeeded."]; - __weak XCTestExpectation *responded = [self expectationWithDescription:@"Response received."]; - __weak XCTestExpectation *validResponse = [self expectationWithDescription:@"Valid response."]; +- (void)testLargeUnaryRPC { + __weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyUnary"]; RMTSimpleRequest *request = [[[[[[RMTSimpleRequestBuilder alloc] init] - setResponseSize:100] - setFillUsername:YES] - setFillOauthScope:YES] + setResponseType:RMTPayloadTypeCompressable] + setResponseSize:314159] + setPayloadBuilder:[[[RMTPayloadBuilder alloc] init] + setBody:[NSMutableData dataWithLength:271828]]] build]; + [_service unaryCallWithRequest:request handler:^(RMTSimpleResponse *response, NSError *error) { XCTAssertNil(error, @"Finished with unexpected error: %@", error); - [noRPCError fulfill]; - XCTAssertNotNil(response, @"nil response received."); - [responded fulfill]; - // We expect empty strings, not nil: - XCTAssertNotNil(response.username, @"Response's username is nil."); - XCTAssertNotNil(response.oauthScope, @"Response's OAuth scope is nil."); - [validResponse fulfill]; + + id expectedResponse = [[[[RMTSimpleResponseBuilder alloc] init] + setPayloadBuilder:[[[[RMTPayloadBuilder alloc] init] + setType:RMTPayloadTypeCompressable] + setBody:[NSMutableData dataWithLength:314159]]] + build]; + XCTAssertEqualObjects(response, expectedResponse); + + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:2. handler:nil]; +} + +- (void)testClientStreamingRPC { + __weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyUnary"]; + + id request1 = [[[[RMTStreamingInputCallRequestBuilder alloc] init] + setPayloadBuilder:[[[RMTPayloadBuilder alloc] init] + setBody:[NSMutableData dataWithLength:27182]]] + build]; + id request2 = [[[[RMTStreamingInputCallRequestBuilder alloc] init] + setPayloadBuilder:[[[RMTPayloadBuilder alloc] init] + setBody:[NSMutableData dataWithLength:8]]] + build]; + id request3 = [[[[RMTStreamingInputCallRequestBuilder alloc] init] + setPayloadBuilder:[[[RMTPayloadBuilder alloc] init] + setBody:[NSMutableData dataWithLength:1828]]] + build]; + id request4 = [[[[RMTStreamingInputCallRequestBuilder alloc] init] + setPayloadBuilder:[[[RMTPayloadBuilder alloc] init] + setBody:[NSMutableData dataWithLength:45904]]] + build]; + id writer = [GRXWriter writerWithContainer:@[request1, request2, request3, request4]]; + + [_service streamingInputCallWithRequestsWriter:writer + handler:^(RMTStreamingInputCallResponse *response, NSError *error) { + XCTAssertNil(error, @"Finished with unexpected error: %@", error); + + id expectedResponse = [[[[RMTStreamingInputCallResponseBuilder alloc] init] + setAggregatedPayloadSize:74922] + build]; + XCTAssertEqualObjects(response, expectedResponse); + + [expectation fulfill]; }]; [self waitForExpectationsWithTimeout:2. handler:nil];