#include #include namespace larra::xmpp { TEST(Jid, Basic) { auto jid = FullJid{.username = "user"}; const auto jid2 = std::move(jid).Server("server").Resource("resource"); EXPECT_EQ(jid2.server, "server"); EXPECT_EQ(jid2.username, "user"); EXPECT_EQ(jid2.resource, "resource"); } TEST(Jid, Parse) { const auto jid = Jid::Parse("user@server/resource"); EXPECT_TRUE(std::get_if(&jid)); const auto& fullJid = std::get(jid); EXPECT_EQ(fullJid.username, "user"); EXPECT_EQ(fullJid.server, "server"); EXPECT_EQ(fullJid.resource, "resource"); const auto jid2 = Jid::Parse("server/resource"); EXPECT_TRUE(std::get_if(&jid2)); const auto& resourceJid = std::get(jid2); EXPECT_EQ(resourceJid.server, "server"); EXPECT_EQ(resourceJid.resource, "resource"); const auto jid3 = Jid::Parse("user@server"); EXPECT_TRUE(std::get_if(&jid3)); const auto& bareJid = std::get(jid3); EXPECT_EQ(bareJid.username, "user"); EXPECT_EQ(bareJid.server, "server"); } TEST(Jid, ToString) { EXPECT_EQ(ToString(FullJid{.username = "user", .server = "server", .resource = "resource"}), "user@server/resource"); EXPECT_EQ(ToString(BareJid{.username = "user", .server = "server"}), "user@server"); EXPECT_EQ(ToString(BareResourceJid{.server = "server", .resource = "resource"}), "server/resource"); } } // namespace larra::xmpp