diff options
author | Elliott Hughes <enh@google.com> | 2016-08-23 15:53:45 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2016-08-31 09:35:44 -0700 |
commit | d3ff6e5231f53a95518532ff74a7256aabbf32e5 (patch) | |
tree | f718a1e42c11432a30f0e6addb514dea87c2ea63 /base/file_test.cpp | |
parent | e461b37965ff609ea36c1fbb6e4e8df1fb7b7d7f (diff) | |
download | system_core-d3ff6e5231f53a95518532ff74a7256aabbf32e5.tar.gz system_core-d3ff6e5231f53a95518532ff74a7256aabbf32e5.tar.bz2 system_core-d3ff6e5231f53a95518532ff74a7256aabbf32e5.zip |
Add android::base::Readlink.
Bug: http://b/30988271
Change-Id: Ib844d7c9e33465dabf7aee5e24dc3d1d8d799abd
Diffstat (limited to 'base/file_test.cpp')
-rw-r--r-- | base/file_test.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/base/file_test.cpp b/base/file_test.cpp index 17755bfed..ca01ee88a 100644 --- a/base/file_test.cpp +++ b/base/file_test.cpp @@ -110,3 +110,29 @@ TEST(file, RemoveFileIfExist) { ASSERT_FALSE(android::base::RemoveFileIfExists(td.path, &err)); ASSERT_EQ("is not a regular or symbol link file", err); } + +TEST(file, Readlink) { +#if !defined(_WIN32) + // Linux doesn't allow empty symbolic links. + std::string min("x"); + // ext2 and ext4 both have PAGE_SIZE limits. + std::string max(static_cast<size_t>(4096 - 1), 'x'); + + TemporaryDir td; + std::string min_path{std::string(td.path) + "/" + "min"}; + std::string max_path{std::string(td.path) + "/" + "max"}; + + ASSERT_EQ(0, symlink(min.c_str(), min_path.c_str())); + ASSERT_EQ(0, symlink(max.c_str(), max_path.c_str())); + + std::string result; + + result = "wrong"; + ASSERT_TRUE(android::base::Readlink(min_path, &result)); + ASSERT_EQ(min, result); + + result = "wrong"; + ASSERT_TRUE(android::base::Readlink(max_path, &result)); + ASSERT_EQ(max, result); +#endif +} |