From cbf26b76c7715969610b75048719f8cec676b656 Mon Sep 17 00:00:00 2001 From: Spencer Low Date: Mon, 3 Aug 2015 20:43:24 -0700 Subject: [PATCH] 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 --- adb/adb_utils_test.cpp | 2 +- base/file_test.cpp | 37 ++++++++++--------------------------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/adb/adb_utils_test.cpp b/adb/adb_utils_test.cpp index 34b54e79e..17c8d0a1c 100644 --- a/adb/adb_utils_test.cpp +++ b/adb/adb_utils_test.cpp @@ -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)); diff --git a/base/file_test.cpp b/base/file_test.cpp index 2158421e9..77b92681a 100644 --- a/base/file_test.cpp +++ b/base/file_test.cpp @@ -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())); }