userver: /data/code/userver/libraries/protobuf/tests/json/float_special_from_json_test.cpp Source File
Loading...
Searching...
No Matches
float_special_from_json_test.cpp
1#include <gtest/gtest.h>
2
3#include <userver/protobuf/json/convert.hpp>
4#include <userver/utest/assert_macros.hpp>
5
6#include "utils.hpp"
7
8USERVER_NAMESPACE_BEGIN
9
10namespace protobuf::json::tests {
11
12template <typename T>
13class FloatSpecialFromJsonTest : public ::testing::Test {
14public:
15 using Param = T;
16};
17
18using FpTypes = ::testing::Types<
19 FloatQuietNan,
20 FloatSignalingNan,
21 FloatPositiveInfinity,
22 FloatNegativeInfinity,
23 DoubleQuietNan,
24 DoubleSignalingNan,
25 DoublePositiveInfinity,
26 DoubleNegativeInfinity>;
27
28TYPED_TEST_SUITE(FloatSpecialFromJsonTest, FpTypes);
29
30TYPED_TEST(FloatSpecialFromJsonTest, Test) {
31 using Param = typename TestFixture::Param;
32 using Message = typename Param::Message;
33
34 if constexpr (Param::kSkip) {
35 return;
36 }
37
38 const auto& json = Param::kJson;
39 const auto& expected_data = Param::kValue;
40
41 Message message;
42 Message expected_message;
43 Message sample_message;
44 formats::json::Value input = PrepareJsonTestData(json);
45 expected_message = PrepareTestData(expected_data);
46
47 message.set_field1(100.001);
48
49 UASSERT_NO_THROW((message = JsonToMessage<Message>(input)));
50 UASSERT_NO_THROW(InitSampleMessage(json, sample_message));
51
52 CheckMessageEqual(message, sample_message);
53 CheckMessageEqual(message, expected_message);
54}
55
56} // namespace protobuf::json::tests
57
58USERVER_NAMESPACE_END