diff options
author | yazevnul <yazevnul@yandex-team.ru> | 2022-02-10 16:46:48 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:48 +0300 |
commit | 9abfb1a53b7f7b791444d1378e645d8fad9b06ed (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /library/cpp/protobuf | |
parent | 8cbc307de0221f84c80c42dcbe07d40727537e2c (diff) | |
download | ydb-9abfb1a53b7f7b791444d1378e645d8fad9b06ed.tar.gz |
Restoring authorship annotation for <yazevnul@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/protobuf')
23 files changed, 593 insertions, 593 deletions
diff --git a/library/cpp/protobuf/json/json2proto.cpp b/library/cpp/protobuf/json/json2proto.cpp index b70c39d3b5..640c10f5a5 100644 --- a/library/cpp/protobuf/json/json2proto.cpp +++ b/library/cpp/protobuf/json/json2proto.cpp @@ -72,7 +72,7 @@ static TString GetFieldName(const google::protobuf::FieldDescriptor& field, NProtobufJson::ToSnakeCaseDense(&name); break; default: - Y_VERIFY_DEBUG(false, "Unknown FieldNameMode."); + Y_VERIFY_DEBUG(false, "Unknown FieldNameMode."); } return name; } @@ -85,7 +85,7 @@ JsonString2Field(const NJson::TJsonValue& json, using namespace google::protobuf; const Reflection* reflection = proto.GetReflection(); - Y_ASSERT(!!reflection); + Y_ASSERT(!!reflection); if (!json.IsString() && !config.CastRobust) { ythrow yexception() << "Invalid type of JSON field '" << field.name() << "': " @@ -94,7 +94,7 @@ JsonString2Field(const NJson::TJsonValue& json, } TString value = json.GetStringRobust(); for (size_t i = 0, endI = config.StringTransforms.size(); i < endI; ++i) { - Y_ASSERT(!!config.StringTransforms[i]); + Y_ASSERT(!!config.StringTransforms[i]); if (!!config.StringTransforms[i]) { if (field.type() == google::protobuf::FieldDescriptor::TYPE_BYTES) { config.StringTransforms[i]->TransformBytes(value); @@ -130,10 +130,10 @@ JsonEnum2Field(const NJson::TJsonValue& json, using namespace google::protobuf; const Reflection* reflection = proto.GetReflection(); - Y_ASSERT(!!reflection); + Y_ASSERT(!!reflection); const EnumDescriptor* enumField = field.enum_type(); - Y_ASSERT(!!enumField); + Y_ASSERT(!!enumField); /// @todo configure name/numerical value const EnumValueDescriptor* enumFieldValue = nullptr; @@ -343,7 +343,7 @@ Json2RepeatedField(const NJson::TJsonValue& json, } const Reflection* reflection = proto.GetReflection(); - Y_ASSERT(!!reflection); + Y_ASSERT(!!reflection); if (isMap) { const THashMap<TString, NJson::TJsonValue> jsonMap = fieldJson.GetMap(); diff --git a/library/cpp/protobuf/json/json_output_create.h b/library/cpp/protobuf/json/json_output_create.h index 42005bad28..ad3889f5e9 100644 --- a/library/cpp/protobuf/json/json_output_create.h +++ b/library/cpp/protobuf/json/json_output_create.h @@ -9,7 +9,7 @@ namespace NJson { struct TJsonWriterConfig; } -class IOutputStream; +class IOutputStream; class TStringStream; namespace NProtobufJson { diff --git a/library/cpp/protobuf/json/proto2json.h b/library/cpp/protobuf/json/proto2json.h index 2f7277be08..89a1781a40 100644 --- a/library/cpp/protobuf/json/proto2json.h +++ b/library/cpp/protobuf/json/proto2json.h @@ -19,7 +19,7 @@ namespace NJson { class TJsonWriter; } -class IOutputStream; +class IOutputStream; class TStringStream; namespace NProtobufJson { diff --git a/library/cpp/protobuf/json/ut/filter_ut.cpp b/library/cpp/protobuf/json/ut/filter_ut.cpp index daa2d98af4..95c227666f 100644 --- a/library/cpp/protobuf/json/ut/filter_ut.cpp +++ b/library/cpp/protobuf/json/ut/filter_ut.cpp @@ -19,8 +19,8 @@ static NProtobufJsonUt::TFilterTest GetTestMsg() { return msg; } -Y_UNIT_TEST_SUITE(TProto2JsonFilterTest){ - Y_UNIT_TEST(TestFilterPrinter){ +Y_UNIT_TEST_SUITE(TProto2JsonFilterTest){ + Y_UNIT_TEST(TestFilterPrinter){ NProtobufJsonUt::TFilterTest msg = GetTestMsg(); { TString expected = R"({"OptFiltered":"1","NotFiltered":"23","RepFiltered":[45,67],)" @@ -61,7 +61,7 @@ Y_UNIT_TEST_SUITE(TProto2JsonFilterTest){ } } -Y_UNIT_TEST(NoUnnecessaryCopyFunctor) { +Y_UNIT_TEST(NoUnnecessaryCopyFunctor) { size_t CopyCount = 0; struct TFunctorMock { TFunctorMock(size_t* copyCount) diff --git a/library/cpp/protobuf/json/ut/inline_ut.cpp b/library/cpp/protobuf/json/ut/inline_ut.cpp index 548b6c2960..c29ad32e7d 100644 --- a/library/cpp/protobuf/json/ut/inline_ut.cpp +++ b/library/cpp/protobuf/json/ut/inline_ut.cpp @@ -21,8 +21,8 @@ static NProtobufJsonUt::TInlineTest GetTestMsg() { return msg; } -Y_UNIT_TEST_SUITE(TProto2JsonInlineTest){ - Y_UNIT_TEST(TestNormalPrint){ +Y_UNIT_TEST_SUITE(TProto2JsonInlineTest){ + Y_UNIT_TEST(TestNormalPrint){ NProtobufJsonUt::TInlineTest msg = GetTestMsg(); // normal print should output these fields as just string values TString expRaw = R"({"OptJson":"{\"a\":1,\"b\":\"000\"}","NotJson":"12{}34","RepJson":["{}","[1,2]"],)" @@ -35,7 +35,7 @@ myRaw = PrintInlined(msg, [](const NProtoBuf::Message&, const NProtoBuf::FieldDe UNIT_ASSERT_STRINGS_EQUAL(myRaw, expRaw); // result is the same } -Y_UNIT_TEST(TestInliningPrinter) { +Y_UNIT_TEST(TestInliningPrinter) { NProtobufJsonUt::TInlineTest msg = GetTestMsg(); // inlined print should output these fields as inlined json sub-objects TString expInlined = R"({"OptJson":{"a":1,"b":"000"},"NotJson":"12{}34","RepJson":[{},[1,2]],)" @@ -54,7 +54,7 @@ Y_UNIT_TEST(TestInliningPrinter) { } } -Y_UNIT_TEST(TestNoValues) { +Y_UNIT_TEST(TestNoValues) { // no values - no printing NProtobufJsonUt::TInlineTest msg; msg.MutableInner()->AddNumber(100); @@ -66,7 +66,7 @@ Y_UNIT_TEST(TestNoValues) { UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined); } -Y_UNIT_TEST(TestMissingKeyModeNull) { +Y_UNIT_TEST(TestMissingKeyModeNull) { NProtobufJsonUt::TInlineTest msg; msg.MutableInner()->AddNumber(100); msg.MutableInner()->AddNumber(200); @@ -79,7 +79,7 @@ Y_UNIT_TEST(TestMissingKeyModeNull) { UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined); } -Y_UNIT_TEST(TestMissingKeyModeDefault) { +Y_UNIT_TEST(TestMissingKeyModeDefault) { NProtobufJsonUt::TInlineTestDefaultValues msg; TString expInlined = R"({"OptJson":{"default":1},"Number":0,"RepJson":[],"Inner":{"OptJson":{"default":2}}})"; @@ -90,7 +90,7 @@ Y_UNIT_TEST(TestMissingKeyModeDefault) { UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined); } -Y_UNIT_TEST(NoUnnecessaryCopyFunctor) { +Y_UNIT_TEST(NoUnnecessaryCopyFunctor) { size_t CopyCount = 0; struct TFunctorMock { TFunctorMock(size_t* copyCount) diff --git a/library/cpp/protobuf/json/ut/json2proto_ut.cpp b/library/cpp/protobuf/json/ut/json2proto_ut.cpp index 271db47dc4..0dfe57bc7a 100644 --- a/library/cpp/protobuf/json/ut/json2proto_ut.cpp +++ b/library/cpp/protobuf/json/ut/json2proto_ut.cpp @@ -70,8 +70,8 @@ namespace { } } -Y_UNIT_TEST_SUITE(TJson2ProtoTest) { - Y_UNIT_TEST(TestFlatOptional){ +Y_UNIT_TEST_SUITE(TJson2ProtoTest) { + Y_UNIT_TEST(TestFlatOptional){ {const NJson::TJsonValue& json = CreateFlatJson(); TFlatOptional proto; Json2Proto(json, proto); @@ -96,7 +96,7 @@ Y_UNIT_TEST_SUITE(TJson2ProtoTest) { #undef DEFINE_FIELD } // TestFlatOptional -Y_UNIT_TEST(TestFlatRequired){ +Y_UNIT_TEST(TestFlatRequired){ {const NJson::TJsonValue& json = CreateFlatJson(); TFlatRequired proto; Json2Proto(json, proto); @@ -118,7 +118,7 @@ UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); #undef DEFINE_FIELD } // TestFlatRequired -Y_UNIT_TEST(TestNameGenerator) { +Y_UNIT_TEST(TestNameGenerator) { TJson2ProtoConfig cfg; cfg.SetNameGenerator([](const NProtoBuf::FieldDescriptor&) { return "42"; }); @@ -131,7 +131,7 @@ Y_UNIT_TEST(TestNameGenerator) { UNIT_ASSERT_PROTOS_EQUAL(expected, proto); } -Y_UNIT_TEST(TestFlatNoCheckRequired) { +Y_UNIT_TEST(TestFlatNoCheckRequired) { { const NJson::TJsonValue& json = CreateFlatJson(); TFlatRequired proto; @@ -157,7 +157,7 @@ Y_UNIT_TEST(TestFlatNoCheckRequired) { #undef DEFINE_FIELD } // TestFlatNoCheckRequired -Y_UNIT_TEST(TestFlatRepeated){ +Y_UNIT_TEST(TestFlatRepeated){ {const NJson::TJsonValue& json = CreateRepeatedFlatJson(); TFlatRepeated proto; Json2Proto(json, proto); @@ -182,7 +182,7 @@ UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); #undef DEFINE_REPEATED_FIELD } // TestFlatRepeated -Y_UNIT_TEST(TestCompositeOptional){ +Y_UNIT_TEST(TestCompositeOptional){ {const NJson::TJsonValue& json = CreateCompositeJson(); TCompositeOptional proto; Json2Proto(json, proto); @@ -207,7 +207,7 @@ UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); #undef DEFINE_FIELD } // TestCompositeOptional -Y_UNIT_TEST(TestCompositeOptionalStringBuf){ +Y_UNIT_TEST(TestCompositeOptionalStringBuf){ {NJson::TJsonValue json = CreateCompositeJson(); json["Part"]["Double"] = 42.5; TCompositeOptional proto; @@ -240,7 +240,7 @@ UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); #undef DEFINE_FIELD } // TestCompositeOptionalStringBuf -Y_UNIT_TEST(TestCompositeRequired) { +Y_UNIT_TEST(TestCompositeRequired) { { const NJson::TJsonValue& json = CreateCompositeJson(); TCompositeRequired proto; @@ -257,7 +257,7 @@ Y_UNIT_TEST(TestCompositeRequired) { } } // TestCompositeRequired -Y_UNIT_TEST(TestCompositeRepeated) { +Y_UNIT_TEST(TestCompositeRepeated) { { NJson::TJsonValue json; NJson::TJsonValue array; @@ -302,7 +302,7 @@ Y_UNIT_TEST(TestCompositeRepeated) { } } // TestCompositeRepeated -Y_UNIT_TEST(TestInvalidEnum) { +Y_UNIT_TEST(TestInvalidEnum) { { NJson::TJsonValue json; json.InsertValue("Enum", "E_100"); @@ -318,7 +318,7 @@ Y_UNIT_TEST(TestInvalidEnum) { } } -Y_UNIT_TEST(TestFieldNameMode) { +Y_UNIT_TEST(TestFieldNameMode) { // Original case 1 { TString modelStr(R"_({"String":"value"})_"); @@ -514,7 +514,7 @@ public: } }; -Y_UNIT_TEST(TestInvalidJson) { +Y_UNIT_TEST(TestInvalidJson) { NJson::TJsonValue val{"bad value"}; TFlatOptional proto; UNIT_ASSERT_EXCEPTION(Json2Proto(val, proto), yexception); @@ -527,7 +527,7 @@ Y_UNIT_TEST(TestInvalidRepeatedFieldWithMapAsObject) { UNIT_ASSERT_EXCEPTION(Json2Proto(TStringBuf(R"({"Part":{"Boo":{}}})"), proto, config), yexception); } -Y_UNIT_TEST(TestStringTransforms) { +Y_UNIT_TEST(TestStringTransforms) { // Check that strings and bytes are transformed { TString modelStr(R"_({"String":"value_str", "Bytes": "value_bytes"})_"); @@ -585,7 +585,7 @@ Y_UNIT_TEST(TestStringTransforms) { } } // TestStringTransforms -Y_UNIT_TEST(TestCastFromString) { +Y_UNIT_TEST(TestCastFromString) { // single fields { NJson::TJsonValue json; @@ -634,7 +634,7 @@ Y_UNIT_TEST(TestCastFromString) { } } // TestCastFromString -Y_UNIT_TEST(TestMap) { +Y_UNIT_TEST(TestMap) { TMapType modelProto; auto& items = *modelProto.MutableItems(); @@ -651,7 +651,7 @@ Y_UNIT_TEST(TestMap) { UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); } // TestMap -Y_UNIT_TEST(TestCastRobust) { +Y_UNIT_TEST(TestCastRobust) { NJson::TJsonValue json; json["I32"] = "5"; json["Bool"] = 1; @@ -741,7 +741,7 @@ Y_UNIT_TEST(TestValueVectorizer) { } } -Y_UNIT_TEST(TestMapAsObject) { +Y_UNIT_TEST(TestMapAsObject) { TMapType modelProto; auto& items = *modelProto.MutableItems(); @@ -759,7 +759,7 @@ Y_UNIT_TEST(TestMapAsObject) { UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); } // TestMapAsObject -Y_UNIT_TEST(TestComplexMapAsObject_I32) { +Y_UNIT_TEST(TestComplexMapAsObject_I32) { TestComplexMapAsObject( [](TComplexMapType& proto) { auto& items = *proto.MutableI32(); @@ -770,7 +770,7 @@ Y_UNIT_TEST(TestComplexMapAsObject_I32) { R"_({"I32":{"1":1,"-2":-2,"3":3}})_"); } // TestComplexMapAsObject_I32 -Y_UNIT_TEST(TestComplexMapAsObject_I64) { +Y_UNIT_TEST(TestComplexMapAsObject_I64) { TestComplexMapAsObject( [](TComplexMapType& proto) { auto& items = *proto.MutableI64(); @@ -781,7 +781,7 @@ Y_UNIT_TEST(TestComplexMapAsObject_I64) { R"_({"I64":{"2147483649":2147483649,"-2147483650":-2147483650,"2147483651":2147483651}})_"); } // TestComplexMapAsObject_I64 -Y_UNIT_TEST(TestComplexMapAsObject_UI32) { +Y_UNIT_TEST(TestComplexMapAsObject_UI32) { TestComplexMapAsObject( [](TComplexMapType& proto) { auto& items = *proto.MutableUI32(); @@ -792,7 +792,7 @@ Y_UNIT_TEST(TestComplexMapAsObject_UI32) { R"_({"UI32":{"1073741825":1073741825,"1073741826":1073741826,"1073741827":1073741827}})_"); } // TestComplexMapAsObject_UI32 -Y_UNIT_TEST(TestComplexMapAsObject_UI64) { +Y_UNIT_TEST(TestComplexMapAsObject_UI64) { TestComplexMapAsObject( [](TComplexMapType& proto) { auto& items = *proto.MutableUI64(); @@ -803,7 +803,7 @@ Y_UNIT_TEST(TestComplexMapAsObject_UI64) { R"_({"UI64":{"9223372036854775809":9223372036854775809,"9223372036854775810":9223372036854775810,"9223372036854775811":9223372036854775811}})_"); } // TestComplexMapAsObject_UI64 -Y_UNIT_TEST(TestComplexMapAsObject_SI32) { +Y_UNIT_TEST(TestComplexMapAsObject_SI32) { TestComplexMapAsObject( [](TComplexMapType& proto) { auto& items = *proto.MutableSI32(); @@ -814,7 +814,7 @@ Y_UNIT_TEST(TestComplexMapAsObject_SI32) { R"_({"SI32":{"1":1,"-2":-2,"3":3}})_"); } // TestComplexMapAsObject_SI32 -Y_UNIT_TEST(TestComplexMapAsObject_SI64) { +Y_UNIT_TEST(TestComplexMapAsObject_SI64) { TestComplexMapAsObject( [](TComplexMapType& proto) { auto& items = *proto.MutableSI64(); @@ -825,7 +825,7 @@ Y_UNIT_TEST(TestComplexMapAsObject_SI64) { R"_({"SI64":{"2147483649":2147483649,"-2147483650":-2147483650,"2147483651":2147483651}})_"); } // TestComplexMapAsObject_SI64 -Y_UNIT_TEST(TestComplexMapAsObject_FI32) { +Y_UNIT_TEST(TestComplexMapAsObject_FI32) { TestComplexMapAsObject( [](TComplexMapType& proto) { auto& items = *proto.MutableFI32(); @@ -836,7 +836,7 @@ Y_UNIT_TEST(TestComplexMapAsObject_FI32) { R"_({"FI32":{"1073741825":1073741825,"1073741826":1073741826,"1073741827":1073741827}})_"); } // TestComplexMapAsObject_FI32 -Y_UNIT_TEST(TestComplexMapAsObject_FI64) { +Y_UNIT_TEST(TestComplexMapAsObject_FI64) { TestComplexMapAsObject( [](TComplexMapType& proto) { auto& items = *proto.MutableFI64(); @@ -847,7 +847,7 @@ Y_UNIT_TEST(TestComplexMapAsObject_FI64) { R"_({"FI64":{"9223372036854775809":9223372036854775809,"9223372036854775810":9223372036854775810,"9223372036854775811":9223372036854775811}})_"); } // TestComplexMapAsObject_FI64 -Y_UNIT_TEST(TestComplexMapAsObject_SFI32) { +Y_UNIT_TEST(TestComplexMapAsObject_SFI32) { TestComplexMapAsObject( [](TComplexMapType& proto) { auto& items = *proto.MutableSFI32(); @@ -858,7 +858,7 @@ Y_UNIT_TEST(TestComplexMapAsObject_SFI32) { R"_({"SFI32":{"1":1,"-2":-2,"3":3}})_"); } // TestComplexMapAsObject_SFI32 -Y_UNIT_TEST(TestComplexMapAsObject_SFI64) { +Y_UNIT_TEST(TestComplexMapAsObject_SFI64) { TestComplexMapAsObject( [](TComplexMapType& proto) { auto& items = *proto.MutableSFI64(); @@ -869,7 +869,7 @@ Y_UNIT_TEST(TestComplexMapAsObject_SFI64) { R"_({"SFI64":{"2147483649":2147483649,"-2147483650":-2147483650,"2147483651":2147483651}})_"); } // TestComplexMapAsObject_SFI64 -Y_UNIT_TEST(TestComplexMapAsObject_Bool) { +Y_UNIT_TEST(TestComplexMapAsObject_Bool) { TestComplexMapAsObject( [](TComplexMapType& proto) { auto& items = *proto.MutableBool(); @@ -879,7 +879,7 @@ Y_UNIT_TEST(TestComplexMapAsObject_Bool) { R"_({"Bool":{"true":true,"false":false}})_"); } // TestComplexMapAsObject_Bool -Y_UNIT_TEST(TestComplexMapAsObject_String) { +Y_UNIT_TEST(TestComplexMapAsObject_String) { TestComplexMapAsObject( [](TComplexMapType& proto) { auto& items = *proto.MutableString(); @@ -891,7 +891,7 @@ Y_UNIT_TEST(TestComplexMapAsObject_String) { R"_({"String":{"key1":"value1","key2":"value2","key3":"value3","":"value4"}})_"); } // TestComplexMapAsObject_String -Y_UNIT_TEST(TestComplexMapAsObject_Enum) { +Y_UNIT_TEST(TestComplexMapAsObject_Enum) { TestComplexMapAsObject( [](TComplexMapType& proto) { auto& items = *proto.MutableEnum(); @@ -943,7 +943,7 @@ Y_UNIT_TEST(TestComplexMapAsObject_EnumStringSnakeCaseInsensitive) { ); } // TestComplexMapAsObject_EnumStringCaseInsensetive -Y_UNIT_TEST(TestComplexMapAsObject_Float) { +Y_UNIT_TEST(TestComplexMapAsObject_Float) { TestComplexMapAsObject( [](TComplexMapType& proto) { auto& items = *proto.MutableFloat(); @@ -954,7 +954,7 @@ Y_UNIT_TEST(TestComplexMapAsObject_Float) { R"_({"Float":{"key1":0.1,"key2":0.2,"key3":0.3}})_"); } // TestComplexMapAsObject_Float -Y_UNIT_TEST(TestComplexMapAsObject_Double) { +Y_UNIT_TEST(TestComplexMapAsObject_Double) { TestComplexMapAsObject( [](TComplexMapType& proto) { auto& items = *proto.MutableDouble(); @@ -965,7 +965,7 @@ Y_UNIT_TEST(TestComplexMapAsObject_Double) { R"_({"Double":{"key1":0.1,"key2":0.2,"key3":0.3}})_"); } // TestComplexMapAsObject_Double -Y_UNIT_TEST(TestComplexMapAsObject_Nested) { +Y_UNIT_TEST(TestComplexMapAsObject_Nested) { TestComplexMapAsObject( [](TComplexMapType& proto) { TComplexMapType inner; @@ -979,7 +979,7 @@ Y_UNIT_TEST(TestComplexMapAsObject_Nested) { R"_({"Nested":{"key1":{"String":{"key":"value"}},"key2":{"String":{"key":"value"}},"key3":{"String":{"key":"value"}}}})_"); } // TestComplexMapAsObject_Nested -Y_UNIT_TEST(TestMapAsObjectConfigNotSet) { +Y_UNIT_TEST(TestMapAsObjectConfigNotSet) { TString modelStr(R"_({"Items":{"key":"value"}})_"); TJson2ProtoConfig config; diff --git a/library/cpp/protobuf/json/ut/proto2json_ut.cpp b/library/cpp/protobuf/json/ut/proto2json_ut.cpp index 0a56cc2a8c..07e52d7f2f 100644 --- a/library/cpp/protobuf/json/ut/proto2json_ut.cpp +++ b/library/cpp/protobuf/json/ut/proto2json_ut.cpp @@ -25,8 +25,8 @@ using namespace NProtobufJson; using namespace NProtobufJsonTest; -Y_UNIT_TEST_SUITE(TProto2JsonFlatTest) { - Y_UNIT_TEST(TestFlatDefault) { +Y_UNIT_TEST_SUITE(TProto2JsonFlatTest) { + Y_UNIT_TEST(TestFlatDefault) { using namespace ::google::protobuf; TFlatDefault proto; NJson::TJsonValue json; @@ -74,7 +74,7 @@ Y_UNIT_TEST_SUITE(TProto2JsonFlatTest) { #undef DEFINE_FIELD } - Y_UNIT_TEST(TestNameGenerator) { + Y_UNIT_TEST(TestNameGenerator) { TNameGeneratorType proto; proto.SetField(42); @@ -87,7 +87,7 @@ Y_UNIT_TEST_SUITE(TProto2JsonFlatTest) { UNIT_ASSERT_STRINGS_EQUAL(R"({"42":42})", str.Str()); } - Y_UNIT_TEST(TestEnumValueGenerator) { + Y_UNIT_TEST(TestEnumValueGenerator) { TEnumValueGeneratorType proto; proto.SetEnum(TEnumValueGeneratorType::ENUM_42); @@ -100,7 +100,7 @@ Y_UNIT_TEST_SUITE(TProto2JsonFlatTest) { UNIT_ASSERT_STRINGS_EQUAL(R"({"Enum":"42"})", str.Str()); } - Y_UNIT_TEST(TestFlatOptional){ + Y_UNIT_TEST(TestFlatOptional){ {TFlatOptional proto; FillFlatProto(&proto); const NJson::TJsonValue& modelJson = CreateFlatJson(); @@ -141,7 +141,7 @@ Y_UNIT_TEST_SUITE(TProto2JsonFlatTest) { #undef DEFINE_FIELD } // TestFlatOptional -Y_UNIT_TEST(TestFlatRequired){ +Y_UNIT_TEST(TestFlatRequired){ {TFlatRequired proto; FillFlatProto(&proto); const NJson::TJsonValue& modelJson = CreateFlatJson(); @@ -182,7 +182,7 @@ const NJson::TJsonValue& modelJson = CreateFlatJson(); #undef DEFINE_FIELD } // TestFlatRequired -Y_UNIT_TEST(TestFlatRepeated) { +Y_UNIT_TEST(TestFlatRepeated) { { TFlatRepeated proto; FillRepeatedProto(&proto); @@ -227,7 +227,7 @@ Y_UNIT_TEST(TestFlatRepeated) { #undef DEFINE_REPEATED_FIELD } // TestFlatRepeated -Y_UNIT_TEST(TestCompositeOptional){ +Y_UNIT_TEST(TestCompositeOptional){ {TCompositeOptional proto; FillCompositeProto(&proto); const NJson::TJsonValue& modelJson = CreateCompositeJson(); @@ -268,7 +268,7 @@ const NJson::TJsonValue& modelJson = CreateCompositeJson(); #undef DEFINE_FIELD } // TestCompositeOptional -Y_UNIT_TEST(TestCompositeRequired){ +Y_UNIT_TEST(TestCompositeRequired){ {TCompositeRequired proto; FillCompositeProto(&proto); const NJson::TJsonValue& modelJson = CreateCompositeJson(); @@ -309,7 +309,7 @@ const NJson::TJsonValue& modelJson = CreateCompositeJson(); #undef DEFINE_FIELD } // TestCompositeRequired -Y_UNIT_TEST(TestCompositeRepeated) { +Y_UNIT_TEST(TestCompositeRepeated) { { TFlatOptional partProto; FillFlatProto(&partProto); @@ -371,7 +371,7 @@ Y_UNIT_TEST(TestCompositeRepeated) { } } // TestCompositeRepeated -Y_UNIT_TEST(TestEnumConfig) { +Y_UNIT_TEST(TestEnumConfig) { { TFlatOptional proto; proto.SetEnum(E_1); @@ -438,7 +438,7 @@ Y_UNIT_TEST(TestEnumConfig) { } } // TestEnumConfig -Y_UNIT_TEST(TestMissingSingleKeyConfig) { +Y_UNIT_TEST(TestMissingSingleKeyConfig) { { TFlatOptional proto; NJson::TJsonValue modelJson(NJson::JSON_MAP); @@ -513,7 +513,7 @@ Y_UNIT_TEST(TestMissingSingleKeyConfig) { } } // TestMissingSingleKeyConfig -Y_UNIT_TEST(TestMissingRepeatedKeyNoConfig) { +Y_UNIT_TEST(TestMissingRepeatedKeyNoConfig) { { TFlatRepeated proto; NJson::TJsonValue modelJson(NJson::JSON_MAP); @@ -524,7 +524,7 @@ Y_UNIT_TEST(TestMissingRepeatedKeyNoConfig) { } } // TestMissingRepeatedKeyNoConfig -Y_UNIT_TEST(TestMissingRepeatedKeyConfig) { +Y_UNIT_TEST(TestMissingRepeatedKeyConfig) { { TFlatRepeated proto; NJson::TJsonValue modelJson(NJson::JSON_MAP); @@ -564,7 +564,7 @@ Y_UNIT_TEST(TestMissingRepeatedKeyConfig) { } } // TestMissingRepeatedKeyConfig -Y_UNIT_TEST(TestEscaping) { +Y_UNIT_TEST(TestEscaping) { // No escape { TString modelStr(R"_({"String":"value\""})_"); @@ -632,7 +632,7 @@ public: } }; -Y_UNIT_TEST(TestBytesTransform) { +Y_UNIT_TEST(TestBytesTransform) { // Test that string field is not changed { TString modelStr(R"_({"String":"value"})_"); @@ -662,7 +662,7 @@ Y_UNIT_TEST(TestBytesTransform) { } } -Y_UNIT_TEST(TestFieldNameMode) { +Y_UNIT_TEST(TestFieldNameMode) { // Original case 1 { TString modelStr(R"_({"String":"value"})_"); @@ -888,21 +888,21 @@ Y_UNIT_TEST(TestFieldNameMode) { /// TODO: test missing keys } // TestFieldNameMode -Y_UNIT_TEST(TestNan) { +Y_UNIT_TEST(TestNan) { TFlatOptional proto; proto.SetDouble(std::numeric_limits<double>::quiet_NaN()); UNIT_ASSERT_EXCEPTION(Proto2Json(proto, TProto2JsonConfig()), yexception); } // TestNan -Y_UNIT_TEST(TestInf) { +Y_UNIT_TEST(TestInf) { TFlatOptional proto; proto.SetFloat(std::numeric_limits<float>::infinity()); UNIT_ASSERT_EXCEPTION(Proto2Json(proto, TProto2JsonConfig()), yexception); } // TestInf -Y_UNIT_TEST(TestMap) { +Y_UNIT_TEST(TestMap) { TMapType proto; auto& items = *proto.MutableItems(); @@ -931,7 +931,7 @@ Y_UNIT_TEST(TestMap) { UNIT_ASSERT_EQUAL(jsonItems, modelItems); } // TestMap -Y_UNIT_TEST(TestMapAsObject) { +Y_UNIT_TEST(TestMapAsObject) { TMapType proto; auto& items = *proto.MutableItems(); @@ -949,7 +949,7 @@ Y_UNIT_TEST(TestMapAsObject) { UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr); } // TestMapAsObject -Y_UNIT_TEST(TestMapWTF) { +Y_UNIT_TEST(TestMapWTF) { TMapType proto; auto& items = *proto.MutableItems(); @@ -965,7 +965,7 @@ Y_UNIT_TEST(TestMapWTF) { UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr); } // TestMapWTF -Y_UNIT_TEST(TestStringifyLongNumbers) { +Y_UNIT_TEST(TestStringifyLongNumbers) { #define TEST_SINGLE(flag, value, expectString) \ do { \ TFlatOptional proto; \ diff --git a/library/cpp/protobuf/json/ut/string_transform_ut.cpp b/library/cpp/protobuf/json/ut/string_transform_ut.cpp index 7b0595e6cb..a31dabcb0f 100644 --- a/library/cpp/protobuf/json/ut/string_transform_ut.cpp +++ b/library/cpp/protobuf/json/ut/string_transform_ut.cpp @@ -3,8 +3,8 @@ #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/protobuf/json/proto2json.h> -Y_UNIT_TEST_SUITE(TDoubleEscapeTransform) { - Y_UNIT_TEST(TestEmptyString) { +Y_UNIT_TEST_SUITE(TDoubleEscapeTransform) { + Y_UNIT_TEST(TestEmptyString) { const NProtobufJson::IStringTransform& transform = NProtobufJson::TDoubleEscapeTransform(); TString s; s = ""; @@ -12,7 +12,7 @@ Y_UNIT_TEST_SUITE(TDoubleEscapeTransform) { UNIT_ASSERT_EQUAL(s, ""); } - Y_UNIT_TEST(TestAlphabeticString) { + Y_UNIT_TEST(TestAlphabeticString) { const NProtobufJson::IStringTransform& transform = NProtobufJson::TDoubleEscapeTransform(); TString s; s = "abacaba"; @@ -20,7 +20,7 @@ Y_UNIT_TEST_SUITE(TDoubleEscapeTransform) { UNIT_ASSERT_EQUAL(s, "abacaba"); } - Y_UNIT_TEST(TestRussianSymbols) { + Y_UNIT_TEST(TestRussianSymbols) { const NProtobufJson::IStringTransform& transform = NProtobufJson::TDoubleEscapeTransform(); TString s; s = "тест"; @@ -28,7 +28,7 @@ Y_UNIT_TEST_SUITE(TDoubleEscapeTransform) { UNIT_ASSERT_EQUAL(s, "\\\\321\\\\202\\\\320\\\\265\\\\321\\\\201\\\\321\\\\202"); } - Y_UNIT_TEST(TestEscapeSpecialSymbols) { + Y_UNIT_TEST(TestEscapeSpecialSymbols) { const NProtobufJson::IStringTransform& transform = NProtobufJson::TDoubleEscapeTransform(); TString s; s = "aba\\ca\"ba"; @@ -38,8 +38,8 @@ Y_UNIT_TEST_SUITE(TDoubleEscapeTransform) { } } -Y_UNIT_TEST_SUITE(TDoubleUnescapeTransform) { - Y_UNIT_TEST(TestEmptyString) { +Y_UNIT_TEST_SUITE(TDoubleUnescapeTransform) { + Y_UNIT_TEST(TestEmptyString) { const NProtobufJson::IStringTransform& transform = NProtobufJson::TDoubleUnescapeTransform(); TString s; s = ""; @@ -47,7 +47,7 @@ Y_UNIT_TEST_SUITE(TDoubleUnescapeTransform) { UNIT_ASSERT_EQUAL("", s); } - Y_UNIT_TEST(TestAlphabeticString) { + Y_UNIT_TEST(TestAlphabeticString) { const NProtobufJson::IStringTransform& transform = NProtobufJson::TDoubleUnescapeTransform(); TString s; s = "abacaba"; @@ -56,7 +56,7 @@ Y_UNIT_TEST_SUITE(TDoubleUnescapeTransform) { UNIT_ASSERT_EQUAL("abacaba", s); } - Y_UNIT_TEST(TestRussianSymbols) { + Y_UNIT_TEST(TestRussianSymbols) { const NProtobufJson::IStringTransform& transform = NProtobufJson::TDoubleUnescapeTransform(); TString s; s = "\\\\321\\\\202\\\\320\\\\265\\\\321\\\\201\\\\321\\\\202"; @@ -64,7 +64,7 @@ Y_UNIT_TEST_SUITE(TDoubleUnescapeTransform) { UNIT_ASSERT_EQUAL("тест", s); } - Y_UNIT_TEST(TestEscapeSpecialSymbols) { + Y_UNIT_TEST(TestEscapeSpecialSymbols) { const NProtobufJson::IStringTransform& transform = NProtobufJson::TDoubleUnescapeTransform(); TString s; s = "aba\\\\\\\\ca\\\\\\\"ba"; @@ -72,7 +72,7 @@ Y_UNIT_TEST_SUITE(TDoubleUnescapeTransform) { UNIT_ASSERT_EQUAL("aba\\ca\"ba", s); } - Y_UNIT_TEST(TestEscapeSpecialSymbolsDifficultCases) { + Y_UNIT_TEST(TestEscapeSpecialSymbolsDifficultCases) { const NProtobufJson::IStringTransform& transform = NProtobufJson::TDoubleUnescapeTransform(); TString s; s = "\\\\\\\\\\\\\\\\"; diff --git a/library/cpp/protobuf/util/is_equal.h b/library/cpp/protobuf/util/is_equal.h index d47cb37cb7..13c0aae63d 100644 --- a/library/cpp/protobuf/util/is_equal.h +++ b/library/cpp/protobuf/util/is_equal.h @@ -1,22 +1,22 @@ #pragma once -#include <util/generic/fwd.h> +#include <util/generic/fwd.h> -namespace google { - namespace protobuf { - class Message; +namespace google { + namespace protobuf { + class Message; class FieldDescriptor; - } -} + } +} namespace NProtoBuf { using ::google::protobuf::FieldDescriptor; using ::google::protobuf::Message; -} +} -namespace NProtoBuf { +namespace NProtoBuf { // Reflection-based equality check for arbitrary protobuf messages - + // Strict comparison: optional field without value is NOT equal to // a field with explicitly set default value. bool IsEqual(const Message& m1, const Message& m2); diff --git a/library/cpp/protobuf/util/is_equal_ut.cpp b/library/cpp/protobuf/util/is_equal_ut.cpp index 96e77c95c6..3ca4c90dd5 100644 --- a/library/cpp/protobuf/util/is_equal_ut.cpp +++ b/library/cpp/protobuf/util/is_equal_ut.cpp @@ -5,19 +5,19 @@ #include <google/protobuf/descriptor.h> -Y_UNIT_TEST_SUITE(ProtobufIsEqual) { +Y_UNIT_TEST_SUITE(ProtobufIsEqual) { const ::google::protobuf::Descriptor* Descr = TSampleForIsEqual::descriptor(); const ::google::protobuf::FieldDescriptor* NameDescr = Descr->field(0); const ::google::protobuf::FieldDescriptor* InnerDescr = Descr->field(1); - Y_UNIT_TEST(CheckDescriptors) { + Y_UNIT_TEST(CheckDescriptors) { UNIT_ASSERT(Descr); UNIT_ASSERT(NameDescr); UNIT_ASSERT_VALUES_EQUAL(NameDescr->name(), "Name"); UNIT_ASSERT_VALUES_EQUAL(InnerDescr->name(), "Inner"); } - Y_UNIT_TEST(IsEqual1) { + Y_UNIT_TEST(IsEqual1) { TSampleForIsEqual a; TSampleForIsEqual b; @@ -33,7 +33,7 @@ Y_UNIT_TEST_SUITE(ProtobufIsEqual) { UNIT_ASSERT(!NProtoBuf::IsEqualField(a, b, *NameDescr)); } - Y_UNIT_TEST(IsEqual2) { + Y_UNIT_TEST(IsEqual2) { TSampleForIsEqual a; TSampleForIsEqual b; @@ -50,7 +50,7 @@ Y_UNIT_TEST_SUITE(ProtobufIsEqual) { UNIT_ASSERT(!equalField); } - Y_UNIT_TEST(IsEqual3) { + Y_UNIT_TEST(IsEqual3) { TSampleForIsEqual a; TSampleForIsEqual b; @@ -74,7 +74,7 @@ Y_UNIT_TEST_SUITE(ProtobufIsEqual) { UNIT_ASSERT(!NProtoBuf::IsEqualField(a, b, *NameDescr)); } - Y_UNIT_TEST(IsEqualDefault) { + Y_UNIT_TEST(IsEqualDefault) { TSampleForIsEqual a; TSampleForIsEqual b; diff --git a/library/cpp/protobuf/util/iterators_ut.cpp b/library/cpp/protobuf/util/iterators_ut.cpp index 7a255f0188..9ebcff2963 100644 --- a/library/cpp/protobuf/util/iterators_ut.cpp +++ b/library/cpp/protobuf/util/iterators_ut.cpp @@ -9,8 +9,8 @@ using NProtoBuf::TFieldsIterator; using NProtoBuf::TConstField; -Y_UNIT_TEST_SUITE(Iterators) { - Y_UNIT_TEST(Count) { +Y_UNIT_TEST_SUITE(Iterators) { + Y_UNIT_TEST(Count) { const NProtobufUtilUt::TWalkTest proto; const NProtoBuf::Descriptor* d = proto.GetDescriptor(); TFieldsIterator dbegin(d), dend(d, d->field_count()); @@ -36,7 +36,7 @@ Y_UNIT_TEST_SUITE(Iterators) { UNIT_ASSERT_VALUES_EQUAL(values, 1); } - Y_UNIT_TEST(AnyOf) { + Y_UNIT_TEST(AnyOf) { NProtobufUtilUt::TWalkTest proto; const NProtoBuf::Descriptor* d = proto.GetDescriptor(); TFieldsIterator begin(d), end(d, d->field_count()); diff --git a/library/cpp/protobuf/util/merge.cpp b/library/cpp/protobuf/util/merge.cpp index 19e1e6bafc..dc2b9cc806 100644 --- a/library/cpp/protobuf/util/merge.cpp +++ b/library/cpp/protobuf/util/merge.cpp @@ -1,8 +1,8 @@ #include "merge.h" -#include "simple_reflection.h" - +#include "simple_reflection.h" + #include <google/protobuf/message.h> - + #include <library/cpp/protobuf/util/proto/merge.pb.h> namespace NProtoBuf { diff --git a/library/cpp/protobuf/util/merge.h b/library/cpp/protobuf/util/merge.h index 4acea08697..924975f141 100644 --- a/library/cpp/protobuf/util/merge.h +++ b/library/cpp/protobuf/util/merge.h @@ -1,14 +1,14 @@ #pragma once -namespace google { - namespace protobuf { - class Message; - } -} +namespace google { + namespace protobuf { + class Message; + } +} -namespace NProtoBuf { - using Message = ::google::protobuf::Message; -} +namespace NProtoBuf { + using Message = ::google::protobuf::Message; +} namespace NProtoBuf { // Similiar to Message::MergeFrom, overwrites existing repeated fields diff --git a/library/cpp/protobuf/util/merge_ut.cpp b/library/cpp/protobuf/util/merge_ut.cpp index 01bf3d1a48..22217db183 100644 --- a/library/cpp/protobuf/util/merge_ut.cpp +++ b/library/cpp/protobuf/util/merge_ut.cpp @@ -5,7 +5,7 @@ using namespace NProtoBuf; -Y_UNIT_TEST_SUITE(ProtobufMerge) { +Y_UNIT_TEST_SUITE(ProtobufMerge) { static void InitProto(NProtobufUtilUt::TMergeTest & p, bool isSrc) { size_t start = isSrc ? 0 : 100; @@ -35,7 +35,7 @@ Y_UNIT_TEST_SUITE(ProtobufMerge) { mm3->AddB(start + 13); } - Y_UNIT_TEST(CustomMerge) { + Y_UNIT_TEST(CustomMerge) { NProtobufUtilUt::TMergeTest src, dst; InitProto(src, true); InitProto(dst, false); diff --git a/library/cpp/protobuf/util/pb_io.cpp b/library/cpp/protobuf/util/pb_io.cpp index ab808fd6f4..6270ee0624 100644 --- a/library/cpp/protobuf/util/pb_io.cpp +++ b/library/cpp/protobuf/util/pb_io.cpp @@ -8,11 +8,11 @@ #include <google/protobuf/text_format.h> #include <util/generic/string.h> -#include <util/stream/file.h> -#include <util/stream/str.h> +#include <util/stream/file.h> +#include <util/stream/str.h> #include <util/string/cast.h> -namespace NProtoBuf { +namespace NProtoBuf { class TEnumIdValuePrinter : public google::protobuf::TextFormat::FastFieldValuePrinter { public: @@ -34,7 +34,7 @@ namespace NProtoBuf { } catch (const std::exception&) { return false; } - } + } void SerializeToBase64String(const Message& m, TString& dataBase64) { TString rawData; @@ -58,8 +58,8 @@ namespace NProtoBuf { } catch (const std::exception&) { return false; } - } - + } + const TString ShortUtf8DebugString(const Message& message) { TextFormat::Printer printer; printer.SetSingleLineMode(true); @@ -93,21 +93,21 @@ int operator&(NProtoBuf::Message& m, IBinSaver& f) { return 0; } -void SerializeToTextFormat(const NProtoBuf::Message& m, IOutputStream& out) { - NProtoBuf::io::TCopyingOutputStreamAdaptor adaptor(&out); +void SerializeToTextFormat(const NProtoBuf::Message& m, IOutputStream& out) { + NProtoBuf::io::TCopyingOutputStreamAdaptor adaptor(&out); - if (!NProtoBuf::TextFormat::Print(m, &adaptor)) { + if (!NProtoBuf::TextFormat::Print(m, &adaptor)) { ythrow yexception() << "SerializeToTextFormat failed on Print"; - } + } } void SerializeToTextFormat(const NProtoBuf::Message& m, const TString& fileName) { /* TUnbufferedFileOutput is unbuffered, but TCopyingOutputStreamAdaptor adds - * a buffer on top of it. */ + * a buffer on top of it. */ TUnbufferedFileOutput stream(fileName); - SerializeToTextFormat(m, stream); -} - + SerializeToTextFormat(m, stream); +} + void SerializeToTextFormatWithEnumId(const NProtoBuf::Message& m, IOutputStream& out) { google::protobuf::TextFormat::Printer printer; printer.SetDefaultFieldValuePrinter(new NProtoBuf::TEnumIdValuePrinter()); @@ -130,20 +130,20 @@ void SerializeToTextFormatPretty(const NProtoBuf::Message& m, IOutputStream& out } } -static void ConfigureParser(const EParseFromTextFormatOptions options, - NProtoBuf::TextFormat::Parser& p) { - if (options & EParseFromTextFormatOption::AllowUnknownField) { - p.AllowUnknownField(true); - } -} - -void ParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m, - const EParseFromTextFormatOptions options) { - NProtoBuf::io::TCopyingInputStreamAdaptor adaptor(&in); - NProtoBuf::TextFormat::Parser p; - ConfigureParser(options, p); - - if (!p.Parse(&adaptor, &m)) { +static void ConfigureParser(const EParseFromTextFormatOptions options, + NProtoBuf::TextFormat::Parser& p) { + if (options & EParseFromTextFormatOption::AllowUnknownField) { + p.AllowUnknownField(true); + } +} + +void ParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m, + const EParseFromTextFormatOptions options) { + NProtoBuf::io::TCopyingInputStreamAdaptor adaptor(&in); + NProtoBuf::TextFormat::Parser p; + ConfigureParser(options, p); + + if (!p.Parse(&adaptor, &m)) { // remove everything that may have been read m.Clear(); ythrow yexception() << "ParseFromTextFormat failed on Parse for " << m.GetTypeName(); @@ -151,71 +151,71 @@ void ParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m, } void ParseFromTextFormat(const TString& fileName, NProtoBuf::Message& m, - const EParseFromTextFormatOptions options) { + const EParseFromTextFormatOptions options) { /* TUnbufferedFileInput is unbuffered, but TCopyingInputStreamAdaptor adds - * a buffer on top of it. */ + * a buffer on top of it. */ TUnbufferedFileInput stream(fileName); - ParseFromTextFormat(stream, m, options); -} - + ParseFromTextFormat(stream, m, options); +} + bool TryParseFromTextFormat(const TString& fileName, NProtoBuf::Message& m, - const EParseFromTextFormatOptions options) { - try { - ParseFromTextFormat(fileName, m, options); - } catch (std::exception&) { - return false; - } - - return true; + const EParseFromTextFormatOptions options) { + try { + ParseFromTextFormat(fileName, m, options); + } catch (std::exception&) { + return false; + } + + return true; } -bool TryParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m, - const EParseFromTextFormatOptions options) { - try { - ParseFromTextFormat(in, m, options); - } catch (std::exception&) { - return false; - } - - return true; -} - -void MergeFromTextFormat(IInputStream& in, NProtoBuf::Message& m, - const EParseFromTextFormatOptions options) { - NProtoBuf::io::TCopyingInputStreamAdaptor adaptor(&in); - NProtoBuf::TextFormat::Parser p; - ConfigureParser(options, p); - if (!p.Merge(&adaptor, &m)) { - ythrow yexception() << "MergeFromTextFormat failed on Merge for " << m.GetTypeName(); - } -} - -void MergeFromTextFormat(const TString& fileName, NProtoBuf::Message& m, - const EParseFromTextFormatOptions options) { +bool TryParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m, + const EParseFromTextFormatOptions options) { + try { + ParseFromTextFormat(in, m, options); + } catch (std::exception&) { + return false; + } + + return true; +} + +void MergeFromTextFormat(IInputStream& in, NProtoBuf::Message& m, + const EParseFromTextFormatOptions options) { + NProtoBuf::io::TCopyingInputStreamAdaptor adaptor(&in); + NProtoBuf::TextFormat::Parser p; + ConfigureParser(options, p); + if (!p.Merge(&adaptor, &m)) { + ythrow yexception() << "MergeFromTextFormat failed on Merge for " << m.GetTypeName(); + } +} + +void MergeFromTextFormat(const TString& fileName, NProtoBuf::Message& m, + const EParseFromTextFormatOptions options) { /* TUnbufferedFileInput is unbuffered, but TCopyingInputStreamAdaptor adds - * a buffer on top of it. */ + * a buffer on top of it. */ TUnbufferedFileInput stream(fileName); - MergeFromTextFormat(stream, m, options); -} - -bool TryMergeFromTextFormat(const TString& fileName, NProtoBuf::Message& m, - const EParseFromTextFormatOptions options) { - try { - MergeFromTextFormat(fileName, m, options); - } catch (std::exception&) { - return false; - } - - return true; -} - -bool TryMergeFromTextFormat(IInputStream& in, NProtoBuf::Message& m, - const EParseFromTextFormatOptions options) { - try { - MergeFromTextFormat(in, m, options); - } catch (std::exception&) { - return false; - } - - return true; -} + MergeFromTextFormat(stream, m, options); +} + +bool TryMergeFromTextFormat(const TString& fileName, NProtoBuf::Message& m, + const EParseFromTextFormatOptions options) { + try { + MergeFromTextFormat(fileName, m, options); + } catch (std::exception&) { + return false; + } + + return true; +} + +bool TryMergeFromTextFormat(IInputStream& in, NProtoBuf::Message& m, + const EParseFromTextFormatOptions options) { + try { + MergeFromTextFormat(in, m, options); + } catch (std::exception&) { + return false; + } + + return true; +} diff --git a/library/cpp/protobuf/util/pb_io.h b/library/cpp/protobuf/util/pb_io.h index a431b4200b..493c84cb5f 100644 --- a/library/cpp/protobuf/util/pb_io.h +++ b/library/cpp/protobuf/util/pb_io.h @@ -1,37 +1,37 @@ #pragma once -#include <util/generic/fwd.h> -#include <util/generic/flags.h> +#include <util/generic/fwd.h> +#include <util/generic/flags.h> -struct IBinSaver; +struct IBinSaver; -namespace google { - namespace protobuf { +namespace google { + namespace protobuf { class Message; - } -} - -namespace NProtoBuf { - using Message = ::google::protobuf::Message; -} - -class IInputStream; -class IOutputStream; - -namespace NProtoBuf { - /* Parse base64 URL encoded serialized message from string. - */ + } +} + +namespace NProtoBuf { + using Message = ::google::protobuf::Message; +} + +class IInputStream; +class IOutputStream; + +namespace NProtoBuf { + /* Parse base64 URL encoded serialized message from string. + */ void ParseFromBase64String(const TStringBuf dataBase64, Message& m, bool allowUneven = false); bool TryParseFromBase64String(const TStringBuf dataBase64, Message& m, bool allowUneven = false); - template <typename T> + template <typename T> static T ParseFromBase64String(const TStringBuf& dataBase64, bool allowUneven = false) { - T m; + T m; ParseFromBase64String(dataBase64, m, allowUneven); - return m; - } + return m; + } - /* Serialize message into string and apply base64 URL encoding. - */ + /* Serialize message into string and apply base64 URL encoding. + */ TString SerializeToBase64String(const Message& m); void SerializeToBase64String(const Message& m, TString& dataBase64); bool TrySerializeToBase64String(const Message& m, TString& dataBase64); @@ -44,10 +44,10 @@ namespace NProtoBuf { int operator&(NProtoBuf::Message& m, IBinSaver& f); -// Write a textual representation of the given message to the given file. +// Write a textual representation of the given message to the given file. void SerializeToTextFormat(const NProtoBuf::Message& m, const TString& fileName); -void SerializeToTextFormat(const NProtoBuf::Message& m, IOutputStream& out); - +void SerializeToTextFormat(const NProtoBuf::Message& m, IOutputStream& out); + // Write a textual representation of the given message to the given output stream // with flags UseShortRepeatedPrimitives and UseUtf8StringEscaping set to true. void SerializeToTextFormatPretty(const NProtoBuf::Message& m, IOutputStream& out); @@ -56,83 +56,83 @@ void SerializeToTextFormatPretty(const NProtoBuf::Message& m, IOutputStream& out // use enum id instead of enum name for all enum fields. void SerializeToTextFormatWithEnumId(const NProtoBuf::Message& m, IOutputStream& out); -enum class EParseFromTextFormatOption : ui64 { - // Unknown fields will be ignored by the parser - AllowUnknownField = 1 -}; - -Y_DECLARE_FLAGS(EParseFromTextFormatOptions, EParseFromTextFormatOption); - -// Parse a text-format protocol message from the given file into message object. +enum class EParseFromTextFormatOption : ui64 { + // Unknown fields will be ignored by the parser + AllowUnknownField = 1 +}; + +Y_DECLARE_FLAGS(EParseFromTextFormatOptions, EParseFromTextFormatOption); + +// Parse a text-format protocol message from the given file into message object. void ParseFromTextFormat(const TString& fileName, NProtoBuf::Message& m, - const EParseFromTextFormatOptions options = {}); -// NOTE: will read `in` till the end. -void ParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m, - const EParseFromTextFormatOptions options = {}); - -/* @return `true` if parsing was successfull and `false` otherwise. - * - * @see `ParseFromTextFormat` - */ + const EParseFromTextFormatOptions options = {}); +// NOTE: will read `in` till the end. +void ParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m, + const EParseFromTextFormatOptions options = {}); + +/* @return `true` if parsing was successfull and `false` otherwise. + * + * @see `ParseFromTextFormat` + */ bool TryParseFromTextFormat(const TString& fileName, NProtoBuf::Message& m, - const EParseFromTextFormatOptions options = {}); -// NOTE: will read `in` till the end. -bool TryParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m, - const EParseFromTextFormatOptions options = {}); - -// @see `ParseFromTextFormat` -template <typename T> + const EParseFromTextFormatOptions options = {}); +// NOTE: will read `in` till the end. +bool TryParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m, + const EParseFromTextFormatOptions options = {}); + +// @see `ParseFromTextFormat` +template <typename T> static T ParseFromTextFormat(const TString& fileName, - const EParseFromTextFormatOptions options = {}) { - T message; - ParseFromTextFormat(fileName, message, options); - return message; -} - -// @see `ParseFromTextFormat` -// NOTE: will read `in` till the end. -template <typename T> -static T ParseFromTextFormat(IInputStream& in, - const EParseFromTextFormatOptions options = {}) { - T message; - ParseFromTextFormat(in, message, options); - return message; -} - -// Merge a text-format protocol message from the given file into message object. -// -// NOTE: Even when parsing failed and exception was thrown `m` may be different from its original -// value. User must implement transactional logic around `MergeFromTextFormat` by himself. -void MergeFromTextFormat(const TString& fileName, NProtoBuf::Message& m, - const EParseFromTextFormatOptions options = {}); -// NOTE: will read `in` till the end. -void MergeFromTextFormat(IInputStream& in, NProtoBuf::Message& m, - const EParseFromTextFormatOptions options = {}); -/* @return `true` if parsing was successfull and `false` otherwise. - * - * @see `MergeFromTextFormat` - */ -bool TryMergeFromTextFormat(const TString& fileName, NProtoBuf::Message& m, - const EParseFromTextFormatOptions options = {}); -// NOTE: will read `in` till the end. -bool TryMergeFromTextFormat(IInputStream& in, NProtoBuf::Message& m, - const EParseFromTextFormatOptions options = {}); - -// @see `MergeFromTextFormat` -template <typename T> -static T MergeFromTextFormat(const TString& fileName, - const EParseFromTextFormatOptions options = {}) { - T message; - MergeFromTextFormat(fileName, message, options); - return message; -} - -// @see `MergeFromTextFormat` -// NOTE: will read `in` till the end. -template <typename T> -static T MergeFromTextFormat(IInputStream& in, - const EParseFromTextFormatOptions options = {}) { - T message; - MergeFromTextFormat(in, message, options); - return message; -} + const EParseFromTextFormatOptions options = {}) { + T message; + ParseFromTextFormat(fileName, message, options); + return message; +} + +// @see `ParseFromTextFormat` +// NOTE: will read `in` till the end. +template <typename T> +static T ParseFromTextFormat(IInputStream& in, + const EParseFromTextFormatOptions options = {}) { + T message; + ParseFromTextFormat(in, message, options); + return message; +} + +// Merge a text-format protocol message from the given file into message object. +// +// NOTE: Even when parsing failed and exception was thrown `m` may be different from its original +// value. User must implement transactional logic around `MergeFromTextFormat` by himself. +void MergeFromTextFormat(const TString& fileName, NProtoBuf::Message& m, + const EParseFromTextFormatOptions options = {}); +// NOTE: will read `in` till the end. +void MergeFromTextFormat(IInputStream& in, NProtoBuf::Message& m, + const EParseFromTextFormatOptions options = {}); +/* @return `true` if parsing was successfull and `false` otherwise. + * + * @see `MergeFromTextFormat` + */ +bool TryMergeFromTextFormat(const TString& fileName, NProtoBuf::Message& m, + const EParseFromTextFormatOptions options = {}); +// NOTE: will read `in` till the end. +bool TryMergeFromTextFormat(IInputStream& in, NProtoBuf::Message& m, + const EParseFromTextFormatOptions options = {}); + +// @see `MergeFromTextFormat` +template <typename T> +static T MergeFromTextFormat(const TString& fileName, + const EParseFromTextFormatOptions options = {}) { + T message; + MergeFromTextFormat(fileName, message, options); + return message; +} + +// @see `MergeFromTextFormat` +// NOTE: will read `in` till the end. +template <typename T> +static T MergeFromTextFormat(IInputStream& in, + const EParseFromTextFormatOptions options = {}) { + T message; + MergeFromTextFormat(in, message, options); + return message; +} diff --git a/library/cpp/protobuf/util/pb_io_ut.cpp b/library/cpp/protobuf/util/pb_io_ut.cpp index 32bba7bc40..875d6dc602 100644 --- a/library/cpp/protobuf/util/pb_io_ut.cpp +++ b/library/cpp/protobuf/util/pb_io_ut.cpp @@ -1,22 +1,22 @@ -#include "pb_io.h" - -#include "is_equal.h" - +#include "pb_io.h" + +#include "is_equal.h" + #include <library/cpp/protobuf/util/ut/common_ut.pb.h> - + #include <library/cpp/testing/unittest/registar.h> - -#include <util/folder/path.h> -#include <util/folder/tempdir.h> -#include <util/stream/file.h> -#include <util/stream/str.h> - -static NProtobufUtilUt::TTextTest GetCorrectMessage() { - NProtobufUtilUt::TTextTest m; - m.SetFoo(42); - return m; -} - + +#include <util/folder/path.h> +#include <util/folder/tempdir.h> +#include <util/stream/file.h> +#include <util/stream/str.h> + +static NProtobufUtilUt::TTextTest GetCorrectMessage() { + NProtobufUtilUt::TTextTest m; + m.SetFoo(42); + return m; +} + static NProtobufUtilUt::TTextEnumTest GetCorrectEnumMessage() { NProtobufUtilUt::TTextEnumTest m; m.SetSlot(NProtobufUtilUt::TTextEnumTest::EET_SLOT_1); @@ -25,41 +25,41 @@ static NProtobufUtilUt::TTextEnumTest GetCorrectEnumMessage() { static const TString CORRECT_MESSAGE = R"(Foo: 42 -)"; +)"; static const TString CORRECT_ENUM_NAME_MESSAGE = R"(Slot: EET_SLOT_1 )"; static const TString CORRECT_ENUM_ID_MESSAGE = R"(Slot: 1 )"; - + static const TString INCORRECT_MESSAGE = R"(Bar: 1 -)"; +)"; static const TString INCORRECT_ENUM_NAME_MESSAGE = R"(Slot: EET_SLOT_3 )"; static const TString INCORRECT_ENUM_ID_MESSAGE = R"(Slot: 3 )"; - + static const TString CORRECT_BASE64_MESSAGE = "CCo,"; static const TString CORRECT_UNEVEN_BASE64_MESSAGE = "CCo"; static const TString INCORRECT_BASE64_MESSAGE = "CC"; -Y_UNIT_TEST_SUITE(TTestProtoBufIO) { - Y_UNIT_TEST(TestBase64) { - { - NProtobufUtilUt::TTextTest message; - UNIT_ASSERT(NProtoBuf::TryParseFromBase64String(CORRECT_BASE64_MESSAGE, message)); - } - { - NProtobufUtilUt::TTextTest message; - UNIT_ASSERT(!NProtoBuf::TryParseFromBase64String(INCORRECT_BASE64_MESSAGE, message)); - } - { +Y_UNIT_TEST_SUITE(TTestProtoBufIO) { + Y_UNIT_TEST(TestBase64) { + { + NProtobufUtilUt::TTextTest message; + UNIT_ASSERT(NProtoBuf::TryParseFromBase64String(CORRECT_BASE64_MESSAGE, message)); + } + { + NProtobufUtilUt::TTextTest message; + UNIT_ASSERT(!NProtoBuf::TryParseFromBase64String(INCORRECT_BASE64_MESSAGE, message)); + } + { NProtobufUtilUt::TTextTest message; UNIT_ASSERT(NProtoBuf::TryParseFromBase64String(CORRECT_UNEVEN_BASE64_MESSAGE , message, true)); } @@ -68,134 +68,134 @@ Y_UNIT_TEST_SUITE(TTestProtoBufIO) { UNIT_ASSERT(!NProtoBuf::TryParseFromBase64String(CORRECT_UNEVEN_BASE64_MESSAGE , message, false)); } { - UNIT_ASSERT_VALUES_EQUAL(CORRECT_BASE64_MESSAGE, NProtoBuf::SerializeToBase64String(GetCorrectMessage())); - } - { - const auto m = NProtoBuf::ParseFromBase64String<NProtobufUtilUt::TTextTest>(CORRECT_BASE64_MESSAGE); - UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m)); - } - } - - Y_UNIT_TEST(TestParseFromTextFormat) { - TTempDir tempDir; - const TFsPath correctFileName = TFsPath{tempDir()} / "correct.pb.txt"; - const TFsPath incorrectFileName = TFsPath{tempDir()} / "incorrect.pb.txt"; - + UNIT_ASSERT_VALUES_EQUAL(CORRECT_BASE64_MESSAGE, NProtoBuf::SerializeToBase64String(GetCorrectMessage())); + } + { + const auto m = NProtoBuf::ParseFromBase64String<NProtobufUtilUt::TTextTest>(CORRECT_BASE64_MESSAGE); + UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m)); + } + } + + Y_UNIT_TEST(TestParseFromTextFormat) { + TTempDir tempDir; + const TFsPath correctFileName = TFsPath{tempDir()} / "correct.pb.txt"; + const TFsPath incorrectFileName = TFsPath{tempDir()} / "incorrect.pb.txt"; + TFileOutput{correctFileName}.Write(CORRECT_MESSAGE); TFileOutput{incorrectFileName}.Write(INCORRECT_MESSAGE); - - { - NProtobufUtilUt::TTextTest message; - UNIT_ASSERT(TryParseFromTextFormat(correctFileName, message)); - } - { - NProtobufUtilUt::TTextTest message; - UNIT_ASSERT(!TryParseFromTextFormat(incorrectFileName, message)); - } - { - NProtobufUtilUt::TTextTest message; - TStringInput in{CORRECT_MESSAGE}; - UNIT_ASSERT(TryParseFromTextFormat(in, message)); - } - { - NProtobufUtilUt::TTextTest message; - TStringInput in{INCORRECT_MESSAGE}; - UNIT_ASSERT(!TryParseFromTextFormat(in, message)); - } - { - NProtobufUtilUt::TTextTest message; - UNIT_ASSERT_NO_EXCEPTION(TryParseFromTextFormat(incorrectFileName, message)); - } - { - NProtobufUtilUt::TTextTest message; - UNIT_ASSERT(!TryParseFromTextFormat("this_file_doesnt_exists", message)); - } - { - NProtobufUtilUt::TTextTest message; - UNIT_ASSERT_NO_EXCEPTION(TryParseFromTextFormat("this_file_doesnt_exists", message)); - } - { - NProtobufUtilUt::TTextTest message; + + { + NProtobufUtilUt::TTextTest message; + UNIT_ASSERT(TryParseFromTextFormat(correctFileName, message)); + } + { + NProtobufUtilUt::TTextTest message; + UNIT_ASSERT(!TryParseFromTextFormat(incorrectFileName, message)); + } + { + NProtobufUtilUt::TTextTest message; + TStringInput in{CORRECT_MESSAGE}; + UNIT_ASSERT(TryParseFromTextFormat(in, message)); + } + { + NProtobufUtilUt::TTextTest message; + TStringInput in{INCORRECT_MESSAGE}; + UNIT_ASSERT(!TryParseFromTextFormat(in, message)); + } + { + NProtobufUtilUt::TTextTest message; + UNIT_ASSERT_NO_EXCEPTION(TryParseFromTextFormat(incorrectFileName, message)); + } + { + NProtobufUtilUt::TTextTest message; + UNIT_ASSERT(!TryParseFromTextFormat("this_file_doesnt_exists", message)); + } + { + NProtobufUtilUt::TTextTest message; + UNIT_ASSERT_NO_EXCEPTION(TryParseFromTextFormat("this_file_doesnt_exists", message)); + } + { + NProtobufUtilUt::TTextTest message; UNIT_ASSERT_EXCEPTION(ParseFromTextFormat("this_file_doesnt_exists", message), TFileError); } { - NProtobufUtilUt::TTextTest message; - UNIT_ASSERT_NO_EXCEPTION(ParseFromTextFormat(correctFileName, message)); - } - { - NProtobufUtilUt::TTextTest message; - UNIT_ASSERT_EXCEPTION(ParseFromTextFormat(incorrectFileName, message), yexception); - } - { - NProtobufUtilUt::TTextTest message; - TStringInput in{CORRECT_MESSAGE}; - UNIT_ASSERT_NO_EXCEPTION(ParseFromTextFormat(in, message)); - } - { - NProtobufUtilUt::TTextTest message; - TStringInput in{INCORRECT_MESSAGE}; - UNIT_ASSERT_EXCEPTION(ParseFromTextFormat(in, message), yexception); - } - { - NProtobufUtilUt::TTextTest m; + NProtobufUtilUt::TTextTest message; + UNIT_ASSERT_NO_EXCEPTION(ParseFromTextFormat(correctFileName, message)); + } + { + NProtobufUtilUt::TTextTest message; + UNIT_ASSERT_EXCEPTION(ParseFromTextFormat(incorrectFileName, message), yexception); + } + { + NProtobufUtilUt::TTextTest message; + TStringInput in{CORRECT_MESSAGE}; + UNIT_ASSERT_NO_EXCEPTION(ParseFromTextFormat(in, message)); + } + { + NProtobufUtilUt::TTextTest message; + TStringInput in{INCORRECT_MESSAGE}; + UNIT_ASSERT_EXCEPTION(ParseFromTextFormat(in, message), yexception); + } + { + NProtobufUtilUt::TTextTest m; const auto f = [&correctFileName](NProtobufUtilUt::TTextTest& mm) { mm = ParseFromTextFormat<NProtobufUtilUt::TTextTest>(correctFileName); - }; - UNIT_ASSERT_NO_EXCEPTION(f(m)); - UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m)); - } - { - UNIT_ASSERT_EXCEPTION(ParseFromTextFormat<NProtobufUtilUt::TTextTest>(incorrectFileName), yexception); - } - { - NProtobufUtilUt::TTextTest m; - TStringInput in{CORRECT_MESSAGE}; + }; + UNIT_ASSERT_NO_EXCEPTION(f(m)); + UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m)); + } + { + UNIT_ASSERT_EXCEPTION(ParseFromTextFormat<NProtobufUtilUt::TTextTest>(incorrectFileName), yexception); + } + { + NProtobufUtilUt::TTextTest m; + TStringInput in{CORRECT_MESSAGE}; const auto f = [&in](NProtobufUtilUt::TTextTest& mm) { mm = ParseFromTextFormat<NProtobufUtilUt::TTextTest>(in); - }; - UNIT_ASSERT_NO_EXCEPTION(f(m)); - UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m)); - } - { - TStringInput in{INCORRECT_MESSAGE}; - UNIT_ASSERT_EXCEPTION(ParseFromTextFormat<NProtobufUtilUt::TTextTest>(in), yexception); - } - { + }; + UNIT_ASSERT_NO_EXCEPTION(f(m)); + UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m)); + } + { + TStringInput in{INCORRECT_MESSAGE}; + UNIT_ASSERT_EXCEPTION(ParseFromTextFormat<NProtobufUtilUt::TTextTest>(in), yexception); + } + { const TFsPath correctFileName2 = TFsPath{tempDir()} / "serialized.pb.txt"; - const auto original = GetCorrectMessage(); + const auto original = GetCorrectMessage(); UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormat(original, correctFileName2)); const auto serializedStr = TUnbufferedFileInput{correctFileName2}.ReadAll(); - UNIT_ASSERT_VALUES_EQUAL(serializedStr, CORRECT_MESSAGE); - } - { - const auto original = GetCorrectMessage(); - TStringStream out; - UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormat(original, out)); - UNIT_ASSERT_VALUES_EQUAL(out.Str(), CORRECT_MESSAGE); - } - { - NProtobufUtilUt::TTextTest m; + UNIT_ASSERT_VALUES_EQUAL(serializedStr, CORRECT_MESSAGE); + } + { + const auto original = GetCorrectMessage(); + TStringStream out; + UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormat(original, out)); + UNIT_ASSERT_VALUES_EQUAL(out.Str(), CORRECT_MESSAGE); + } + { + NProtobufUtilUt::TTextTest m; const auto f = [&correctFileName](NProtobufUtilUt::TTextTest& mm) { mm = ParseFromTextFormat<NProtobufUtilUt::TTextTest>( correctFileName, EParseFromTextFormatOption::AllowUnknownField); - }; - UNIT_ASSERT_NO_EXCEPTION(f(m)); - UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m)); - } - { - const NProtobufUtilUt::TTextTest empty; - NProtobufUtilUt::TTextTest m; + }; + UNIT_ASSERT_NO_EXCEPTION(f(m)); + UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m)); + } + { + const NProtobufUtilUt::TTextTest empty; + NProtobufUtilUt::TTextTest m; const auto f = [&incorrectFileName](NProtobufUtilUt::TTextTest& mm) { mm = ParseFromTextFormat<NProtobufUtilUt::TTextTest>( incorrectFileName, EParseFromTextFormatOption::AllowUnknownField); - }; - UNIT_ASSERT_NO_EXCEPTION(f(m)); - UNIT_ASSERT(NProtoBuf::IsEqual(empty, m)); - } - } - + }; + UNIT_ASSERT_NO_EXCEPTION(f(m)); + UNIT_ASSERT(NProtoBuf::IsEqual(empty, m)); + } + } + Y_UNIT_TEST(TestSerializeToTextFormatWithEnumId) { TTempDir tempDir; const TFsPath correctNameFileName = TFsPath{tempDir()} / "correct_name.pb.txt"; @@ -250,139 +250,139 @@ Y_UNIT_TEST_SUITE(TTestProtoBufIO) { } } - Y_UNIT_TEST(TestMergeFromTextFormat) { - // - // Tests cases below are identical to `Parse` tests - // - TTempDir tempDir; - const TFsPath correctFileName = TFsPath{tempDir()} / "correct.pb.txt"; - const TFsPath incorrectFileName = TFsPath{tempDir()} / "incorrect.pb.txt"; - + Y_UNIT_TEST(TestMergeFromTextFormat) { + // + // Tests cases below are identical to `Parse` tests + // + TTempDir tempDir; + const TFsPath correctFileName = TFsPath{tempDir()} / "correct.pb.txt"; + const TFsPath incorrectFileName = TFsPath{tempDir()} / "incorrect.pb.txt"; + TFileOutput{correctFileName}.Write(CORRECT_MESSAGE); TFileOutput{incorrectFileName}.Write(INCORRECT_MESSAGE); - - { - NProtobufUtilUt::TTextTest message; - UNIT_ASSERT(TryMergeFromTextFormat(correctFileName, message)); - } - { - NProtobufUtilUt::TTextTest message; - UNIT_ASSERT(!TryMergeFromTextFormat(incorrectFileName, message)); - } - { - NProtobufUtilUt::TTextTest message; - TStringInput in{CORRECT_MESSAGE}; - UNIT_ASSERT(TryMergeFromTextFormat(in, message)); - } - { - NProtobufUtilUt::TTextTest message; - TStringInput in{INCORRECT_MESSAGE}; - UNIT_ASSERT(!TryMergeFromTextFormat(in, message)); - } - { - NProtobufUtilUt::TTextTest message; - UNIT_ASSERT_NO_EXCEPTION(TryMergeFromTextFormat(incorrectFileName, message)); - } - { - NProtobufUtilUt::TTextTest message; - UNIT_ASSERT(!TryMergeFromTextFormat("this_file_doesnt_exists", message)); - } - { - NProtobufUtilUt::TTextTest message; - UNIT_ASSERT_NO_EXCEPTION(TryMergeFromTextFormat("this_file_doesnt_exists", message)); - } - { - NProtobufUtilUt::TTextTest message; - UNIT_ASSERT_EXCEPTION(MergeFromTextFormat("this_file_doesnt_exists", message), TFileError); - } - { - NProtobufUtilUt::TTextTest message; - UNIT_ASSERT_NO_EXCEPTION(MergeFromTextFormat(correctFileName, message)); - } - { - NProtobufUtilUt::TTextTest message; - UNIT_ASSERT_EXCEPTION(MergeFromTextFormat(incorrectFileName, message), yexception); - } - { - NProtobufUtilUt::TTextTest message; - TStringInput in{CORRECT_MESSAGE}; - UNIT_ASSERT_NO_EXCEPTION(MergeFromTextFormat(in, message)); - } - { - NProtobufUtilUt::TTextTest message; - TStringInput in{INCORRECT_MESSAGE}; - UNIT_ASSERT_EXCEPTION(MergeFromTextFormat(in, message), yexception); - } - { - NProtobufUtilUt::TTextTest m; - const auto f = [&correctFileName](NProtobufUtilUt::TTextTest& mm) { - mm = MergeFromTextFormat<NProtobufUtilUt::TTextTest>(correctFileName); - }; - UNIT_ASSERT_NO_EXCEPTION(f(m)); - UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m)); - } - { - UNIT_ASSERT_EXCEPTION(MergeFromTextFormat<NProtobufUtilUt::TTextTest>(incorrectFileName), yexception); - } - { - NProtobufUtilUt::TTextTest m; - TStringInput in{CORRECT_MESSAGE}; - const auto f = [&in](NProtobufUtilUt::TTextTest& mm) { - mm = MergeFromTextFormat<NProtobufUtilUt::TTextTest>(in); - }; - UNIT_ASSERT_NO_EXCEPTION(f(m)); - UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m)); - } - { - TStringInput in{INCORRECT_MESSAGE}; - UNIT_ASSERT_EXCEPTION(MergeFromTextFormat<NProtobufUtilUt::TTextTest>(in), yexception); - } - { - const TFsPath correctFileName2 = TFsPath{tempDir()} / "serialized.pb.txt"; - const auto original = GetCorrectMessage(); - UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormat(original, correctFileName2)); + + { + NProtobufUtilUt::TTextTest message; + UNIT_ASSERT(TryMergeFromTextFormat(correctFileName, message)); + } + { + NProtobufUtilUt::TTextTest message; + UNIT_ASSERT(!TryMergeFromTextFormat(incorrectFileName, message)); + } + { + NProtobufUtilUt::TTextTest message; + TStringInput in{CORRECT_MESSAGE}; + UNIT_ASSERT(TryMergeFromTextFormat(in, message)); + } + { + NProtobufUtilUt::TTextTest message; + TStringInput in{INCORRECT_MESSAGE}; + UNIT_ASSERT(!TryMergeFromTextFormat(in, message)); + } + { + NProtobufUtilUt::TTextTest message; + UNIT_ASSERT_NO_EXCEPTION(TryMergeFromTextFormat(incorrectFileName, message)); + } + { + NProtobufUtilUt::TTextTest message; + UNIT_ASSERT(!TryMergeFromTextFormat("this_file_doesnt_exists", message)); + } + { + NProtobufUtilUt::TTextTest message; + UNIT_ASSERT_NO_EXCEPTION(TryMergeFromTextFormat("this_file_doesnt_exists", message)); + } + { + NProtobufUtilUt::TTextTest message; + UNIT_ASSERT_EXCEPTION(MergeFromTextFormat("this_file_doesnt_exists", message), TFileError); + } + { + NProtobufUtilUt::TTextTest message; + UNIT_ASSERT_NO_EXCEPTION(MergeFromTextFormat(correctFileName, message)); + } + { + NProtobufUtilUt::TTextTest message; + UNIT_ASSERT_EXCEPTION(MergeFromTextFormat(incorrectFileName, message), yexception); + } + { + NProtobufUtilUt::TTextTest message; + TStringInput in{CORRECT_MESSAGE}; + UNIT_ASSERT_NO_EXCEPTION(MergeFromTextFormat(in, message)); + } + { + NProtobufUtilUt::TTextTest message; + TStringInput in{INCORRECT_MESSAGE}; + UNIT_ASSERT_EXCEPTION(MergeFromTextFormat(in, message), yexception); + } + { + NProtobufUtilUt::TTextTest m; + const auto f = [&correctFileName](NProtobufUtilUt::TTextTest& mm) { + mm = MergeFromTextFormat<NProtobufUtilUt::TTextTest>(correctFileName); + }; + UNIT_ASSERT_NO_EXCEPTION(f(m)); + UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m)); + } + { + UNIT_ASSERT_EXCEPTION(MergeFromTextFormat<NProtobufUtilUt::TTextTest>(incorrectFileName), yexception); + } + { + NProtobufUtilUt::TTextTest m; + TStringInput in{CORRECT_MESSAGE}; + const auto f = [&in](NProtobufUtilUt::TTextTest& mm) { + mm = MergeFromTextFormat<NProtobufUtilUt::TTextTest>(in); + }; + UNIT_ASSERT_NO_EXCEPTION(f(m)); + UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m)); + } + { + TStringInput in{INCORRECT_MESSAGE}; + UNIT_ASSERT_EXCEPTION(MergeFromTextFormat<NProtobufUtilUt::TTextTest>(in), yexception); + } + { + const TFsPath correctFileName2 = TFsPath{tempDir()} / "serialized.pb.txt"; + const auto original = GetCorrectMessage(); + UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormat(original, correctFileName2)); const auto serializedStr = TUnbufferedFileInput{correctFileName2}.ReadAll(); - UNIT_ASSERT_VALUES_EQUAL(serializedStr, CORRECT_MESSAGE); - } - { - const auto original = GetCorrectMessage(); - TStringStream out; - UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormat(original, out)); - UNIT_ASSERT_VALUES_EQUAL(out.Str(), CORRECT_MESSAGE); - } - { - NProtobufUtilUt::TTextTest m; - const auto f = [&correctFileName](NProtobufUtilUt::TTextTest& mm) { - mm = MergeFromTextFormat<NProtobufUtilUt::TTextTest>( + UNIT_ASSERT_VALUES_EQUAL(serializedStr, CORRECT_MESSAGE); + } + { + const auto original = GetCorrectMessage(); + TStringStream out; + UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormat(original, out)); + UNIT_ASSERT_VALUES_EQUAL(out.Str(), CORRECT_MESSAGE); + } + { + NProtobufUtilUt::TTextTest m; + const auto f = [&correctFileName](NProtobufUtilUt::TTextTest& mm) { + mm = MergeFromTextFormat<NProtobufUtilUt::TTextTest>( correctFileName, EParseFromTextFormatOption::AllowUnknownField); - }; - UNIT_ASSERT_NO_EXCEPTION(f(m)); - UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m)); - } - { - const NProtobufUtilUt::TTextTest empty; - NProtobufUtilUt::TTextTest m; - const auto f = [&incorrectFileName](NProtobufUtilUt::TTextTest& mm) { - mm = MergeFromTextFormat<NProtobufUtilUt::TTextTest>( + }; + UNIT_ASSERT_NO_EXCEPTION(f(m)); + UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m)); + } + { + const NProtobufUtilUt::TTextTest empty; + NProtobufUtilUt::TTextTest m; + const auto f = [&incorrectFileName](NProtobufUtilUt::TTextTest& mm) { + mm = MergeFromTextFormat<NProtobufUtilUt::TTextTest>( incorrectFileName, EParseFromTextFormatOption::AllowUnknownField); - }; - UNIT_ASSERT_NO_EXCEPTION(f(m)); - UNIT_ASSERT(NProtoBuf::IsEqual(empty, m)); - } - - // - // Test cases for `Merge` - // - { - NProtobufUtilUt::TTextTest message; - message.SetFoo(100500); - TStringInput in{CORRECT_MESSAGE}; - UNIT_ASSERT(TryMergeFromTextFormat(in, message)); - UNIT_ASSERT(NProtoBuf::IsEqual(message, GetCorrectMessage())); - } - } + }; + UNIT_ASSERT_NO_EXCEPTION(f(m)); + UNIT_ASSERT(NProtoBuf::IsEqual(empty, m)); + } + + // + // Test cases for `Merge` + // + { + NProtobufUtilUt::TTextTest message; + message.SetFoo(100500); + TStringInput in{CORRECT_MESSAGE}; + UNIT_ASSERT(TryMergeFromTextFormat(in, message)); + UNIT_ASSERT(NProtoBuf::IsEqual(message, GetCorrectMessage())); + } + } Y_UNIT_TEST(TestMergeFromString) { NProtobufUtilUt::TMergeTest message; @@ -415,4 +415,4 @@ Y_UNIT_TEST_SUITE(TTestProtoBufIO) { UNIT_ASSERT(NProtoBuf::IsEqual(message, m3)); } } -} +} diff --git a/library/cpp/protobuf/util/repeated_field_utils_ut.cpp b/library/cpp/protobuf/util/repeated_field_utils_ut.cpp index d8944cad04..58aaaa9e12 100644 --- a/library/cpp/protobuf/util/repeated_field_utils_ut.cpp +++ b/library/cpp/protobuf/util/repeated_field_utils_ut.cpp @@ -5,8 +5,8 @@ using namespace NProtoBuf; -Y_UNIT_TEST_SUITE(RepeatedFieldUtils) { - Y_UNIT_TEST(RemoveIf) { +Y_UNIT_TEST_SUITE(RepeatedFieldUtils) { + Y_UNIT_TEST(RemoveIf) { { NProtobufUtilUt::TWalkTest msg; msg.AddRepInt(0); diff --git a/library/cpp/protobuf/util/simple_reflection.h b/library/cpp/protobuf/util/simple_reflection.h index 94723d8155..61e877a787 100644 --- a/library/cpp/protobuf/util/simple_reflection.h +++ b/library/cpp/protobuf/util/simple_reflection.h @@ -145,7 +145,7 @@ namespace NProtoBuf { } /* void Swap(TMutableField& f) { - Y_ASSERT(Field() == f.Field()); + Y_ASSERT(Field() == f.Field()); // not implemented yet, TODO: implement when Reflection::Mutable(Ptr)RepeatedField // is ported into arcadia protobuf library from up-stream. diff --git a/library/cpp/protobuf/util/simple_reflection_ut.cpp b/library/cpp/protobuf/util/simple_reflection_ut.cpp index bd5b32e463..169d4703c9 100644 --- a/library/cpp/protobuf/util/simple_reflection_ut.cpp +++ b/library/cpp/protobuf/util/simple_reflection_ut.cpp @@ -6,7 +6,7 @@ using namespace NProtoBuf; -Y_UNIT_TEST_SUITE(ProtobufSimpleReflection) { +Y_UNIT_TEST_SUITE(ProtobufSimpleReflection) { static TSample GenSampleForMergeFrom() { TSample smf; smf.SetOneStr("one str"); @@ -19,7 +19,7 @@ Y_UNIT_TEST_SUITE(ProtobufSimpleReflection) { return smf; } - Y_UNIT_TEST(MergeFromGeneric) { + Y_UNIT_TEST(MergeFromGeneric) { const TSample src(GenSampleForMergeFrom()); TSample dst; const Descriptor* descr = dst.GetDescriptor(); @@ -51,7 +51,7 @@ Y_UNIT_TEST_SUITE(ProtobufSimpleReflection) { } } - Y_UNIT_TEST(MergeFromSelf) { + Y_UNIT_TEST(MergeFromSelf) { const TSample sample(GenSampleForMergeFrom()); TSample msg(sample); const Descriptor* descr = msg.GetDescriptor(); @@ -65,7 +65,7 @@ Y_UNIT_TEST_SUITE(ProtobufSimpleReflection) { UNIT_ASSERT_VALUES_EQUAL(msg.GetOneMsg().RepIntSize(), sample.GetOneMsg().RepIntSize()); } - Y_UNIT_TEST(MergeFromAnotherFD) { + Y_UNIT_TEST(MergeFromAnotherFD) { const TSample sample(GenSampleForMergeFrom()); TSample msg(GenSampleForMergeFrom()); const Descriptor* descr = msg.GetDescriptor(); @@ -96,7 +96,7 @@ Y_UNIT_TEST_SUITE(ProtobufSimpleReflection) { } } - Y_UNIT_TEST(RemoveByIndex) { + Y_UNIT_TEST(RemoveByIndex) { TSample msg; const Descriptor* descr = msg.GetDescriptor(); @@ -142,7 +142,7 @@ Y_UNIT_TEST_SUITE(ProtobufSimpleReflection) { } } - Y_UNIT_TEST(GetFieldByPath) { + Y_UNIT_TEST(GetFieldByPath) { // Simple get by path { TSample msg; diff --git a/library/cpp/protobuf/util/ut/common_ut.proto b/library/cpp/protobuf/util/ut/common_ut.proto index 638f13778c..9cf803ffbf 100644 --- a/library/cpp/protobuf/util/ut/common_ut.proto +++ b/library/cpp/protobuf/util/ut/common_ut.proto @@ -58,10 +58,10 @@ message TMergeTest { repeated TMergeTestMerge NoMergeRepSub = 4 [(DontMergeField)=true]; optional TMergeTestNoMerge NoMergeOptSub = 5; } - -message TTextTest { - optional uint32 Foo = 1; -} + +message TTextTest { + optional uint32 Foo = 1; +} message TTextEnumTest { enum EnumTest { diff --git a/library/cpp/protobuf/util/ut/ya.make b/library/cpp/protobuf/util/ut/ya.make index c358aac35c..701ba9a8c8 100644 --- a/library/cpp/protobuf/util/ut/ya.make +++ b/library/cpp/protobuf/util/ut/ya.make @@ -7,7 +7,7 @@ SRCS( sample_for_is_equal.proto sample_for_simple_reflection.proto common_ut.proto - pb_io_ut.cpp + pb_io_ut.cpp is_equal_ut.cpp iterators_ut.cpp simple_reflection_ut.cpp diff --git a/library/cpp/protobuf/util/walk_ut.cpp b/library/cpp/protobuf/util/walk_ut.cpp index 319e87983e..2ea6071b17 100644 --- a/library/cpp/protobuf/util/walk_ut.cpp +++ b/library/cpp/protobuf/util/walk_ut.cpp @@ -6,7 +6,7 @@ using namespace NProtoBuf; -Y_UNIT_TEST_SUITE(ProtobufWalk) { +Y_UNIT_TEST_SUITE(ProtobufWalk) { static void InitProto(NProtobufUtilUt::TWalkTest & p, int level = 0) { p.SetOptInt(1); p.AddRepInt(2); |