summaryrefslogtreecommitdiff
path: root/test/file_test.hh
blob: af66dfc9fa6602767208cb0aaeb010c832ecce21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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