aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/cpp
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2017-02-15 15:24:33 +0000
committerGravatar Yue Gan <yueg@google.com>2017-02-15 19:19:24 +0000
commit3635539af5cce8c8d3795f745c678c890b45e9b5 (patch)
tree9a55f23f9ae85aa734c4ffd94befc67f743da5d8 /src/test/cpp
parentac29b78000afdb95afc7e97efd2b1299ebea4dac (diff)
Bazel client, Windows, tests: use CreateJuction
Use the JNI library's CreateJuction in file_windows_test. See https://github.com/bazelbuild/bazel/issues/2107 -- Change-Id: I4ef1536d43691fe7a2ae3ee457064d4e8f4ac6d7 Reviewed-on: https://cr.bazel.build/8895 PiperOrigin-RevId: 147594365 MOS_MIGRATED_REVID=147594365
Diffstat (limited to 'src/test/cpp')
-rw-r--r--src/test/cpp/util/BUILD10
-rw-r--r--src/test/cpp/util/file_windows_test.cc54
2 files changed, 23 insertions, 41 deletions
diff --git a/src/test/cpp/util/BUILD b/src/test/cpp/util/BUILD
index 3e696ce828..7d158da2fa 100644
--- a/src/test/cpp/util/BUILD
+++ b/src/test/cpp/util/BUILD
@@ -38,8 +38,14 @@ cc_test(
"//src/main/cpp/util:file",
"//third_party:gtest",
] + select({
- "//src:windows": [":windows_test_util"],
- "//src:windows_msvc": [":windows_test_util"],
+ "//src:windows": [
+ ":windows_test_util",
+ "//src/main/native:windows_jni_lib",
+ ],
+ "//src:windows_msvc": [
+ ":windows_test_util",
+ "//src/main/native:windows_jni_lib",
+ ],
"//conditions:default": [],
}),
)
diff --git a/src/test/cpp/util/file_windows_test.cc b/src/test/cpp/util/file_windows_test.cc
index da84efe437..28fea406bc 100644
--- a/src/test/cpp/util/file_windows_test.cc
+++ b/src/test/cpp/util/file_windows_test.cc
@@ -22,6 +22,7 @@
#include "gtest/gtest.h"
#include "src/main/cpp/util/file.h"
#include "src/main/cpp/util/file_platform.h"
+#include "src/main/native/windows_file_operations.h"
#include "src/test/cpp/util/windows_test_util.h"
#if !defined(COMPILER_MSVC) && !defined(__CYGWIN__)
@@ -53,6 +54,15 @@ class FileWindowsTest : public ::testing::Test {
ASSERT_GT(result.size(), 0); \
}
+#define CREATE_JUNCTION(/* const string& */ name, /* const string& */ target) \
+ { \
+ wstring wname; \
+ wstring wtarget; \
+ EXPECT_TRUE(AsWindowsPath(name, &wname)); \
+ EXPECT_TRUE(AsWindowsPath(target, &wtarget)); \
+ EXPECT_EQ("", windows_util::CreateJunction(wname, wtarget)); \
+ }
+
// Asserts that dir1 can be created with some content, and dir2 doesn't exist.
static void AssertTearDown(const WCHAR* dir1, const WCHAR* dir2) {
wstring wtmpdir(GetTestTmpDirW());
@@ -267,35 +277,6 @@ TEST_F(FileWindowsTest, TestMsysRootRetrieval) {
ResetMsysRootForTesting();
}
-static void RunCommand(const string& cmdline) {
- STARTUPINFOA startupInfo = {sizeof(STARTUPINFO)};
- PROCESS_INFORMATION processInfo;
- // command line maximum size is 32K
- // Source (on 2017-01-04):
- // https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx
- char mutable_cmdline[0x8000];
- strncpy(mutable_cmdline, cmdline.c_str(), 0x8000);
- BOOL ok = CreateProcessA(
- /* lpApplicationName */ NULL,
- /* lpCommandLine */ mutable_cmdline,
- /* lpProcessAttributes */ NULL,
- /* lpThreadAttributes */ NULL,
- /* bInheritHandles */ TRUE,
- /* dwCreationFlags */ 0,
- /* lpEnvironment */ NULL,
- /* lpCurrentDirectory */ NULL,
- /* lpStartupInfo */ &startupInfo,
- /* lpProcessInformation */ &processInfo);
- ASSERT_TRUE(ok);
-
- // Wait 1 second for the process to finish.
- ASSERT_EQ(WAIT_OBJECT_0, WaitForSingleObject(processInfo.hProcess, 1000));
-
- DWORD exit_code = 1;
- ASSERT_TRUE(GetExitCodeProcess(processInfo.hProcess, &exit_code));
- ASSERT_EQ(0, exit_code);
-}
-
TEST_F(FileWindowsTest, TestPathExistsWindows) {
ASSERT_FALSE(PathExists(""));
ASSERT_TRUE(PathExists("."));
@@ -322,14 +303,12 @@ TEST_F(FileWindowsTest, TestPathExistsWindows) {
ASSERT_TRUE(PathExists("/"));
// Create a junction pointing to an existing directory.
- RunCommand(string("cmd.exe /C mklink /J \"") + tmpdir + "/junc1\" \"" +
- fake_msys_root + "\" >NUL 2>NUL");
+ CREATE_JUNCTION(tmpdir + "/junc1", fake_msys_root);
ASSERT_TRUE(PathExists(fake_msys_root));
ASSERT_TRUE(PathExists(JoinPath(tmpdir, "junc1")));
// Create a junction pointing to a non-existent directory.
- RunCommand(string("cmd.exe /C mklink /J \"") + tmpdir + "/junc2\" \"" +
- fake_msys_root + "/i.dont.exist\" >NUL 2>NUL");
+ CREATE_JUNCTION(tmpdir + "/junc2", fake_msys_root + "/i.dont.exist");
ASSERT_FALSE(PathExists(JoinPath(fake_msys_root, "i.dont.exist")));
ASSERT_FALSE(PathExists(JoinPath(tmpdir, "junc2")));
}
@@ -361,8 +340,7 @@ TEST_F(FileWindowsTest, TestIsDirectory) {
// Verify that IsDirectory works for a junction.
string junc1(JoinPath(tmpdir, "junc1"));
- RunCommand(string("cmd.exe /C mklink /J \"") + junc1 + "\" \"" + dir1 +
- "\" >NUL 2>NUL");
+ CREATE_JUNCTION(junc1, dir1);
ASSERT_TRUE(IsDirectory(junc1));
ASSERT_EQ(0, rmdir(dir1.c_str()));
@@ -386,8 +364,7 @@ TEST_F(FileWindowsTest, TestUnlinkPath) {
ASSERT_LT(0, fprintf(fh, "hello\n"));
fclose(fh);
string junc1(JoinPath(tmpdir, "junc1"));
- RunCommand(string("cmd.exe /C mklink /J \"") + junc1 + "\" \"" + dir1 +
- "\" >NUL 2>NUL");
+ CREATE_JUNCTION(junc1, dir1);
ASSERT_TRUE(PathExists(junc1));
ASSERT_TRUE(PathExists(JoinPath(junc1, "foo.txt")));
@@ -444,8 +421,7 @@ TEST_F(FileWindowsTest, CanAccess) {
ASSERT_TRUE(CanAccessDirectory(dir));
string junc(JoinPath(tmpdir, "junc1"));
- RunCommand(string("cmd.exe /C mklink /J \"") + junc + "\" \"" + dir +
- "\" >NUL 2>NUL");
+ CREATE_JUNCTION(junc, dir);
ASSERT_FALSE(CanReadFile(junc));
ASSERT_FALSE(CanExecuteFile(junc));
ASSERT_TRUE(CanAccessDirectory(junc));