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, |
(...skipping 21 matching lines...) Expand all Loading... | |
32 #endif // OS_POSIX | 32 #endif // OS_POSIX |
33 | 33 |
34 namespace crashpad { | 34 namespace crashpad { |
35 namespace test { | 35 namespace test { |
36 namespace { | 36 namespace { |
37 | 37 |
38 bool FileExists(const base::FilePath& path) { | 38 bool FileExists(const base::FilePath& path) { |
39 #if defined(OS_POSIX) | 39 #if defined(OS_POSIX) |
40 struct stat st; | 40 struct stat st; |
41 int rv = lstat(path.value().c_str(), &st); | 41 int rv = lstat(path.value().c_str(), &st); |
42 const char* stat_function = "lstat"; | |
Mark Mentovai
2015/01/08 17:40:44
For char constants, use:
const char stat_functi
scottmg
2015/01/08 18:25:55
Done.
| |
42 #elif defined(OS_WIN) | 43 #elif defined(OS_WIN) |
43 struct _stat st; | 44 struct _stat st; |
44 int rv = _wstat(path.value().c_str(), &st); | 45 int rv = _wstat(path.value().c_str(), &st); |
46 const char* stat_function = "_wstat"; | |
45 #else | 47 #else |
46 #error "Not implemented" | 48 #error "Not implemented" |
47 #endif | 49 #endif |
48 if (rv < 0) { | 50 if (rv < 0) { |
49 EXPECT_EQ(ENOENT, errno) << ErrnoMessage("lstat") << " " << path.value(); | 51 EXPECT_EQ(ENOENT, errno) << ErrnoMessage(stat_function) << " " |
52 << path.value(); | |
50 return false; | 53 return false; |
51 } | 54 } |
52 return true; | 55 return true; |
53 } | 56 } |
54 | 57 |
55 void CreateFile(const base::FilePath& path) { | 58 void CreateFile(const base::FilePath& path) { |
56 #if defined(OS_POSIX) | 59 #if defined(OS_POSIX) |
57 int fd = HANDLE_EINTR(creat(path.value().c_str(), 0644)); | 60 int fd = HANDLE_EINTR(creat(path.value().c_str(), 0644)); |
58 ASSERT_GE(fd, 0) << ErrnoMessage("creat") << " " << path.value(); | 61 ASSERT_GE(fd, 0) << ErrnoMessage("creat") << " " << path.value(); |
59 ASSERT_EQ(0, IGNORE_EINTR(close(fd))) | 62 ASSERT_EQ(0, IGNORE_EINTR(close(fd))) |
60 << ErrnoMessage("close") << " " << path.value(); | 63 << ErrnoMessage("close") << " " << path.value(); |
61 #elif defined(OS_WIN) | 64 #elif defined(OS_WIN) |
62 int fd = _wcreat(path.value().c_str(), 0644); | 65 int fd = _wcreat(path.value().c_str(), 0644); |
63 ASSERT_GE(fd, 0) << ErrnoMessage("_wcreat") << " " << path.value(); | 66 ASSERT_GE(fd, 0) << ErrnoMessage("_wcreat") << " " << path.value(); |
64 ASSERT_EQ(0, _close(fd)) << ErrnoMessage("_close") << " " << path.value(); | 67 ASSERT_EQ(0, _close(fd)) << ErrnoMessage("_close") << " " << path.value(); |
65 #else | 68 #else |
66 #error "Not implemented" | 69 #error "Not implemented" |
67 #endif | 70 #endif |
68 EXPECT_TRUE(FileExists(path)); | 71 EXPECT_TRUE(FileExists(path)); |
69 } | 72 } |
70 | 73 |
71 void CreateDirectory(const base::FilePath& path) { | 74 void CreateDirectory(const base::FilePath& path) { |
72 #if defined(OS_POSIX) | 75 #if defined(OS_POSIX) |
73 ASSERT_EQ(0, mkdir(path.value().c_str(), 0755)) | 76 ASSERT_EQ(0, mkdir(path.value().c_str(), 0755)) |
74 << ErrnoMessage("mkdir") << " " << path.value(); | 77 << ErrnoMessage("mkdir") << " " << path.value(); |
Robert Sesek
2015/01/08 17:40:30
You could use this same pattern here, too.
scottmg
2015/01/08 18:25:55
Seems more verbose here since it's only one statem
| |
75 #elif defined(OS_WIN) | 78 #elif defined(OS_WIN) |
76 ASSERT_EQ(0, _wmkdir(path.value().c_str())) | 79 ASSERT_EQ(0, _wmkdir(path.value().c_str())) |
77 << ErrnoMessage("_wmkdir") << " " << path.value(); | 80 << ErrnoMessage("_wmkdir") << " " << path.value(); |
78 #else | 81 #else |
79 #error "Not implemented" | 82 #error "Not implemented" |
80 #endif | 83 #endif |
81 ASSERT_TRUE(FileExists(path)); | 84 ASSERT_TRUE(FileExists(path)); |
82 } | 85 } |
83 | 86 |
84 TEST(ScopedTempDir, Empty) { | 87 TEST(ScopedTempDir, Empty) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 | 134 |
132 EXPECT_FALSE(FileExists(file1)); | 135 EXPECT_FALSE(FileExists(file1)); |
133 EXPECT_FALSE(FileExists(file2)); | 136 EXPECT_FALSE(FileExists(file2)); |
134 EXPECT_FALSE(FileExists(child_dir)); | 137 EXPECT_FALSE(FileExists(child_dir)); |
135 EXPECT_FALSE(FileExists(parent)); | 138 EXPECT_FALSE(FileExists(parent)); |
136 } | 139 } |
137 | 140 |
138 } // namespace | 141 } // namespace |
139 } // namespace test | 142 } // namespace test |
140 } // namespace crashpad | 143 } // namespace crashpad |
OLD | NEW |