029-diff-generic.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. // SPDX-FileCopyrightText: 2019-2023 Ivan Baidakou
  3. #include "test-utils.h"
  4. #include "access.h"
  5. #include "model/cluster.h"
  6. #include "model/misc/error_code.h"
  7. #include "model/diff/cluster_diff.h"
  8. using namespace syncspirit;
  9. using namespace syncspirit::model;
  10. using namespace syncspirit::proto;
  11. using namespace syncspirit::test;
  12. struct fail_diff_t : diff::cluster_diff_t {
  13. outcome::result<void> apply_impl(cluster_t &) const noexcept override {
  14. auto ec = make_error_code(error_code_t::source_device_not_exists);
  15. return outcome::failure(ec);
  16. }
  17. };
  18. TEST_CASE("generic cluster diff", "[model]") {
  19. auto my_id = device_id_t::from_string("KHQNO2S-5QSILRK-YX4JZZ4-7L77APM-QNVGZJT-EKU7IFI-PNEPBMY-4MXFMQD").value();
  20. auto my_device = device_t::create(my_id, "my-device").value();
  21. auto cluster = cluster_ptr_t(new cluster_t(my_device, 1, 1));
  22. auto diff = diff::cluster_diff_ptr_t(new fail_diff_t());
  23. CHECK(!cluster->is_tainted());
  24. CHECK(!diff->apply(*cluster));
  25. CHECK(cluster->is_tainted());
  26. }