| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright 2018 gRPC authors. |
| 4 |
* |
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
* you may not use this file except in compliance with the License. |
| 7 |
* You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
* |
| 17 |
*/ |
| 18 |
|
| 19 |
#import <XCTest/XCTest.h> |
| 20 |
|
| 21 |
#import <GRPCClient/GRPCCall.h> |
| 22 |
|
| 23 |
#import "../../GRPCClient/private/GRPCCore/NSError+GRPC.h" |
| 24 |
|
| 25 |
@interface NSErrorUnitTests : XCTestCase |
| 26 |
|
| 27 |
@end |
| 28 |
|
| 29 |
@implementation NSErrorUnitTests |
| 30 |
|
| 31 |
- (void)testNSError { |
| 32 |
const char *kDetails = "test details"; |
| 33 |
const char *kErrorString = "test errorString"; |
| 34 |
NSError *error1 = [NSError grpc_errorFromStatusCode:GRPC_STATUS_OK details:nil errorString:nil]; |
| 35 |
NSError *error2 = [NSError grpc_errorFromStatusCode:GRPC_STATUS_CANCELLED |
| 36 |
details:kDetails |
| 37 |
errorString:kErrorString]; |
| 38 |
NSError *error3 = [NSError grpc_errorFromStatusCode:GRPC_STATUS_UNAUTHENTICATED |
| 39 |
details:kDetails |
| 40 |
errorString:nil]; |
| 41 |
NSError *error4 = [NSError grpc_errorFromStatusCode:GRPC_STATUS_UNAVAILABLE |
| 42 |
details:nil |
| 43 |
errorString:nil]; |
| 44 |
|
| 45 |
XCTAssertNil(error1); |
| 46 |
XCTAssertEqual(error2.code, 1); |
| 47 |
XCTAssertEqualObjects(error2.domain, @"io.grpc"); |
| 48 |
XCTAssertEqualObjects(error2.userInfo[NSLocalizedDescriptionKey], |
| 49 |
[NSString stringWithUTF8String:kDetails]); |
| 50 |
XCTAssertEqualObjects(error2.userInfo[NSDebugDescriptionErrorKey], |
| 51 |
[NSString stringWithUTF8String:kErrorString]); |
| 52 |
XCTAssertEqual(error3.code, 16); |
| 53 |
XCTAssertEqualObjects(error3.domain, @"io.grpc"); |
| 54 |
XCTAssertEqualObjects(error3.userInfo[NSLocalizedDescriptionKey], |
| 55 |
[NSString stringWithUTF8String:kDetails]); |
| 56 |
XCTAssertNil(error3.userInfo[NSDebugDescriptionErrorKey]); |
| 57 |
XCTAssertEqual(error4.code, 14); |
| 58 |
XCTAssertEqualObjects(error4.domain, @"io.grpc"); |
| 59 |
XCTAssertNil(error4.userInfo[NSLocalizedDescriptionKey]); |
| 60 |
XCTAssertNil(error4.userInfo[NSDebugDescriptionErrorKey]); |
| 61 |
} |
| 62 |
|
| 63 |
@end |