From 89b97677765cdc8d99319d85619f551ed5107d25 Mon Sep 17 00:00:00 2001
From: Josh Gao <jmgao@google.com>
Date: Thu, 28 Jul 2016 18:30:46 -0700
Subject: [PATCH] adb: extract Windows bits out of directory_exists test.

Bug: http://b/30481559
Bug: https://code.google.com/p/android/issues/detail?id=214633
Change-Id: I8f20b3cd5aef6a77c2b4f194b914b4295397d73f
(cherry picked from commit 3bdc76025b9b1a8416f00b5f1b57a51c6c9c604d)
---
 adb/adb_utils_test.cpp | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/adb/adb_utils_test.cpp b/adb/adb_utils_test.cpp
index f1ebaa1304..d5c33d36fd 100644
--- a/adb/adb_utils_test.cpp
+++ b/adb/adb_utils_test.cpp
@@ -52,25 +52,35 @@ TEST(adb_utils, directory_exists) {
 
   ASSERT_TRUE(directory_exists(profiles_dir));
 
+  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
+}
+
+#if defined(_WIN32)
+TEST(adb_utils, directory_exists_win32_symlink_junction) {
+  char profiles_dir[MAX_PATH];
+  DWORD cch = arraysize(profiles_dir);
+
+  // On typical Windows 7, returns C:\Users
+  ASSERT_TRUE(GetProfilesDirectoryA(profiles_dir, &cch));
+
   // 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")));
+  EXPECT_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
+  EXPECT_FALSE(directory_exists(subdir(profiles_dir, "Default User")));
 }
+#endif
 
 TEST(adb_utils, escape_arg) {
   ASSERT_EQ(R"('')", escape_arg(""));
-- 
GitLab