summaryrefslogtreecommitdiff
path: root/adb/adb_utils_test.cpp
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2016-08-01 21:54:00 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2016-08-01 21:54:00 +0000
commitc97b73aa83fc7b80b60d88d856675d4ab502296d (patch)
tree7b5be430480532fe17a952681b78811893f62bf4 /adb/adb_utils_test.cpp
parent4efbce14b5b9075f0c190feb6603464f6207a24e (diff)
parentf551ea0f6309465eeab70404076bd881320f4883 (diff)
Merge changes I1d398d19,I8f20b3cd
* changes: adb: fix stat on Windows. adb: extract Windows bits out of directory_exists test.
Diffstat (limited to 'adb/adb_utils_test.cpp')
-rw-r--r--adb/adb_utils_test.cpp42
1 files changed, 29 insertions, 13 deletions
diff --git a/adb/adb_utils_test.cpp b/adb/adb_utils_test.cpp
index 9daa397d0c..4cac485080 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(""));
@@ -113,14 +123,20 @@ TEST(adb_utils, adb_dirname) {
void test_mkdirs(const std::string& basepath) {
// Test creating a directory hierarchy.
- EXPECT_TRUE(mkdirs(basepath));
+ ASSERT_TRUE(mkdirs(basepath));
// Test finding an existing directory hierarchy.
- EXPECT_TRUE(mkdirs(basepath));
+ ASSERT_TRUE(mkdirs(basepath));
+ // Test mkdirs on an existing hierarchy with a trailing slash.
+ ASSERT_TRUE(mkdirs(basepath + '/'));
+#if defined(_WIN32)
+ ASSERT_TRUE(mkdirs(basepath + '\\'));
+#endif
+
const std::string filepath = basepath + "/file";
// Verify that the hierarchy was created by trying to create a file in it.
- EXPECT_NE(-1, adb_creat(filepath.c_str(), 0600));
+ ASSERT_NE(-1, adb_creat(filepath.c_str(), 0600));
// If a file exists where we want a directory, the operation should fail.
- EXPECT_FALSE(mkdirs(filepath));
+ ASSERT_FALSE(mkdirs(filepath));
}
TEST(adb_utils, mkdirs) {