Chromium Code Reviews| Index: util/test/scoped_temp_dir_test.cc |
| diff --git a/util/test/scoped_temp_dir_test.cc b/util/test/scoped_temp_dir_test.cc |
| index 1e80a828a138150d92872d7810403d50484e2ab6..fd2d9c2fb93d2103a9db48cf1768f6b5e851ba63 100644 |
| --- a/util/test/scoped_temp_dir_test.cc |
| +++ b/util/test/scoped_temp_dir_test.cc |
| @@ -18,12 +18,19 @@ |
| #include <fcntl.h> |
| #include <string.h> |
| #include <sys/stat.h> |
| -#include <unistd.h> |
| #include "base/posix/eintr_wrapper.h" |
| +#include "build/build_config.h" |
| #include "gtest/gtest.h" |
| #include "util/test/errors.h" |
| +#if defined(OS_POSIX) |
|
Robert Sesek
2015/01/07 23:38:25
Should these come before the project #includes?
scottmg
2015/01/08 00:16:11
They require build/build_config.h, so must go afte
|
| +#include <unistd.h> |
| +#elif defined(OS_WIN) |
| +#include <direct.h> |
| +#include <io.h> |
| +#endif // OS_POSIX |
| + |
| namespace crashpad { |
| namespace test { |
| namespace { |
| @@ -32,14 +39,17 @@ bool FileExists(const base::FilePath& path) { |
| #if defined(OS_POSIX) |
| struct stat st; |
| int rv = lstat(path.value().c_str(), &st); |
| +#elif defined(OS_WIN) |
| + struct _stat st; |
| + int rv = _wstat(path.value().c_str(), &st); |
| +#else |
| +#error "Not implemented" |
| +#endif |
| if (rv < 0) { |
| EXPECT_EQ(ENOENT, errno) << ErrnoMessage("lstat") << " " << path.value(); |
|
Mark Mentovai
2015/01/08 17:22:20
The string isn’t right for Windows. :(
scottmg
2015/01/08 17:39:28
Oops, thanks: https://codereview.chromium.org/8368
|
| return false; |
| } |
| return true; |
| -#else |
| -#error "Not implemented" |
| -#endif |
| } |
| void CreateFile(const base::FilePath& path) { |
| @@ -48,6 +58,10 @@ void CreateFile(const base::FilePath& path) { |
| ASSERT_GE(fd, 0) << ErrnoMessage("creat") << " " << path.value(); |
| ASSERT_EQ(0, IGNORE_EINTR(close(fd))) |
| << ErrnoMessage("close") << " " << path.value(); |
| +#elif defined(OS_WIN) |
| + int fd = _wcreat(path.value().c_str(), 0644); |
| + ASSERT_GE(fd, 0) << ErrnoMessage("_wcreat") << " " << path.value(); |
| + ASSERT_EQ(0, _close(fd)) << ErrnoMessage("_close") << " " << path.value(); |
| #else |
| #error "Not implemented" |
| #endif |
| @@ -58,6 +72,9 @@ void CreateDirectory(const base::FilePath& path) { |
| #if defined(OS_POSIX) |
| ASSERT_EQ(0, mkdir(path.value().c_str(), 0755)) |
| << ErrnoMessage("mkdir") << " " << path.value(); |
| +#elif defined(OS_WIN) |
| + ASSERT_EQ(0, _wmkdir(path.value().c_str())) |
| + << ErrnoMessage("_wmkdir") << " " << path.value(); |
| #else |
| #error "Not implemented" |
| #endif |
| @@ -82,10 +99,10 @@ TEST(ScopedTempDir, WithTwoFiles) { |
| parent = dir.path(); |
| ASSERT_TRUE(FileExists(parent)); |
| - file1 = parent.Append("test1"); |
| + file1 = parent.Append(FILE_PATH_LITERAL("test1")); |
| CreateFile(file1); |
| - file2 = parent.Append("test 2"); |
| + file2 = parent.Append(FILE_PATH_LITERAL("test 2")); |
| CreateFile(file2); |
| } |
| @@ -102,13 +119,13 @@ TEST(ScopedTempDir, WithRecursiveDirectory) { |
| parent = dir.path(); |
| ASSERT_TRUE(FileExists(parent)); |
| - file1 = parent.Append(".first-level file"); |
| + file1 = parent.Append(FILE_PATH_LITERAL(".first-level file")); |
| CreateFile(file1); |
| - child_dir = parent.Append("subdir"); |
| + child_dir = parent.Append(FILE_PATH_LITERAL("subdir")); |
| CreateDirectory(child_dir); |
| - file2 = child_dir.Append("second level file"); |
| + file2 = child_dir.Append(FILE_PATH_LITERAL("second level file")); |
| CreateFile(file2); |
| } |