Ditto 4.5.3
Loading...
Searching...
No Matches
TestHelpers.hpp
1#include "Ditto.h"
2#include "gtest/gtest.h"
3#include <filesystem.hpp>
4
5#include <algorithm>
6#include <chrono>
7#include <climits>
8#include <functional>
9#include <future>
10#include <random>
11#include <vector>
12
13using random_bytes_engine =
14 std::independent_bits_engine<std::default_random_engine, 16,
15 unsigned short>;
16
17#define ASSERT_RESOLVES(future, timeout) \
18 ASSERT_TRUE(future.wait_for(timeout) == std::future_status::ready) \
19 << "Future timed out";
20
21#define ASSERT_NOT_RESOLVES(future, timeout) \
22 ASSERT_NE(future.wait_for(timeout), std::future_status::ready) \
23 << "Future was resolved";
24
26public:
29 std::string path();
30
31private:
32 std::string ditto_dir;
33};
34
35namespace TestHelpers {
36extern const std::string test_license;
37ditto::Ditto get_unlicensed_ditto(TempPersistenceDir &temp_dir);
38ditto::Ditto get_ditto(TempPersistenceDir &temp_dir);
39std::vector<nlohmann::json>
40map_doc_value(std::vector<ditto::Document> const &documents);
41std::vector<nlohmann::json>
42map_doc_value_without_id(std::vector<ditto::Document> const &documents);
43std::vector<ditto::DocumentId>
44map_doc_id(std::vector<ditto::Document> documents);
45nlohmann::json doc_value_without_id(std::shared_ptr<ditto::Document> document);
46nlohmann::json json_without_id(nlohmann::json j);
47std::string
48get_ditto_repo_directory_from_child(ghc::filesystem::path child_path);
49std::vector<uint8_t> get_random_bytes(uint32_t num_bytes);
50std::string get_random_string(std::size_t length);
51
52template <class T> nlohmann::json register_json(T value) {
53 return nlohmann::json({{"_value", value},
54 {"_ditto_internal_type_jkb12973t4b",
55 DittoCrdtType::DITTO_CRDT_TYPE_REGISTER}});
56}
57
58nlohmann::json counter_json(double value);
59} // namespace TestHelpers
Definition TestHelpers.hpp:25
The entrypoint to the Ditto SDK.
Definition Ditto.hpp:32
Definition filesystem.hpp:222
basic_json<> json
default JSON class
Definition json.hpp:2933