test-utils.h 792 B

1234567891011121314151617181920212223242526272829
  1. #pragma once
  2. #include <boost/filesystem.hpp>
  3. #include "model/device.h"
  4. namespace syncspirit::test {
  5. namespace bfs = boost::filesystem;
  6. namespace sys = boost::system;
  7. struct path_guard_t {
  8. bfs::path& path;
  9. path_guard_t(bfs::path& path_): path{path_}{}
  10. ~path_guard_t() {
  11. if (!getenv("SYNCSPIRIT_TEST_KEEP_PATH"))
  12. bfs::remove_all(path);
  13. }
  14. };
  15. bfs::path file_path(const char* test_file);
  16. std::string read_file(const char* test_file);
  17. std::string read_file(const bfs::path& path);
  18. void write_file(const bfs::path& path, std::string_view content);
  19. std::string device_id2sha256(std::string_view device_id);
  20. model::device_ptr_t make_device(std::string_view device_id, std::string_view name = "");
  21. std::string hash_string(const std::string_view &hash) noexcept;
  22. }