Adds test that sends proto and expects one

pull/1331/head
Jorge Canizales 10 years ago
parent aa5611bed7
commit 6a84b3d269
  1. 34
      src/objective-c/examples/Sample/SampleTests/SampleTests.m

@ -38,6 +38,7 @@
#import <gRPC/GRPCMethodName.h>
#import <gRPC/GRXWriter+Immediate.h>
#import <gRPC/GRXWriteable.h>
#import <Route_guide/Route_guide.pb.h>
@interface SampleTests : XCTestCase
@end
@ -101,4 +102,37 @@
[self waitForExpectationsWithTimeout:2.0 handler:nil];
}
- (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:-30E7] build];
id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[point data]];
GRPCCall *call = [[GRPCCall alloc] initWithHost:@"127.0.0.1:8980"
method:method
requestsWriter:requestsWriter];
id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
XCTAssertNotNil(value, @"nil value received as response.");
[response fulfill];
RGDFeature *feature = [RGDFeature parseFromData:value];
NSLog(@"%@ %@", feature.name, feature.location);
[expectedResponse fulfill];
} completionHandler:^(NSError *errorOrNil) {
XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil);
[completion fulfill];
}];
[call startWithWriteable:responsesWriteable];
[self waitForExpectationsWithTimeout:2.0 handler:nil];
}
@end

Loading…
Cancel
Save