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 | |
| 16 | #include "webrtc/base/checks.h" |
| 17 | #include "webrtc/typedefs.h" |
kthelgason | 2f08879 | 2017-05-30 01:48:47 -0700 | [diff] [blame] | 18 | #include "webrtc/sdk/objc/Framework/Classes/Common/helpers.h" |
henrika | 1d34fe9 | 2015-06-16 10:04:20 +0200 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | namespace test { |
| 22 | |
kthelgason | c1b661e | 2017-01-09 01:40:03 -0800 | [diff] [blame] | 23 | using webrtc::ios::NSStringFromStdString; |
| 24 | using webrtc::ios::StdStringFromNSString; |
henrika | 1d34fe9 | 2015-06-16 10:04:20 +0200 | [diff] [blame] | 25 | |
| 26 | // For iOS, resource files are added to the application bundle in the root |
| 27 | // and not in separate folders as is the case for other platforms. This method |
| 28 | // therefore removes any prepended folders and uses only the actual file name. |
| 29 | std::string IOSResourcePath(std::string name, std::string extension) { |
| 30 | @autoreleasepool { |
| 31 | NSString* path = NSStringFromStdString(name); |
| 32 | NSString* fileName = path.lastPathComponent; |
| 33 | NSString* fileType = NSStringFromStdString(extension); |
| 34 | // Get full pathname for the resource identified by the name and extension. |
| 35 | NSString* pathString = [[NSBundle mainBundle] pathForResource:fileName |
| 36 | ofType:fileType]; |
| 37 | return StdStringFromNSString(pathString); |
| 38 | } |
| 39 | } |
| 40 | |
Kári Tristan Helgason | 470c088 | 2016-10-03 13:13:29 +0200 | [diff] [blame] | 41 | std::string IOSRootPath() { |
| 42 | @autoreleasepool { |
| 43 | NSBundle* mainBundle = [NSBundle mainBundle]; |
| 44 | return StdStringFromNSString(mainBundle.bundlePath) + "/"; |
| 45 | } |
| 46 | } |
| 47 | |
kjellander | 0206000 | 2016-02-16 22:06:12 -0800 | [diff] [blame] | 48 | // For iOS, we don't have access to the output directory. Return the path to the |
| 49 | // temporary directory instead. This is mostly used by tests that need to write |
| 50 | // output files to disk. |
| 51 | std::string IOSOutputPath() { |
| 52 | @autoreleasepool { |
| 53 | NSString* tempDir = NSTemporaryDirectory(); |
| 54 | if (tempDir == nil) |
| 55 | tempDir = @"/tmp"; |
| 56 | return StdStringFromNSString(tempDir); |
| 57 | } |
| 58 | } |
| 59 | |
henrika | 1d34fe9 | 2015-06-16 10:04:20 +0200 | [diff] [blame] | 60 | } // namespace test |
| 61 | } // namespace webrtc |
| 62 | |
| 63 | #endif // defined(WEBRTC_IOS) |