blob: 887885d2bcb9e917a756321abe7795e1e5579466 [file] [log] [blame]
henrika1d34fe92015-06-16 10:04:20 +02001/*
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
henrika1d34fe92015-06-16 10:04:20 +020013#import <Foundation/Foundation.h>
14#include <string.h>
15
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020016#import "sdk/objc/helpers/NSString+StdString.h"
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "rtc_base/checks.h"
henrika1d34fe92015-06-16 10:04:20 +020019
20namespace webrtc {
21namespace test {
22
henrika1d34fe92015-06-16 10:04:20 +020023// 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 {
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020028 NSString* path = [NSString stringForStdString:name];
henrika1d34fe92015-06-16 10:04:20 +020029 NSString* fileName = path.lastPathComponent;
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020030 NSString* fileType = [NSString stringForStdString:extension];
henrika1d34fe92015-06-16 10:04:20 +020031 // Get full pathname for the resource identified by the name and extension.
32 NSString* pathString = [[NSBundle mainBundle] pathForResource:fileName
33 ofType:fileType];
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020034 return [NSString stdStringForString:pathString];
henrika1d34fe92015-06-16 10:04:20 +020035 }
36}
37
Kári Tristan Helgason470c0882016-10-03 13:13:29 +020038std::string IOSRootPath() {
39 @autoreleasepool {
40 NSBundle* mainBundle = [NSBundle mainBundle];
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020041 return [NSString stdStringForString:mainBundle.bundlePath] + "/";
Kári Tristan Helgason470c0882016-10-03 13:13:29 +020042 }
43}
44
kjellander02060002016-02-16 22:06:12 -080045// 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";
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020053 return [NSString stdStringForString:tempDir];
kjellander02060002016-02-16 22:06:12 -080054 }
55}
56
henrika1d34fe92015-06-16 10:04:20 +020057} // namespace test
58} // namespace webrtc
59
60#endif // defined(WEBRTC_IOS)