summaryrefslogtreecommitdiffstats
path: root/init/util_test.cpp
diff options
context:
space:
mode:
authorWonsik Kim <wonsik@google.com>2017-03-31 00:18:13 +0000
committerWonsik Kim <wonsik@google.com>2017-03-31 00:18:13 +0000
commit395e29472fa012c4177d981d9ce699625b706f4f (patch)
treea7aef5560033a0c94516ecf62c22ae0de281400a /init/util_test.cpp
parent82bac0de6d95bcdf45729516f6a4f29eb2681118 (diff)
downloadsystem_core-395e29472fa012c4177d981d9ce699625b706f4f.tar.gz
system_core-395e29472fa012c4177d981d9ce699625b706f4f.tar.bz2
system_core-395e29472fa012c4177d981d9ce699625b706f4f.zip
Revert "init: use read_file and write_file to implement do_copy builtin"
This reverts commit 82bac0de6d95bcdf45729516f6a4f29eb2681118. Change-Id: Ibfdf453bd85ba4fcd1948b78bd22e639a883653e
Diffstat (limited to 'init/util_test.cpp')
-rw-r--r--init/util_test.cpp71
1 files changed, 0 insertions, 71 deletions
diff --git a/init/util_test.cpp b/init/util_test.cpp
index 4e82e76f9..24c75c42d 100644
--- a/init/util_test.cpp
+++ b/init/util_test.cpp
@@ -17,15 +17,9 @@
#include "util.h"
#include <errno.h>
-#include <fcntl.h>
-
-#include <sys/stat.h>
#include <gtest/gtest.h>
-#include <android-base/stringprintf.h>
-#include <android-base/test_utils.h>
-
TEST(util, read_file_ENOENT) {
std::string s("hello");
errno = 0;
@@ -34,35 +28,6 @@ TEST(util, read_file_ENOENT) {
EXPECT_EQ("", s); // s was cleared.
}
-TEST(util, read_file_group_writeable) {
- std::string s("hello");
- TemporaryFile tf;
- ASSERT_TRUE(tf.fd != -1);
- EXPECT_TRUE(write_file(tf.path, s.c_str())) << strerror(errno);
- EXPECT_NE(-1, fchmodat(AT_FDCWD, tf.path, 0620, AT_SYMLINK_NOFOLLOW)) << strerror(errno);
- EXPECT_FALSE(read_file(tf.path, &s)) << strerror(errno);
- EXPECT_EQ("", s); // s was cleared.
-}
-
-TEST(util, read_file_world_writeable) {
- std::string s("hello");
- TemporaryFile tf;
- ASSERT_TRUE(tf.fd != -1);
- EXPECT_TRUE(write_file(tf.path, s.c_str())) << strerror(errno);
- EXPECT_NE(-1, fchmodat(AT_FDCWD, tf.path, 0602, AT_SYMLINK_NOFOLLOW)) << strerror(errno);
- EXPECT_FALSE(read_file(tf.path, &s)) << strerror(errno);
- EXPECT_EQ("", s); // s was cleared.
-}
-
-TEST(util, read_file_symbol_link) {
- std::string s("hello");
- errno = 0;
- // lrwxrwxrwx 1 root root 13 1970-01-01 00:00 charger -> /sbin/healthd
- EXPECT_FALSE(read_file("/charger", &s));
- EXPECT_EQ(ELOOP, errno);
- EXPECT_EQ("", s); // s was cleared.
-}
-
TEST(util, read_file_success) {
std::string s("hello");
EXPECT_TRUE(read_file("/proc/version", &s));
@@ -72,42 +37,6 @@ TEST(util, read_file_success) {
EXPECT_STREQ("Linux", s.c_str());
}
-TEST(util, write_file_not_exist) {
- std::string s("hello");
- std::string s2("hello");
- TemporaryDir test_dir;
- std::string path = android::base::StringPrintf("%s/does-not-exist", test_dir.path);
- EXPECT_TRUE(write_file(path.c_str(), s.c_str()));
- EXPECT_TRUE(read_file(path.c_str(), &s2));
- EXPECT_EQ(s, s2);
- struct stat sb;
- int fd = open(path.c_str(), O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
- EXPECT_NE(-1, fd);
- EXPECT_EQ(0, fstat(fd, &sb));
- EXPECT_NE(0u, sb.st_mode & S_IRUSR);
- EXPECT_NE(0u, sb.st_mode & S_IWUSR);
- EXPECT_EQ(0u, sb.st_mode & S_IXUSR);
- EXPECT_EQ(0u, sb.st_mode & S_IRGRP);
- EXPECT_EQ(0u, sb.st_mode & S_IWGRP);
- EXPECT_EQ(0u, sb.st_mode & S_IXGRP);
- EXPECT_EQ(0u, sb.st_mode & S_IROTH);
- EXPECT_EQ(0u, sb.st_mode & S_IWOTH);
- EXPECT_EQ(0u, sb.st_mode & S_IXOTH);
- EXPECT_EQ(0, unlink(path.c_str()));
-}
-
-TEST(util, write_file_exist) {
- std::string s2("");
- TemporaryFile tf;
- ASSERT_TRUE(tf.fd != -1);
- EXPECT_TRUE(write_file(tf.path, "1hello1")) << strerror(errno);
- EXPECT_TRUE(read_file(tf.path, &s2));
- EXPECT_STREQ("1hello1", s2.c_str());
- EXPECT_TRUE(write_file(tf.path, "2hello2"));
- EXPECT_TRUE(read_file(tf.path, &s2));
- EXPECT_STREQ("2hello2", s2.c_str());
-}
-
TEST(util, decode_uid) {
EXPECT_EQ(0U, decode_uid("root"));
EXPECT_EQ(UINT_MAX, decode_uid("toot"));