#include #include #include namespace larra::xmpp { TEST(Roster, SerializeAndParse) { FullJid jid{.username = "test", .server = "server", .resource = "res"}; // NOLINT auto roster = iq::GetRoster{.id = "1", .from = jid, .payload = iq::Roster{.items = {{"u1", "s1"}, {"u2", "s2"}, {"u3", "s3"}}}}; xmlpp::Document doc; auto node = doc.create_root_node("iq"); node << roster; auto parse_res = decltype(roster)::Parse(node); ASSERT_EQ(roster.payload.items.size(), parse_res.payload.items.size()); for(const auto& [idx, expect_el, parsed_el] : std::views::zip(std::views::iota(0), roster.payload.items, parse_res.payload.items)) { EXPECT_EQ(expect_el, parsed_el) << "Mismatched on idx: " << idx; } } static constexpr std::string_view kRosterPrintExpectedData = "Roster: [\n\tu1@s1\n\tu2@s2\n\tu3@s3\n\t]"; TEST(Roster, Print) { FullJid jid{.username = "test", .server = "server", .resource = "res"}; // NOLINT auto roster = iq::GetRoster{.id = "1", .from = jid, .payload = iq::Roster{.items = {{"u1", "s1"}, {"u2", "s2"}, {"u3", "s3"}}}}; EXPECT_NO_THROW({ auto roster_str = ToString(roster.payload); EXPECT_EQ(kRosterPrintExpectedData.length(), roster_str.capacity()); EXPECT_EQ(kRosterPrintExpectedData, roster_str); }); } } // namespace larra::xmpp