MQTTSuite
Loading...
Searching...
No Matches
json-patch.cpp
Go to the documentation of this file.
1#include "../src/json-patch.hpp"
2
3#include <iostream>
4
5using nlohmann::json_patch;
6
7#define OK(code)
8 do {
9 try {
10 code;
11 } catch (const std::exception &e) {
12 std::cerr << "UNEXPECTED FAILED: " << e.what() << "\n";
13 return 1;
14 }
15 } while (0)
16
17#define KO(code)
18 do {
19 try {
20 code;
21 std::cerr << "UNEXPECTED SUCCESS.\n";
22 return 1;
23 } catch (const std::exception &e) {
24 std::cerr << "EXPECTED FAIL: " << e.what() << "\n";
25 }
26 } while (0)
27
28int main(void)
29{
30 OK(json_patch p1(R"([{"op":"add","path":"/0/renderable/bg","value":"Black"}])"_json));
31 OK(json_patch p1(R"([{"op":"replace","path":"/0/renderable/bg","value":"Black"}])"_json));
32 OK(json_patch p1(R"([{"op":"remove","path":"/0/renderable/bg"}])"_json));
33
34 // value not needed
35 KO(json_patch p1(R"([{"op":"remove","path":"/0/renderable/bg", "value":"Black"}])"_json));
36 // value missing
37 KO(json_patch p1(R"([{"op":"add","path":"/0/renderable/bg"}])"_json));
38 // value missing
39 KO(json_patch p1(R"([{"op":"replace","path":"/0/renderable/bg"}])"_json));
40
41 // wrong op
42 KO(json_patch p1(R"([{"op":"ad","path":"/0/renderable/bg","value":"Black"}])"_json));
43
44 // invalid json-pointer
45 KO(json_patch p1(R"([{"op":"add","path":"0/renderable/bg","value":"Black"}])"_json));
46
47 return 0;
48}
json_patch(json &&patch)
int main()
Definition format.cpp:34
#define KO(code)
#define OK(code)
Definition json-patch.cpp:7