-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_json.cpp
More file actions
69 lines (57 loc) · 2.25 KB
/
test_json.cpp
File metadata and controls
69 lines (57 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "test_settings.hpp"
#ifdef ENABLE_TESTS
#include "../utils_lib/external/doctest.hpp"
#include "../utils_lib/utils_json.hpp"
#include "../utils_lib/utils_string.hpp"
#include "../utils_lib/utils_logger.hpp"
//#define TEST_JSON_LOG_STEPS
TEST_CASE("Test utils::json::to_ubjson") {
UTILS_PROFILE_SCOPE("utils::json::to_ubjson");
utils::json start = R"(
{
"LABELS": {
"YELLOW": {
"DEFAULT": {
"BM_HILLBOOST_ACTIVE__NAK": {
"description": "Bitmask to activate the hillboost functionality. Checks z_bc_hillboost__nak",
"func": "NAK_IO",
"info_param_names": ["Hill Boost"],
"name": "BM_HILLBOOST_ACTIVE__NAK",
"type": 0,
"value": 0,
"value_choices": [["no", 0], ["yes", 16]],
"value_unit": "-"
}
}
}
}
}
)"_json;
REQUIRE(start.size() > 0);
#ifdef TEST_JSON_LOG_STEPS
utils::Logger::Stream(std::setw(4), start, utils::Logger::CRLF,
utils::Logger::LINE<>);
#endif
std::vector<std::uint8_t> bson = utils::json::to_ubjson(start);
std::string bson_str = utils::string::join(bson);
REQUIRE(bson.size() > 0);
#ifdef TEST_JSON_LOG_STEPS
utils::Logger::Stream(bson_str, utils::Logger::CRLF, utils::Logger::LINE<>);
#endif
std::string encoded = utils::string::to_base64(bson.data(), bson.size());
CHECK(utils::string::is_base64(encoded));
#ifdef TEST_JSON_LOG_STEPS
utils::Logger::Stream(encoded, utils::Logger::CRLF, utils::Logger::LINE<>);
#endif
std::string decoded = utils::string::from_base64(encoded);
CHECK(decoded == bson_str);
#ifdef TEST_JSON_LOG_STEPS
utils::Logger::Stream(decoded, utils::Logger::CRLF, utils::Logger::LINE<>);
#endif
auto jsbson = utils::json::from_ubjson(decoded);
CHECK(jsbson == start);
#ifdef TEST_JSON_LOG_STEPS
utils::Logger::Stream(std::setw(4), jsbson, utils::Logger::CRLF, utils::Logger::LINE<>);
#endif
}
#endif