2024-08-30 13:01:35 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include <larra/stream.hpp>
|
|
|
|
|
|
|
|
namespace larra::xmpp {
|
|
|
|
|
|
|
|
constexpr std::string_view kSerializedData =
|
|
|
|
R"(<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' xml:lang='en' version='1.0' id='abc' from='user@example.com' />
|
|
|
|
)";
|
|
|
|
|
|
|
|
constexpr std::string_view kCheckSerializeData =
|
2024-09-03 15:36:08 +00:00
|
|
|
R"(<stream:stream from="user@example.com" to="example.com" id="abc" version="1.0" xml:lang="en" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" />
|
2024-08-30 13:01:35 +00:00
|
|
|
)";
|
|
|
|
|
|
|
|
TEST(Stream, Serialize) {
|
2024-09-03 15:36:08 +00:00
|
|
|
UserStream originalStream;
|
2024-08-30 13:01:35 +00:00
|
|
|
originalStream.from = BareJid{"user", "example.com"};
|
2024-09-03 15:36:08 +00:00
|
|
|
originalStream.to = "example.com";
|
2024-08-30 13:01:35 +00:00
|
|
|
originalStream.id = "abc";
|
|
|
|
originalStream.version = "1.0";
|
|
|
|
originalStream.xmlLang = "en";
|
|
|
|
|
|
|
|
pugi::xml_document doc;
|
|
|
|
pugi::xml_node streamNode = doc.append_child("stream:stream");
|
|
|
|
streamNode << originalStream;
|
|
|
|
|
|
|
|
std::ostringstream oss;
|
|
|
|
doc.child("stream:stream").print(oss, "\t");
|
|
|
|
const std::string serializedData = oss.str();
|
|
|
|
|
|
|
|
ASSERT_EQ(serializedData, kCheckSerializeData);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Stream, Deserialize) {
|
|
|
|
pugi::xml_document parsedDoc;
|
|
|
|
parsedDoc.load_string(kSerializedData.data());
|
|
|
|
|
|
|
|
const UserStream deserializedStream = UserStream::Parse(parsedDoc.child("stream:stream"));
|
|
|
|
ASSERT_TRUE(deserializedStream.from.has_value());
|
|
|
|
ASSERT_EQ(ToString(*deserializedStream.from), "user@example.com");
|
|
|
|
|
|
|
|
ASSERT_FALSE(deserializedStream.to.has_value());
|
|
|
|
|
|
|
|
ASSERT_TRUE(deserializedStream.id.has_value());
|
|
|
|
ASSERT_EQ(deserializedStream.id.value(), "abc");
|
|
|
|
|
|
|
|
ASSERT_TRUE(deserializedStream.version.has_value());
|
|
|
|
ASSERT_EQ(deserializedStream.version.value(), "1.0");
|
|
|
|
|
|
|
|
ASSERT_TRUE(deserializedStream.xmlLang.has_value());
|
|
|
|
ASSERT_EQ(deserializedStream.xmlLang.value(), "en");
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace larra::xmpp
|