|
| 1 | +/*! |
| 2 | + * iOS SDK |
| 3 | + * |
| 4 | + * Tencent is pleased to support the open source community by making |
| 5 | + * Hippy available. |
| 6 | + * |
| 7 | + * Copyright (C) 2019 THL A29 Limited, a Tencent company. |
| 8 | + * All rights reserved. |
| 9 | + * |
| 10 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 11 | + * you may not use this file except in compliance with the License. |
| 12 | + * You may obtain a copy of the License at |
| 13 | + * |
| 14 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | + * |
| 16 | + * Unless required by applicable law or agreed to in writing, software |
| 17 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 18 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | + * See the License for the specific language governing permissions and |
| 20 | + * limitations under the License. |
| 21 | + */ |
| 22 | + |
| 23 | +#import <XCTest/XCTest.h> |
| 24 | +#import <hippy/HippyBridge.h> |
| 25 | +#import <hippy/HippyFileHandler.h> |
| 26 | + |
| 27 | +@interface HippyFileHandlerTest : XCTestCase |
| 28 | + |
| 29 | +/// Test sandboxDirectory for file handler |
| 30 | +@property (nonatomic, strong) NSURL *sandboxDirectory; |
| 31 | + |
| 32 | +@end |
| 33 | + |
| 34 | +@implementation HippyFileHandlerTest |
| 35 | + |
| 36 | +- (void)setUp { |
| 37 | + self.sandboxDirectory = [NSURL fileURLWithPath:@"/path/to/sandbox"]; |
| 38 | +} |
| 39 | + |
| 40 | +- (void)tearDown { |
| 41 | + // Put teardown code here. This method is called after the invocation of each test method in the class. |
| 42 | +} |
| 43 | + |
| 44 | +- (void)testAbsoluteURLFromHippyFileURL_AppBundlePath { |
| 45 | + NSURL *fileUrl = [NSURL URLWithString:@"hpfile://appbundle/testfile.txt"]; |
| 46 | + NSURL *expectedURL = [[NSBundle mainBundle] URLForResource:@"testfile" withExtension:@"txt"]; |
| 47 | + NSURL *resultURL = HippyFileHandler::AbsoluteURLFromHippyFileURL(fileUrl,self.sandboxDirectory); |
| 48 | + XCTAssertEqualObjects(resultURL, expectedURL, @"The URLs should be equal for app bundle paths."); |
| 49 | +} |
| 50 | + |
| 51 | +- (void)testAbsoluteURLFromHippyFileURL_ContainerPath { |
| 52 | + NSURL *fileUrl = [NSURL URLWithString:@"hpfile://container/Documents/testfile.txt"]; |
| 53 | + NSString *containerPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/testfile.txt"]; |
| 54 | + NSURL *expectedURL = [NSURL fileURLWithPath:containerPath]; |
| 55 | + NSURL *resultURL = HippyFileHandler::AbsoluteURLFromHippyFileURL(fileUrl,self.sandboxDirectory); |
| 56 | + XCTAssertEqualObjects(resultURL, expectedURL, @"The URLs should be equal for container paths."); |
| 57 | +} |
| 58 | + |
| 59 | +- (void)testAbsoluteURLFromHippyFileURL_SandboxRelativePath { |
| 60 | + NSURL *fileUrl = [NSURL URLWithString:@"hpfile://./testfile.txt"]; |
| 61 | + NSURL *expectedURL = [NSURL fileURLWithPath:@"testfile.txt" relativeToURL:self.sandboxDirectory]; |
| 62 | + NSURL *resultURL = HippyFileHandler::AbsoluteURLFromHippyFileURL(fileUrl,self.sandboxDirectory); |
| 63 | + XCTAssertEqualObjects(resultURL, expectedURL, @"The URLs should be equal for sandbox relative paths."); |
| 64 | +} |
| 65 | + |
| 66 | +- (void)testAbsoluteURLFromHippyFileURL_InvalidPrefix { |
| 67 | + NSURL *fileUrl = [NSURL URLWithString:@"invalid://testfile.txt"]; |
| 68 | + NSURL *expectedURL = fileUrl; |
| 69 | + NSURL *resultURL = HippyFileHandler::AbsoluteURLFromHippyFileURL(fileUrl,self.sandboxDirectory); |
| 70 | + XCTAssertEqualObjects(resultURL, expectedURL, @"The URLs should be equal for invalid prefixes."); |
| 71 | +} |
| 72 | + |
| 73 | +@end |
0 commit comments