summaryrefslogtreecommitdiff
path: root/test/utils/cpp/tmp_dir.test.cpp
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2025-02-14 17:33:21 +0100
committerMaksim Denisov <denisov.maksim@huawei.com>2025-03-24 09:25:05 +0100
commit032f811496b5b4bf5762fe3310a0534e289ef9fb (patch)
tree49d8af60e86d3f641483c7e2d65eebab822c92eb /test/utils/cpp/tmp_dir.test.cpp
parent91f648dbcf9e6e5638a16dc8aee85e8236ad53d4 (diff)
downloadjustbuild-032f811496b5b4bf5762fe3310a0534e289ef9fb.tar.gz
Test nested TmpDir
Diffstat (limited to 'test/utils/cpp/tmp_dir.test.cpp')
-rw-r--r--test/utils/cpp/tmp_dir.test.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/utils/cpp/tmp_dir.test.cpp b/test/utils/cpp/tmp_dir.test.cpp
index c8754bb3..0bc4d9d0 100644
--- a/test/utils/cpp/tmp_dir.test.cpp
+++ b/test/utils/cpp/tmp_dir.test.cpp
@@ -57,4 +57,43 @@ TEST_CASE("tmp_dir", "[tmp_dir]") {
}
REQUIRE(not FileSystemManager::Exists(temp_dir_path_2));
}
+
+ SECTION("nested directories") {
+ auto parent_dir = TmpDir::Create(test_tempdir / "test_dir");
+ REQUIRE(parent_dir != nullptr);
+ std::filesystem::path const parent = parent_dir->GetPath();
+
+ auto child_dir_1 = TmpDir::CreateNestedDirectory(parent_dir);
+ REQUIRE(child_dir_1);
+ std::filesystem::path const child_1 = child_dir_1->GetPath();
+
+ auto child_dir_2 = TmpDir::CreateNestedDirectory(parent_dir);
+ REQUIRE(child_dir_2);
+ std::filesystem::path const child_2 = child_dir_2->GetPath();
+
+ REQUIRE(FileSystemManager::Exists(parent));
+ REQUIRE(FileSystemManager::Exists(child_1));
+ REQUIRE(FileSystemManager::Exists(child_2));
+
+ // Kill the parent directory. child_1 and child_2 still retain
+ // references to the parent object, so all folders should remain alive:
+ parent_dir = nullptr;
+ REQUIRE(FileSystemManager::Exists(parent));
+ REQUIRE(FileSystemManager::Exists(child_1));
+ REQUIRE(FileSystemManager::Exists(child_2));
+
+ // Kill child_1. child_1 dies, but child_2 retains a reference to the
+ // parent directory, so parent and child_2 must be alive:
+ child_dir_1 = nullptr;
+ REQUIRE(FileSystemManager::Exists(parent));
+ REQUIRE(not FileSystemManager::Exists(child_1));
+ REQUIRE(FileSystemManager::Exists(child_2));
+
+ // Kill child_2. All directories should be destroyed:
+ child_dir_2 = nullptr;
+
+ REQUIRE(not FileSystemManager::Exists(parent));
+ REQUIRE(not FileSystemManager::Exists(child_1));
+ REQUIRE(not FileSystemManager::Exists(child_2));
+ }
}