38 lines
1.1 KiB
C++
38 lines
1.1 KiB
C++
|
module;
|
||
|
#include <gtest/gtest.h>
|
||
|
export module tests.jid;
|
||
|
import larra.library.jid;
|
||
|
|
||
|
namespace larra::xmpp {
|
||
|
|
||
|
TEST(Jid, Basic) {
|
||
|
auto jid = Jid{.username = "user"};
|
||
|
EXPECT_FALSE(jid.IsValid());
|
||
|
|
||
|
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_EQ(jid.Username(), "user");
|
||
|
EXPECT_EQ(jid.Server(), "server");
|
||
|
EXPECT_EQ(jid.Resource(), "resource");
|
||
|
const auto jid2 = Jid::Parse("server/resource");
|
||
|
EXPECT_EQ(jid2.Server(), "server");
|
||
|
EXPECT_EQ(jid2.Resource(), "resource");
|
||
|
const auto jid3 = Jid::Parse("user@server");
|
||
|
EXPECT_EQ(jid3.Username(), "user");
|
||
|
EXPECT_EQ(jid3.Server(), "server");
|
||
|
}
|
||
|
|
||
|
TEST(Jid, ToString) {
|
||
|
EXPECT_EQ((Jid{.server = "server", .username = "user", .resource = "resource"}.ToString()), "user@server/resource");
|
||
|
EXPECT_EQ((Jid{.server = "server", .username = "user"}.ToString()), "user@server");
|
||
|
EXPECT_THROW(std::ignore = Jid{}.ToString(), std::invalid_argument);
|
||
|
}
|
||
|
|
||
|
} // namespace larra::xmpp
|