* Remove travis file * Apply pre-commit fixes * Modernize cmake file - Added JSON_VALIDATOR_SHARED_LIBS to properly handle shared-library - Bumped minimum cmake to 3.11 to use no-source add_library - Bumped minimum cmake to 3.14 to properly support FetchContent (FetchContent_MakeAvailable) - Converted Hunter package manager to FetchContent (It is plenty mature these days) - Added namespace to exported target - Made the cmake file compatible with FetchContent * Use simplified FetchContent CI * Add simple status messages * Handle nlohmann dependency Not an ideal approach, but required in order for the exported target to have appropriate linkage. Maybe this can be designed to become a PRIVATE link library, but then how does it ensure the target is installed? * Remove CMake-install test This will be moved to packaging integration tests * Enable code coverage * Reconfigure ci presets Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
49 lines
1.9 KiB
C++
49 lines
1.9 KiB
C++
#include "../src/json-patch.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
using nlohmann::json_patch;
|
|
|
|
#define OK(code) \
|
|
do { \
|
|
try { \
|
|
code; \
|
|
} catch (const std::exception &e) { \
|
|
std::cerr << "UNEXPECTED FAILED: " << e.what() << "\n"; \
|
|
return 1; \
|
|
} \
|
|
} while (0)
|
|
|
|
#define KO(code) \
|
|
do { \
|
|
try { \
|
|
code; \
|
|
std::cerr << "UNEXPECTED SUCCESS.\n"; \
|
|
return 1; \
|
|
} catch (const std::exception &e) { \
|
|
std::cerr << "EXPECTED FAIL: " << e.what() << "\n"; \
|
|
} \
|
|
} while (0)
|
|
|
|
int main(void)
|
|
{
|
|
OK(json_patch p1(R"([{"op":"add","path":"/0/renderable/bg","value":"Black"}])"_json));
|
|
OK(json_patch p1(R"([{"op":"replace","path":"/0/renderable/bg","value":"Black"}])"_json));
|
|
OK(json_patch p1(R"([{"op":"remove","path":"/0/renderable/bg"}])"_json));
|
|
|
|
// value not needed
|
|
KO(json_patch p1(R"([{"op":"remove","path":"/0/renderable/bg", "value":"Black"}])"_json));
|
|
// value missing
|
|
KO(json_patch p1(R"([{"op":"add","path":"/0/renderable/bg"}])"_json));
|
|
// value missing
|
|
KO(json_patch p1(R"([{"op":"replace","path":"/0/renderable/bg"}])"_json));
|
|
|
|
// wrong op
|
|
KO(json_patch p1(R"([{"op":"ad","path":"/0/renderable/bg","value":"Black"}])"_json));
|
|
|
|
// invalid json-pointer
|
|
KO(json_patch p1(R"([{"op":"add","path":"0/renderable/bg","value":"Black"}])"_json));
|
|
|
|
return 0;
|
|
}
|