Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: webrtc/test/testsupport/fileutils.h

Issue 2513363004: WebRTC: Replace ProjectRootPath by ResourcePath (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <stdio.h> 11 #include <stdio.h>
12 12
13 // File utilities for testing purposes.
14 //
15 // The ProjectRootPath() method is a convenient way of getting an absolute
16 // path to the project source tree root directory. Using this, it is easy to
17 // refer to test resource files in a portable way.
18 //
19 // Notice that even if Windows platforms use backslash as path delimiter, it is
20 // also supported to use slash, so there's no need for #ifdef checks in test
21 // code for setting up the paths to the resource files.
22 //
23 // Example use:
24 // Assume we have the following code being used in a test source file:
25 // const std::string kInputFile = webrtc::test::ProjectRootPath() +
26 // "test/data/voice_engine/audio_long16.wav";
27 // // Use the kInputFile for the tests...
28 //
29 // Then here's some example outputs for different platforms:
30 // Linux:
31 // * Source tree located in /home/user/webrtc/trunk
32 // * Test project located in /home/user/webrtc/trunk/src/testproject
33 // * Test binary compiled as:
34 // /home/user/webrtc/trunk/out/Debug/testproject_unittests
35 // Then ProjectRootPath() will return /home/user/webrtc/trunk/ no matter if
36 // the test binary is executed from standing in either of:
37 // /home/user/webrtc/trunk
38 // or
39 // /home/user/webrtc/trunk/out/Debug
40 // (or any other directory below the trunk for that matter).
41 //
42 // Windows:
43 // * Source tree located in C:\Users\user\webrtc\trunk
44 // * Test project located in C:\Users\user\webrtc\trunk\src\testproject
45 // * Test binary compiled as:
46 // C:\Users\user\webrtc\trunk\src\testproject\Debug\testproject_unittests.exe
47 // Then ProjectRootPath() will return C:\Users\user\webrtc\trunk\ when the
48 // test binary is executed from inside Visual Studio.
49 // It will also return the same path if the test is executed from a command
50 // prompt standing in C:\Users\user\webrtc\trunk\src\testproject\Debug
51 //
52 // Mac:
53 // * Source tree located in /Users/user/webrtc/trunk
54 // * Test project located in /Users/user/webrtc/trunk/src/testproject
55 // * Test binary compiled as:
56 // /Users/user/webrtc/trunk/xcodebuild/Debug/testproject_unittests
57 // Then ProjectRootPath() will return /Users/user/webrtc/trunk/ no matter if
58 // the test binary is executed from standing in either of:
59 // /Users/user/webrtc/trunk
60 // or
61 // /Users/user/webrtc/trunk/out/Debug
62 // (or any other directory below the trunk for that matter).
63
64 #ifndef WEBRTC_TEST_TESTSUPPORT_FILEUTILS_H_ 13 #ifndef WEBRTC_TEST_TESTSUPPORT_FILEUTILS_H_
65 #define WEBRTC_TEST_TESTSUPPORT_FILEUTILS_H_ 14 #define WEBRTC_TEST_TESTSUPPORT_FILEUTILS_H_
66 15
67 #include <string> 16 #include <string>
68 17
69 namespace webrtc { 18 namespace webrtc {
70 namespace test { 19 namespace test {
71 20
72 // This is the "directory" returned if the ProjectPath() function fails 21 // This is the "directory" returned if the ProjectPath() function fails
73 // to find the project root. 22 // to find the project root.
74 extern const char* kCannotFindProjectRootDir; 23 extern const char* kCannotFindProjectRootDir;
75 24
76 // Finds the root dir of the project, to be able to set correct paths to
77 // resource files used by tests.
78 // For desktop, we assume that the project root is two levels above (i.e. the
79 // current working directory + /../../)
80 // For Android, it is assumed to be /sdcard/chromium_tests_root/
81 // For iOS, the resource files are assumed to be included in the test's .app
82 // bundle.
83 // If the current working directory is above the project root dir, it will not
84 // be found.
85 //
86 // If symbolic links occur in the path they will be resolved and the actual
87 // directory will be returned.
88 //
89 // Returns the absolute path to the project root dir (usually the trunk dir)
90 // WITH a trailing path delimiter.
91 // If the project root is not found, the string specified by
92 // kCannotFindProjectRootDir is returned.
93 std::string ProjectRootPath();
94
95 // Creates and returns the absolute path to the output directory where log files 25 // Creates and returns the absolute path to the output directory where log files
96 // and other test artifacts should be put. The output directory is generally a 26 // and other test artifacts should be put. The output directory is generally a
97 // directory named "out" at the top-level of the project, i.e. a subfolder to 27 // directory named "out" at the top-level of the project, i.e. a subfolder to
98 // the path returned by ProjectRootPath(). The exception is Android where we use 28 // the path returned by ProjectRootPath(). The exception is Android where we use
99 // /sdcard/ instead. 29 // /sdcard/ instead.
100 // 30 //
101 // Details described for ProjectRootPath() apply here too. 31 // If symbolic links occur in the path they will be resolved and the actual
32 // directory will be returned.
102 // 33 //
103 // Returns the path WITH a trailing path delimiter. If the project root is not 34 // Returns the path WITH a trailing path delimiter. If the project root is not
104 // found, the current working directory ("./") is returned as a fallback. 35 // found, the current working directory ("./") is returned as a fallback.
105 std::string OutputPath(); 36 std::string OutputPath();
106 37
107 // Generates an empty file with a unique name in the specified directory and 38 // Generates an empty file with a unique name in the specified directory and
108 // returns the file name and path. 39 // returns the file name and path.
109 std::string TempFilename(const std::string &dir, const std::string &prefix); 40 std::string TempFilename(const std::string &dir, const std::string &prefix);
110 41
111 // Returns a path to a resource file for the currently executing platform. 42 // Returns a path to a resource file for the currently executing platform.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // but can also be an absolute path. The intention with this function is to pass 82 // but can also be an absolute path. The intention with this function is to pass
152 // the argv[0] being sent into the main function to make it possible for 83 // the argv[0] being sent into the main function to make it possible for
153 // fileutils.h to find the correct project paths even when the working directory 84 // fileutils.h to find the correct project paths even when the working directory
154 // is outside the project tree (which happens in some cases). 85 // is outside the project tree (which happens in some cases).
155 void SetExecutablePath(const std::string& path_to_executable); 86 void SetExecutablePath(const std::string& path_to_executable);
156 87
157 } // namespace test 88 } // namespace test
158 } // namespace webrtc 89 } // namespace webrtc
159 90
160 #endif // WEBRTC_TEST_TESTSUPPORT_FILEUTILS_H_ 91 #endif // WEBRTC_TEST_TESTSUPPORT_FILEUTILS_H_
OLDNEW
« no previous file with comments | « webrtc/modules/media_file/media_file_unittest.cc ('k') | webrtc/test/testsupport/fileutils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698