aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/protobuf/json/ut/json.h
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/protobuf/json/ut/json.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/protobuf/json/ut/json.h')
-rw-r--r--library/cpp/protobuf/json/ut/json.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/library/cpp/protobuf/json/ut/json.h b/library/cpp/protobuf/json/ut/json.h
new file mode 100644
index 0000000000..c1f108e6e4
--- /dev/null
+++ b/library/cpp/protobuf/json/ut/json.h
@@ -0,0 +1,69 @@
+#pragma once
+
+#include <library/cpp/protobuf/json/ut/test.pb.h>
+
+#include <library/cpp/json/json_value.h>
+
+#include <cstdarg>
+
+#include <util/generic/hash_set.h>
+#include <util/generic/string.h>
+
+#include <util/system/defaults.h>
+
+namespace NProtobufJsonTest {
+ inline NJson::TJsonValue
+ CreateFlatJson(const THashSet<TString>& skippedKeys = THashSet<TString>()) {
+ NJson::TJsonValue json;
+
+#define DEFINE_FIELD(name, value) \
+ if (skippedKeys.find(#name) == skippedKeys.end()) \
+ json.InsertValue(#name, value);
+#include "fields.incl"
+#undef DEFINE_FIELD
+
+ return json;
+ }
+
+ inline NJson::TJsonValue
+ CreateRepeatedFlatJson(const THashSet<TString>& skippedKeys = THashSet<TString>()) {
+ NJson::TJsonValue json;
+
+#define DEFINE_REPEATED_FIELD(name, type, ...) \
+ if (skippedKeys.find(#name) == skippedKeys.end()) { \
+ type values[] = {__VA_ARGS__}; \
+ NJson::TJsonValue array(NJson::JSON_ARRAY); \
+ for (size_t i = 0, end = Y_ARRAY_SIZE(values); i < end; ++i) { \
+ array.AppendValue(values[i]); \
+ } \
+ json.InsertValue(#name, array); \
+ }
+#include "repeated_fields.incl"
+#undef DEFINE_REPEATED_FIELD
+
+ return json;
+ }
+
+ inline NJson::TJsonValue
+ CreateCompositeJson(const THashSet<TString>& skippedKeys = THashSet<TString>()) {
+ const NJson::TJsonValue& part = CreateFlatJson(skippedKeys);
+ NJson::TJsonValue json;
+ json.InsertValue("Part", part);
+
+ return json;
+ }
+
+#define UNIT_ASSERT_JSONS_EQUAL(lhs, rhs) \
+ if (lhs != rhs) { \
+ UNIT_ASSERT_STRINGS_EQUAL(lhs.GetStringRobust(), rhs.GetStringRobust()); \
+ }
+
+#define UNIT_ASSERT_JSON_STRINGS_EQUAL(lhs, rhs) \
+ if (lhs != rhs) { \
+ NJson::TJsonValue _lhs_json, _rhs_json; \
+ UNIT_ASSERT(NJson::ReadJsonTree(lhs, &_lhs_json)); \
+ UNIT_ASSERT(NJson::ReadJsonTree(rhs, &_rhs_json)); \
+ UNIT_ASSERT_JSONS_EQUAL(_lhs_json, _rhs_json); \
+ }
+
+}