summaryrefslogtreecommitdiff
path: root/test/file_test.hh
diff options
context:
space:
mode:
Diffstat (limited to 'test/file_test.hh')
-rw-r--r--test/file_test.hh45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/file_test.hh b/test/file_test.hh
new file mode 100644
index 0000000..af66dfc
--- /dev/null
+++ b/test/file_test.hh
@@ -0,0 +1,45 @@
+#ifndef FILE_TEST_HH
+#define FILE_TEST_HH
+
+#include "unique_fd.hh"
+
+#include <filesystem>
+#include <gtest/gtest.h>
+#include <utility>
+
+class FileTest : public testing::Test {
+public:
+ static unique_fd create_temp_file(std::string const& extension,
+ std::filesystem::path* path);
+
+protected:
+ FileTest();
+ ~FileTest() override;
+
+ void SetUp() override;
+
+ std::filesystem::path const& path() const {
+ return path_;
+ }
+
+ void write(std::string_view content);
+
+ int fd() const {
+ return fd_.get();
+ }
+
+ unique_fd release() {
+ return std::move(fd_);
+ }
+
+ void close();
+
+protected:
+ virtual std::string const& extension();
+
+private:
+ std::filesystem::path path_;
+ unique_fd fd_;
+};
+
+#endif // FILE_TEST_HH