userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
bytes_to_json_test.cpp
1
#
include
<
gtest
/
gtest
.
h
>
2
3
#
include
<
ostream
>
4
#
include
<
string
>
5
6
#
include
<
fmt
/
format
.
h
>
7
8
#
include
<
userver
/
protobuf
/
json
/
convert
.
hpp
>
9
#
include
<
userver
/
utest
/
assert_macros
.
hpp
>
10
#
include
<
userver
/
utils
/
encoding
/
hex
.
hpp
>
11
12
#
include
"utils.hpp"
13
14
USERVER_NAMESPACE_BEGIN
15
16
namespace
protobuf::json::tests {
17
18
struct
BytesToJsonSuccessTestParam {
19
BytesMessageData
input = {};
20
std::string expected_json = {};
21
PrintOptions
options = {};
22
};
23
24
void
PrintTo(
const
BytesToJsonSuccessTestParam& param, std::ostream* os) {
25
*os << fmt::format(
"{{ input = {{.field1='{}'}} }}"
,
utils
::
encoding
::
ToHex
(
param.input.field1
)
);
26
}
27
28
class
BytesToJsonSuccessTest :
public
::testing::TestWithParam<BytesToJsonSuccessTestParam> {};
29
30
INSTANTIATE_TEST_SUITE_P(
31
,
32
BytesToJsonSuccessTest,
33
::
testing
::Values(
34
BytesToJsonSuccessTestParam{BytesMessageData{
""
}, R"({})"},
35
BytesToJsonSuccessTestParam{
36
BytesMessageData{
""
},
37
R"({"field1":""})",
38
{.
always_print_fields_with_no_presence
=
true
}
39
},
40
BytesToJsonSuccessTestParam{
BytesMessageData
{std::string(
"\xfb\xfb"
, 2)}, R"({"field1":"+/s="})"}
41
)
42
);
43
44
TEST_P(BytesToJsonSuccessTest, Test) {
45
const
auto
& param = GetParam();
46
47
auto
input = PrepareTestData(param.input);
48
formats::
json
::
Value
json;
49
formats::
json
::
Value
expected_json;
50
formats::
json
::
Value
sample_json;
51
52
UASSERT_NO_THROW
((json = MessageToJson(input, param.options)));
53
UASSERT_NO_THROW
((expected_json = PrepareJsonTestData(param.expected_json)));
54
UASSERT_NO_THROW
((sample_json = CreateSampleJson(input, param.options)));
55
56
EXPECT_EQ(json, expected_json);
57
EXPECT_EQ(expected_json, sample_json);
58
}
59
60
}
// namespace protobuf::json::tests
61
62
USERVER_NAMESPACE_END
protobuf
tests
json
bytes_to_json_test.cpp
Generated on
for userver by
Doxygen
1.17.0