summaryrefslogtreecommitdiff
path: root/adb/adb_utils_test.cpp
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 /adb/adb_utils_test.cpp
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 'adb/adb_utils_test.cpp')
-rw-r--r--adb/adb_utils_test.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/adb/adb_utils_test.cpp b/adb/adb_utils_test.cpp
index 309ac02c98..9c9f85c7da 100644
--- a/adb/adb_utils_test.cpp
+++ b/adb/adb_utils_test.cpp
@@ -16,6 +16,13 @@
#include "adb_utils.h"
+#ifdef _WIN32
+#include <windows.h>
+#include <userenv.h>
+#endif
+
+#include <string>
+
#include <gtest/gtest.h>
#include <stdlib.h>
@@ -23,12 +30,46 @@
#include "sysdeps.h"
+#include <base/macros.h>
#include <base/test_utils.h>
+#ifdef _WIN32
+static std::string subdir(const char* parent, const char* child) {
+ std::string str(parent);
+ str += OS_PATH_SEPARATOR;
+ str += child;
+ return str;
+}
+#endif
+
TEST(adb_utils, directory_exists) {
+#ifdef _WIN32
+ char profiles_dir[MAX_PATH];
+ DWORD cch = arraysize(profiles_dir);
+
+ // On typical Windows 7, returns C:\Users
+ ASSERT_TRUE(GetProfilesDirectory(profiles_dir, &cch));
+
+ ASSERT_TRUE(directory_exists(profiles_dir));
+
+ // On modern (English?) Windows, this is a directory symbolic link to
+ // C:\ProgramData. Symbolic links are rare on Windows and the user requires
+ // a special permission (by default granted to Administrative users) to
+ // create symbolic links.
+ ASSERT_FALSE(directory_exists(subdir(profiles_dir, "All Users")));
+
+ // On modern (English?) Windows, this is a directory junction to
+ // C:\Users\Default. Junctions are used throughout user profile directories
+ // for backwards compatibility and they don't require any special permissions
+ // to create.
+ ASSERT_FALSE(directory_exists(subdir(profiles_dir, "Default User")));
+
+ ASSERT_FALSE(directory_exists(subdir(profiles_dir, "does-not-exist")));
+#else
ASSERT_TRUE(directory_exists("/proc"));
ASSERT_FALSE(directory_exists("/proc/self")); // Symbolic link.
ASSERT_FALSE(directory_exists("/proc/does-not-exist"));
+#endif
}
TEST(adb_utils, escape_arg) {