aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/protobuf/json/ut/proto.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/proto.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/protobuf/json/ut/proto.h')
-rw-r--r--library/cpp/protobuf/json/ut/proto.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/library/cpp/protobuf/json/ut/proto.h b/library/cpp/protobuf/json/ut/proto.h
new file mode 100644
index 0000000000..8183bfc8e1
--- /dev/null
+++ b/library/cpp/protobuf/json/ut/proto.h
@@ -0,0 +1,62 @@
+#pragma once
+
+#include <util/generic/hash_set.h>
+#include <util/generic/string.h>
+
+#include <util/system/defaults.h>
+
+namespace NProtobufJsonTest {
+ template <typename TProto>
+ inline void
+ FillFlatProto(TProto* proto,
+ const THashSet<TString>& skippedFields = THashSet<TString>()) {
+#define DEFINE_FIELD(name, value) \
+ if (skippedFields.find(#name) == skippedFields.end()) \
+ proto->Set##name(value);
+#include <library/cpp/protobuf/json/ut/fields.incl>
+#undef DEFINE_FIELD
+ }
+
+ template <typename TRepeatedField, typename TValue>
+ inline void
+ AddValue(TRepeatedField* field, TValue value) {
+ field->Add(value);
+ }
+
+ inline void
+ AddValue(google::protobuf::RepeatedPtrField<TString>* field, const TString& value) {
+ *(field->Add()) = value;
+ }
+
+ inline void
+ FillRepeatedProto(TFlatRepeated* proto,
+ const THashSet<TString>& skippedFields = THashSet<TString>()) {
+#define DEFINE_REPEATED_FIELD(name, type, ...) \
+ if (skippedFields.find(#name) == skippedFields.end()) { \
+ type values[] = {__VA_ARGS__}; \
+ for (size_t i = 0, end = Y_ARRAY_SIZE(values); i < end; ++i) { \
+ AddValue(proto->Mutable##name(), values[i]); \
+ } \
+ }
+#include <library/cpp/protobuf/json/ut/repeated_fields.incl>
+#undef DEFINE_REPEATED_FIELD
+ }
+
+ template <typename TProto>
+ inline void
+ FillCompositeProto(TProto* proto, const THashSet<TString>& skippedFields = THashSet<TString>()) {
+ FillFlatProto(proto->MutablePart(), skippedFields);
+ }
+
+#define UNIT_ASSERT_PROTOS_EQUAL(lhs, rhs) \
+ do { \
+ if (lhs.SerializeAsString() != rhs.SerializeAsString()) { \
+ Cerr << ">>>>>>>>>> lhs != rhs:" << Endl; \
+ Cerr << lhs.DebugString() << Endl; \
+ Cerr << rhs.DebugString() << Endl; \
+ UNIT_ASSERT_STRINGS_EQUAL(lhs.DebugString(), rhs.DebugString()); \
+ UNIT_ASSERT_STRINGS_EQUAL(lhs.SerializeAsString(), rhs.SerializeAsString()); \
+ } \
+ } while (false);
+
+}