larra/tests/jid.cpp

46 lines
1.4 KiB
C++
Raw Permalink Normal View History

2024-08-27 10:11:02 +00:00
#include <gtest/gtest.h>
2024-08-30 13:00:01 +00:00
#include <larra/jid.hpp>
2024-08-27 10:11:02 +00:00
namespace larra::xmpp {
TEST(Jid, Basic) {
2024-08-27 11:53:22 +00:00
auto jid = FullJid{.username = "user"};
2024-08-27 10:11:02 +00:00
const auto jid2 = std::move(jid).Server("server").Resource("resource");
2024-08-27 11:53:22 +00:00
EXPECT_EQ(jid2.server, "server");
EXPECT_EQ(jid2.username, "user");
EXPECT_EQ(jid2.resource, "resource");
2024-08-27 10:11:02 +00:00
}
TEST(Jid, Parse) {
const auto jid = Jid::Parse("user@server/resource");
2024-08-27 11:53:22 +00:00
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");
2024-08-27 10:11:02 +00:00
const auto jid2 = Jid::Parse("server/resource");
2024-08-27 11:53:22 +00:00
EXPECT_TRUE(std::get_if<BareResourceJid>(&jid2));
const auto& resourceJid = std::get<BareResourceJid>(jid2);
EXPECT_EQ(resourceJid.server, "server");
EXPECT_EQ(resourceJid.resource, "resource");
2024-08-27 10:11:02 +00:00
const auto jid3 = Jid::Parse("user@server");
2024-08-27 11:53:22 +00:00
EXPECT_TRUE(std::get_if<BareJid>(&jid3));
const auto& bareJid = std::get<BareJid>(jid3);
EXPECT_EQ(bareJid.username, "user");
EXPECT_EQ(bareJid.server, "server");
2024-08-27 10:11:02 +00:00
}
TEST(Jid, ToString) {
2024-08-27 11:53:22 +00:00
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");
2024-08-27 10:11:02 +00:00
}
} // namespace larra::xmpp