aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Jorge Canizales <jcanizales@gmail.com>2015-05-15 15:47:09 -0700
committerGravatar Jorge Canizales <jcanizales@gmail.com>2015-05-15 15:47:09 -0700
commitdc73a32cbb2abeba6c14e62473b3774fce641918 (patch)
treebba4d33de1deb0fd6a49fe08e39e7159dcc506b6 /src
parentac25e00dbd2fe62bf63ee4e32803410be99e304d (diff)
parent25750d9b1e269b29bf8296ad8f7ace47242253e6 (diff)
Merge pull request #1626 from murgatroid99/objective_c_interop_tests
More Objective-C interop tests
Diffstat (limited to 'src')
-rw-r--r--src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m63
1 files changed, 61 insertions, 2 deletions
diff --git a/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m b/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m
index 2ef6a6e4ab..72ceed0c31 100644
--- a/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m
+++ b/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m
@@ -31,9 +31,12 @@
*
*/
+#include <grpc/status.h>
+
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
+#import <gRPC/ProtoRPC.h>
#import <gRPC/GRXWriter+Immediate.h>
#import <RemoteTest/Messages.pb.h>
#import <RemoteTest/Test.pb.h>
@@ -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