#include "helpers.hpp" #include "utils/labeled_tuple.hpp" #include #include using namespace testing; struct TestingLabelDouble { static std::string str() { return "DoubleValue"; } }; struct TestingLabelString { static std::string str() { return "StringValue"; } }; using LabeledTestingTuple = utils::LabeledTuple, TestingLabelDouble, TestingLabelString>; class TestLabeledTupleDoubleSpecialization : public Test, public WithParamInterface< std::tuple>> { public: const std::string string_value = "Some value"; }; TEST_P(TestLabeledTupleDoubleSpecialization, serializeAndDeserializeMakesSameTuple) { auto [double_value, expected_serialized_value] = GetParam(); LabeledTestingTuple initial(double_value, string_value); nlohmann::json serialized(initial); EXPECT_EQ(serialized["StringValue"], string_value); auto& actual_serialized_value = serialized["DoubleValue"]; if (std::holds_alternative(expected_serialized_value)) { EXPECT_TRUE(actual_serialized_value.is_string()); EXPECT_EQ(actual_serialized_value.get(), std::get(expected_serialized_value)); } else { EXPECT_TRUE(actual_serialized_value.is_number()); EXPECT_EQ(actual_serialized_value.get(), std::get(expected_serialized_value)); } LabeledTestingTuple deserialized = serialized.get(); EXPECT_EQ(initial, deserialized); } INSTANTIATE_TEST_SUITE_P( _, TestLabeledTupleDoubleSpecialization, Values(std::make_tuple(10.0, std::variant(10.0)), std::make_tuple(std::numeric_limits::infinity(), std::variant("inf")), std::make_tuple(-std::numeric_limits::infinity(), std::variant("-inf")), std::make_tuple(std::numeric_limits::quiet_NaN(), std::variant("NaN")))); TEST(TestLabeledTupleDoubleSpecializationNegative, ThrowsWhenUnknownLiteralDuringDeserialization) { nlohmann::json data = nlohmann::json{{"DoubleValue", "FooBar"}, {"StringValue", "Some Text Val"}}; EXPECT_THROW(data.get(), std::invalid_argument); }