Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c6195530 authored by Elliott Hughes's avatar Elliott Hughes Committed by Android Git Automerger
Browse files

am db3492cf: Merge "win32: adb_test/libbase_test fixes"

* commit 'db3492cf':
  win32: adb_test/libbase_test fixes
parents 2fbae482 db3492cf
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ TEST(adb_utils, directory_exists) {
  DWORD cch = arraysize(profiles_dir);

  // On typical Windows 7, returns C:\Users
  ASSERT_TRUE(GetProfilesDirectory(profiles_dir, &cch));
  ASSERT_TRUE(GetProfilesDirectoryA(profiles_dir, &cch));

  ASSERT_TRUE(directory_exists(profiles_dir));

+10 −27
Original line number Diff line number Diff line
@@ -78,38 +78,21 @@ TEST(file, WriteStringToFd) {
  EXPECT_EQ("abc", s);
}

TEST(file, ReadFully) {
#ifdef _WIN32
  VersionFile ver;
  ASSERT_NE(ver.filename, nullptr);
  const char* filename = ver.filename;
  // Note that ReadFully() does CR/LF translation, so we expect \n, not \r\n.
  const char expected[] = "\nMicrosoft Windows";
#else
  const char* filename = "/proc/version";
  const char expected[] = "Linux";
#endif
  int fd = open(filename, O_RDONLY);
  ASSERT_NE(-1, fd) << strerror(errno);

  char buf[1024];
  memset(buf, 0, sizeof(buf));
  ASSERT_TRUE(android::base::ReadFully(fd, buf, sizeof(expected) - 1));
  ASSERT_STREQ(expected, buf);

  ASSERT_EQ(0, lseek(fd, 0, SEEK_SET)) << strerror(errno);

  ASSERT_FALSE(android::base::ReadFully(fd, buf, sizeof(buf)));

  close(fd);
}

TEST(file, WriteFully) {
  TemporaryFile tf;
  ASSERT_TRUE(tf.fd != -1);
  ASSERT_TRUE(android::base::WriteFully(tf.fd, "abc", 3));

  ASSERT_EQ(0, lseek(tf.fd, 0, SEEK_SET)) << strerror(errno);

  std::string s;
  ASSERT_TRUE(android::base::ReadFileToString(tf.path, &s))
  s.resize(3);
  ASSERT_TRUE(android::base::ReadFully(tf.fd, &s[0], s.size()))
    << strerror(errno);
  EXPECT_EQ("abc", s);

  ASSERT_EQ(0, lseek(tf.fd, 0, SEEK_SET)) << strerror(errno);

  s.resize(1024);
  ASSERT_FALSE(android::base::ReadFully(tf.fd, &s[0], s.size()));
}