OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/test/testsupport/fileutils.h" | 11 #include "webrtc/test/testsupport/fileutils.h" |
12 | 12 |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 | 14 |
15 #include <fstream> | |
16 #include <iostream> | |
15 #include <list> | 17 #include <list> |
16 #include <string> | 18 #include <string> |
17 | 19 |
20 #include "webrtc/base/pathutils.h" | |
18 #include "webrtc/test/gtest.h" | 21 #include "webrtc/test/gtest.h" |
19 | 22 |
20 #ifdef WIN32 | 23 #ifdef WIN32 |
21 #define chdir _chdir | 24 #define chdir _chdir |
22 static const char* kPathDelimiter = "\\"; | 25 static const char* kPathDelimiter = "\\"; |
23 #else | 26 #else |
24 static const char* kPathDelimiter = "/"; | 27 static const char* kPathDelimiter = "/"; |
25 #endif | 28 #endif |
26 | 29 |
27 static const std::string kResourcesDir = "resources"; | 30 static const char kTestName[] = "fileutils_unittest"; |
28 static const std::string kTestName = "fileutils_unittest"; | 31 static const char kExtension[] = "tmp"; |
29 static const std::string kExtension = "tmp"; | |
30 | 32 |
31 namespace webrtc { | 33 namespace webrtc { |
34 namespace test { | |
35 | |
36 namespace { | |
37 | |
38 void WriteStringInFile(const std::string& what, const std::string& file_path) { | |
kjellander_webrtc
2017/05/22 18:22:20
what -> contents?
AleBzk
2017/05/23 11:10:10
Acknowledged.
| |
39 std::ofstream out(file_path); | |
40 out << what; | |
41 out.close(); | |
42 } | |
43 | |
44 } // namespace | |
32 | 45 |
33 // Test fixture to restore the working directory between each test, since some | 46 // Test fixture to restore the working directory between each test, since some |
34 // of them change it with chdir during execution (not restored by the | 47 // of them change it with chdir during execution (not restored by the |
35 // gtest framework). | 48 // gtest framework). |
36 class FileUtilsTest : public testing::Test { | 49 class FileUtilsTest : public testing::Test { |
37 protected: | 50 protected: |
38 FileUtilsTest() { | 51 FileUtilsTest() { |
39 } | 52 } |
40 ~FileUtilsTest() override {} | 53 ~FileUtilsTest() override {} |
41 // Runs before the first test | 54 // Runs before the first test |
(...skipping 121 matching lines...) Loading... | |
163 // Check that an existing file is not recognized as an existing directory. | 176 // Check that an existing file is not recognized as an existing directory. |
164 std::string temp_filename = webrtc::test::TempFilename( | 177 std::string temp_filename = webrtc::test::TempFilename( |
165 webrtc::test::OutputPath(), "TempFilenameTest"); | 178 webrtc::test::OutputPath(), "TempFilenameTest"); |
166 ASSERT_TRUE(webrtc::test::FileExists(temp_filename)) | 179 ASSERT_TRUE(webrtc::test::FileExists(temp_filename)) |
167 << "Couldn't find file: " << temp_filename; | 180 << "Couldn't find file: " << temp_filename; |
168 ASSERT_FALSE(webrtc::test::DirExists(temp_filename)) | 181 ASSERT_FALSE(webrtc::test::DirExists(temp_filename)) |
169 << "Existing file recognized as existing directory"; | 182 << "Existing file recognized as existing directory"; |
170 remove(temp_filename.c_str()); | 183 remove(temp_filename.c_str()); |
171 } | 184 } |
172 | 185 |
186 TEST_F(FileUtilsTest, RemoveDirRecursively) { | |
187 rtc::Pathname temp_directory(OutputPath()); | |
188 temp_directory.AppendFolder("TempFileUtilsTestRemoveDirRecursively"); | |
189 EXPECT_TRUE(CreateDir(temp_directory.pathname())); | |
190 | |
191 // Add a file. | |
192 std::string temp_filename1 = TempFilename( | |
193 temp_directory.pathname(), "TempFilenameTest"); | |
194 WriteStringInFile("test", temp_filename1); | |
195 | |
196 // Add a non-empty directory. | |
197 rtc::Pathname temp_subdir(temp_directory.pathname()); | |
198 temp_subdir.AppendFolder("subdir"); | |
199 EXPECT_TRUE(CreateDir(temp_subdir.pathname())); | |
200 std::string temp_filename2 = TempFilename( | |
201 temp_subdir.pathname(), "TempFilenameTestInSubDir"); | |
202 WriteStringInFile("test", temp_filename2); | |
203 | |
204 EXPECT_EQ(4u, RemoveDirRecursively(temp_directory)); | |
205 EXPECT_FALSE(DirExists(temp_directory.pathname())); | |
206 } | |
207 | |
208 } // namespace test | |
173 } // namespace webrtc | 209 } // namespace webrtc |
OLD | NEW |