larra/tests/serialization.cpp

29 lines
1,003 B
C++
Raw Normal View History

2024-10-06 18:56:10 +00:00
#include <gtest/gtest.h>
#include <larra/serialization.hpp>
#include <larra/stream_error.hpp>
namespace larra::xmpp {
TEST(Parse, Variant) {
xmlpp::Document doc;
auto node = doc.create_root_node("stream:error");
node->add_child_element("unsupported-stanza-type");
node->set_namespace_declaration("urn:ietf:params:xml:ns:xmpp-streams");
auto streamError = Serialization<StreamError>::Parse(node);
EXPECT_TRUE(std::get_if<error::stream::UnsupportedStanzaType>(&streamError));
}
TEST(Serialize, Variant) {
using S = Serialization<StreamError>;
StreamError data = error::stream::UnsupportedStanzaType{};
xmlpp::Document doc;
auto node = doc.create_root_node("stream:error");
S::Serialize(node, data);
EXPECT_EQ(doc.write_to_string(),
std::string_view{"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<stream:error><unsupported-stanza-type "
"xmlns=\"urn:ietf:params:xml:ns:xmpp-streams\"/></stream:error>\n"});
}
} // namespace larra::xmpp