* commit 'c61955305e4e6b222801e694af9d578b39485ac5': win32: adb_test/libbase_test fixes
This commit is contained in:
commit
08fe47e3bd
2 changed files with 11 additions and 28 deletions
|
|
@ -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));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue