summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorSpencer Low <CompareAndSwap@gmail.com>2015-05-24 15:36:28 -0700
committerElliott Hughes <enh@google.com>2015-08-03 12:44:43 -0700
commitcf168a82e99e97e3ad95e37b7065f6b8e7f7390b (patch)
treee91766b85be94d6e1ad85a312d0fb71113fe77ac /base
parentbb3b45d27c9ef67c66efdec687325fa9707c6665 (diff)
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>
Diffstat (limited to 'base')
-rw-r--r--base/file_test.cpp28
1 files changed, 14 insertions, 14 deletions
diff --git a/base/file_test.cpp b/base/file_test.cpp
index 4056684ef..2158421e9 100644
--- a/base/file_test.cpp
+++ b/base/file_test.cpp
@@ -34,17 +34,7 @@ TEST(file, ReadFileToString_ENOENT) {
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, WriteStringToFd) {
}
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);