larra/tests/roster.cpp
Ivan-lis 7685385559
Some checks failed
PR Check / on-push-commit-check (push) Failing after 11m10s
Feature: iq::Roster
2024-11-17 23:29:51 +00:00

39 lines
1.4 KiB
C++

#include <gtest/gtest.h>
#include <larra/roster.hpp>
#include "larra/jid.hpp"
namespace larra::xmpp {
TEST(Roster, SerializeAndParse) {
FullJid jid{.username = "test", .server = "server", .resource = "res"}; // NOLINT
auto roster = iq::MakeGetRoster(jid);
roster.payload.items.emplace_back("u1", "s1");
roster.payload.items.emplace_back("u2", "s2");
roster.payload.items.emplace_back("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;
// std::cerr << " " << "idx: " << idx << "; expect_el: " << expect_el << "; parsed_el: " << parsed_el << '\n';
}
}
TEST(Roster, Print) {
FullJid jid{.username = "test", .server = "server", .resource = "res"}; // NOLINT
auto roster = iq::MakeGetRoster(jid);
roster.payload.items.emplace_back("u1", "s1");
roster.payload.items.emplace_back("u2", "s2");
roster.payload.items.emplace_back("u3", "s3");
EXPECT_NO_THROW({ std::cerr << "[ ] Roster payload: " << ToString(roster.payload) << '\n'; });
}
} // namespace larra::xmpp