Index: base/files/file_util_unittest.cc |
diff --git a/base/files/file_util_unittest.cc b/base/files/file_util_unittest.cc |
index a0d0a28927f6eae9c672fa201f30291765300369..c620c9d6b774f27be8126d13e75af65312f97a29 100644 |
--- a/base/files/file_util_unittest.cc |
+++ b/base/files/file_util_unittest.cc |
@@ -20,6 +20,7 @@ |
#include "base/macros.h" |
#include "base/path_service.h" |
#include "base/strings/string_util.h" |
+#include "base/strings/stringprintf.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/test/test_file_util.h" |
#include "base/threading/platform_thread.h" |
@@ -33,6 +34,7 @@ |
#include <shlobj.h> |
#include <tchar.h> |
#include <winioctl.h> |
+#include "base/environment.h" |
#include "base/win/scoped_handle.h" |
#include "base/win/windows_version.h" |
#endif |
@@ -1664,6 +1666,71 @@ TEST_F(FileUtilTest, GetTempDirTest) { |
::_tputenv_s(kTmpKey, _T("")); |
} |
} |
+ |
+TEST_F(FileUtilTest, IsOnNetworkDrive) { |
+ struct LocalTestData { |
+ const FilePath::CharType* input; |
+ bool expected; |
+ }; |
+ |
+ const LocalTestData local_cases[] = { |
+ { FPL(""), false }, |
+ { FPL("c:\\"), false }, |
+ { FPL("c:"), false }, |
+ { FPL("c:\\windows\\notepad.exe"), false } |
+ }; |
+ |
+ for (const auto& test_case : local_cases) { |
+ FilePath input(test_case.input); |
+ bool observed = IsOnNetworkDrive(input); |
+ EXPECT_EQ(test_case.expected, observed) << " input: " << input.value(); |
+ } |
+ |
+ Environment* env = Environment::Create(); |
+ ASSERT_TRUE(!!env); |
+ |
+ std::string network_server; |
+ std::string network_share; |
+ |
+ // To test IsOnNetworkDrive() for remote cases, set up a file server |
Will Harris
2016/04/15 23:42:19
added environment variables for testing network sh
|
+ // and place a file called file.txt on the server e.g. |
+ // \\DC01\TESTSHARE\file.txt |
+ // then set the two environment variables: |
+ // set BASE_TEST_FILE_SERVER=DC01 |
+ // set BASE_TEST_FILE_SHARE=TESTSHARE |
+ if (!env->GetVar("BASE_TEST_FILE_SERVER", &network_server) || |
+ !env->GetVar("BASE_TEST_FILE_SHARE", &network_share)) { |
+ return; |
+ } |
+ |
+ struct NetworkTestData { |
+ const char* input; |
+ bool format_string_both; |
+ bool expected; |
+ }; |
+ |
+ const NetworkTestData network_cases[] = { |
+ { "\\\\%hs", false, false }, |
+ { "\\\\%hs\\", false, false }, |
+ { "\\\\%hs\\file.txt", false, false }, |
+ { "\\\\%hs\\%hs", true, true }, |
+ { "\\\\%hs\\%hs\\", true, true }, |
+ { "\\\\%hs\\%hs\\file.txt", true, true } |
+ }; |
+ |
+ for (const auto& test_case : network_cases) { |
+ std::string full_path; |
+ if (test_case.format_string_both) { |
+ full_path = base::StringPrintf(test_case.input, network_server.c_str(), |
Will Harris
2016/04/15 23:51:08
in retrospect I should probably just use ExpandEnv
|
+ network_share.c_str()); |
+ } else { |
+ full_path = base::StringPrintf(test_case.input, network_server.c_str()); |
+ } |
+ FilePath input(base::UTF8ToUTF16(full_path)); |
+ EXPECT_EQ(test_case.expected, IsOnNetworkDrive(input)) << " input : " |
+ << input.value(); |
+ } |
+} |
#endif // OS_WIN |
TEST_F(FileUtilTest, CreateTemporaryFileTest) { |