Skip to content
Snippets Groups Projects
Commit 206e75b6 authored by Jorge Canizales's avatar Jorge Canizales
Browse files

Adjust remote tests to use proto3

parent fd88e465
No related branches found
No related tags found
No related merge requests found
...@@ -38,8 +38,10 @@ ...@@ -38,8 +38,10 @@
#import <gRPC/ProtoRPC.h> #import <gRPC/ProtoRPC.h>
#import <gRPC/GRXWriter+Immediate.h> #import <gRPC/GRXWriter+Immediate.h>
#import <RemoteTest/Messages.pb.h> #import <RemoteTest/Empty.pbobjc.h>
#import <RemoteTest/Test.pb.h> #import <RemoteTest/Messages.pbobjc.h>
#import <RemoteTest/Test.pbobjc.h>
#import <RemoteTest/Test.pbrpc.h>
@interface RemoteProtoTests : XCTestCase @interface RemoteProtoTests : XCTestCase
@end @end
...@@ -57,12 +59,12 @@ ...@@ -57,12 +59,12 @@
- (void)testEmptyUnaryRPC { - (void)testEmptyUnaryRPC {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyUnary"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyUnary"];
RMTEmpty *request = [RMTEmpty defaultInstance]; RMTEmpty *request = [RMTEmpty message];
[_service emptyCallWithRequest:request handler:^(RMTEmpty *response, NSError *error) { [_service emptyCallWithRequest:request handler:^(RMTEmpty *response, NSError *error) {
XCTAssertNil(error, @"Finished with unexpected error: %@", error); XCTAssertNil(error, @"Finished with unexpected error: %@", error);
id expectedResponse = [RMTEmpty defaultInstance]; id expectedResponse = [RMTEmpty message];
XCTAssertEqualObjects(response, expectedResponse); XCTAssertEqualObjects(response, expectedResponse);
[expectation fulfill]; [expectation fulfill];
...@@ -74,21 +76,17 @@ ...@@ -74,21 +76,17 @@
- (void)testLargeUnaryRPC { - (void)testLargeUnaryRPC {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"LargeUnary"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"LargeUnary"];
RMTSimpleRequest *request = [[[[[[RMTSimpleRequestBuilder alloc] init] RMTSimpleRequest *request = [RMTSimpleRequest message];
setResponseType:RMTPayloadTypeCompressable] request.responseType = RMTPayloadType_Compressable;
setResponseSize:314159] request.responseSize = 314159;
setPayloadBuilder:[[[RMTPayloadBuilder alloc] init] request.payload.body = [NSMutableData dataWithLength:271828];
setBody:[NSMutableData dataWithLength:271828]]]
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);
id expectedResponse = [[[[RMTSimpleResponseBuilder alloc] init] RMTSimpleResponse *expectedResponse = [RMTSimpleResponse message];
setPayloadBuilder:[[[[RMTPayloadBuilder alloc] init] expectedResponse.payload.type = RMTPayloadType_Compressable;
setType:RMTPayloadTypeCompressable] expectedResponse.payload.body = [NSMutableData dataWithLength:314159];
setBody:[NSMutableData dataWithLength:314159]]]
build];
XCTAssertEqualObjects(response, expectedResponse); XCTAssertEqualObjects(response, expectedResponse);
[expectation fulfill]; [expectation fulfill];
...@@ -100,31 +98,27 @@ ...@@ -100,31 +98,27 @@
- (void)testClientStreamingRPC { - (void)testClientStreamingRPC {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"ClientStreaming"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"ClientStreaming"];
id request1 = [[[[RMTStreamingInputCallRequestBuilder alloc] init] RMTStreamingInputCallRequest *request1 = [RMTStreamingInputCallRequest message];
setPayloadBuilder:[[[RMTPayloadBuilder alloc] init] request1.payload.body = [NSMutableData dataWithLength:27182];
setBody:[NSMutableData dataWithLength:27182]]]
build]; RMTStreamingInputCallRequest *request2 = [RMTStreamingInputCallRequest message];
id request2 = [[[[RMTStreamingInputCallRequestBuilder alloc] init] request2.payload.body = [NSMutableData dataWithLength:8];
setPayloadBuilder:[[[RMTPayloadBuilder alloc] init]
setBody:[NSMutableData dataWithLength:8]]] RMTStreamingInputCallRequest *request3 = [RMTStreamingInputCallRequest message];
build]; request3.payload.body = [NSMutableData dataWithLength:1828];
id request3 = [[[[RMTStreamingInputCallRequestBuilder alloc] init]
setPayloadBuilder:[[[RMTPayloadBuilder alloc] init] RMTStreamingInputCallRequest *request4 = [RMTStreamingInputCallRequest message];
setBody:[NSMutableData dataWithLength:1828]]] request4.payload.body = [NSMutableData dataWithLength:45904];
build];
id request4 = [[[[RMTStreamingInputCallRequestBuilder alloc] init]
setPayloadBuilder:[[[RMTPayloadBuilder alloc] init]
setBody:[NSMutableData dataWithLength:45904]]]
build];
id<GRXWriter> writer = [GRXWriter writerWithContainer:@[request1, request2, request3, request4]]; id<GRXWriter> writer = [GRXWriter writerWithContainer:@[request1, request2, request3, request4]];
[_service streamingInputCallWithRequestsWriter:writer [_service streamingInputCallWithRequestsWriter:writer
handler:^(RMTStreamingInputCallResponse *response, NSError *error) { handler:^(RMTStreamingInputCallResponse *response,
NSError *error) {
XCTAssertNil(error, @"Finished with unexpected error: %@", error); XCTAssertNil(error, @"Finished with unexpected error: %@", error);
id expectedResponse = [[[[RMTStreamingInputCallResponseBuilder alloc] init] RMTStreamingInputCallResponse *expectedResponse = [RMTStreamingInputCallResponse message];
setAggregatedPayloadSize:74922] expectedResponse.aggregatedPayloadSize = 74922;
build];
XCTAssertEqualObjects(response, expectedResponse); XCTAssertEqualObjects(response, expectedResponse);
[expectation fulfill]; [expectation fulfill];
...@@ -136,28 +130,27 @@ ...@@ -136,28 +130,27 @@
- (void)testServerStreamingRPC { - (void)testServerStreamingRPC {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"ServerStreaming"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"ServerStreaming"];
NSArray *expectedSizes = @[@31415, @9, @2653, @58979]; NSArray *expectedSizes = @[@31415, @9, @2653, @58979];
RMTStreamingOutputCallRequest *request = [RMTStreamingOutputCallRequest message];
for (NSNumber *size in expectedSizes) {
RMTResponseParameters *parameters = [RMTResponseParameters message];
parameters.size = [size integerValue];
[request.responseParametersArray addObject:parameters];
}
__block int index = 0; __block int index = 0;
id request = [[[[[[[RMTStreamingOutputCallRequestBuilder alloc] init] [_service streamingOutputCallWithRequest:request
addResponseParameters:[[[[RMTResponseParametersBuilder alloc] init] handler:^(BOOL done,
setSize:31415] build]] RMTStreamingOutputCallResponse *response,
addResponseParameters:[[[[RMTResponseParametersBuilder alloc] init] NSError *error){
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); XCTAssertNil(error, @"Finished with unexpected error: %@", error);
id expectedResponseBuilder = [[RMTStreamingOutputCallResponseBuilder alloc] init];
id expectedPayload = [[[[[RMTPayloadBuilder alloc] init] RMTStreamingOutputCallResponse *expectedResponse = [RMTStreamingOutputCallResponse message];
setType:RMTPayloadTypeCompressable] expectedResponse.payload.type = RMTPayloadType_Compressable;
setBody:[NSMutableData dataWithLength:[expectedSizes[index] unsignedIntegerValue]]] int expectedSize = [expectedSizes[index] unsignedIntegerValue];
build]; expectedResponse.payload.body = [NSMutableData dataWithLength:expectedSize];
expectedResponseBuilder = [expectedResponseBuilder setPayload:expectedPayload];
id expectedResponse = [expectedResponseBuilder build];
XCTAssertEqualObjects(response, expectedResponse); XCTAssertEqualObjects(response, expectedResponse);
[expectation fulfill]; [expectation fulfill];
index += 1; index += 1;
}]; }];
...@@ -168,11 +161,13 @@ ...@@ -168,11 +161,13 @@
- (void)testEmptyStreamRPC { - (void)testEmptyStreamRPC {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyStream"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyStream"];
[_service fullDuplexCallWithRequestsWriter:[GRXWriter emptyWriter] [_service fullDuplexCallWithRequestsWriter:[GRXWriter emptyWriter]
handler:^(bool done, RMTStreamingOutputCallResponse *response, NSError *error) { handler:^(BOOL done,
XCTAssertNil(error, @"Finished with unexpected error: %@", error); RMTStreamingOutputCallResponse *response,
XCTAssert(done, @"Unexpected response: %@", response); NSError *error) {
[expectation fulfill]; XCTAssertNil(error, @"Finished with unexpected error: %@", error);
}]; XCTAssert(done, @"Unexpected response: %@", response);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:4 handler:nil]; [self waitForExpectationsWithTimeout:4 handler:nil];
} }
...@@ -180,10 +175,11 @@ ...@@ -180,10 +175,11 @@
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"CancelAfterBegin"]; __weak XCTestExpectation *expectation = [self expectationWithDescription:@"CancelAfterBegin"];
// TODO(mlumish): change to writing that blocks instead of writing // TODO(mlumish): change to writing that blocks instead of writing
ProtoRPC *call = [_service RPCToStreamingInputCallWithRequestsWriter:[GRXWriter emptyWriter] ProtoRPC *call = [_service RPCToStreamingInputCallWithRequestsWriter:[GRXWriter emptyWriter]
handler:^(RMTStreamingInputCallResponse *response, NSError *error) { handler:^(RMTStreamingInputCallResponse *response,
XCTAssertEqual([error code], GRPC_STATUS_CANCELLED); NSError *error) {
[expectation fulfill]; XCTAssertEqual(error.code, GRPC_STATUS_CANCELLED);
}]; [expectation fulfill];
}];
[call start]; [call start];
[call cancel]; [call cancel];
[self waitForExpectationsWithTimeout:1 handler:nil]; [self waitForExpectationsWithTimeout:1 handler:nil];
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#import <gRPC/GRPCMethodName.h> #import <gRPC/GRPCMethodName.h>
#import <gRPC/GRXWriter+Immediate.h> #import <gRPC/GRXWriter+Immediate.h>
#import <gRPC/GRXWriteable.h> #import <gRPC/GRXWriteable.h>
#import <RemoteTest/Messages.pb.h> #import <RemoteTest/Messages.pbobjc.h>
@interface RemoteTests : XCTestCase @interface RemoteTests : XCTestCase
@end @end
...@@ -111,11 +111,10 @@ ...@@ -111,11 +111,10 @@
interface:@"TestService" interface:@"TestService"
method:@"UnaryCall"]; method:@"UnaryCall"];
RMTSimpleRequest *request = [[[[[[RMTSimpleRequestBuilder alloc] init] RMTSimpleRequest *request = [[RMTSimpleRequest alloc] init];
setResponseSize:100] request.responseSize = 100;
setFillUsername:YES] request.fillUsername = YES;
setFillOauthScope:YES] request.fillOauthScope = YES;
build];
id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[request data]]; id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[request data]];
GRPCCall *call = [[GRPCCall alloc] initWithHost:@"grpc-test.sandbox.google.com" GRPCCall *call = [[GRPCCall alloc] initWithHost:@"grpc-test.sandbox.google.com"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment