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

Commit db3492cf authored by Elliott Hughes's avatar Elliott Hughes Committed by Gerrit Code Review
Browse files

Merge "win32: adb_test/libbase_test fixes"

parents c672cb07 cbf26b76
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -48,7 +48,7 @@ TEST(adb_utils, directory_exists) {
  DWORD cch = arraysize(profiles_dir);
  DWORD cch = arraysize(profiles_dir);


  // On typical Windows 7, returns C:\Users
  // 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));
  ASSERT_TRUE(directory_exists(profiles_dir));


+10 −27
Original line number Original line Diff line number Diff line
@@ -78,38 +78,21 @@ TEST(file, WriteStringToFd) {
  EXPECT_EQ("abc", s);
  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) {
TEST(file, WriteFully) {
  TemporaryFile tf;
  TemporaryFile tf;
  ASSERT_TRUE(tf.fd != -1);
  ASSERT_TRUE(tf.fd != -1);
  ASSERT_TRUE(android::base::WriteFully(tf.fd, "abc", 3));
  ASSERT_TRUE(android::base::WriteFully(tf.fd, "abc", 3));

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

  std::string s;
  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);
    << strerror(errno);
  EXPECT_EQ("abc", s);
  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()));
}
}