Implements empty_unary, large_unary, and client_streaming integration tests.

As defined in the spec.
pull/1399/head
Jorge Canizales 10 years ago
parent 8bf5fc88d4
commit 9d96aa6e4c
  1. 87
      src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m

@ -34,6 +34,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#import <gRPC/GRXWriter+Immediate.h>
#import <RemoteTest/Messages.pb.h> #import <RemoteTest/Messages.pb.h>
#import <RemoteTest/Test.pb.h> #import <RemoteTest/Test.pb.h>
@ -48,40 +49,82 @@
_service = [[RMTTestService alloc] initWithHost:@"grpc-test.sandbox.google.com"]; _service = [[RMTTestService alloc] initWithHost:@"grpc-test.sandbox.google.com"];
} }
- (void)testEmptyRPC { // Tests as described here: https://github.com/grpc/grpc/blob/master/doc/interop-test-descriptions.md
__weak XCTestExpectation *noRPCError = [self expectationWithDescription:@"RPC succeeded."];
__weak XCTestExpectation *responded = [self expectationWithDescription:@"Response received."];
[_service emptyCallWithRequest:[RMTEmpty defaultInstance] - (void)testEmptyUnaryRPC {
handler:^(RMTEmpty *response, NSError *error) { __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); XCTAssertNil(error, @"Finished with unexpected error: %@", error);
[noRPCError fulfill];
XCTAssertNotNil(response, @"nil response received."); id expectedResponse = [RMTEmpty defaultInstance];
[responded fulfill]; XCTAssertEqualObjects(response, expectedResponse);
[expectation fulfill];
}]; }];
[self waitForExpectationsWithTimeout:2. handler:nil]; [self waitForExpectationsWithTimeout:2. handler:nil];
} }
- (void)testSimpleProtoRPC { - (void)testLargeUnaryRPC {
__weak XCTestExpectation *noRPCError = [self expectationWithDescription:@"RPC succeeded."]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyUnary"];
__weak XCTestExpectation *responded = [self expectationWithDescription:@"Response received."];
__weak XCTestExpectation *validResponse = [self expectationWithDescription:@"Valid response."];
RMTSimpleRequest *request = [[[[[[RMTSimpleRequestBuilder alloc] init] RMTSimpleRequest *request = [[[[[[RMTSimpleRequestBuilder alloc] init]
setResponseSize:100] setResponseType:RMTPayloadTypeCompressable]
setFillUsername:YES] setResponseSize:314159]
setFillOauthScope:YES] setPayloadBuilder:[[[RMTPayloadBuilder alloc] init]
setBody:[NSMutableData dataWithLength:271828]]]
build]; build];
[_service unaryCallWithRequest:request handler:^(RMTSimpleResponse *response, NSError *error) { [_service unaryCallWithRequest:request handler:^(RMTSimpleResponse *response, NSError *error) {
XCTAssertNil(error, @"Finished with unexpected error: %@", error); XCTAssertNil(error, @"Finished with unexpected error: %@", error);
[noRPCError fulfill];
XCTAssertNotNil(response, @"nil response received."); id expectedResponse = [[[[RMTSimpleResponseBuilder alloc] init]
[responded fulfill]; setPayloadBuilder:[[[[RMTPayloadBuilder alloc] init]
// We expect empty strings, not nil: setType:RMTPayloadTypeCompressable]
XCTAssertNotNil(response.username, @"Response's username is nil."); setBody:[NSMutableData dataWithLength:314159]]]
XCTAssertNotNil(response.oauthScope, @"Response's OAuth scope is nil."); build];
[validResponse fulfill]; 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<GRXWriter> 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]; [self waitForExpectationsWithTimeout:2. handler:nil];

Loading…
Cancel
Save