OLD | NEW |
| (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 #ifndef CRASHPAD_UTIL_TEST_SCOPED_TEMP_DIR_ | |
16 #define CRASHPAD_UTIL_TEST_SCOPED_TEMP_DIR_ | |
17 | |
18 #include "base/basictypes.h" | |
19 #include "base/files/file_path.h" | |
20 | |
21 namespace crashpad { | |
22 namespace test { | |
23 | |
24 //! \brief A RAII object that creates a temporary directory for testing. | |
25 //! | |
26 //! Upon construction, a temporary directory will be created. Failure to create | |
27 //! the directory is fatal. On destruction, the directory and all its contents | |
28 //! will be removed. | |
29 class ScopedTempDir { | |
30 public: | |
31 ScopedTempDir(); | |
32 ~ScopedTempDir(); | |
33 | |
34 //! \brief Returns the path of the temporary directory. | |
35 //! | |
36 //! \return The temporary directory path. | |
37 const base::FilePath& path() const { return path_; } | |
38 | |
39 //! \brief Moves the temporary directory to a new temporary location. | |
40 void Rename(); | |
41 | |
42 private: | |
43 //! \brief Creates the temporary directory and asserts success of the | |
44 //! operation. | |
45 static base::FilePath CreateTemporaryDirectory(); | |
46 | |
47 //! \brief Removes all files and subdirectories at the given \a path, | |
48 //! including the \a path itself. | |
49 //! | |
50 //! Failures are recorded by gtest expectations. | |
51 //! | |
52 //! \param[in] path The path to delete, along with its contents. This must | |
53 //! reference a directory. | |
54 static void RecursivelyDeleteTemporaryDirectory(const base::FilePath& path); | |
55 | |
56 base::FilePath path_; | |
57 | |
58 DISALLOW_COPY_AND_ASSIGN(ScopedTempDir); | |
59 }; | |
60 | |
61 } // namespace test | |
62 } // namespace crashpad | |
63 | |
64 #endif // CRASHPAD_UTIL_TEST_SCOPED_TEMP_DIR_ | |
OLD | NEW |