Add ability to override detection of resource location and source root
Bug: webrtc:9792
Change-Id: I944d2e1c1b4b4154a90eba6fbe9c417aad17498d
Reviewed-on: https://webrtc-review.googlesource.com/c/107401
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25319}
diff --git a/test/testsupport/fileutils.cc b/test/testsupport/fileutils.cc
index ba1e793..0eac8d5 100644
--- a/test/testsupport/fileutils.cc
+++ b/test/testsupport/fileutils.cc
@@ -59,6 +59,7 @@
#include "rtc_base/arraysize.h"
#include "rtc_base/checks.h"
#include "rtc_base/stringutils.h"
+#include "test/testsupport/fileutils_override.h"
namespace webrtc {
namespace test {
@@ -71,20 +72,8 @@
const char* kPathDelimiter = "/";
#endif
-#if defined(WEBRTC_ANDROID)
-// This is a special case in Chrome infrastructure. See
-// base/test/test_support_android.cc.
-const char* kAndroidChromiumTestsRoot = "/sdcard/chromium_tests_root/";
-#endif
-
-#if !defined(WEBRTC_IOS)
-const char* kResourcesDirName = "resources";
-#endif
-
} // namespace
-const char* kCannotFindProjectRootDir = "ERROR_CANNOT_FIND_PROJECT_ROOT_DIR";
-
std::string DirName(const std::string& path) {
if (path.empty())
return "";
@@ -109,69 +98,12 @@
S_ISDIR(directory_info.st_mode);
}
-// Finds the WebRTC src dir.
-// The returned path always ends with a path separator.
-std::string ProjectRootPath() {
-#if defined(WEBRTC_ANDROID)
- return kAndroidChromiumTestsRoot;
-#elif defined WEBRTC_IOS
- return IOSRootPath();
-#elif defined(WEBRTC_MAC)
- std::string path;
- GetNSExecutablePath(&path);
- std::string exe_dir = DirName(path);
- // On Mac, tests execute in out/Whatever, so src is two levels up except if
- // the test is bundled (which our tests are not), in which case it's 5 levels.
- return DirName(DirName(exe_dir)) + kPathDelimiter;
-#elif defined(WEBRTC_POSIX)
- char buf[PATH_MAX];
- ssize_t count = ::readlink("/proc/self/exe", buf, arraysize(buf));
- if (count <= 0) {
- RTC_NOTREACHED() << "Unable to resolve /proc/self/exe.";
- return kCannotFindProjectRootDir;
- }
- // On POSIX, tests execute in out/Whatever, so src is two levels up.
- std::string exe_dir = DirName(std::string(buf, count));
- return DirName(DirName(exe_dir)) + kPathDelimiter;
-#elif defined(WEBRTC_WIN)
- wchar_t buf[MAX_PATH];
- buf[0] = 0;
- if (GetModuleFileName(NULL, buf, MAX_PATH) == 0)
- return kCannotFindProjectRootDir;
-
- std::string exe_path = rtc::ToUtf8(std::wstring(buf));
- std::string exe_dir = DirName(exe_path);
- return DirName(DirName(exe_dir)) + kPathDelimiter;
-#endif
-}
-
std::string OutputPath() {
-#if defined(WEBRTC_IOS)
- return IOSOutputPath();
-#elif defined(WEBRTC_ANDROID)
- return kAndroidChromiumTestsRoot;
-#else
- std::string path = ProjectRootPath();
- RTC_DCHECK_NE(path, kCannotFindProjectRootDir);
- path += "out";
- if (!CreateDir(path)) {
- return "./";
- }
- return path + kPathDelimiter;
-#endif
+ return webrtc::test::internal::OutputPath();
}
std::string WorkingDir() {
-#if defined(WEBRTC_ANDROID)
- return kAndroidChromiumTestsRoot;
-#endif
- char path_buffer[FILENAME_MAX];
- if (!GET_CURRENT_DIR(path_buffer, sizeof(path_buffer))) {
- fprintf(stderr, "Cannot get current directory!\n");
- return "./";
- } else {
- return std::string(path_buffer);
- }
+ return webrtc::test::internal::WorkingDir();
}
// Generate a temporary filename in a safe way.
@@ -298,13 +230,7 @@
std::string ResourcePath(const std::string& name,
const std::string& extension) {
-#if defined(WEBRTC_IOS)
- return IOSResourcePath(name, extension);
-#else
- std::string resources_path =
- ProjectRootPath() + kResourcesDirName + kPathDelimiter;
- return resources_path + name + "." + extension;
-#endif
+ return webrtc::test::internal::ResourcePath(name, extension);
}
std::string JoinFilename(const std::string& dir, const std::string& name) {