#include #include namespace { static constexpr auto kExpectedData = "\n37\n"; struct SomeStruct { int value; constexpr auto operator==(const SomeStruct&) const -> bool = default; static constexpr auto kDefaultName = "some"; static constexpr auto Parse(xmlpp::Element* element) -> SomeStruct { auto node = element->get_first_child_text(); if(!node) { throw std::runtime_error{"Not found value"}; } return {std::stoi(node->get_content())}; } friend constexpr auto operator<<(xmlpp::Element* element, const SomeStruct& self) { auto node = element->add_child_text(std::to_string(self.value)); node->set_name("value"); } }; } // namespace namespace larra::xmpp { TEST(IQ, Serialize) { iq::Get iq{.id = "id", .payload = SomeStruct{.value = 37}}; // NOLINT xmlpp::Document doc; Serialization>::Serialize(doc.create_root_node("iq"), iq); EXPECT_EQ(doc.write_to_string(), kExpectedData); } TEST(IQ, Parse) { iq::Get iq{.id = "id", .payload = SomeStruct{.value = 37}}; // NOLINT xmlpp::Document doc; auto node = doc.create_root_node("iq"); using S = Serialization>; S::Serialize(node, iq); EXPECT_EQ(S::Parse(node), iq); } } // namespace larra::xmpp