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 "absl/strings/string_view.h" 19#include "rtc_base/checks.h" 20 21namespace webrtc { 22namespace test { 23 24// For iOS, resource files are added to the application bundle in the root 25// and not in separate folders as is the case for other platforms. This method 26// therefore removes any prepended folders and uses only the actual file name. 27std::string IOSResourcePath(absl::string_view name, absl::string_view extension) { 28 @autoreleasepool { 29 NSString* path = [NSString stringForAbslStringView:name]; 30 NSString* fileName = path.lastPathComponent; 31 NSString* fileType = [NSString stringForAbslStringView:extension]; 32 // Get full pathname for the resource identified by the name and extension. 33 NSString* pathString = [[NSBundle mainBundle] pathForResource:fileName 34 ofType:fileType]; 35 return [NSString stdStringForString:pathString]; 36 } 37} 38 39std::string IOSRootPath() { 40 @autoreleasepool { 41 NSBundle* mainBundle = [NSBundle mainBundle]; 42 return [NSString stdStringForString:mainBundle.bundlePath] + "/"; 43 } 44} 45 46// For iOS, we don't have access to the output directory. Return the path to the 47// temporary directory instead. This is mostly used by tests that need to write 48// output files to disk. 49std::string IOSOutputPath() { 50 @autoreleasepool { 51 NSString* tempDir = NSTemporaryDirectory(); 52 if (tempDir == nil) 53 tempDir = @"/tmp"; 54 return [NSString stdStringForString:tempDir]; 55 } 56} 57 58} // namespace test 59} // namespace webrtc 60 61#endif // defined(WEBRTC_IOS) 62