2015-07-13 15:42:32 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
2015-07-13 15:42:32 +00:00
|
|
|
*
|
2017-05-06 03:50:47 +00:00
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
2015-07-13 15:42:32 +00:00
|
|
|
*
|
|
|
|
*/
|
2015-06-06 20:37:36 +00:00
|
|
|
|
|
|
|
#import <XCTest/XCTest.h>
|
|
|
|
|
2016-11-23 15:47:52 +00:00
|
|
|
#import <React/RCTConvert.h>
|
2016-11-24 17:44:51 +00:00
|
|
|
#import <React/RCTUtils.h>
|
2015-06-06 20:37:36 +00:00
|
|
|
|
|
|
|
@interface RCTConvert_NSURLTests : XCTestCase
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RCTConvert_NSURLTests
|
|
|
|
|
|
|
|
#define TEST_URL(name, _input, _expectedURL) \
|
|
|
|
- (void)test_##name { \
|
|
|
|
NSURL *result = [RCTConvert NSURL:_input]; \
|
2015-08-04 23:18:03 +00:00
|
|
|
XCTAssertEqualObjects(result.absoluteString, _expectedURL); \
|
2015-06-06 20:37:36 +00:00
|
|
|
} \
|
|
|
|
|
|
|
|
#define TEST_PATH(name, _input, _expectedPath) \
|
|
|
|
- (void)test_##name { \
|
|
|
|
NSURL *result = [RCTConvert NSURL:_input]; \
|
|
|
|
XCTAssertEqualObjects(result.path, _expectedPath); \
|
|
|
|
} \
|
|
|
|
|
|
|
|
#define TEST_BUNDLE_PATH(name, _input, _expectedPath) \
|
2015-11-05 17:23:30 +00:00
|
|
|
TEST_PATH(name, _input, [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:_expectedPath])
|
2015-06-06 20:37:36 +00:00
|
|
|
|
|
|
|
// Basic tests
|
|
|
|
TEST_URL(basic, @"http://example.com", @"http://example.com")
|
2015-06-12 18:05:01 +00:00
|
|
|
TEST_URL(null, (id)kCFNull, nil)
|
2015-06-06 20:37:36 +00:00
|
|
|
|
2015-07-13 17:33:39 +00:00
|
|
|
// Resource files
|
2015-06-06 20:37:36 +00:00
|
|
|
TEST_PATH(fileURL, @"file:///blah/hello.jsbundle", @"/blah/hello.jsbundle")
|
|
|
|
TEST_BUNDLE_PATH(filePath, @"blah/hello.jsbundle", @"blah/hello.jsbundle")
|
|
|
|
TEST_BUNDLE_PATH(filePathWithSpaces, @"blah blah/hello.jsbundle", @"blah blah/hello.jsbundle")
|
|
|
|
TEST_BUNDLE_PATH(filePathWithEncodedSpaces, @"blah%20blah/hello.jsbundle", @"blah blah/hello.jsbundle")
|
|
|
|
TEST_BUNDLE_PATH(imageAt2XPath, @"images/foo@2x.jpg", @"images/foo@2x.jpg")
|
|
|
|
TEST_BUNDLE_PATH(imageFile, @"foo.jpg", @"foo.jpg")
|
|
|
|
|
2015-07-13 17:33:39 +00:00
|
|
|
// User documents
|
2015-08-04 23:18:03 +00:00
|
|
|
TEST_PATH(documentsFolder, @"~/Documents",
|
|
|
|
[NSSearchPathForDirectoriesInDomains
|
|
|
|
(NSDocumentDirectory, NSUserDomainMask, YES) firstObject])
|
2015-07-13 17:33:39 +00:00
|
|
|
|
2015-06-06 20:37:36 +00:00
|
|
|
// Remote files
|
|
|
|
TEST_URL(fullURL, @"http://example.com/blah/hello.jsbundle", @"http://example.com/blah/hello.jsbundle")
|
|
|
|
TEST_URL(urlWithSpaces, @"http://example.com/blah blah/foo", @"http://example.com/blah%20blah/foo")
|
|
|
|
TEST_URL(urlWithEncodedSpaces, @"http://example.com/blah%20blah/foo", @"http://example.com/blah%20blah/foo")
|
|
|
|
TEST_URL(imageURL, @"http://example.com/foo@2x.jpg", @"http://example.com/foo@2x.jpg")
|
|
|
|
TEST_URL(imageURLWithSpaces, @"http://example.com/blah foo@2x.jpg", @"http://example.com/blah%20foo@2x.jpg")
|
|
|
|
|
2015-08-04 23:18:03 +00:00
|
|
|
// Unicode
|
|
|
|
TEST_URL(unicodeURL,
|
|
|
|
@"https://ru.wikipedia.org/wiki/\u0417\u0430\u0433\u043B\u0430\u0432"
|
|
|
|
"\u043D\u0430\u044F_\u0441\u0442\u0440\u0430\u043D\u0438\u0446\u0430",
|
|
|
|
@"https://ru.wikipedia.org/wiki/%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2"
|
|
|
|
"%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0")
|
|
|
|
|
2015-07-13 17:33:39 +00:00
|
|
|
// Data URLs
|
|
|
|
- (void)testDataURL
|
|
|
|
{
|
|
|
|
NSURL *expectedURL = RCTDataURL(@"text/plain", [@"abcde" dataUsingEncoding:NSUTF8StringEncoding]);
|
|
|
|
NSURL *testURL = [NSURL URLWithString:@"data:text/plain;base64,YWJjZGU="];
|
|
|
|
XCTAssertEqualObjects([testURL absoluteString], [expectedURL absoluteString]);
|
|
|
|
}
|
|
|
|
|
2015-06-06 20:37:36 +00:00
|
|
|
@end
|