| OLD | NEW |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "test/scoped_temp_dir.h" | 15 #include "test/scoped_temp_dir.h" |
| 16 | 16 |
| 17 #include <errno.h> | |
| 18 #include <fcntl.h> | 17 #include <fcntl.h> |
| 19 #include <string.h> | 18 #include <string.h> |
| 20 #include <sys/stat.h> | |
| 21 | 19 |
| 22 #include "base/posix/eintr_wrapper.h" | 20 #include "base/posix/eintr_wrapper.h" |
| 23 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 24 #include "gtest/gtest.h" | 22 #include "gtest/gtest.h" |
| 25 #include "test/errors.h" | 23 #include "test/errors.h" |
| 24 #include "test/file.h" |
| 26 | 25 |
| 27 #if defined(OS_POSIX) | 26 #if defined(OS_POSIX) |
| 28 #include <unistd.h> | 27 #include <unistd.h> |
| 29 #elif defined(OS_WIN) | 28 #elif defined(OS_WIN) |
| 30 #include <direct.h> | 29 #include <direct.h> |
| 31 #include <io.h> | 30 #include <io.h> |
| 32 #endif // OS_POSIX | 31 #endif // OS_POSIX |
| 33 | 32 |
| 34 namespace crashpad { | 33 namespace crashpad { |
| 35 namespace test { | 34 namespace test { |
| 36 namespace { | 35 namespace { |
| 37 | 36 |
| 38 bool FileExists(const base::FilePath& path) { | |
| 39 #if defined(OS_POSIX) | |
| 40 struct stat st; | |
| 41 int rv = lstat(path.value().c_str(), &st); | |
| 42 const char stat_function[] = "lstat"; | |
| 43 #elif defined(OS_WIN) | |
| 44 struct _stat st; | |
| 45 int rv = _wstat(path.value().c_str(), &st); | |
| 46 const char stat_function[] = "_wstat"; | |
| 47 #else | |
| 48 #error "Not implemented" | |
| 49 #endif | |
| 50 if (rv < 0) { | |
| 51 EXPECT_EQ(ENOENT, errno) << ErrnoMessage(stat_function) << " " | |
| 52 << path.value(); | |
| 53 return false; | |
| 54 } | |
| 55 return true; | |
| 56 } | |
| 57 | |
| 58 void CreateFile(const base::FilePath& path) { | 37 void CreateFile(const base::FilePath& path) { |
| 59 #if defined(OS_POSIX) | 38 #if defined(OS_POSIX) |
| 60 int fd = HANDLE_EINTR(creat(path.value().c_str(), 0644)); | 39 int fd = HANDLE_EINTR(creat(path.value().c_str(), 0644)); |
| 61 ASSERT_GE(fd, 0) << ErrnoMessage("creat") << " " << path.value(); | 40 ASSERT_GE(fd, 0) << ErrnoMessage("creat") << " " << path.value(); |
| 62 ASSERT_EQ(0, IGNORE_EINTR(close(fd))) | 41 ASSERT_EQ(0, IGNORE_EINTR(close(fd))) |
| 63 << ErrnoMessage("close") << " " << path.value(); | 42 << ErrnoMessage("close") << " " << path.value(); |
| 64 #elif defined(OS_WIN) | 43 #elif defined(OS_WIN) |
| 65 int fd = _wcreat(path.value().c_str(), _S_IREAD | _S_IWRITE); | 44 int fd = _wcreat(path.value().c_str(), _S_IREAD | _S_IWRITE); |
| 66 ASSERT_GE(fd, 0) << ErrnoMessage("_wcreat") << " " << path.value(); | 45 ASSERT_GE(fd, 0) << ErrnoMessage("_wcreat") << " " << path.value(); |
| 67 ASSERT_EQ(0, _close(fd)) << ErrnoMessage("_close") << " " << path.value(); | 46 ASSERT_EQ(0, _close(fd)) << ErrnoMessage("_close") << " " << path.value(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 113 |
| 135 EXPECT_FALSE(FileExists(file1)); | 114 EXPECT_FALSE(FileExists(file1)); |
| 136 EXPECT_FALSE(FileExists(file2)); | 115 EXPECT_FALSE(FileExists(file2)); |
| 137 EXPECT_FALSE(FileExists(child_dir)); | 116 EXPECT_FALSE(FileExists(child_dir)); |
| 138 EXPECT_FALSE(FileExists(parent)); | 117 EXPECT_FALSE(FileExists(parent)); |
| 139 } | 118 } |
| 140 | 119 |
| 141 } // namespace | 120 } // namespace |
| 142 } // namespace test | 121 } // namespace test |
| 143 } // namespace crashpad | 122 } // namespace crashpad |
| OLD | NEW |