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