Ivan-lis
a4e973ca32
All checks were successful
PR Check / on-push-commit-check (push) Successful in 11m42s
36 lines
1.3 KiB
C++
36 lines
1.3 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include <larra/jid.hpp>
|
|
#include <larra/roster.hpp>
|
|
|
|
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 parseRes = decltype(roster)::Parse(node);
|
|
|
|
ASSERT_EQ(roster.payload.items.size(), parseRes.payload.items.size());
|
|
for(const auto& [idx, expectEl, parsedEl] : std::views::zip(std::views::iota(0), roster.payload.items, parseRes.payload.items)) {
|
|
EXPECT_EQ(expectEl, parsedEl) << "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 rosterStr = ToString(roster.payload);
|
|
EXPECT_EQ(kRosterPrintExpectedData.length(), rosterStr.capacity());
|
|
EXPECT_EQ(kRosterPrintExpectedData, rosterStr);
|
|
});
|
|
}
|
|
|
|
} // namespace larra::xmpp
|