Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(107)

Side by Side Diff: src/common/tests/auto_tempdir.h

Issue 328001: Correcting compilation warnings. (Closed) Base URL: http://google-breakpad.googlecode.com/svn/trunk/
Patch Set: '' Created 13 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/common/mac/macho_walker.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 // Utility class for creating a temporary directory for unit tests
31 // that is deleted in the destructor.
32 #ifndef GOOGLE_BREAKPAD_COMMON_TESTS_AUTO_TEMPDIR
33 #define GOOGLE_BREAKPAD_COMMON_TESTS_AUTO_TEMPDIR
34
35 #include <dirent.h>
36 #include <sys/types.h>
37
38 #include <string>
39
40 #include "breakpad_googletest_includes.h"
41
42 #if !defined(__ANDROID__)
43 #define TEMPDIR "/tmp"
44 #else
45 #define TEMPDIR "/data/local/tmp"
46 #endif
47
48 namespace google_breakpad {
49
50 class AutoTempDir {
51 public:
52 AutoTempDir() {
53 char temp_dir[] = TEMPDIR "/breakpad.XXXXXXXXXX";
54 EXPECT_TRUE(mkdtemp(temp_dir) != NULL);
55 path_.assign(temp_dir);
56 }
57
58 ~AutoTempDir() {
59 DeleteRecursively(path_);
60 }
61
62 const std::string& path() {
63 return path_;
64 }
65
66 private:
67 std::string path_;
Mark Mentovai 2011/11/23 14:19:43 Normally the data members follow functions. http:
68
69 void DeleteRecursively(const std::string& path) {
70 // First remove any files in the dir
71 DIR* dir = opendir(path.c_str());
72 if (!dir)
73 return;
74
75 dirent* entry;
76 while ((entry = readdir(dir)) != NULL) {
77 if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
78 continue;
79 std::string entry_path = path + "/" + entry->d_name;
80 struct stat stats;
81 EXPECT_TRUE(lstat(entry_path.c_str(), &stats) == 0);
82 if (S_ISDIR(stats.st_mode))
83 DeleteRecursively(entry_path);
84 else
85 EXPECT_TRUE(unlink(entry_path.c_str()) == 0);
86 }
87 EXPECT_TRUE(closedir(dir) == 0);
88 EXPECT_TRUE(rmdir(path.c_str()) == 0);
89 }
90
91 // prevent copy construction and assignment
92 AutoTempDir(const AutoTempDir&);
93 AutoTempDir& operator=(const AutoTempDir&);
94 };
95
96 } // namespace google_breakpad
97
98 #endif // GOOGLE_BREAKPAD_COMMON_TESTS_AUTO_TEMPDIR
OLDNEW
« no previous file with comments | « src/common/mac/macho_walker.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 1004:630ec63f810e-tainted