summaryrefslogtreecommitdiff
path: root/test/libapt/file-helpers.h
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2020-05-18 11:55:54 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2020-05-18 15:55:36 +0200
commitc470d92366d7c3c239a689f0a10d6d0d9daafbff (patch)
tree955534f65524c3f81f36119012b6cd995a9619d0 /test/libapt/file-helpers.h
parent37cc8dcda9e97e0b9420d37bb886081fa629847d (diff)
Allow prefix to be a complete filename for GetTempFile
Our testcases had their own implementation of GetTempFile with the feature of a temporary file with a choosen suffix. Merging this into GetTempFile lets us drop this duplicate and hence test more our code rather than testing our helpers for test implementation. And then hashsums_test had another implementationā€¦ and extracttar wasn't even trying to use a real tempfileā€¦ one GetTempFile to rule them all! That also ensures that these tempfiles are created in a temporary directory rather than the current directory which is a nice touch and tries a little harder to clean up those tempfiles.
Diffstat (limited to 'test/libapt/file-helpers.h')
-rw-r--r--test/libapt/file-helpers.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/test/libapt/file-helpers.h b/test/libapt/file-helpers.h
index f639c1cbc..4ce0fb2a3 100644
--- a/test/libapt/file-helpers.h
+++ b/test/libapt/file-helpers.h
@@ -22,8 +22,20 @@ 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);
-#define createTemporaryFile(id, fd, filename, content) \
- ASSERT_NO_FATAL_FAILURE(helperCreateTemporaryFile(id, fd, filename, content))
-void helperCreateTemporaryFile(std::string const &id, FileFd &fd, std::string * const filename, char const * const content);
+
+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