Added tests for code coverage

pull/5315/head
Test User 9 years ago
parent 1fd052f43c
commit 9656eca510
  1. 45
      src/objective-c/tests/GRPCClientTests.m
  2. 2
      src/objective-c/tests/InteropTestsLocalCleartext.m
  3. 11
      src/objective-c/tests/InteropTestsLocalSSL.m
  4. 23
      src/objective-c/tests/RxLibraryUnitTests.m

@ -41,11 +41,11 @@
#import <RemoteTest/Messages.pbobjc.h>
#import <RxLibrary/GRXWriteable.h>
#import <RxLibrary/GRXWriter+Immediate.h>
#import <GRPCClient/GRPCCall+ChannelArg.h>
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;
static ProtoMethod *kUnaryCallMethod;
@ -127,8 +127,8 @@ 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];
}];
@ -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,39 @@ static ProtoMethod *kUnaryCallMethod;
[self waitForExpectationsWithTimeout:8 handler:nil];
}
- (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

@ -49,7 +49,7 @@ static NSString * const kLocalCleartextHost = @"localhost:5050";
- (void)setUp {
// Register test server as non-SSL.
[GRPCCall useInsecureConnectionsForHost:kLocalCleartextHost];
[GRPCCall useInsecureConnectionsForHost:nil];
[super setUp];
}

@ -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

@ -137,4 +137,27 @@
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);
}
- (void)testBufferedPipeSetState {
}
@end

Loading…
Cancel
Save