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

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

Issue 1051533002: test: Move util/test to its own top-level directory, test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Rebase Created 5 years, 8 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
OLDNEW
(Empty)
1 // Copyright 2015 The Crashpad Authors. All rights reserved.
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 <dirent.h>
18 #include <string.h>
19 #include <unistd.h>
20
21 #include "base/logging.h"
22 #include "gtest/gtest.h"
23 #include "util/test/errors.h"
24
25 namespace crashpad {
26 namespace test {
27
28 void ScopedTempDir::Rename() {
29 base::FilePath move_to = CreateTemporaryDirectory();
30 PCHECK(rename(path_.value().c_str(), move_to.value().c_str()) == 0);
31 path_ = move_to;
32 }
33
34 // static
35 base::FilePath ScopedTempDir::CreateTemporaryDirectory() {
36 char dir_template[] = "/tmp/com.googlecode.crashpad.test.XXXXXX";
37 PCHECK(mkdtemp(dir_template)) << "mkdtemp " << dir_template;
38 return base::FilePath(dir_template);
39 }
40
41 // static
42 void ScopedTempDir::RecursivelyDeleteTemporaryDirectory(
43 const base::FilePath& path) {
44 DIR* dir = opendir(path.value().c_str());
45 ASSERT_TRUE(dir) << ErrnoMessage("opendir") << " " << path.value();
46
47 dirent* entry;
48 while ((entry = readdir(dir))) {
49 if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
50 continue;
51 }
52
53 base::FilePath entry_path = path.Append(entry->d_name);
54 if (entry->d_type == DT_DIR) {
55 RecursivelyDeleteTemporaryDirectory(entry_path);
56 } else {
57 EXPECT_EQ(0, unlink(entry_path.value().c_str()))
58 << ErrnoMessage("unlink") << " " << entry_path.value();
59 }
60 }
61
62 EXPECT_EQ(0, closedir(dir))
63 << ErrnoMessage("closedir") << " " << path.value();
64 EXPECT_EQ(0, rmdir(path.value().c_str()))
65 << ErrnoMessage("rmdir") << " " << path.value();
66 }
67
68 } // namespace test
69 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698