test-utils.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. // SPDX-FileCopyrightText: 2019-2023 Ivan Baidakou
  3. #pragma once
  4. #include <catch2/catch_all.hpp>
  5. #include <boost/filesystem.hpp>
  6. #include "model/device.h"
  7. #include "model/diff/cluster_diff.h"
  8. #include "syncspirit-test-export.h"
  9. #if defined(WIN32) || defined(_WIN32) || defined(__WIN32)
  10. #define SYNCSPIRIT_WIN
  11. #endif
  12. namespace syncspirit::test {
  13. namespace bfs = boost::filesystem;
  14. namespace sys = boost::system;
  15. struct SYNCSPIRIT_TEST_API path_guard_t {
  16. bfs::path &path;
  17. path_guard_t(bfs::path &path_) : path{path_} {}
  18. ~path_guard_t() {
  19. if (!getenv("SYNCSPIRIT_TEST_KEEP_PATH")) {
  20. sys::error_code ec;
  21. if (bfs::exists(path, ec)) {
  22. bfs::permissions(path, bfs::perms::owner_all, ec);
  23. if (ec) {
  24. printf("error setting permissions : %s: %s\n", path.string().c_str(), ec.message().c_str());
  25. }
  26. }
  27. bfs::remove_all(path, ec);
  28. if (ec) {
  29. printf("error removing %s : %s\n", path.string().c_str(), ec.message().c_str());
  30. }
  31. }
  32. }
  33. };
  34. SYNCSPIRIT_TEST_API bfs::path locate_path(const char *test_file);
  35. SYNCSPIRIT_TEST_API std::string read_file(const bfs::path &path);
  36. SYNCSPIRIT_TEST_API void write_file(const bfs::path &path, std::string_view content);
  37. SYNCSPIRIT_TEST_API std::string device_id2sha256(std::string_view device_id);
  38. SYNCSPIRIT_TEST_API model::device_ptr_t make_device(std::string_view device_id, std::string_view name = "");
  39. SYNCSPIRIT_TEST_API std::string hash_string(const std::string_view &hash) noexcept;
  40. } // namespace syncspirit::test