henrika | 1d34fe9 | 2015-06-16 10:04:20 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #if defined(WEBRTC_IOS) |
| 12 | |
henrika | 1d34fe9 | 2015-06-16 10:04:20 +0200 | [diff] [blame] | 13 | #import <Foundation/Foundation.h> |
| 14 | #include <string.h> |
| 15 | |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame^] | 16 | #import "sdk/objc/helpers/NSString+StdString.h" |
| 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "rtc_base/checks.h" |
henrika | 1d34fe9 | 2015-06-16 10:04:20 +0200 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | namespace test { |
| 22 | |
henrika | 1d34fe9 | 2015-06-16 10:04:20 +0200 | [diff] [blame] | 23 | // For iOS, resource files are added to the application bundle in the root |
| 24 | // and not in separate folders as is the case for other platforms. This method |
| 25 | // therefore removes any prepended folders and uses only the actual file name. |
| 26 | std::string IOSResourcePath(std::string name, std::string extension) { |
| 27 | @autoreleasepool { |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame^] | 28 | NSString* path = [NSString stringForStdString:name]; |
henrika | 1d34fe9 | 2015-06-16 10:04:20 +0200 | [diff] [blame] | 29 | NSString* fileName = path.lastPathComponent; |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame^] | 30 | NSString* fileType = [NSString stringForStdString:extension]; |
henrika | 1d34fe9 | 2015-06-16 10:04:20 +0200 | [diff] [blame] | 31 | // Get full pathname for the resource identified by the name and extension. |
| 32 | NSString* pathString = [[NSBundle mainBundle] pathForResource:fileName |
| 33 | ofType:fileType]; |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame^] | 34 | return [NSString stdStringForString:pathString]; |
henrika | 1d34fe9 | 2015-06-16 10:04:20 +0200 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | |
Kári Tristan Helgason | 470c088 | 2016-10-03 13:13:29 +0200 | [diff] [blame] | 38 | std::string IOSRootPath() { |
| 39 | @autoreleasepool { |
| 40 | NSBundle* mainBundle = [NSBundle mainBundle]; |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame^] | 41 | return [NSString stdStringForString:mainBundle.bundlePath] + "/"; |
Kári Tristan Helgason | 470c088 | 2016-10-03 13:13:29 +0200 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
kjellander | 0206000 | 2016-02-16 22:06:12 -0800 | [diff] [blame] | 45 | // For iOS, we don't have access to the output directory. Return the path to the |
| 46 | // temporary directory instead. This is mostly used by tests that need to write |
| 47 | // output files to disk. |
| 48 | std::string IOSOutputPath() { |
| 49 | @autoreleasepool { |
| 50 | NSString* tempDir = NSTemporaryDirectory(); |
| 51 | if (tempDir == nil) |
| 52 | tempDir = @"/tmp"; |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame^] | 53 | return [NSString stdStringForString:tempDir]; |
kjellander | 0206000 | 2016-02-16 22:06:12 -0800 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
henrika | 1d34fe9 | 2015-06-16 10:04:20 +0200 | [diff] [blame] | 57 | } // namespace test |
| 58 | } // namespace webrtc |
| 59 | |
| 60 | #endif // defined(WEBRTC_IOS) |