|
|
@ -40,62 +40,62 @@ |
|
|
|
#import <RxLibrary/GRXWriteable.h> |
|
|
|
#import <RxLibrary/GRXWriteable.h> |
|
|
|
|
|
|
|
|
|
|
|
@interface SampleTests : XCTestCase |
|
|
|
@interface SampleTests : XCTestCase |
|
|
|
|
|
|
|
|
|
|
|
@end |
|
|
|
@end |
|
|
|
|
|
|
|
|
|
|
|
@implementation SampleTests |
|
|
|
@implementation SampleTests |
|
|
|
|
|
|
|
|
|
|
|
- (void)setUp { |
|
|
|
- (void)testConnectionToLocalServer { |
|
|
|
[super setUp]; |
|
|
|
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"Server reachable."]; |
|
|
|
// Put setup code here. This method is called before the invocation of each test method in the class. |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)tearDown { |
|
|
|
|
|
|
|
// Put teardown code here. This method is called after the invocation of each test method in the class. |
|
|
|
|
|
|
|
[super tearDown]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)testExample { |
|
|
|
|
|
|
|
// This is an example of a functional test case. |
|
|
|
|
|
|
|
XCTAssert(YES, @"Pass"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)testPerformanceExample { |
|
|
|
|
|
|
|
// This is an example of a performance test case. |
|
|
|
|
|
|
|
[self measureBlock:^{ |
|
|
|
|
|
|
|
// Put the code you want to measure the time of here. |
|
|
|
|
|
|
|
}]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)testConnectionToSandboxServer { |
|
|
|
|
|
|
|
XCTestExpectation *expectation = [self expectationWithDescription:@"Server reachable."]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This method isn't implemented by the local server. |
|
|
|
GRPCMethodName *method = [[GRPCMethodName alloc] initWithPackage:@"grpc.testing" |
|
|
|
GRPCMethodName *method = [[GRPCMethodName alloc] initWithPackage:@"grpc.testing" |
|
|
|
interface:@"TestService" |
|
|
|
interface:@"TestService" |
|
|
|
method:@"EmptyCall"]; |
|
|
|
method:@"EmptyCall"]; |
|
|
|
|
|
|
|
|
|
|
|
id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[NSData data]]; |
|
|
|
id<GRXWriter> requestsWriter = [GRXWriter writerWithValue:[NSData data]]; |
|
|
|
|
|
|
|
|
|
|
|
GRPCCall *call = [[GRPCCall alloc] initWithHost:@"grpc-test.sandbox.google.com:443" |
|
|
|
GRPCCall *call = [[GRPCCall alloc] initWithHost:@"127.0.0.1:8980" |
|
|
|
method:method |
|
|
|
method:method |
|
|
|
requestsWriter:requestsWriter]; |
|
|
|
requestsWriter:requestsWriter]; |
|
|
|
|
|
|
|
|
|
|
|
id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) { |
|
|
|
id<GRXWriteable> responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) { |
|
|
|
NSLog(@"Received unexpected response: %@", value); |
|
|
|
XCTFail(@"Received unexpected response: %@", value); |
|
|
|
} completionHandler:^(NSError *errorOrNil) { |
|
|
|
} completionHandler:^(NSError *errorOrNil) { |
|
|
|
if (errorOrNil) { |
|
|
|
XCTAssertNotNil(errorOrNil, @"Finished without error!"); |
|
|
|
NSLog(@"Finished with error: %@", errorOrNil); |
|
|
|
XCTAssertEqual(errorOrNil.code, 12, @"Finished with unexpected error: %@", errorOrNil); |
|
|
|
} else { |
|
|
|
[expectation fulfill]; |
|
|
|
[expectation fulfill]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}]; |
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
|
|
[call startWithWriteable:responsesWriteable]; |
|
|
|
[call startWithWriteable:responsesWriteable]; |
|
|
|
|
|
|
|
|
|
|
|
[self waitForExpectationsWithTimeout:10.0 handler:^(NSError *error) { |
|
|
|
[self waitForExpectationsWithTimeout:10.0 handler:nil]; |
|
|
|
if(error) { |
|
|
|
} |
|
|
|
XCTFail(@"Server unreachable. Error: %@", error); |
|
|
|
|
|
|
|
} |
|
|
|
- (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" |
|
|
|
|
|
|
|
method:@"RecordRoute"]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
id<GRXWriter> requestsWriter = [GRXWriter emptyWriter]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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."); |
|
|
|
|
|
|
|
XCTAssertEqual([value length], 0, @"Non-empty response received: %@", value); |
|
|
|
|
|
|
|
[response fulfill]; |
|
|
|
|
|
|
|
} completionHandler:^(NSError *errorOrNil) { |
|
|
|
|
|
|
|
XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil); |
|
|
|
|
|
|
|
[completion fulfill]; |
|
|
|
}]; |
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[call startWithWriteable:responsesWriteable]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[self waitForExpectationsWithTimeout:10.0 handler:nil]; |
|
|
|
} |
|
|
|
} |
|
|
|
@end |
|
|
|
@end |
|
|
|