aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/protobuf/json/ut
diff options
context:
space:
mode:
authorVasily Gerasimov <UgnineSirdis@gmail.com>2022-02-10 16:49:09 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:09 +0300
commit6cdc8f140213c595e4ad38bc3d97fcef1146b8c3 (patch)
treef69637041e6fed76ebae0c74ae1fa0c4be6ab5b4 /library/cpp/protobuf/json/ut
parente5d4696304c6689379ac7ce334512404d4b7836c (diff)
downloadydb-6cdc8f140213c595e4ad38bc3d97fcef1146b8c3.tar.gz
Restoring authorship annotation for Vasily Gerasimov <UgnineSirdis@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/protobuf/json/ut')
-rw-r--r--library/cpp/protobuf/json/ut/filter_ut.cpp58
-rw-r--r--library/cpp/protobuf/json/ut/filter_ut.proto38
-rw-r--r--library/cpp/protobuf/json/ut/inline_ut.cpp62
-rw-r--r--library/cpp/protobuf/json/ut/inline_ut.proto20
-rw-r--r--library/cpp/protobuf/json/ut/proto2json_ut.cpp12
-rw-r--r--library/cpp/protobuf/json/ut/ya.make6
6 files changed, 98 insertions, 98 deletions
diff --git a/library/cpp/protobuf/json/ut/filter_ut.cpp b/library/cpp/protobuf/json/ut/filter_ut.cpp
index 95c227666f..a5f17f0230 100644
--- a/library/cpp/protobuf/json/ut/filter_ut.cpp
+++ b/library/cpp/protobuf/json/ut/filter_ut.cpp
@@ -1,47 +1,47 @@
#include <library/cpp/protobuf/json/ut/filter_ut.pb.h>
-
+
#include <library/cpp/protobuf/json/filter.h>
#include <library/cpp/protobuf/json/field_option.h>
#include <library/cpp/protobuf/json/proto2json.h>
#include <library/cpp/testing/unittest/registar.h>
-
-using namespace NProtobufJson;
-
-static NProtobufJsonUt::TFilterTest GetTestMsg() {
- NProtobufJsonUt::TFilterTest msg;
- msg.SetOptFiltered("1");
- msg.SetNotFiltered("23");
- msg.AddRepFiltered(45);
- msg.AddRepFiltered(67);
- msg.MutableInner()->AddNumber(100);
- msg.MutableInner()->AddNumber(200);
- msg.MutableInner()->SetInnerFiltered(235);
- return msg;
-}
-
+
+using namespace NProtobufJson;
+
+static NProtobufJsonUt::TFilterTest GetTestMsg() {
+ NProtobufJsonUt::TFilterTest msg;
+ msg.SetOptFiltered("1");
+ msg.SetNotFiltered("23");
+ msg.AddRepFiltered(45);
+ msg.AddRepFiltered(67);
+ msg.MutableInner()->AddNumber(100);
+ msg.MutableInner()->AddNumber(200);
+ msg.MutableInner()->SetInnerFiltered(235);
+ return msg;
+}
+
Y_UNIT_TEST_SUITE(TProto2JsonFilterTest){
Y_UNIT_TEST(TestFilterPrinter){
- NProtobufJsonUt::TFilterTest msg = GetTestMsg();
+ NProtobufJsonUt::TFilterTest msg = GetTestMsg();
{
TString expected = R"({"OptFiltered":"1","NotFiltered":"23","RepFiltered":[45,67],)"
R"("Inner":{"Number":[100,200],"InnerFiltered":235}})";
TString my = Proto2Json(msg);
UNIT_ASSERT_STRINGS_EQUAL(my, expected);
}
-
+
{
TString expected = R"({"NotFiltered":"23",)"
R"("Inner":{"Number":[100,200]}})";
TString my = PrintWithFilter(msg, MakeFieldOptionFunctor(NProtobufJsonUt::filter_test, false));
UNIT_ASSERT_STRINGS_EQUAL(my, expected);
}
-
+
{
TString expected = R"({"OptFiltered":"1","RepFiltered":[45,67]})";
TString my = PrintWithFilter(msg, MakeFieldOptionFunctor(NProtobufJsonUt::filter_test));
UNIT_ASSERT_STRINGS_EQUAL(my, expected);
}
-
+
{
TString expected = R"({"OptFiltered":"1","NotFiltered":"23",)"
R"("Inner":{"Number":[100,200]}})";
@@ -66,25 +66,25 @@ Y_UNIT_TEST(NoUnnecessaryCopyFunctor) {
struct TFunctorMock {
TFunctorMock(size_t* copyCount)
: CopyCount(copyCount)
- {
+ {
UNIT_ASSERT(*CopyCount <= 1);
- }
-
+ }
+
TFunctorMock(const TFunctorMock& f)
: CopyCount(f.CopyCount)
- {
+ {
++*CopyCount;
- }
-
+ }
+
TFunctorMock(TFunctorMock&& f) = default;
-
+
bool operator()(const NProtoBuf::Message&, const NProtoBuf::FieldDescriptor*) const {
return false;
}
-
+
size_t* CopyCount;
};
-
+
TProto2JsonConfig cfg;
TFilteringPrinter<> printer(TFunctorMock(&CopyCount), cfg);
UNIT_ASSERT(CopyCount <= 1);
diff --git a/library/cpp/protobuf/json/ut/filter_ut.proto b/library/cpp/protobuf/json/ut/filter_ut.proto
index 29d630ade4..c4866ed813 100644
--- a/library/cpp/protobuf/json/ut/filter_ut.proto
+++ b/library/cpp/protobuf/json/ut/filter_ut.proto
@@ -1,20 +1,20 @@
import "google/protobuf/descriptor.proto";
-
-package NProtobufJsonUt;
-
-extend google.protobuf.FieldOptions {
- optional bool filter_test = 58255;
- optional bool export_test = 58256;
-}
-
-message TFilterTest {
- optional string OptFiltered = 1 [(filter_test) = true, (export_test) = true];
- optional string NotFiltered = 2 [(export_test) = true];
- repeated uint64 RepFiltered = 3 [(filter_test) = true];
-
- message TInner {
- repeated uint32 Number = 1 [(export_test) = true];
- optional int32 InnerFiltered = 2 [(filter_test) = true];
- }
- optional TInner Inner = 4 [(export_test) = true];
-}
+
+package NProtobufJsonUt;
+
+extend google.protobuf.FieldOptions {
+ optional bool filter_test = 58255;
+ optional bool export_test = 58256;
+}
+
+message TFilterTest {
+ optional string OptFiltered = 1 [(filter_test) = true, (export_test) = true];
+ optional string NotFiltered = 2 [(export_test) = true];
+ repeated uint64 RepFiltered = 3 [(filter_test) = true];
+
+ message TInner {
+ repeated uint32 Number = 1 [(export_test) = true];
+ optional int32 InnerFiltered = 2 [(filter_test) = true];
+ }
+ optional TInner Inner = 4 [(export_test) = true];
+}
diff --git a/library/cpp/protobuf/json/ut/inline_ut.cpp b/library/cpp/protobuf/json/ut/inline_ut.cpp
index c29ad32e7d..048e3fa275 100644
--- a/library/cpp/protobuf/json/ut/inline_ut.cpp
+++ b/library/cpp/protobuf/json/ut/inline_ut.cpp
@@ -9,42 +9,42 @@
using namespace NProtobufJson;
-static NProtobufJsonUt::TInlineTest GetTestMsg() {
- NProtobufJsonUt::TInlineTest msg;
- msg.SetOptJson(R"({"a":1,"b":"000"})");
- msg.SetNotJson("12{}34");
- msg.AddRepJson("{}");
- msg.AddRepJson("[1,2]");
- msg.MutableInner()->AddNumber(100);
- msg.MutableInner()->AddNumber(200);
- msg.MutableInner()->SetInnerJson(R"({"xxx":[]})");
- return msg;
-}
-
+static NProtobufJsonUt::TInlineTest GetTestMsg() {
+ NProtobufJsonUt::TInlineTest msg;
+ msg.SetOptJson(R"({"a":1,"b":"000"})");
+ msg.SetNotJson("12{}34");
+ msg.AddRepJson("{}");
+ msg.AddRepJson("[1,2]");
+ msg.MutableInner()->AddNumber(100);
+ msg.MutableInner()->AddNumber(200);
+ msg.MutableInner()->SetInnerJson(R"({"xxx":[]})");
+ return msg;
+}
+
Y_UNIT_TEST_SUITE(TProto2JsonInlineTest){
Y_UNIT_TEST(TestNormalPrint){
- NProtobufJsonUt::TInlineTest msg = GetTestMsg();
+ 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]"],)"
R"("Inner":{"Number":[100,200],"InnerJson":"{\"xxx\":[]}"}})";
TString myRaw;
Proto2Json(msg, myRaw);
UNIT_ASSERT_STRINGS_EQUAL(myRaw, expRaw);
-
+
myRaw = PrintInlined(msg, [](const NProtoBuf::Message&, const NProtoBuf::FieldDescriptor*) { return false; });
UNIT_ASSERT_STRINGS_EQUAL(myRaw, expRaw); // result is the same
}
-
+
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]],)"
R"("Inner":{"Number":[100,200],"InnerJson":{"xxx":[]}}})";
-
+
{
TString myInlined = PrintInlined(msg, MakeFieldOptionFunctor(NProtobufJsonUt::inline_test));
UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined);
- }
+ }
{
auto functor = [](const NProtoBuf::Message&, const NProtoBuf::FieldDescriptor* field) {
return field->name() == "OptJson" || field->name() == "RepJson" || field->name() == "InnerJson";
@@ -53,7 +53,7 @@ Y_UNIT_TEST(TestInliningPrinter) {
UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined);
}
}
-
+
Y_UNIT_TEST(TestNoValues) {
// no values - no printing
NProtobufJsonUt::TInlineTest msg;
@@ -61,35 +61,35 @@ Y_UNIT_TEST(TestNoValues) {
msg.MutableInner()->AddNumber(200);
TString expInlined = R"({"Inner":{"Number":[100,200]}})";
-
+
TString myInlined = PrintInlined(msg, MakeFieldOptionFunctor(NProtobufJsonUt::inline_test));
UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined);
}
-
+
Y_UNIT_TEST(TestMissingKeyModeNull) {
NProtobufJsonUt::TInlineTest msg;
msg.MutableInner()->AddNumber(100);
msg.MutableInner()->AddNumber(200);
-
+
TString expInlined = R"({"OptJson":null,"NotJson":null,"RepJson":null,"Inner":{"Number":[100,200],"InnerJson":null}})";
-
+
TProto2JsonConfig cfg;
cfg.SetMissingSingleKeyMode(TProto2JsonConfig::MissingKeyNull).SetMissingRepeatedKeyMode(TProto2JsonConfig::MissingKeyNull);
TString myInlined = PrintInlined(msg, MakeFieldOptionFunctor(NProtobufJsonUt::inline_test), cfg);
UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined);
}
-
+
Y_UNIT_TEST(TestMissingKeyModeDefault) {
NProtobufJsonUt::TInlineTestDefaultValues msg;
-
+
TString expInlined = R"({"OptJson":{"default":1},"Number":0,"RepJson":[],"Inner":{"OptJson":{"default":2}}})";
-
+
TProto2JsonConfig cfg;
cfg.SetMissingSingleKeyMode(TProto2JsonConfig::MissingKeyDefault).SetMissingRepeatedKeyMode(TProto2JsonConfig::MissingKeyDefault);
TString myInlined = PrintInlined(msg, MakeFieldOptionFunctor(NProtobufJsonUt::inline_test), cfg);
UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined);
}
-
+
Y_UNIT_TEST(NoUnnecessaryCopyFunctor) {
size_t CopyCount = 0;
struct TFunctorMock {
@@ -98,22 +98,22 @@ Y_UNIT_TEST(NoUnnecessaryCopyFunctor) {
{
UNIT_ASSERT(*CopyCount <= 1);
}
-
+
TFunctorMock(const TFunctorMock& f)
: CopyCount(f.CopyCount)
{
++*CopyCount;
}
-
+
TFunctorMock(TFunctorMock&& f) = default;
-
+
bool operator()(const NProtoBuf::Message&, const NProtoBuf::FieldDescriptor*) const {
return false;
}
-
+
size_t* CopyCount;
};
-
+
TProto2JsonConfig cfg;
TInliningPrinter<> printer(TFunctorMock(&CopyCount), cfg);
UNIT_ASSERT(CopyCount <= 1);
diff --git a/library/cpp/protobuf/json/ut/inline_ut.proto b/library/cpp/protobuf/json/ut/inline_ut.proto
index 76bd10232d..147c3369dd 100644
--- a/library/cpp/protobuf/json/ut/inline_ut.proto
+++ b/library/cpp/protobuf/json/ut/inline_ut.proto
@@ -17,13 +17,13 @@ message TInlineTest {
}
optional TInner Inner = 4;
}
-
-message TInlineTestDefaultValues {
- optional string OptJson = 1 [(inline_test) = true, default = "{\"default\":1}"];
- optional uint32 Number = 2;
- repeated string RepJson = 3 [(inline_test) = true];
- message TInner {
- optional string OptJson = 1 [(inline_test) = true, default = "{\"default\":2}"];
- }
- optional TInner Inner = 4;
-}
+
+message TInlineTestDefaultValues {
+ optional string OptJson = 1 [(inline_test) = true, default = "{\"default\":1}"];
+ optional uint32 Number = 2;
+ repeated string RepJson = 3 [(inline_test) = true];
+ message TInner {
+ optional string OptJson = 1 [(inline_test) = true, default = "{\"default\":2}"];
+ }
+ optional TInner Inner = 4;
+}
diff --git a/library/cpp/protobuf/json/ut/proto2json_ut.cpp b/library/cpp/protobuf/json/ut/proto2json_ut.cpp
index 07e52d7f2f..9dbec774e2 100644
--- a/library/cpp/protobuf/json/ut/proto2json_ut.cpp
+++ b/library/cpp/protobuf/json/ut/proto2json_ut.cpp
@@ -20,8 +20,8 @@
#include <util/system/defaults.h>
#include <util/system/yassert.h>
-#include <limits>
-
+#include <limits>
+
using namespace NProtobufJson;
using namespace NProtobufJsonTest;
@@ -887,18 +887,18 @@ Y_UNIT_TEST(TestFieldNameMode) {
/// TODO: test missing keys
} // TestFieldNameMode
-
+
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) {
TFlatOptional proto;
proto.SetFloat(std::numeric_limits<float>::infinity());
-
+
UNIT_ASSERT_EXCEPTION(Proto2Json(proto, TProto2JsonConfig()), yexception);
} // TestInf
diff --git a/library/cpp/protobuf/json/ut/ya.make b/library/cpp/protobuf/json/ut/ya.make
index b60a6d3c17..ac6aebeab8 100644
--- a/library/cpp/protobuf/json/ut/ya.make
+++ b/library/cpp/protobuf/json/ut/ya.make
@@ -3,14 +3,14 @@ UNITTEST_FOR(library/cpp/protobuf/json)
OWNER(avitella)
SRCS(
- filter_ut.cpp
+ filter_ut.cpp
json2proto_ut.cpp
proto2json_ut.cpp
inline_ut.proto
inline_ut.cpp
string_transform_ut.cpp
- filter_ut.proto
- test.proto
+ filter_ut.proto
+ test.proto
util_ut.cpp
)