aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/examples/Sample/SampleTests
diff options
context:
space:
mode:
authorGravatar Michael Lumish <mlumish@google.com>2015-05-18 10:40:06 -0700
committerGravatar Michael Lumish <mlumish@google.com>2015-05-18 10:40:06 -0700
commit7dff30d8fb366960adc11ca4b62009023e489853 (patch)
treef65b366613b9d3b615ae563738a2e1d0b919e2b1 /src/objective-c/examples/Sample/SampleTests
parent9e28875206d03a5fc5b1c5c51ebe4c0a7506f717 (diff)
parent05456f81c5d8ae93aed407d6503fc44136d1f6de (diff)
Merge pull request #1636 from jcanizales/move-sample-to-proto3
Move sample app and tests to proto3
Diffstat (limited to 'src/objective-c/examples/Sample/SampleTests')
-rw-r--r--src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m122
-rw-r--r--src/objective-c/examples/Sample/SampleTests/RemoteTests.m11
-rw-r--r--src/objective-c/examples/Sample/SampleTests/SampleTests.m30
3 files changed, 88 insertions, 75 deletions
diff --git a/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m b/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m
index 72ceed0c31..f5c444d171 100644
--- a/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m
+++ b/src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m
@@ -38,8 +38,10 @@
#import <gRPC/ProtoRPC.h>
#import <gRPC/GRXWriter+Immediate.h>
-#import <RemoteTest/Messages.pb.h>
-#import <RemoteTest/Test.pb.h>
+#import <RemoteTest/Empty.pbobjc.h>
+#import <RemoteTest/Messages.pbobjc.h>
+#import <RemoteTest/Test.pbobjc.h>
+#import <RemoteTest/Test.pbrpc.h>
@interface RemoteProtoTests : XCTestCase
@end
@@ -57,12 +59,12 @@
- (void)testEmptyUnaryRPC {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyUnary"];
- RMTEmpty *request = [RMTEmpty defaultInstance];
+ RMTEmpty *request = [RMTEmpty message];
[_service emptyCallWithRequest:request handler:^(RMTEmpty *response, NSError *error) {
XCTAssertNil(error, @"Finished with unexpected error: %@", error);
- id expectedResponse = [RMTEmpty defaultInstance];
+ id expectedResponse = [RMTEmpty message];
XCTAssertEqualObjects(response, expectedResponse);
[expectation fulfill];
@@ -74,21 +76,17 @@
- (void)testLargeUnaryRPC {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"LargeUnary"];
- RMTSimpleRequest *request = [[[[[[RMTSimpleRequestBuilder alloc] init]
- setResponseType:RMTPayloadTypeCompressable]
- setResponseSize:314159]
- setPayloadBuilder:[[[RMTPayloadBuilder alloc] init]
- setBody:[NSMutableData dataWithLength:271828]]]
- build];
+ RMTSimpleRequest *request = [RMTSimpleRequest message];
+ request.responseType = RMTPayloadType_Compressable;
+ request.responseSize = 314159;
+ request.payload.body = [NSMutableData dataWithLength:271828];
[_service unaryCallWithRequest:request handler:^(RMTSimpleResponse *response, NSError *error) {
XCTAssertNil(error, @"Finished with unexpected error: %@", error);
- id expectedResponse = [[[[RMTSimpleResponseBuilder alloc] init]
- setPayloadBuilder:[[[[RMTPayloadBuilder alloc] init]
- setType:RMTPayloadTypeCompressable]
- setBody:[NSMutableData dataWithLength:314159]]]
- build];
+ RMTSimpleResponse *expectedResponse = [RMTSimpleResponse message];
+ expectedResponse.payload.type = RMTPayloadType_Compressable;
+ expectedResponse.payload.body = [NSMutableData dataWithLength:314159];
XCTAssertEqualObjects(response, expectedResponse);
[expectation fulfill];
@@ -100,31 +98,27 @@
- (void)testClientStreamingRPC {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"ClientStreaming"];
- 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];
+ RMTStreamingInputCallRequest *request1 = [RMTStreamingInputCallRequest message];
+ request1.payload.body = [NSMutableData dataWithLength:27182];
+
+ RMTStreamingInputCallRequest *request2 = [RMTStreamingInputCallRequest message];
+ request2.payload.body = [NSMutableData dataWithLength:8];
+
+ RMTStreamingInputCallRequest *request3 = [RMTStreamingInputCallRequest message];
+ request3.payload.body = [NSMutableData dataWithLength:1828];
+
+ RMTStreamingInputCallRequest *request4 = [RMTStreamingInputCallRequest message];
+ request4.payload.body = [NSMutableData dataWithLength:45904];
+
id<GRXWriter> writer = [GRXWriter writerWithContainer:@[request1, request2, request3, request4]];
[_service streamingInputCallWithRequestsWriter:writer
- handler:^(RMTStreamingInputCallResponse *response, NSError *error) {
+ handler:^(RMTStreamingInputCallResponse *response,
+ NSError *error) {
XCTAssertNil(error, @"Finished with unexpected error: %@", error);
- id expectedResponse = [[[[RMTStreamingInputCallResponseBuilder alloc] init]
- setAggregatedPayloadSize:74922]
- build];
+ RMTStreamingInputCallResponse *expectedResponse = [RMTStreamingInputCallResponse message];
+ expectedResponse.aggregatedPayloadSize = 74922;
XCTAssertEqualObjects(response, expectedResponse);
[expectation fulfill];
@@ -136,28 +130,27 @@
- (void)testServerStreamingRPC {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"ServerStreaming"];
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;
- 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){
+ [_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];
+
+ RMTStreamingOutputCallResponse *expectedResponse = [RMTStreamingOutputCallResponse message];
+ expectedResponse.payload.type = RMTPayloadType_Compressable;
+ int expectedSize = [expectedSizes[index] unsignedIntegerValue];
+ expectedResponse.payload.body = [NSMutableData dataWithLength:expectedSize];
XCTAssertEqualObjects(response, expectedResponse);
-
+
[expectation fulfill];
index += 1;
}];
@@ -168,11 +161,13 @@
- (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];
- }];
+ 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];
}
@@ -180,10 +175,11 @@
__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];
- }];
+ handler:^(RMTStreamingInputCallResponse *response,
+ NSError *error) {
+ XCTAssertEqual(error.code, GRPC_STATUS_CANCELLED);
+ [expectation fulfill];
+ }];
[call start];
[call cancel];
[self waitForExpectationsWithTimeout:1 handler:nil];
diff --git a/src/objective-c/examples/Sample/SampleTests/RemoteTests.m b/src/objective-c/examples/Sample/SampleTests/RemoteTests.m
index 6091aa9d31..553c813b0b 100644
--- a/src/objective-c/examples/Sample/SampleTests/RemoteTests.m
+++ b/src/objective-c/examples/Sample/SampleTests/RemoteTests.m
@@ -38,7 +38,7 @@
#import <gRPC/GRPCMethodName.h>
#import <gRPC/GRXWriter+Immediate.h>
#import <gRPC/GRXWriteable.h>
-#import <RemoteTest/Messages.pb.h>
+#import <RemoteTest/Messages.pbobjc.h>
@interface RemoteTests : XCTestCase
@end
@@ -111,11 +111,10 @@
interface:@"TestService"
method:@"UnaryCall"];
- RMTSimpleRequest *request = [[[[[[RMTSimpleRequestBuilder alloc] init]
- setResponseSize:100]
- setFillUsername:YES]
- setFillOauthScope:YES]
- build];
+ RMTSimpleRequest *request = [[RMTSimpleRequest alloc] init];
+ request.responseSize = 100;
+ request.fillUsername = YES;
+ request.fillOauthScope = YES;
id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[request data]];
GRPCCall *call = [[GRPCCall alloc] initWithHost:@"grpc-test.sandbox.google.com"
diff --git a/src/objective-c/examples/Sample/SampleTests/SampleTests.m b/src/objective-c/examples/Sample/SampleTests/SampleTests.m
index 6d6875c233..b1a0f78a01 100644
--- a/src/objective-c/examples/Sample/SampleTests/SampleTests.m
+++ b/src/objective-c/examples/Sample/SampleTests/SampleTests.m
@@ -38,7 +38,8 @@
#import <gRPC/GRPCMethodName.h>
#import <gRPC/GRXWriter+Immediate.h>
#import <gRPC/GRXWriteable.h>
-#import <Route_guide/Route_guide.pb.h>
+#import <Route_guide/RouteGuide.pbobjc.h>
+#import <Route_guide/RouteGuide.pbrpc.h>
@interface SampleTests : XCTestCase
@end
@@ -105,15 +106,15 @@
- (void)testSimpleProtoRPC {
__weak XCTestExpectation *response = [self expectationWithDescription:@"Response received."];
- __weak XCTestExpectation *expectedResponse =
- [self expectationWithDescription:@"Expected response."];
__weak XCTestExpectation *completion = [self expectationWithDescription:@"RPC completed."];
GRPCMethodName *method = [[GRPCMethodName alloc] initWithPackage:@"grpc.example.routeguide"
interface:@"RouteGuide"
method:@"GetFeature"];
- RGDPoint *point = [[[[[RGDPointBuilder alloc] init] setLatitude:28E7] setLongitude:-15E7] build];
+ RGDPoint *point = [RGDPoint message];
+ point.latitude = 28E7;
+ point.longitude = -15E7;
id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[point data]];
GRPCCall *call = [[GRPCCall alloc] initWithHost:@"http://127.0.0.1:8980"
@@ -122,11 +123,10 @@
id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
XCTAssertNotNil(value, @"nil value received as response.");
- [response fulfill];
RGDFeature *feature = [RGDFeature parseFromData:value];
XCTAssertEqualObjects(point, feature.location);
XCTAssertNotNil(feature.name, @"Response's name is nil.");
- [expectedResponse fulfill];
+ [response fulfill];
} completionHandler:^(NSError *errorOrNil) {
XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil);
[completion fulfill];
@@ -136,4 +136,22 @@
[self waitForExpectationsWithTimeout:2.0 handler:nil];
}
+
+- (void)testSimpleProtoRPCUsingGeneratedService {
+ __weak XCTestExpectation *completion = [self expectationWithDescription:@"RPC completed."];
+
+ RGDPoint *point = [RGDPoint message];
+ point.latitude = 28E7;
+ point.longitude = -15E7;
+
+ RGDRouteGuide *service = [[RGDRouteGuide alloc] initWithHost:@"http://127.0.0.1:8980"];
+ [service getFeatureWithRequest:point handler:^(RGDFeature *response, NSError *error) {
+ XCTAssertNil(error, @"Finished with unexpected error: %@", error);
+ XCTAssertEqualObjects(point, response.location);
+ XCTAssertNotNil(response.name, @"Response's name is nil.");
+ [completion fulfill];
+ }];
+
+ [self waitForExpectationsWithTimeout:2.0 handler:nil];
+}
@end