diff options
| author | robot-piglet <[email protected]> | 2025-08-08 16:06:37 +0300 |
|---|---|---|
| committer | robot-piglet <[email protected]> | 2025-08-08 16:23:20 +0300 |
| commit | 2d176796ad5d5cc4a93658e9d5c346203b6dcadd (patch) | |
| tree | 1cdfb15922c7facc96c4d10c99f29c8ccb8463ba /library/cpp/protobuf/json/ut/json_ordered.h | |
| parent | a9a64643aae00fd89fca5a63b5bdc4fc1cf5b523 (diff) | |
Intermediate changes
commit_hash:0723a1f77acac11c7a51d04edfadaeb1fe12915d
Diffstat (limited to 'library/cpp/protobuf/json/ut/json_ordered.h')
| -rw-r--r-- | library/cpp/protobuf/json/ut/json_ordered.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/library/cpp/protobuf/json/ut/json_ordered.h b/library/cpp/protobuf/json/ut/json_ordered.h new file mode 100644 index 00000000000..6e656a79bcf --- /dev/null +++ b/library/cpp/protobuf/json/ut/json_ordered.h @@ -0,0 +1,69 @@ +#pragma once + +#include <library/cpp/protobuf/json/ut/test.pb.h> + +#include <library/cpp/json/ordered_maps/json_value_ordered.h> + +#include <cstdarg> + +#include <util/generic/hash_set.h> +#include <util/generic/string.h> + +#include <util/system/defaults.h> + +namespace NProtobufJsonTest { + inline NJson::NOrderedJson::TJsonValue + CreateFlatOrderedJson(const THashSet<TString>& skippedKeys = THashSet<TString>()) { + NJson::NOrderedJson::TJsonValue json; + +#define DEFINE_FIELD(name, value) \ + if (skippedKeys.find(#name) == skippedKeys.end()) \ + json.InsertValue(#name, value); +#include <library/cpp/protobuf/json/ut/fields.incl> +#undef DEFINE_FIELD + + return json; + } + + inline NJson::NOrderedJson::TJsonValue + CreateRepeatedFlatOrderedJson(const THashSet<TString>& skippedKeys = THashSet<TString>()) { + NJson::NOrderedJson::TJsonValue json; + +#define DEFINE_REPEATED_FIELD(name, type, ...) \ + if (skippedKeys.find(#name) == skippedKeys.end()) { \ + type values[] = {__VA_ARGS__}; \ + NJson::NOrderedJson::TJsonValue array(NJson::NOrderedJson::JSON_ARRAY); \ + for (size_t i = 0, end = Y_ARRAY_SIZE(values); i < end; ++i) { \ + array.AppendValue(values[i]); \ + } \ + json.InsertValue(#name, array); \ + } +#include <library/cpp/protobuf/json/ut/repeated_fields.incl> +#undef DEFINE_REPEATED_FIELD + + return json; + } + + inline NJson::NOrderedJson::TJsonValue + CreateCompositeOrderedJson(const THashSet<TString>& skippedKeys = THashSet<TString>()) { + const NJson::NOrderedJson::TJsonValue& part = CreateFlatOrderedJson(skippedKeys); + NJson::NOrderedJson::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::NOrderedJson::TJsonValue _lhs_json, _rhs_json; \ + UNIT_ASSERT(NJson::NOrderedJson::ReadJsonTree(lhs, &_lhs_json)); \ + UNIT_ASSERT(NJson::NOrderedJson::ReadJsonTree(rhs, &_rhs_json)); \ + UNIT_ASSERT_JSONS_EQUAL(_lhs_json, _rhs_json); \ + } + +} |
