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