summaryrefslogtreecommitdiffstats
path: root/test/libapt/file-helpers.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 06:14:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 06:14:41 +0000
commit549a391d6438e828001eeeaf235b080c054a7bf3 (patch)
tree1bb6b1ea5987fa167a1d13abe82209cc882dd94b /test/libapt/file-helpers.h
parentInitial commit. (diff)
downloadapt-549a391d6438e828001eeeaf235b080c054a7bf3.tar.xz
apt-549a391d6438e828001eeeaf235b080c054a7bf3.zip
Adding upstream version 2.2.4.upstream/2.2.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/libapt/file-helpers.h')
-rw-r--r--test/libapt/file-helpers.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/libapt/file-helpers.h b/test/libapt/file-helpers.h
new file mode 100644
index 0000000..4ce0fb2
--- /dev/null
+++ b/test/libapt/file-helpers.h
@@ -0,0 +1,41 @@
+#ifndef APT_TESTS_FILE_HELPERS
+#define APT_TESTS_FILE_HELPERS
+
+#include <string>
+
+#include <gtest/gtest.h>
+
+class FileFd;
+
+#define createTemporaryDirectory(id, dir) \
+ ASSERT_NO_FATAL_FAILURE(helperCreateTemporaryDirectory(id, dir))
+void helperCreateTemporaryDirectory(std::string const &id, std::string &dir);
+#define removeDirectory(dir) \
+ ASSERT_NO_FATAL_FAILURE(helperRemoveDirectory(dir))
+void helperRemoveDirectory(std::string const &dir);
+#define createFile(dir, name) \
+ ASSERT_NO_FATAL_FAILURE(helperCreateFile(dir, name))
+void helperCreateFile(std::string const &dir, std::string const &name);
+#define createDirectory(dir, name) \
+ ASSERT_NO_FATAL_FAILURE(helperCreateDirectory(dir, name))
+void helperCreateDirectory(std::string const &dir, std::string const &name);
+#define createLink(dir, targetname, linkname) \
+ ASSERT_NO_FATAL_FAILURE(helperCreateLink(dir, targetname, linkname))
+void helperCreateLink(std::string const &dir, std::string const &targetname, std::string const &linkname);
+
+class ScopedFileDeleter {
+ std::string _filename;
+public:
+ ScopedFileDeleter(std::string const &filename);
+ ScopedFileDeleter(ScopedFileDeleter const &) = delete;
+ ScopedFileDeleter(ScopedFileDeleter &&);
+ ScopedFileDeleter& operator=(ScopedFileDeleter const &) = delete;
+ ScopedFileDeleter& operator=(ScopedFileDeleter &&);
+ ~ScopedFileDeleter();
+
+ std::string Name() const { return _filename; }
+};
+void openTemporaryFile(std::string const &id, FileFd &fd, char const * const content = nullptr, bool const ImmediateUnlink = true);
+ScopedFileDeleter createTemporaryFile(std::string const &id, char const * const content = nullptr);
+
+#endif