Chromium Code Reviews| Index: webrtc/test/testsupport/fileutils_unittest.cc |
| diff --git a/webrtc/test/testsupport/fileutils_unittest.cc b/webrtc/test/testsupport/fileutils_unittest.cc |
| index 132436f0040974dd151bceb43105f720bb9154d5..7ff829b56e81701cde6313c3d306714d30848fc5 100644 |
| --- a/webrtc/test/testsupport/fileutils_unittest.cc |
| +++ b/webrtc/test/testsupport/fileutils_unittest.cc |
| @@ -12,9 +12,12 @@ |
| #include <stdio.h> |
| +#include <fstream> |
| +#include <iostream> |
| #include <list> |
| #include <string> |
| +#include "webrtc/base/pathutils.h" |
| #include "webrtc/test/gtest.h" |
| #ifdef WIN32 |
| @@ -24,11 +27,21 @@ static const char* kPathDelimiter = "\\"; |
| static const char* kPathDelimiter = "/"; |
| #endif |
| -static const std::string kResourcesDir = "resources"; |
| -static const std::string kTestName = "fileutils_unittest"; |
| -static const std::string kExtension = "tmp"; |
| +static const char kTestName[] = "fileutils_unittest"; |
| +static const char kExtension[] = "tmp"; |
| namespace webrtc { |
| +namespace test { |
| + |
| +namespace { |
| + |
| +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.
|
| + std::ofstream out(file_path); |
| + out << what; |
| + out.close(); |
| +} |
| + |
| +} // namespace |
| // Test fixture to restore the working directory between each test, since some |
| // of them change it with chdir during execution (not restored by the |
| @@ -170,4 +183,27 @@ TEST_F(FileUtilsTest, DirExists) { |
| remove(temp_filename.c_str()); |
| } |
| +TEST_F(FileUtilsTest, RemoveDirRecursively) { |
| + rtc::Pathname temp_directory(OutputPath()); |
| + temp_directory.AppendFolder("TempFileUtilsTestRemoveDirRecursively"); |
| + EXPECT_TRUE(CreateDir(temp_directory.pathname())); |
| + |
| + // Add a file. |
| + std::string temp_filename1 = TempFilename( |
| + temp_directory.pathname(), "TempFilenameTest"); |
| + WriteStringInFile("test", temp_filename1); |
| + |
| + // Add a non-empty directory. |
| + rtc::Pathname temp_subdir(temp_directory.pathname()); |
| + temp_subdir.AppendFolder("subdir"); |
| + EXPECT_TRUE(CreateDir(temp_subdir.pathname())); |
| + std::string temp_filename2 = TempFilename( |
| + temp_subdir.pathname(), "TempFilenameTestInSubDir"); |
| + WriteStringInFile("test", temp_filename2); |
| + |
| + EXPECT_EQ(4u, RemoveDirRecursively(temp_directory)); |
| + EXPECT_FALSE(DirExists(temp_directory.pathname())); |
| +} |
| + |
| +} // namespace test |
| } // namespace webrtc |