mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-19 18:03:47 +00:00
win: porting for scoped_temp_dir_test
Uses the posix-y CRT functions rather than Win32 API for consistency/similarity to the POSIX code path as it's localized test code anyway. R=rsesek@chromium.org BUG=crashpad:1 Review URL: https://codereview.chromium.org/826003003
This commit is contained in:
parent
7b161de65c
commit
b0545c2627
@ -18,12 +18,19 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "base/posix/eintr_wrapper.h"
|
#include "base/posix/eintr_wrapper.h"
|
||||||
|
#include "build/build_config.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "util/test/errors.h"
|
#include "util/test/errors.h"
|
||||||
|
|
||||||
|
#if defined(OS_POSIX)
|
||||||
|
#include <unistd.h>
|
||||||
|
#elif defined(OS_WIN)
|
||||||
|
#include <direct.h>
|
||||||
|
#include <io.h>
|
||||||
|
#endif // OS_POSIX
|
||||||
|
|
||||||
namespace crashpad {
|
namespace crashpad {
|
||||||
namespace test {
|
namespace test {
|
||||||
namespace {
|
namespace {
|
||||||
@ -32,14 +39,17 @@ bool FileExists(const base::FilePath& path) {
|
|||||||
#if defined(OS_POSIX)
|
#if defined(OS_POSIX)
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int rv = lstat(path.value().c_str(), &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) {
|
if (rv < 0) {
|
||||||
EXPECT_EQ(ENOENT, errno) << ErrnoMessage("lstat") << " " << path.value();
|
EXPECT_EQ(ENOENT, errno) << ErrnoMessage("lstat") << " " << path.value();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
#else
|
|
||||||
#error "Not implemented"
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateFile(const base::FilePath& path) {
|
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_GE(fd, 0) << ErrnoMessage("creat") << " " << path.value();
|
||||||
ASSERT_EQ(0, IGNORE_EINTR(close(fd)))
|
ASSERT_EQ(0, IGNORE_EINTR(close(fd)))
|
||||||
<< ErrnoMessage("close") << " " << path.value();
|
<< 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
|
#else
|
||||||
#error "Not implemented"
|
#error "Not implemented"
|
||||||
#endif
|
#endif
|
||||||
@ -58,6 +72,9 @@ void CreateDirectory(const base::FilePath& path) {
|
|||||||
#if defined(OS_POSIX)
|
#if defined(OS_POSIX)
|
||||||
ASSERT_EQ(0, mkdir(path.value().c_str(), 0755))
|
ASSERT_EQ(0, mkdir(path.value().c_str(), 0755))
|
||||||
<< ErrnoMessage("mkdir") << " " << path.value();
|
<< ErrnoMessage("mkdir") << " " << path.value();
|
||||||
|
#elif defined(OS_WIN)
|
||||||
|
ASSERT_EQ(0, _wmkdir(path.value().c_str()))
|
||||||
|
<< ErrnoMessage("_wmkdir") << " " << path.value();
|
||||||
#else
|
#else
|
||||||
#error "Not implemented"
|
#error "Not implemented"
|
||||||
#endif
|
#endif
|
||||||
@ -82,10 +99,10 @@ TEST(ScopedTempDir, WithTwoFiles) {
|
|||||||
parent = dir.path();
|
parent = dir.path();
|
||||||
ASSERT_TRUE(FileExists(parent));
|
ASSERT_TRUE(FileExists(parent));
|
||||||
|
|
||||||
file1 = parent.Append("test1");
|
file1 = parent.Append(FILE_PATH_LITERAL("test1"));
|
||||||
CreateFile(file1);
|
CreateFile(file1);
|
||||||
|
|
||||||
file2 = parent.Append("test 2");
|
file2 = parent.Append(FILE_PATH_LITERAL("test 2"));
|
||||||
CreateFile(file2);
|
CreateFile(file2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,13 +119,13 @@ TEST(ScopedTempDir, WithRecursiveDirectory) {
|
|||||||
parent = dir.path();
|
parent = dir.path();
|
||||||
ASSERT_TRUE(FileExists(parent));
|
ASSERT_TRUE(FileExists(parent));
|
||||||
|
|
||||||
file1 = parent.Append(".first-level file");
|
file1 = parent.Append(FILE_PATH_LITERAL(".first-level file"));
|
||||||
CreateFile(file1);
|
CreateFile(file1);
|
||||||
|
|
||||||
child_dir = parent.Append("subdir");
|
child_dir = parent.Append(FILE_PATH_LITERAL("subdir"));
|
||||||
CreateDirectory(child_dir);
|
CreateDirectory(child_dir);
|
||||||
|
|
||||||
file2 = child_dir.Append("second level file");
|
file2 = child_dir.Append(FILE_PATH_LITERAL("second level file"));
|
||||||
CreateFile(file2);
|
CreateFile(file2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user