diff options
author | Jorge Canizales <jcanizales@google.com> | 2016-02-24 19:31:57 -0800 |
---|---|---|
committer | Jorge Canizales <jcanizales@google.com> | 2016-02-24 19:31:57 -0800 |
commit | c333cc9305f92434af132e7a3c328467faa28bd0 (patch) | |
tree | 6cfb55f0aad5eeba07ae8e38708612f2225f30c0 | |
parent | 2063a1c26aa146b75627f467f511e686fcbe054c (diff) | |
parent | 1c2890d6fb559282692daffa5b3c2e65220cd5e3 (diff) |
Merge pull request #5315 from makdharma/master
Added tests for code coverage
-rw-r--r-- | src/objective-c/tests/GRPCClientTests.m | 44 | ||||
-rw-r--r-- | src/objective-c/tests/InteropTestsLocalSSL.m | 11 | ||||
-rw-r--r-- | src/objective-c/tests/RxLibraryUnitTests.m | 20 |
3 files changed, 71 insertions, 4 deletions
diff --git a/src/objective-c/tests/GRPCClientTests.m b/src/objective-c/tests/GRPCClientTests.m index 00c4b8830d..619f2cf56d 100644 --- a/src/objective-c/tests/GRPCClientTests.m +++ b/src/objective-c/tests/GRPCClientTests.m @@ -35,6 +35,7 @@ #import <XCTest/XCTest.h> #import <GRPCClient/GRPCCall.h> +#import <GRPCClient/GRPCCall+ChannelArg.h> #import <GRPCClient/GRPCCall+OAuth2.h> #import <GRPCClient/GRPCCall+Tests.h> #import <ProtoRPC/ProtoMethod.h> @@ -45,6 +46,7 @@ static NSString * const kHostAddress = @"localhost:5050"; static NSString * const kPackage = @"grpc.testing"; static NSString * const kService = @"TestService"; +static NSString * const kRemoteSSLHost = @"grpc-test.sandbox.googleapis.com"; static ProtoMethod *kInexistentMethod; static ProtoMethod *kEmptyCallMethod; @@ -127,8 +129,7 @@ static ProtoMethod *kUnaryCallMethod; XCTFail(@"Received unexpected response: %@", value); } completionHandler:^(NSError *errorOrNil) { XCTAssertNotNil(errorOrNil, @"Finished without error!"); - // TODO(jcanizales): The server should return code 12 UNIMPLEMENTED, not 5 NOT FOUND. - XCTAssertEqual(errorOrNil.code, 5, @"Finished with unexpected error: %@", errorOrNil); + XCTAssertEqual(errorOrNil.code, 12, @"Finished with unexpected error: %@", errorOrNil); [expectation fulfill]; }]; @@ -191,7 +192,6 @@ static ProtoMethod *kUnaryCallMethod; [self waitForExpectationsWithTimeout:8 handler:nil]; } -// TODO(jcanizales): Activate this test against the remote server. - (void)testMetadata { __weak XCTestExpectation *expectation = [self expectationWithDescription:@"RPC unauthorized."]; @@ -200,7 +200,7 @@ static ProtoMethod *kUnaryCallMethod; request.fillOauthScope = YES; GRXWriter *requestsWriter = [GRXWriter writerWithValue:[request data]]; - GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress + GRPCCall *call = [[GRPCCall alloc] initWithHost:kRemoteSSLHost path:kUnaryCallMethod.HTTPPath requestsWriter:requestsWriter]; @@ -257,4 +257,40 @@ static ProtoMethod *kUnaryCallMethod; [self waitForExpectationsWithTimeout:8 handler:nil]; } +// TODO(makarandd): Move to a different file that contains only unit tests +- (void)testExceptions { + // Try to set userAgentPrefix for host that is nil. This should cause + // an exception. + @try { + [GRPCCall setUserAgentPrefix:@"Foo" forHost:nil]; + XCTFail(@"Did not receive an exception when host is nil"); + } @catch(NSException *theException) { + NSLog(@"Received exception as expected: %@", theException.name); + } + + // Try to set parameters to nil for GRPCCall. This should cause an exception + @try { + GRPCCall *call = [[GRPCCall alloc] initWithHost:nil + path:nil + requestsWriter:nil]; + XCTFail(@"Did not receive an exception when parameters are nil"); + } @catch(NSException *theException) { + NSLog(@"Received exception as expected: %@", theException.name); + } + + + // Set state to Finished by force + GRXWriter *requestsWriter = [GRXWriter emptyWriter]; + [requestsWriter finishWithError:nil]; + @try { + GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress + path:kUnaryCallMethod.HTTPPath + requestsWriter:requestsWriter]; + XCTFail(@"Did not receive an exception when GRXWriter has incorrect state."); + } @catch(NSException *theException) { + NSLog(@"Received exception as expected: %@", theException.name); + } + +} + @end diff --git a/src/objective-c/tests/InteropTestsLocalSSL.m b/src/objective-c/tests/InteropTestsLocalSSL.m index 9d7afefbfe..f0f4b1d71f 100644 --- a/src/objective-c/tests/InteropTestsLocalSSL.m +++ b/src/objective-c/tests/InteropTestsLocalSSL.m @@ -57,4 +57,15 @@ static NSString * const kLocalSSLHost = @"localhost:5051"; [super setUp]; } +- (void)testExceptions { + // Try to set userAgentPrefix for host that is nil. This should cause + // an exception. + @try { + [GRPCCall useTestCertsPath:nil testName:nil forHost:nil]; + XCTFail(@"Did not receive an exception when parameters are nil"); + } @catch(NSException *theException) { + NSLog(@"Received exception as expected: %@", theException.name); + } +} + @end diff --git a/src/objective-c/tests/RxLibraryUnitTests.m b/src/objective-c/tests/RxLibraryUnitTests.m index a67a4c6cd9..c94dcf533a 100644 --- a/src/objective-c/tests/RxLibraryUnitTests.m +++ b/src/objective-c/tests/RxLibraryUnitTests.m @@ -137,4 +137,24 @@ XCTAssertEqualObjects(handler.errorOrNil, anyError); } +- (void)testBufferedPipeFinishWriteWhilePaused { + // Given: + CapturingSingleValueHandler *handler = [CapturingSingleValueHandler handler]; + id<GRXWriteable> writeable = [GRXWriteable writeableWithSingleHandler:handler.block]; + id anyValue = @7; + + // If: + GRXBufferedPipe *pipe = [GRXBufferedPipe pipe]; + // Write something, then finish + [pipe writeValue:anyValue]; + [pipe writesFinishedWithError:nil]; + // then start the writeable + [pipe startWithWriteable:writeable]; + + // Then: + XCTAssertEqual(handler.timesCalled, 1); + XCTAssertEqualObjects(handler.value, anyValue); + XCTAssertEqualObjects(handler.errorOrNil, nil); +} + @end |