8#include <framework/utilities/FileSystem.h>
9#include <framework/utilities/ScopeGuard.h>
11#include <gtest/gtest.h>
20namespace fs = std::filesystem;
23 TEST(Utilities, TemporaryFile)
29 ASSERT_TRUE(temp.is_open());
30 ASSERT_TRUE(fs::exists(filename));
32 ASSERT_FALSE(fs::exists(filename));
47 std::string relname = fs::relative(filename, fs::temp_directory_path()).string();
62 std::string filename = temp.
getName();
66 EXPECT_TRUE(lk.lock(0));
68 if (pid_t pid = fork()) {
72 EXPECT_TRUE(lk.lock(0));
74 waitpid(pid, &status, 0);
75 EXPECT_TRUE(WIFEXITED(status));
76 EXPECT_EQ(0, WEXITSTATUS(status));
Helper class for locking a file.
Helper file to create a temporary file and ensure deletion if object goes out of scope.
std::string getName() const
get filename of the temporary file
Utility functions related to filename validation and filesystem access.
static bool fileDirExists(const std::string &filename)
Check if the dir containing the filename exists.
static bool isDir(const std::string &filename)
Check if filename points to an existing directory.
static bool fileExists(const std::string &filename)
Check if the file with given filename exists.
static ScopeGuard guardWorkingDirectory()
Create a ScopeGuard of the current working directory.
Abstract base class for different kinds of events.