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