1#include <gtest/gtest.h>
8#include <userver/protobuf/json/convert.hpp>
9#include <userver/utest/assert_macros.hpp>
10#include <userver/utils/encoding/hex.hpp>
14USERVER_NAMESPACE_BEGIN
18struct BytesToJsonSuccessTestParam {
20 std::string expected_json = {};
21 WriteOptions options = {};
24void PrintTo(
const BytesToJsonSuccessTestParam& param, std::ostream* os) {
25 *os << fmt::format(
"{{ input = {{.field1='{}'}} }}", utils
::encoding
::ToHex(param.input.field1
));
28class BytesToJsonSuccessTest :
public ::testing::TestWithParam<BytesToJsonSuccessTestParam> {};
30INSTANTIATE_TEST_SUITE_P(
32 BytesToJsonSuccessTest,
34 BytesToJsonSuccessTestParam{BytesMessageData{
""}, R"({})"},
35 BytesToJsonSuccessTestParam{
38 WriteOptions{.always_print_fields_with_no_presence =
true}
40 BytesToJsonSuccessTestParam{BytesMessageData{std::string(
"\xfb\xfb", 2)}, R"({"field1":"+/s="})"}
44TEST_P(BytesToJsonSuccessTest, Test) {
45 const auto& param = GetParam();
47 auto input = PrepareTestData(param.input);
48 formats::json::Value json, expected_json, sample_json;
50 UASSERT_NO_THROW((json = MessageToJson(input, param.options)));
51 UASSERT_NO_THROW((expected_json = PrepareJsonTestData(param.expected_json)));
52 UASSERT_NO_THROW((sample_json = CreateSampleJson(input, param.options)));
54 EXPECT_EQ(json, expected_json);
55 EXPECT_EQ(expected_json, sample_json);