From 65421290bbf0b7a5c76f8bdb09b63ef3166b3368 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Fri, 14 Feb 2025 17:54:31 +0100 Subject: Test TmpFile --- test/utils/cpp/tmp_dir.test.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/utils/cpp/tmp_dir.test.cpp') diff --git a/test/utils/cpp/tmp_dir.test.cpp b/test/utils/cpp/tmp_dir.test.cpp index 0bc4d9d0..d1f89c11 100644 --- a/test/utils/cpp/tmp_dir.test.cpp +++ b/test/utils/cpp/tmp_dir.test.cpp @@ -96,4 +96,29 @@ TEST_CASE("tmp_dir", "[tmp_dir]") { REQUIRE(not FileSystemManager::Exists(child_1)); REQUIRE(not FileSystemManager::Exists(child_2)); } + + SECTION("temp files") { + auto parent_dir = TmpDir::Create(test_tempdir / "test_dir"); + REQUIRE(parent_dir != nullptr); + std::filesystem::path const parent = parent_dir->GetPath(); + + auto file = TmpDir::CreateFile(parent_dir); + REQUIRE(file != nullptr); + std::filesystem::path const file_path = file->GetPath(); + + REQUIRE(FileSystemManager::Exists(parent)); + REQUIRE(FileSystemManager::Exists(file_path)); + + // Kill the parent directory. File still retains a reference to the + // parent object, so parent should remain alive: + parent_dir = nullptr; + REQUIRE(FileSystemManager::Exists(parent)); + REQUIRE(FileSystemManager::Exists(file_path)); + + // Kill the file. Both the parent directory and the file should be + // deleted: + file = nullptr; + REQUIRE(not FileSystemManager::Exists(parent)); + REQUIRE(not FileSystemManager::Exists(file_path)); + } } -- cgit v1.2.3