sha512sum
9d95d08ab7
All checks were successful
PR Check / on-push-commit-check (push) Successful in 11m53s
53 lines
1.5 KiB
C++
53 lines
1.5 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include <larra/jid.hpp>
|
|
#include <larra/message.hpp>
|
|
|
|
namespace larra::xmpp {
|
|
|
|
namespace {
|
|
|
|
auto CreateTestData() {
|
|
auto doc = std::make_unique<xmlpp::Document>();
|
|
auto node = doc->create_root_node("message");
|
|
node->set_attribute("from", "user1@server.i2p");
|
|
node->set_attribute("to", "user2@server.i2p");
|
|
node->set_attribute("type", "chat");
|
|
node->set_attribute("id", "1");
|
|
node->set_attribute("lang", "en", "xml");
|
|
|
|
auto bodyNode = node->add_child_element("body");
|
|
bodyNode->add_child_text("hello");
|
|
return doc;
|
|
}
|
|
|
|
const Message<BareJid, BareJid> kMessage{
|
|
.from = {.username = "user1", .server = "server.i2p"},
|
|
.to = {.username = "user2", .server = "server.i2p"},
|
|
.type = message::type::kChat,
|
|
.id = "1",
|
|
.language = "en",
|
|
.body = {{.content = "hello"}} //
|
|
};
|
|
|
|
} // namespace
|
|
|
|
TEST(Parse, Message) {
|
|
auto doc = CreateTestData();
|
|
auto node = doc->get_root_node();
|
|
auto message = Serialization<Message<BareJid, BareJid>>::Parse(node);
|
|
|
|
EXPECT_EQ(message, kMessage);
|
|
}
|
|
|
|
TEST(Serialize, Message) {
|
|
auto expected =
|
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<message from=\"user1@server.i2p\" to=\"user2@server.i2p\" type=\"chat\" id=\"1\" "
|
|
"xml:lang=\"en\"><body>hello</body></message>\n";
|
|
xmlpp::Document doc;
|
|
auto node = doc.create_root_node("message");
|
|
Serialization<Message<BareJid, BareJid>>::Serialize(node, kMessage);
|
|
EXPECT_EQ(doc.write_to_string(), expected);
|
|
}
|
|
|
|
} // namespace larra::xmpp
|