From 6a84b3d269fe8965b360fab8f29e923c1d5e52ec Mon Sep 17 00:00:00 2001
From: Jorge Canizales <jcanizales@google.com>
Date: Mon, 23 Mar 2015 11:55:05 -0700
Subject: [PATCH] Adds test that sends proto and expects one

---
 .../examples/Sample/SampleTests/SampleTests.m | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/objective-c/examples/Sample/SampleTests/SampleTests.m b/src/objective-c/examples/Sample/SampleTests/SampleTests.m
index bf0b3642b1..92beb20a6a 100644
--- a/src/objective-c/examples/Sample/SampleTests/SampleTests.m
+++ b/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
-- 
GitLab