From 8e6749e0dd3fd077b5abde2fc91917dd2477f584 Mon Sep 17 00:00:00 2001 From: Artem Titov Date: Tue, 23 Oct 2018 17:02:49 +0200 Subject: [PATCH] Improve fileutils_override implementation internal API. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use absl::optional instead of special constant to show, that we failed to get OutputPath in fileutils_override Bug: webrtc:9792 Change-Id: Ice19a9bf425e88a747dd9b07e82dbb5bdc59685b Reviewed-on: https://webrtc-review.googlesource.com/c/107630 Reviewed-by: Mirko Bonadei Reviewed-by: Patrik Höglund Commit-Queue: Artem Titov Cr-Commit-Position: refs/heads/master@{#25331} --- test/testsupport/fileutils_override.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/testsupport/fileutils_override.cc b/test/testsupport/fileutils_override.cc index f29ddb8804..884069c10d 100644 --- a/test/testsupport/fileutils_override.cc +++ b/test/testsupport/fileutils_override.cc @@ -37,6 +37,7 @@ #include "test/testsupport/macfileutils.h" #endif +#include "absl/types/optional.h" #include "rtc_base/arraysize.h" #include "rtc_base/checks.h" #include "rtc_base/stringutils.h" @@ -68,11 +69,9 @@ const char* kResourcesDirName = "resources"; } // namespace -const char* kCannotFindProjectRootDir = "ERROR_CANNOT_FIND_PROJECT_ROOT_DIR"; - // Finds the WebRTC src dir. // The returned path always ends with a path separator. -std::string ProjectRootPath() { +absl::optional ProjectRootPath() { #if defined(WEBRTC_ANDROID) return kAndroidChromiumTestsRoot; #elif defined WEBRTC_IOS @@ -89,7 +88,7 @@ std::string ProjectRootPath() { ssize_t count = ::readlink("/proc/self/exe", buf, arraysize(buf)); if (count <= 0) { RTC_NOTREACHED() << "Unable to resolve /proc/self/exe."; - return kCannotFindProjectRootDir; + return absl::nullopt; } // On POSIX, tests execute in out/Whatever, so src is two levels up. std::string exe_dir = DirName(std::string(buf, count)); @@ -98,7 +97,7 @@ std::string ProjectRootPath() { wchar_t buf[MAX_PATH]; buf[0] = 0; if (GetModuleFileName(NULL, buf, MAX_PATH) == 0) - return kCannotFindProjectRootDir; + return absl::nullopt; std::string exe_path = rtc::ToUtf8(std::wstring(buf)); std::string exe_dir = DirName(exe_path); @@ -112,9 +111,9 @@ std::string OutputPath() { #elif defined(WEBRTC_ANDROID) return kAndroidChromiumTestsRoot; #else - std::string path = ProjectRootPath(); - RTC_DCHECK_NE(path, kCannotFindProjectRootDir); - path += "out"; + absl::optional path_opt = ProjectRootPath(); + RTC_DCHECK(path_opt); + std::string path = *path_opt + "out"; if (!CreateDir(path)) { return "./"; } @@ -140,8 +139,9 @@ std::string ResourcePath(const std::string& name, #if defined(WEBRTC_IOS) return IOSResourcePath(name, extension); #else - std::string resources_path = - ProjectRootPath() + kResourcesDirName + kPathDelimiter; + absl::optional path_opt = ProjectRootPath(); + RTC_DCHECK(path_opt); + std::string resources_path = *path_opt + kResourcesDirName + kPathDelimiter; return resources_path + name + "." + extension; #endif }