larra/tests/roster.cpp

31 lines
1,020 B
C++
Raw Normal View History

2024-11-16 13:29:13 +00:00
#include <gtest/gtest.h>
#include <larra/roster.hpp>
#include <ranges>
#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");
using S = Serialization<iq::GetRoster>;
xmlpp::Document doc;
auto node = doc.create_root_node("iq");
node << roster;
auto parse_res = iq::Roster::Parse(node);
ASSERT_EQ(roster.payload.items.size(), parse_res.items.size());
for(const auto& [idx, expect_el, parsed_el] : std::views::zip(std::views::iota(0), roster.payload.items, parse_res.items)) {
EXPECT_EQ(expect_el, parsed_el) << "Mismatched on idx: " << idx;
// std::cerr << " " << "idx: " << idx << "; expect_el: " << expect_el << "; parsed_el: " << parsed_el << '\n';
}
}
} // namespace larra::xmpp