larra/tests/roster.cpp

37 lines
1.3 KiB
C++
Raw Normal View History

2024-11-17 23:29:51 +00:00
#include <gtest/gtest.h>
2024-11-18 23:04:57 +00:00
#include <larra/jid.hpp>
2024-11-17 23:29:51 +00:00
#include <larra/roster.hpp>
namespace larra::xmpp {
TEST(Roster, SerializeAndParse) {
FullJid jid{.username = "test", .server = "server", .resource = "res"}; // NOLINT
2024-11-18 23:04:57 +00:00
auto roster = iq::GetRoster{.id = "1", .from = ToString(jid), .payload = iq::Roster{.items = {{"u1", "s1"}, {"u2", "s2"}, {"u3", "s3"}}}};
2024-11-17 23:29:51 +00:00
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;
}
}
2024-11-18 23:04:57 +00:00
static constexpr std::string_view kRosterPrintExpectedData = "Roster: [\n\tu1@s1\n\tu2@s2\n\tu3@s3\n\t]";
2024-11-17 23:29:51 +00:00
TEST(Roster, Print) {
FullJid jid{.username = "test", .server = "server", .resource = "res"}; // NOLINT
2024-11-18 23:04:57 +00:00
auto roster = iq::GetRoster{.id = "1", .from = ToString(jid), .payload = iq::Roster{.items = {{"u1", "s1"}, {"u2", "s2"}, {"u3", "s3"}}}};
2024-11-17 23:29:51 +00:00
2024-11-18 23:04:57 +00:00
EXPECT_NO_THROW({
auto roster_str = ToString(roster.payload);
EXPECT_EQ(kRosterPrintExpectedData.length(), roster_str.capacity());
EXPECT_EQ(kRosterPrintExpectedData, roster_str);
});
2024-11-17 23:29:51 +00:00
}
} // namespace larra::xmpp