Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: util/test/scoped_temp_dir_test.cc

Issue 826003003: win: porting for scoped_temp_dir_test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: . Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "util/test/scoped_temp_dir.h" 15 #include "util/test/scoped_temp_dir.h"
16 16
17 #include <errno.h> 17 #include <errno.h>
18 #include <fcntl.h> 18 #include <fcntl.h>
19 #include <string.h> 19 #include <string.h>
20 #include <sys/stat.h> 20 #include <sys/stat.h>
21 #include <unistd.h>
22 21
23 #include "base/posix/eintr_wrapper.h" 22 #include "base/posix/eintr_wrapper.h"
23 #include "build/build_config.h"
24 #include "gtest/gtest.h" 24 #include "gtest/gtest.h"
25 #include "util/test/errors.h" 25 #include "util/test/errors.h"
26 26
27 #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
28 #include <unistd.h>
29 #elif defined(OS_WIN)
30 #include <direct.h>
31 #include <io.h>
32 #endif // OS_POSIX
33
27 namespace crashpad { 34 namespace crashpad {
28 namespace test { 35 namespace test {
29 namespace { 36 namespace {
30 37
31 bool FileExists(const base::FilePath& path) { 38 bool FileExists(const base::FilePath& path) {
32 #if defined(OS_POSIX) 39 #if defined(OS_POSIX)
33 struct stat st; 40 struct stat st;
34 int rv = lstat(path.value().c_str(), &st); 41 int rv = lstat(path.value().c_str(), &st);
42 #elif defined(OS_WIN)
43 struct _stat st;
44 int rv = _wstat(path.value().c_str(), &st);
45 #else
46 #error "Not implemented"
47 #endif
35 if (rv < 0) { 48 if (rv < 0) {
36 EXPECT_EQ(ENOENT, errno) << ErrnoMessage("lstat") << " " << path.value(); 49 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
37 return false; 50 return false;
38 } 51 }
39 return true; 52 return true;
40 #else
41 #error "Not implemented"
42 #endif
43 } 53 }
44 54
45 void CreateFile(const base::FilePath& path) { 55 void CreateFile(const base::FilePath& path) {
46 #if defined(OS_POSIX) 56 #if defined(OS_POSIX)
47 int fd = HANDLE_EINTR(creat(path.value().c_str(), 0644)); 57 int fd = HANDLE_EINTR(creat(path.value().c_str(), 0644));
48 ASSERT_GE(fd, 0) << ErrnoMessage("creat") << " " << path.value(); 58 ASSERT_GE(fd, 0) << ErrnoMessage("creat") << " " << path.value();
49 ASSERT_EQ(0, IGNORE_EINTR(close(fd))) 59 ASSERT_EQ(0, IGNORE_EINTR(close(fd)))
50 << ErrnoMessage("close") << " " << path.value(); 60 << ErrnoMessage("close") << " " << path.value();
61 #elif defined(OS_WIN)
62 int fd = _wcreat(path.value().c_str(), 0644);
63 ASSERT_GE(fd, 0) << ErrnoMessage("_wcreat") << " " << path.value();
64 ASSERT_EQ(0, _close(fd)) << ErrnoMessage("_close") << " " << path.value();
51 #else 65 #else
52 #error "Not implemented" 66 #error "Not implemented"
53 #endif 67 #endif
54 EXPECT_TRUE(FileExists(path)); 68 EXPECT_TRUE(FileExists(path));
55 } 69 }
56 70
57 void CreateDirectory(const base::FilePath& path) { 71 void CreateDirectory(const base::FilePath& path) {
58 #if defined(OS_POSIX) 72 #if defined(OS_POSIX)
59 ASSERT_EQ(0, mkdir(path.value().c_str(), 0755)) 73 ASSERT_EQ(0, mkdir(path.value().c_str(), 0755))
60 << ErrnoMessage("mkdir") << " " << path.value(); 74 << ErrnoMessage("mkdir") << " " << path.value();
75 #elif defined(OS_WIN)
76 ASSERT_EQ(0, _wmkdir(path.value().c_str()))
77 << ErrnoMessage("_wmkdir") << " " << path.value();
61 #else 78 #else
62 #error "Not implemented" 79 #error "Not implemented"
63 #endif 80 #endif
64 ASSERT_TRUE(FileExists(path)); 81 ASSERT_TRUE(FileExists(path));
65 } 82 }
66 83
67 TEST(ScopedTempDir, Empty) { 84 TEST(ScopedTempDir, Empty) {
68 base::FilePath path; 85 base::FilePath path;
69 { 86 {
70 ScopedTempDir dir; 87 ScopedTempDir dir;
71 path = dir.path(); 88 path = dir.path();
72 EXPECT_TRUE(FileExists(path)); 89 EXPECT_TRUE(FileExists(path));
73 } 90 }
74 EXPECT_FALSE(FileExists(path)); 91 EXPECT_FALSE(FileExists(path));
75 } 92 }
76 93
77 TEST(ScopedTempDir, WithTwoFiles) { 94 TEST(ScopedTempDir, WithTwoFiles) {
78 base::FilePath parent, file1, file2; 95 base::FilePath parent, file1, file2;
79 96
80 { 97 {
81 ScopedTempDir dir; 98 ScopedTempDir dir;
82 parent = dir.path(); 99 parent = dir.path();
83 ASSERT_TRUE(FileExists(parent)); 100 ASSERT_TRUE(FileExists(parent));
84 101
85 file1 = parent.Append("test1"); 102 file1 = parent.Append(FILE_PATH_LITERAL("test1"));
86 CreateFile(file1); 103 CreateFile(file1);
87 104
88 file2 = parent.Append("test 2"); 105 file2 = parent.Append(FILE_PATH_LITERAL("test 2"));
89 CreateFile(file2); 106 CreateFile(file2);
90 } 107 }
91 108
92 EXPECT_FALSE(FileExists(file1)); 109 EXPECT_FALSE(FileExists(file1));
93 EXPECT_FALSE(FileExists(file2)); 110 EXPECT_FALSE(FileExists(file2));
94 EXPECT_FALSE(FileExists(parent)); 111 EXPECT_FALSE(FileExists(parent));
95 } 112 }
96 113
97 TEST(ScopedTempDir, WithRecursiveDirectory) { 114 TEST(ScopedTempDir, WithRecursiveDirectory) {
98 base::FilePath parent, file1, child_dir, file2; 115 base::FilePath parent, file1, child_dir, file2;
99 116
100 { 117 {
101 ScopedTempDir dir; 118 ScopedTempDir dir;
102 parent = dir.path(); 119 parent = dir.path();
103 ASSERT_TRUE(FileExists(parent)); 120 ASSERT_TRUE(FileExists(parent));
104 121
105 file1 = parent.Append(".first-level file"); 122 file1 = parent.Append(FILE_PATH_LITERAL(".first-level file"));
106 CreateFile(file1); 123 CreateFile(file1);
107 124
108 child_dir = parent.Append("subdir"); 125 child_dir = parent.Append(FILE_PATH_LITERAL("subdir"));
109 CreateDirectory(child_dir); 126 CreateDirectory(child_dir);
110 127
111 file2 = child_dir.Append("second level file"); 128 file2 = child_dir.Append(FILE_PATH_LITERAL("second level file"));
112 CreateFile(file2); 129 CreateFile(file2);
113 } 130 }
114 131
115 EXPECT_FALSE(FileExists(file1)); 132 EXPECT_FALSE(FileExists(file1));
116 EXPECT_FALSE(FileExists(file2)); 133 EXPECT_FALSE(FileExists(file2));
117 EXPECT_FALSE(FileExists(child_dir)); 134 EXPECT_FALSE(FileExists(child_dir));
118 EXPECT_FALSE(FileExists(parent)); 135 EXPECT_FALSE(FileExists(parent));
119 } 136 }
120 137
121 } // namespace 138 } // namespace
122 } // namespace test 139 } // namespace test
123 } // namespace crashpad 140 } // namespace crashpad
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698