Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | |
|
Mark Mentovai
2014/12/31 05:51:10
I see why you named it this way, but I think that
Robert Sesek
2015/01/02 17:34:09
Done.
| |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (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 | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 #include "util/test/scoped_temp_dir.h" | |
| 16 | |
| 17 #include <errno.h> | |
| 18 #include <fcntl.h> | |
| 19 #include <string.h> | |
| 20 #include <sys/stat.h> | |
| 21 #include <unistd.h> | |
| 22 | |
| 23 #include "base/posix/eintr_wrapper.h" | |
| 24 #include "gtest/gtest.h" | |
| 25 #include "util/test/errors.h" | |
| 26 | |
| 27 namespace crashpad { | |
| 28 namespace test { | |
| 29 namespace { | |
| 30 | |
| 31 bool FileExists(const base::FilePath& path) { | |
| 32 struct stat st; | |
| 33 int rv = stat(path.value().c_str(), &st); | |
|
Mark Mentovai
2014/12/31 05:51:10
I think it’s good to be in the habit of calling ls
Robert Sesek
2015/01/02 17:34:09
Done.
| |
| 34 if (rv < 0) { | |
| 35 EXPECT_EQ(ENOENT, errno) << "stat expected ENOENT, got " << strerror(errno); | |
|
Mark Mentovai
2014/12/31 05:51:10
The message kinda repeats what the code says, exce
Robert Sesek
2015/01/02 17:34:09
Done.
| |
| 36 return false; | |
| 37 } | |
| 38 return true; | |
| 39 } | |
| 40 | |
| 41 TEST(ScopedTempDir, Empty) { | |
| 42 base::FilePath path; | |
| 43 { | |
| 44 ScopedTempDir dir; | |
| 45 path = dir.path(); | |
| 46 EXPECT_TRUE(FileExists(path)); | |
| 47 } | |
| 48 EXPECT_FALSE(FileExists(path)); | |
| 49 } | |
| 50 | |
| 51 TEST(ScopedTempDir, WithTwoFiles) { | |
| 52 base::FilePath parent, file1, file2; | |
| 53 | |
| 54 { | |
| 55 ScopedTempDir dir; | |
| 56 parent = dir.path(); | |
| 57 ASSERT_TRUE(FileExists(parent)); | |
| 58 | |
| 59 file1 = parent.Append("test1"); | |
| 60 int fd = HANDLE_EINTR(creat(file1.value().c_str(), 0644)); | |
|
Mark Mentovai
2014/12/31 05:51:10
The ASSERT_GE(fd, 0) << ErrnoMessage("creat") is m
Robert Sesek
2015/01/02 17:34:09
Done.
| |
| 61 IGNORE_EINTR(close(fd)); | |
| 62 ASSERT_TRUE(FileExists(file1)); | |
|
Mark Mentovai
2014/12/31 05:51:10
This can be EXPECT_TRUE() since it isn’t a precond
Robert Sesek
2015/01/02 17:34:09
Done.
| |
| 63 | |
| 64 file2 = parent.Append("test 2"); | |
|
Mark Mentovai
2014/12/31 05:51:10
Spaces! Happy to see that.
You should also test w
Robert Sesek
2015/01/02 17:34:09
Done.
| |
| 65 fd = HANDLE_EINTR(creat(file2.value().c_str(), 0644)); | |
| 66 IGNORE_EINTR(close(fd)); | |
| 67 ASSERT_TRUE(FileExists(file2)); | |
| 68 } | |
| 69 | |
| 70 EXPECT_FALSE(FileExists(file1)); | |
| 71 EXPECT_FALSE(FileExists(file2)); | |
| 72 EXPECT_FALSE(FileExists(parent)); | |
| 73 } | |
| 74 | |
| 75 TEST(ScopedTempDir, WithRecursiveDirectory) { | |
| 76 base::FilePath parent, file1, child_dir, file2; | |
| 77 | |
| 78 { | |
| 79 ScopedTempDir dir; | |
| 80 parent = dir.path(); | |
| 81 ASSERT_TRUE(FileExists(parent)); | |
| 82 | |
| 83 file1 = parent.Append("first-level file"); | |
| 84 int fd = HANDLE_EINTR(creat(file1.value().c_str(), 0644)); | |
| 85 IGNORE_EINTR(close(fd)); | |
| 86 ASSERT_TRUE(FileExists(file1)); | |
|
Mark Mentovai
2014/12/31 05:51:10
Same here and on line 96. Line 91 needs to stay an
Robert Sesek
2015/01/02 17:34:09
Done.
| |
| 87 | |
| 88 child_dir = parent.Append("subdir"); | |
| 89 ASSERT_EQ(0, mkdir(child_dir.value().c_str(), 0755)) | |
| 90 << ErrnoMessage("mkdir"); | |
| 91 ASSERT_TRUE(FileExists(child_dir)); | |
| 92 | |
| 93 file2 = child_dir.Append("second level file"); | |
| 94 fd = HANDLE_EINTR(creat(file2.value().c_str(), 0644)); | |
| 95 IGNORE_EINTR(close(fd)); | |
| 96 ASSERT_TRUE(FileExists(file2)); | |
| 97 } | |
| 98 | |
| 99 EXPECT_FALSE(FileExists(file1)); | |
| 100 EXPECT_FALSE(FileExists(file2)); | |
| 101 EXPECT_FALSE(FileExists(child_dir)); | |
| 102 EXPECT_FALSE(FileExists(parent)); | |
| 103 } | |
| 104 | |
| 105 } // namespace | |
| 106 } // namespace test | |
| 107 } // namespace crashpad | |
| OLD | NEW |