summaryrefslogtreecommitdiff
path: root/Source/UnitTests/Common/FileUtilTest.cpp
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2023-02-15 03:12:24 +0100
committerGitHub <noreply@github.com>2023-02-15 03:12:24 +0100
commit089eab96d721dc65e60090f545d41dd6bd5925e9 (patch)
tree2cd69b3477e05c553cf02b1c101786afa3dc203a /Source/UnitTests/Common/FileUtilTest.cpp
parent661b74f4a3d9fee4acf80b4e399a6c45e1f21fa3 (diff)
parentc36994a90d2ac9fe15360e1d2e8764aba784c4e8 (diff)
Merge pull request #11567 from AdmiralCurtiss/create-full-path-behavior-change
Common/FileUtil: Revert behavior of CreateFullPath().
Diffstat (limited to 'Source/UnitTests/Common/FileUtilTest.cpp')
-rw-r--r--Source/UnitTests/Common/FileUtilTest.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/Source/UnitTests/Common/FileUtilTest.cpp b/Source/UnitTests/Common/FileUtilTest.cpp
index 8570c347b4..d361f656f3 100644
--- a/Source/UnitTests/Common/FileUtilTest.cpp
+++ b/Source/UnitTests/Common/FileUtilTest.cpp
@@ -100,3 +100,50 @@ TEST_F(FileUtilTest, DeleteDir)
DeleteDirShouldReturnTrueForInvalidPath(m_invalid_path, behavior);
}
}
+
+TEST_F(FileUtilTest, CreateFullPath)
+{
+ ASSERT_TRUE(!m_directory_path.ends_with('/'));
+ File::CreateDir(m_directory_path);
+
+ // should try to create the directory at m_directory_path, which already exists
+ EXPECT_TRUE(File::IsDirectory(m_directory_path));
+ EXPECT_TRUE(File::CreateFullPath(m_directory_path + "/"));
+
+ // should create the directory (one level)
+ std::string p1 = m_directory_path + "/p1";
+ EXPECT_TRUE(!File::Exists(p1));
+ EXPECT_TRUE(File::CreateFullPath(p1 + "/"));
+ EXPECT_TRUE(File::IsDirectory(p1));
+
+ // should create the directories (multiple levels)
+ std::string p2 = m_directory_path + "/p2";
+ std::string p2a = m_directory_path + "/p2/a";
+ std::string p2b = m_directory_path + "/p2/a/b";
+ std::string p2c = m_directory_path + "/p2/a/b/c";
+ EXPECT_TRUE(!File::Exists(p2));
+ EXPECT_TRUE(!File::Exists(p2a));
+ EXPECT_TRUE(!File::Exists(p2b));
+ EXPECT_TRUE(!File::Exists(p2c));
+ EXPECT_TRUE(File::CreateFullPath(p2c + "/"));
+ EXPECT_TRUE(File::IsDirectory(p2));
+ EXPECT_TRUE(File::IsDirectory(p2a));
+ EXPECT_TRUE(File::IsDirectory(p2b));
+ EXPECT_TRUE(File::IsDirectory(p2c));
+
+ // if the given path ends in a file, the file should be ignored
+ std::string p3 = m_directory_path + "/p3";
+ std::string p3file = m_directory_path + "/p3/test.bin";
+ EXPECT_TRUE(!File::Exists(p3));
+ EXPECT_TRUE(!File::Exists(p3file));
+ EXPECT_TRUE(File::CreateFullPath(p3file));
+ EXPECT_TRUE(File::IsDirectory(p3));
+ EXPECT_TRUE(!File::Exists(p3file));
+
+ // if we try to create a directory where a file already exists, we expect it to fail and leave the
+ // file alone
+ EXPECT_TRUE(File::CreateEmptyFile(p3file));
+ EXPECT_TRUE(File::IsFile(p3file));
+ EXPECT_FALSE(File::CreateFullPath(p3file + "/"));
+ EXPECT_TRUE(File::IsFile(p3file));
+}