larra/tests/jid.cpp
2024-08-27 12:07:03 +00:00

47 lines
1.5 KiB
C++

module;
#include <gtest/gtest.h>
export module tests.jid;
import larra.library.jid;
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<FullJid>(&jid));
const auto& fullJid = std::get<FullJid>(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<BareResourceJid>(&jid2));
const auto& resourceJid = std::get<BareResourceJid>(jid2);
EXPECT_EQ(resourceJid.server, "server");
EXPECT_EQ(resourceJid.resource, "resource");
const auto jid3 = Jid::Parse("user@server");
EXPECT_TRUE(std::get_if<BareJid>(&jid3));
const auto& bareJid = std::get<BareJid>(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