blob: 2467f0c8e54a8717f824a58df8c9bf1c2fbcbcc6 [file] [log] [blame]
kjellander@webrtc.org7951e812011-10-13 12:24:41 +00001/*
2 * Copyright (c) 2011 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
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000011#include <stdio.h>
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000012
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000013#ifndef WEBRTC_TEST_TESTSUPPORT_FILEUTILS_H_
14#define WEBRTC_TEST_TESTSUPPORT_FILEUTILS_H_
kjellander@webrtc.org7951e812011-10-13 12:24:41 +000015
16#include <string>
17
18namespace webrtc {
19namespace test {
20
andrew@webrtc.org0db7dc62011-11-13 01:34:05 +000021// This is the "directory" returned if the ProjectPath() function fails
kjellander@webrtc.org7951e812011-10-13 12:24:41 +000022// to find the project root.
andrew@webrtc.org1e10bb32011-10-31 20:22:02 +000023extern const char* kCannotFindProjectRootDir;
kjellander@webrtc.org7951e812011-10-13 12:24:41 +000024
kjellander@webrtc.org4d8cd9d2011-11-09 11:24:14 +000025// Creates and returns the absolute path to the output directory where log files
phoglund@webrtc.org4aa57b42012-03-22 12:56:54 +000026// and other test artifacts should be put. The output directory is generally a
kjellander@webrtc.org4d8cd9d2011-11-09 11:24:14 +000027// directory named "out" at the top-level of the project, i.e. a subfolder to
phoglund@webrtc.org4aa57b42012-03-22 12:56:54 +000028// the path returned by ProjectRootPath(). The exception is Android where we use
29// /sdcard/ instead.
kjellander@webrtc.org4d8cd9d2011-11-09 11:24:14 +000030//
ehmaldonadod661e9c2016-11-22 10:42:59 -080031// If symbolic links occur in the path they will be resolved and the actual
32// directory will be returned.
kjellander@webrtc.org4d8cd9d2011-11-09 11:24:14 +000033//
andrew@webrtc.org0db7dc62011-11-13 01:34:05 +000034// Returns the path WITH a trailing path delimiter. If the project root is not
35// found, the current working directory ("./") is returned as a fallback.
36std::string OutputPath();
kjellander@webrtc.org4d8cd9d2011-11-09 11:24:14 +000037
kjellander@webrtc.org7de47bc2014-04-16 08:04:26 +000038// Generates an empty file with a unique name in the specified directory and
39// returns the file name and path.
40std::string TempFilename(const std::string &dir, const std::string &prefix);
41
kjellander@webrtc.org4ed4f242011-12-05 16:31:12 +000042// Returns a path to a resource file for the currently executing platform.
43// Adapts to what filenames are currently present in the
44// [project-root]/resources/ dir.
45// Returns an absolute path according to this priority list (the directory
46// part of the path is left out for readability):
47// 1. [name]_[platform]_[architecture].[extension]
48// 2. [name]_[platform].[extension]
49// 3. [name]_[architecture].[extension]
50// 4. [name].[extension]
51// Where
52// * platform is either of "win", "mac" or "linux".
53// * architecture is either of "32" or "64".
54//
55// Arguments:
56// name - Name of the resource file. If a plain filename (no directory path)
57// is supplied, the file is assumed to be located in resources/
58// If a directory path is prepended to the filename, a subdirectory
59// hierarchy reflecting that path is assumed to be present.
60// extension - File extension, without the dot, i.e. "bmp" or "yuv".
61std::string ResourcePath(std::string name, std::string extension);
62
63// Gets the current working directory for the executing program.
64// Returns "./" if for some reason it is not possible to find the working
65// directory.
66std::string WorkingDir();
67
68// Creates a directory if it not already exists.
69// Returns true if successful. Will print an error message to stderr and return
70// false if a file with the same name already exists.
kjellander@webrtc.org7de47bc2014-04-16 08:04:26 +000071bool CreateDir(std::string directory_name);
72
73// Checks if a file exists.
74bool FileExists(std::string& file_name);
kjellander@webrtc.org4ed4f242011-12-05 16:31:12 +000075
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000076// File size of the supplied file in bytes. Will return 0 if the file is
77// empty or if the file does not exist/is readable.
78size_t GetFileSize(std::string filename);
79
kjellander@webrtc.org193600b2012-10-17 04:39:44 +000080// Sets the executable path, i.e. the path to the executable that is being used
81// when launching it. This is usually the path relative to the working directory
82// but can also be an absolute path. The intention with this function is to pass
83// the argv[0] being sent into the main function to make it possible for
84// fileutils.h to find the correct project paths even when the working directory
85// is outside the project tree (which happens in some cases).
86void SetExecutablePath(const std::string& path_to_executable);
kjellander@webrtc.org83b767b2012-10-15 18:14:12 +000087
kjellander@webrtc.org7951e812011-10-13 12:24:41 +000088} // namespace test
andrew@webrtc.org1e10bb32011-10-31 20:22:02 +000089} // namespace webrtc
kjellander@webrtc.org7951e812011-10-13 12:24:41 +000090
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000091#endif // WEBRTC_TEST_TESTSUPPORT_FILEUTILS_H_