#include #include #include namespace larra::xmpp { namespace { auto CreateTestData() { auto doc = std::make_unique(); 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 kMessage{ .from = {.username = "user1", .server = "server.i2p"}, .to = {.username = "user2", .server = "server.i2p"}, .type = message::type::kChat, .id = "1", .language = "en", .body = {message::Body{.content = "hello"}} // }; } // namespace TEST(Parse, Message) { auto doc = CreateTestData(); auto node = doc->get_root_node(); auto message = Serialization>::Parse(node); EXPECT_EQ(message, kMessage); } TEST(Serialize, Message) { auto expected = CreateTestData()->write_to_string(); xmlpp::Document doc; auto node = doc.create_root_node("message"); Serialization>::Serialize(node, kMessage); EXPECT_EQ(doc.write_to_string(), expected); } } // namespace larra::xmpp