aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/tests
diff options
context:
space:
mode:
authorGravatar Craig Tiller <craig.tiller@gmail.com>2015-07-05 21:08:33 -0700
committerGravatar Craig Tiller <craig.tiller@gmail.com>2015-07-05 21:08:33 -0700
commit27166a6f65581a9ee820882e5d7506d6bd07ade6 (patch)
tree0e89c5e09a955b2a074a8b34e0f3fe0a4135f346 /src/objective-c/tests
parent4efb6966bdfb62c725c6614b0d85ea374250bb51 (diff)
parentd1dd3a68a2d4af56f1409327c197590dac6968cb (diff)
Merge github.com:grpc/grpc into flow-like-lava-to-a-barnyard
Conflicts: src/core/surface/call.c src/core/transport/chttp2_transport.c src/core/transport/transport.h
Diffstat (limited to 'src/objective-c/tests')
-rw-r--r--src/objective-c/tests/GRPCClientTests.m109
-rw-r--r--src/objective-c/tests/InteropTests.m14
-rw-r--r--src/objective-c/tests/LocalClearTextTests.m92
-rw-r--r--src/objective-c/tests/Podfile3
-rw-r--r--src/objective-c/tests/RxLibraryUnitTests.m6
5 files changed, 131 insertions, 93 deletions
diff --git a/src/objective-c/tests/GRPCClientTests.m b/src/objective-c/tests/GRPCClientTests.m
index 713ea2848a..e421127ea1 100644
--- a/src/objective-c/tests/GRPCClientTests.m
+++ b/src/objective-c/tests/GRPCClientTests.m
@@ -34,33 +34,47 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
-#import <gRPC/GRPCCall.h>
-#import <gRPC/GRPCMethodName.h>
-#import <gRPC/GRXWriter+Immediate.h>
-#import <gRPC/GRXWriteable.h>
+#import <GRPCClient/GRPCCall.h>
+#import <GRPCClient/GRPCMethodName.h>
#import <RemoteTest/Messages.pbobjc.h>
+#import <RxLibrary/GRXWriteable.h>
+#import <RxLibrary/GRXWriter+Immediate.h>
// These are a few tests similar to InteropTests, but which use the generic gRPC client (GRPCCall)
// rather than a generated proto library on top of it.
+static NSString * const kHostAddress = @"grpc-test.sandbox.google.com";
+static NSString * const kPackage = @"grpc.testing";
+static NSString * const kService = @"TestService";
+
+static GRPCMethodName *kInexistentMethod;
+static GRPCMethodName *kEmptyCallMethod;
+static GRPCMethodName *kUnaryCallMethod;
+
@interface GRPCClientTests : XCTestCase
@end
@implementation GRPCClientTests
-- (void)testConnectionToRemoteServer {
- __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Server reachable."];
-
+- (void)setUp {
// This method isn't implemented by the remote server.
- GRPCMethodName *method = [[GRPCMethodName alloc] initWithPackage:@"grpc.testing"
- interface:@"TestService"
- method:@"Nonexistent"];
+ kInexistentMethod = [[GRPCMethodName alloc] initWithPackage:kPackage
+ interface:kService
+ method:@"Inexistent"];
+ kEmptyCallMethod = [[GRPCMethodName alloc] initWithPackage:kPackage
+ interface:kService
+ method:@"EmptyCall"];
+ kUnaryCallMethod = [[GRPCMethodName alloc] initWithPackage:kPackage
+ interface:kService
+ method:@"UnaryCall"];
+}
- id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[NSData data]];
+- (void)testConnectionToRemoteServer {
+ __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Server reachable."];
- GRPCCall *call = [[GRPCCall alloc] initWithHost:@"grpc-test.sandbox.google.com"
- method:method
- requestsWriter:requestsWriter];
+ GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
+ method:kInexistentMethod
+ requestsWriter:[GRXWriter writerWithValue:[NSData data]]];
id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
XCTFail(@"Received unexpected response: %@", value);
@@ -80,15 +94,9 @@
__weak XCTestExpectation *response = [self expectationWithDescription:@"Empty response received."];
__weak XCTestExpectation *completion = [self expectationWithDescription:@"Empty RPC completed."];
- GRPCMethodName *method = [[GRPCMethodName alloc] initWithPackage:@"grpc.testing"
- interface:@"TestService"
- method:@"EmptyCall"];
-
- id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[NSData data]];
-
- GRPCCall *call = [[GRPCCall alloc] initWithHost:@"grpc-test.sandbox.google.com"
- method:method
- requestsWriter:requestsWriter];
+ GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
+ method:kEmptyCallMethod
+ requestsWriter:[GRXWriter writerWithValue:[NSData data]]];
id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
XCTAssertNotNil(value, @"nil value received as response.");
@@ -105,34 +113,27 @@
}
- (void)testSimpleProtoRPC {
- __weak XCTestExpectation *response = [self expectationWithDescription:@"Response received."];
- __weak XCTestExpectation *expectedResponse =
- [self expectationWithDescription:@"Expected response."];
+ __weak XCTestExpectation *response = [self expectationWithDescription:@"Expected response."];
__weak XCTestExpectation *completion = [self expectationWithDescription:@"RPC completed."];
- GRPCMethodName *method = [[GRPCMethodName alloc] initWithPackage:@"grpc.testing"
- interface:@"TestService"
- method:@"UnaryCall"];
-
- RMTSimpleRequest *request = [[RMTSimpleRequest alloc] init];
+ RMTSimpleRequest *request = [RMTSimpleRequest message];
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"
- method:method
+ GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
+ method:kUnaryCallMethod
requestsWriter:requestsWriter];
id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
XCTAssertNotNil(value, @"nil value received as response.");
- [response fulfill];
XCTAssertGreaterThan(value.length, 0, @"Empty response received.");
- RMTSimpleResponse *response = [RMTSimpleResponse parseFromData:value error:NULL];
+ RMTSimpleResponse *responseProto = [RMTSimpleResponse parseFromData:value error:NULL];
// We expect empty strings, not nil:
- XCTAssertNotNil(response.username, @"Response's username is nil.");
- XCTAssertNotNil(response.oauthScope, @"Response's OAuth scope is nil.");
- [expectedResponse fulfill];
+ XCTAssertNotNil(responseProto.username, @"Response's username is nil.");
+ XCTAssertNotNil(responseProto.oauthScope, @"Response's OAuth scope is nil.");
+ [response fulfill];
} completionHandler:^(NSError *errorOrNil) {
XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil);
[completion fulfill];
@@ -143,4 +144,36 @@
[self waitForExpectationsWithTimeout:2. handler:nil];
}
+- (void)testMetadata {
+ __weak XCTestExpectation *expectation = [self expectationWithDescription:@"RPC unauthorized."];
+
+ RMTSimpleRequest *request = [RMTSimpleRequest message];
+ request.fillUsername = YES;
+ request.fillOauthScope = YES;
+ id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[request data]];
+
+ GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress
+ method:kUnaryCallMethod
+ requestsWriter:requestsWriter];
+
+ call.requestMetadata[@"Authorization"] = @"Bearer bogusToken";
+
+ id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+ XCTFail(@"Received unexpected response: %@", value);
+ } completionHandler:^(NSError *errorOrNil) {
+ XCTAssertNotNil(errorOrNil, @"Finished without error!");
+ XCTAssertEqual(errorOrNil.code, 16, @"Finished with unexpected error: %@", errorOrNil);
+ XCTAssertEqualObjects(call.responseMetadata, errorOrNil.userInfo[kGRPCStatusMetadataKey],
+ @"Metadata in the NSError object and call object differ.");
+ NSString *challengeHeader = call.responseMetadata[@"www-authenticate"];
+ XCTAssertGreaterThan(challengeHeader.length, 0,
+ @"No challenge in response headers %@", call.responseMetadata);
+ [expectation fulfill];
+ }];
+
+ [call startWithWriteable:responsesWriteable];
+
+ [self waitForExpectationsWithTimeout:2. handler:nil];
+}
+
@end
diff --git a/src/objective-c/tests/InteropTests.m b/src/objective-c/tests/InteropTests.m
index 0a512c17dc..74f6b231cf 100644
--- a/src/objective-c/tests/InteropTests.m
+++ b/src/objective-c/tests/InteropTests.m
@@ -36,13 +36,13 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
-#import <gRPC/GRXWriter+Immediate.h>
-#import <gRPC/GRXBufferedPipe.h>
-#import <gRPC/ProtoRPC.h>
+#import <ProtoRPC/ProtoRPC.h>
#import <RemoteTest/Empty.pbobjc.h>
#import <RemoteTest/Messages.pbobjc.h>
#import <RemoteTest/Test.pbobjc.h>
#import <RemoteTest/Test.pbrpc.h>
+#import <RxLibrary/GRXBufferedPipe.h>
+#import <RxLibrary/GRXWriter+Immediate.h>
// Convenience constructors for the generated proto messages:
@@ -174,7 +174,7 @@
__block int index = 0;
[_service streamingOutputCallWithRequest:request
- handler:^(BOOL done,
+ eventHandler:^(BOOL done,
RMTStreamingOutputCallResponse *response,
NSError *error){
XCTAssertNil(error, @"Finished with unexpected error: %@", error);
@@ -211,7 +211,7 @@
[requestsBuffer writeValue:request];
[_service fullDuplexCallWithRequestsWriter:requestsBuffer
- handler:^(BOOL done,
+ eventHandler:^(BOOL done,
RMTStreamingOutputCallResponse *response,
NSError *error) {
XCTAssertNil(error, @"Finished with unexpected error: %@", error);
@@ -242,7 +242,7 @@
- (void)testEmptyStreamRPC {
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"EmptyStream"];
[_service fullDuplexCallWithRequestsWriter:[GRXWriter emptyWriter]
- handler:^(BOOL done,
+ eventHandler:^(BOOL done,
RMTStreamingOutputCallResponse *response,
NSError *error) {
XCTAssertNil(error, @"Finished with unexpected error: %@", error);
@@ -283,7 +283,7 @@
[requestsBuffer writeValue:request];
__block ProtoRPC *call = [_service RPCToFullDuplexCallWithRequestsWriter:requestsBuffer
- handler:^(BOOL done,
+ eventHandler:^(BOOL done,
RMTStreamingOutputCallResponse *response,
NSError *error) {
if (receivedResponse) {
diff --git a/src/objective-c/tests/LocalClearTextTests.m b/src/objective-c/tests/LocalClearTextTests.m
index 6a9496b623..05cc10410a 100644
--- a/src/objective-c/tests/LocalClearTextTests.m
+++ b/src/objective-c/tests/LocalClearTextTests.m
@@ -34,60 +34,66 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
-#import <gRPC/GRPCCall.h>
-#import <gRPC/GRPCMethodName.h>
-#import <gRPC/GRXWriter+Immediate.h>
-#import <gRPC/GRXWriteable.h>
-#import <Route_guide/RouteGuide.pbobjc.h>
-#import <Route_guide/RouteGuide.pbrpc.h>
-
-// These tests require the gRPC-Java "RouteGuide" sample server to be running locally. To do so,
-// install Gradle by following the instructions here: https://docs.gradle.org/current/userguide/installation.html
-// And use it to run the server by following the instructions here: https://github.com/grpc/grpc-java/tree/master/examples
+#import <GRPCClient/GRPCCall.h>
+#import <GRPCClient/GRPCMethodName.h>
+#import <RouteGuide/RouteGuide.pbobjc.h>
+#import <RouteGuide/RouteGuide.pbrpc.h>
+#import <RxLibrary/GRXWriteable.h>
+#import <RxLibrary/GRXWriter+Immediate.h>
+
+// These tests require a gRPC "RouteGuide" sample server to be running locally. You can compile and
+// run one by following the instructions here: https://github.com/grpc/grpc-common/blob/master/cpp/cpptutorial.md#try-it-out
+// Be sure to have the C gRPC library installed in your system (for example, by having followed the
+// instructions at https://github.com/grpc/homebrew-grpc
+
+static NSString * const kRouteGuideHost = @"http://localhost:50051";
+static NSString * const kPackage = @"examples";
+static NSString * const kService = @"RouteGuide";
@interface LocalClearTextTests : XCTestCase
@end
@implementation LocalClearTextTests
-- (void)testConnectionToLocalServer {
- __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Server reachable."];
-
- // This method isn't implemented by the local server.
- GRPCMethodName *method = [[GRPCMethodName alloc] initWithPackage:@"grpc.testing"
- interface:@"TestService"
- method:@"EmptyCall"];
-
- id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[NSData data]];
-
- GRPCCall *call = [[GRPCCall alloc] initWithHost:@"http://127.0.0.1:8980"
- method:method
- requestsWriter:requestsWriter];
-
- id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
- XCTFail(@"Received unexpected response: %@", value);
- } completionHandler:^(NSError *errorOrNil) {
- XCTAssertNotNil(errorOrNil, @"Finished without error!");
- XCTAssertEqual(errorOrNil.code, 12, @"Finished with unexpected error: %@", errorOrNil);
- [expectation fulfill];
- }];
-
- [call startWithWriteable:responsesWriteable];
-
- [self waitForExpectationsWithTimeout:2.0 handler:nil];
-}
+// This test currently fails: see Issue #1907.
+//- (void)testConnectionToLocalServer {
+// __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Server reachable."];
+//
+// // This method isn't implemented by the local server.
+// GRPCMethodName *method = [[GRPCMethodName alloc] initWithPackage:kPackage
+// interface:kService
+// method:@"EmptyCall"];
+//
+// id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[NSData data]];
+//
+// GRPCCall *call = [[GRPCCall alloc] initWithHost:kRouteGuideHost
+// method:method
+// requestsWriter:requestsWriter];
+//
+// id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
+// XCTFail(@"Received unexpected response: %@", value);
+// } completionHandler:^(NSError *errorOrNil) {
+// XCTAssertNotNil(errorOrNil, @"Finished without error!");
+// XCTAssertEqual(errorOrNil.code, 12, @"Finished with unexpected error: %@", errorOrNil);
+// [expectation fulfill];
+// }];
+//
+// [call startWithWriteable:responsesWriteable];
+//
+// [self waitForExpectationsWithTimeout:8.0 handler:nil];
+//}
- (void)testEmptyRPC {
__weak XCTestExpectation *response = [self expectationWithDescription:@"Empty response received."];
__weak XCTestExpectation *completion = [self expectationWithDescription:@"Empty RPC completed."];
- GRPCMethodName *method = [[GRPCMethodName alloc] initWithPackage:@"grpc.example.routeguide"
- interface:@"RouteGuide"
+ GRPCMethodName *method = [[GRPCMethodName alloc] initWithPackage:kPackage
+ interface:kService
method:@"RecordRoute"];
id<GRXWriter> requestsWriter = [GRXWriter emptyWriter];
- GRPCCall *call = [[GRPCCall alloc] initWithHost:@"http://127.0.0.1:8980"
+ GRPCCall *call = [[GRPCCall alloc] initWithHost:kRouteGuideHost
method:method
requestsWriter:requestsWriter];
@@ -109,8 +115,8 @@
__weak XCTestExpectation *response = [self expectationWithDescription:@"Response received."];
__weak XCTestExpectation *completion = [self expectationWithDescription:@"RPC completed."];
- GRPCMethodName *method = [[GRPCMethodName alloc] initWithPackage:@"grpc.example.routeguide"
- interface:@"RouteGuide"
+ GRPCMethodName *method = [[GRPCMethodName alloc] initWithPackage:kPackage
+ interface:kService
method:@"GetFeature"];
RGDPoint *point = [RGDPoint message];
@@ -118,7 +124,7 @@
point.longitude = -15E7;
id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[point data]];
- GRPCCall *call = [[GRPCCall alloc] initWithHost:@"http://127.0.0.1:8980"
+ GRPCCall *call = [[GRPCCall alloc] initWithHost:kRouteGuideHost
method:method
requestsWriter:requestsWriter];
@@ -145,7 +151,7 @@
point.latitude = 28E7;
point.longitude = -15E7;
- RGDRouteGuide *service = [[RGDRouteGuide alloc] initWithHost:@"http://127.0.0.1:8980"];
+ RGDRouteGuide *service = [[RGDRouteGuide alloc] initWithHost:kRouteGuideHost];
[service getFeatureWithRequest:point handler:^(RGDFeature *response, NSError *error) {
XCTAssertNil(error, @"Finished with unexpected error: %@", error);
XCTAssertEqualObjects(point, response.location);
diff --git a/src/objective-c/tests/Podfile b/src/objective-c/tests/Podfile
index c099fb5182..026868db12 100644
--- a/src/objective-c/tests/Podfile
+++ b/src/objective-c/tests/Podfile
@@ -2,9 +2,8 @@ source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
pod 'gRPC', :path => "../../.."
-pod 'Protobuf', :git => 'https://github.com/google/protobuf.git'
pod 'RemoteTest', :path => "../generated_libraries/RemoteTestClient"
-pod 'Route_guide', :path => "../generated_libraries/RouteGuideClient"
+pod 'RouteGuide', :path => "../generated_libraries/RouteGuideClient"
link_with 'AllTests'
diff --git a/src/objective-c/tests/RxLibraryUnitTests.m b/src/objective-c/tests/RxLibraryUnitTests.m
index 89984d9481..5e3162875a 100644
--- a/src/objective-c/tests/RxLibraryUnitTests.m
+++ b/src/objective-c/tests/RxLibraryUnitTests.m
@@ -34,9 +34,9 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
-#import <gRPC/GRXBufferedPipe.h>
-#import <gRPC/GRXWriter.h>
-#import <gRPC/GRXWriteable.h>
+#import <RxLibrary/GRXBufferedPipe.h>
+#import <RxLibrary/GRXWriteable.h>
+#import <RxLibrary/GRXWriter.h>
// A mock of a GRXSingleValueHandler block that can be queried for how many times it was called and
// what were the last values passed to it.