-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add File::Delete and File::DeleteDir tests
- Loading branch information
1 parent
4a55511
commit b35ba42
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright 2020 Dolphin Emulator Project | ||
// Licensed under GPLv2+ | ||
// Refer to the license.txt file included. | ||
|
||
#include <array> | ||
#include <gtest/gtest.h> | ||
|
||
#include "Common/FileUtil.h" | ||
|
||
class FileUtilTest : public testing::Test | ||
{ | ||
protected: | ||
FileUtilTest() | ||
: m_parent_directory(File::CreateTempDir()), m_file_path(m_parent_directory + "/file.txt"), | ||
m_directory_path(m_parent_directory + "/dir"), | ||
m_invalid_path(m_parent_directory + "/invalid.txt") | ||
{ | ||
} | ||
|
||
virtual ~FileUtilTest() | ||
{ | ||
if (m_parent_directory != "") | ||
{ | ||
File::DeleteDirRecursively(m_parent_directory); | ||
} | ||
} | ||
|
||
void SetUp() | ||
{ | ||
if (m_parent_directory == "") | ||
{ | ||
FAIL(); | ||
} | ||
} | ||
|
||
constexpr static std::array<File::IfAbsentBehavior, 2> s_warning_behaviors = { | ||
File::IfAbsentBehavior::ConsoleWarning, | ||
File::IfAbsentBehavior::NoConsoleWarning, | ||
}; | ||
|
||
const std::string m_parent_directory; | ||
const std::string m_file_path; | ||
const std::string m_directory_path; | ||
const std::string m_invalid_path; | ||
}; | ||
|
||
void DeleteShouldNotRemoveDirectory(const std::string& path, File::IfAbsentBehavior behavior) | ||
{ | ||
File::CreateDir(path); | ||
EXPECT_FALSE(File::Delete(path, behavior)); | ||
File::DeleteDir(path, behavior); | ||
} | ||
|
||
void DeleteShouldRemoveFile(const std::string& path, File::IfAbsentBehavior behavior) | ||
{ | ||
File::CreateEmptyFile(path); | ||
EXPECT_TRUE(File::Delete(path, behavior)); | ||
} | ||
|
||
void DeleteShouldReturnTrueForInvalidPath(const std::string& path, File::IfAbsentBehavior behavior) | ||
{ | ||
EXPECT_TRUE(File::Delete(path, behavior)); | ||
} | ||
|
||
void DeleteDirShouldRemoveDirectory(const std::string& path, File::IfAbsentBehavior behavior) | ||
{ | ||
File::CreateDir(path); | ||
EXPECT_TRUE(File::DeleteDir(path, behavior)); | ||
} | ||
|
||
void DeleteDirShouldNotRemoveFile(const std::string& path, File::IfAbsentBehavior behavior) | ||
{ | ||
File::CreateEmptyFile(path); | ||
EXPECT_FALSE(File::DeleteDir(path, behavior)); | ||
File::Delete(path, behavior); | ||
} | ||
|
||
void DeleteDirShouldReturnTrueForInvalidPath(const std::string& path, | ||
File::IfAbsentBehavior behavior) | ||
{ | ||
EXPECT_TRUE(File::DeleteDir(path, behavior)); | ||
} | ||
|
||
TEST_F(FileUtilTest, Delete) | ||
{ | ||
for (const auto behavior : s_warning_behaviors) | ||
{ | ||
DeleteShouldNotRemoveDirectory(m_directory_path, behavior); | ||
DeleteShouldRemoveFile(m_file_path, behavior); | ||
DeleteShouldReturnTrueForInvalidPath(m_invalid_path, behavior); | ||
} | ||
} | ||
|
||
TEST_F(FileUtilTest, DeleteDir) | ||
{ | ||
for (const auto behavior : s_warning_behaviors) | ||
{ | ||
DeleteDirShouldRemoveDirectory(m_directory_path, behavior); | ||
DeleteDirShouldNotRemoveFile(m_file_path, behavior); | ||
DeleteDirShouldReturnTrueForInvalidPath(m_invalid_path, behavior); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters