Add android::base::Realpath.
Bug: http://b/31396973
Test: libbase_test on host and device
Change-Id: I1e5f15c76227ec1c2128baa38eb454d347987703
diff --git a/base/file_test.cpp b/base/file_test.cpp
index 1021326..266131e 100644
--- a/base/file_test.cpp
+++ b/base/file_test.cpp
@@ -159,6 +159,38 @@
#endif
}
+TEST(file, Realpath) {
+#if !defined(_WIN32)
+ TemporaryDir td;
+ std::string basename = android::base::Basename(td.path);
+ std::string dir_name = android::base::Dirname(td.path);
+ std::string base_dir_name = android::base::Basename(dir_name);
+
+ {
+ std::string path = dir_name + "/../" + base_dir_name + "/" + basename;
+ std::string result;
+ ASSERT_TRUE(android::base::Realpath(path, &result));
+ ASSERT_EQ(td.path, result);
+ }
+
+ {
+ std::string path = std::string(td.path) + "/..";
+ std::string result;
+ ASSERT_TRUE(android::base::Realpath(path, &result));
+ ASSERT_EQ(dir_name, result);
+ }
+
+ {
+ errno = 0;
+ std::string path = std::string(td.path) + "/foo.noent";
+ std::string result = "wrong";
+ ASSERT_TRUE(!android::base::Realpath(path, &result));
+ ASSERT_TRUE(result.empty());
+ ASSERT_EQ(ENOENT, errno);
+ }
+#endif
+}
+
TEST(file, GetExecutableDirectory) {
std::string path = android::base::GetExecutableDirectory();
ASSERT_NE("", path);