adb_test/libbase_test: win32: get some tests working
adb_test:
* Fix adb_utils directory_exists test for Windows. The test actually
fails because directory_exists() is not aware of junctions or symlinks,
but I'm not really sure if that is a bad thing (since these are rare on
Windows to begin with).
* Fix crash during transport tests due to mutex not being initialized.
* io tests fail for various reasons (see adb_io_test.cpp for more info).
libbase_test:
* Get it building on Win32 by implementing mkstemp() and mkdtemp().
* Run StringPrintf %z test on Windows because it passes because we build
with __USE_MINGW_ANSI_STDIO which implements %z.
* I didn't fixup the logging tests: some logging tests fail because when
abort() is called on Windows, by default it pops up UI asking whether a
crash dump should be sent to Microsoft. To some degree this makes sense,
as I think LOG(FATAL) does crash dumping in Chromium. This should be
revisited in the future.
Change-Id: Iaa2433e5294ff162e0b2aa9fe6e4ec09a6893f7a
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
diff --git a/base/file_test.cpp b/base/file_test.cpp
index 4056684..2158421 100644
--- a/base/file_test.cpp
+++ b/base/file_test.cpp
@@ -34,17 +34,7 @@
EXPECT_EQ("", s); // s was cleared.
}
-TEST(file, ReadFileToString_success) {
- std::string s("hello");
- ASSERT_TRUE(android::base::ReadFileToString("/proc/version", &s))
- << strerror(errno);
- EXPECT_GT(s.length(), 6U);
- EXPECT_EQ('\n', s[s.length() - 1]);
- s[5] = 0;
- EXPECT_STREQ("Linux", s.c_str());
-}
-
-TEST(file, WriteStringToFile) {
+TEST(file, ReadFileToString_WriteStringToFile) {
TemporaryFile tf;
ASSERT_TRUE(tf.fd != -1);
ASSERT_TRUE(android::base::WriteStringToFile("abc", tf.path))
@@ -89,13 +79,23 @@
}
TEST(file, ReadFully) {
- int fd = open("/proc/version", O_RDONLY);
+#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, 5));
- ASSERT_STREQ("Linux", 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);