userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
oneof_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
11
#
include
"utils.hpp"
12
13
USERVER_NAMESPACE_BEGIN
14
15
namespace
protobuf::json::tests {
16
17
struct
OneofToJsonSuccessTestParam {
18
OneofMessageData
input = {};
19
std::string expected_json = {};
20
PrintOptions
options = {};
21
};
22
23
void
PrintTo(
const
OneofToJsonSuccessTestParam& param, std::ostream* os) {
24
*os << fmt::format(
25
"{{ input = {{.field1={}, .field2={}}} }}"
,
26
(param.input.field1 ? std::to_string(param.input.field1.value()) :
"nullopt"
),
27
param.input.field2.value_or(
"nullopt"
)
28
);
29
}
30
31
class
OneofToJsonSuccessTest :
public
::testing::TestWithParam<OneofToJsonSuccessTestParam> {};
32
33
INSTANTIATE_TEST_SUITE_P(
34
,
35
OneofToJsonSuccessTest,
36
::
testing
::Values(
37
OneofToJsonSuccessTestParam{OneofMessageData{}, R"({})"},
38
OneofToJsonSuccessTestParam{OneofMessageData{.field1 = 10}, R"({"field1":10})"},
39
OneofToJsonSuccessTestParam{OneofMessageData{.field2 =
"hello"
}, R"({"field2":"hello"})"}
40
)
41
);
42
43
TEST_P(OneofToJsonSuccessTest, Test) {
44
const
auto
& param = GetParam();
45
46
auto
input = PrepareTestData(param.input);
47
formats::
json
::
Value
json;
48
formats::
json
::
Value
expected_json;
49
formats::
json
::
Value
sample_json;
50
51
UASSERT_NO_THROW
((json = MessageToJson(input, param.options)));
52
UASSERT_NO_THROW
((expected_json = PrepareJsonTestData(param.expected_json)));
53
UASSERT_NO_THROW
((sample_json = CreateSampleJson(input, param.options)));
54
55
EXPECT_EQ(json, expected_json);
56
EXPECT_EQ(expected_json, sample_json);
57
}
58
59
}
// namespace protobuf::json::tests
60
61
USERVER_NAMESPACE_END
protobuf
tests
json
oneof_to_json_test.cpp
Generated on
for userver by
Doxygen
1.17.0