1#include <gtest/gtest.h>
9#include <userver/protobuf/json/convert.hpp>
10#include <userver/utest/assert_macros.hpp>
14USERVER_NAMESPACE_BEGIN
16namespace protobuf::json::tests {
18constexpr std::uint64_t kMax = std::numeric_limits<std::uint64_t>::max();
20struct UInt64ToJsonSuccessTestParam {
22 std::string expected_json = {};
23 PrintOptions options = {};
26void PrintTo(
const UInt64ToJsonSuccessTestParam& param, std::ostream* os) {
27 *os << fmt::format(
"{{ input = {{.field1={}, .field2={}}} }}", param.input.field1, param.input.field2);
30class UInt64ToJsonSuccessTest :
public ::testing::TestWithParam<UInt64ToJsonSuccessTestParam> {};
32INSTANTIATE_TEST_SUITE_P(
34 UInt64ToJsonSuccessTest,
37 UInt64ToJsonSuccessTestParam{
39 R"({"field1":"0","field2":"0"})",
40 {.always_print_fields_with_no_presence =
true}
42 UInt64ToJsonSuccessTestParam{
UInt64MessageData{1, 2}, R"({"field1":"1","field2":"2"})"},
43 UInt64ToJsonSuccessTestParam{
45 R"({"field1":"18446744073709551615","field2":"18446744073709551615"})"
50TEST_P(UInt64ToJsonSuccessTest, Test) {
51 const auto& param = GetParam();
53 auto input = PrepareTestData(param.input);
56 UASSERT_NO_THROW((json = MessageToJson(input, param.options)));
57 UASSERT_NO_THROW((expected_json = PrepareJsonTestData(param.expected_json)));
58 UASSERT_NO_THROW((sample_json = CreateSampleJson(input, param.options)));
60 EXPECT_EQ(json, expected_json);
61 EXPECT_EQ(expected_json, sample_json);