#include #include namespace larra::xmpp { constexpr std::string_view kSerializedData = R"( )"; constexpr std::string_view kCheckSerializeData = "\n\n"; TEST(Stream, Serialize) { UserStream originalStream; originalStream.from = BareJid{.username = "user", .server = "example.com"}; originalStream.to = "example.com"; originalStream.id = "abc"; originalStream.version = "1.0"; originalStream.xmlLang = "en"; xmlpp::Document doc; auto streamNode = doc.create_root_node(UserStream::kDefaultName, UserStream::kDefaultNamespace, UserStream::kDefaultPrefix); streamNode << originalStream; const std::string serializedData = doc.write_to_string(); ASSERT_EQ(serializedData, kCheckSerializeData); } TEST(Stream, Deserialize) { xmlpp::DomParser parser; parser.parse_memory(static_cast(kSerializedData)); auto parsedDoc = parser.get_document(); const UserStream deserializedStream = UserStream::Parse(parsedDoc->get_root_node()); ASSERT_TRUE(deserializedStream.from.has_value()); ASSERT_EQ(ToString(*deserializedStream.from), "user@example.com"); ASSERT_FALSE(deserializedStream.to.has_value()); ASSERT_TRUE(deserializedStream.id.has_value()); ASSERT_EQ(deserializedStream.id.value(), "abc"); ASSERT_TRUE(deserializedStream.version.has_value()); ASSERT_EQ(deserializedStream.version.value(), "1.0"); ASSERT_TRUE(deserializedStream.xmlLang.has_value()); ASSERT_EQ(deserializedStream.xmlLang.value(), "en"); } } // namespace larra::xmpp