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 13#import <Foundation/Foundation.h> 14#include <string.h> 15 16#import "sdk/objc/helpers/NSString+StdString.h" 17 18#include "rtc_base/checks.h" 19 20namespace webrtc { 21namespace test { 22 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. 26std::string IOSResourcePath(std::string name, std::string extension) { 27 @autoreleasepool { 28 NSString* path = [NSString stringForStdString:name]; 29 NSString* fileName = path.lastPathComponent; 30 NSString* fileType = [NSString stringForStdString:extension]; 31 // Get full pathname for the resource identified by the name and extension. 32 NSString* pathString = [[NSBundle mainBundle] pathForResource:fileName 33 ofType:fileType]; 34 return [NSString stdStringForString:pathString]; 35 } 36} 37 38std::string IOSRootPath() { 39 @autoreleasepool { 40 NSBundle* mainBundle = [NSBundle mainBundle]; 41 return [NSString stdStringForString:mainBundle.bundlePath] + "/"; 42 } 43} 44 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. 48std::string IOSOutputPath() { 49 @autoreleasepool { 50 NSString* tempDir = NSTemporaryDirectory(); 51 if (tempDir == nil) 52 tempDir = @"/tmp"; 53 return [NSString stdStringForString:tempDir]; 54 } 55} 56 57} // namespace test 58} // namespace webrtc 59 60#endif // defined(WEBRTC_IOS) 61