win32: adb_test/libbase_test fixes

- My recent change with -DUNICODE=1 required changing
   GetProfilesDirectory() to GetProfilesDirectoryA() for the ANSI version
   of the API.

 - enh's edit to my previous change deleted a test that used
   /proc/version, but I think another test was missed. Merge that test into
   another.

Change-Id: Ic748549848e7be922bcbf218d5b0c3fca2a90704
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
This commit is contained in:
Spencer Low 2015-08-03 20:43:24 -07:00
parent 516d30d502
commit cbf26b76c7
2 changed files with 11 additions and 28 deletions

View File

@ -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));

View File

@ -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()));
}