Page MenuHomePhorge

serialization-test.cpp
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

serialization-test.cpp

/*
* This file is part of libkazv.
* SPDX-FileCopyrightText: 2021 Tusooa Zhu <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include <libkazv-config.hpp>
#include <catch2/catch_all.hpp>
#include <boost/asio.hpp>
#include <sstream>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <sdk-model.hpp>
#include <client.hpp>
#include <asio-promise-handler.hpp>
#include "client-test-util.hpp"
using namespace Kazv;
using IAr = boost::archive::text_iarchive;
using OAr = boost::archive::text_oarchive;
TEST_CASE("Serialize SdkModel", "[client][serialization]")
{
SdkModel m1;
SdkModel m2;
std::stringstream stream;
{
auto ar = OAr(stream);
ar << m1;
}
{
auto ar = IAr(stream);
ar >> m2;
}
}
TEST_CASE("Serialize LocalEchoDesc", "[client][serialization]")
{
LocalEchoDesc d1{
"some-txn-id",
json{
{"content", {{"lol", "lol"}}},
{"type", "m.room.message"},
},
LocalEchoDesc::Failed,
};
LocalEchoDesc d2;
std::stringstream stream;
{
auto ar = OAr(stream);
ar << d1;
}
{
auto ar = IAr(stream);
ar >> d2;
}
REQUIRE(d1 == d2);
}
TEST_CASE("Serialize LocalEchoDesc, always gives Failed", "[client][serialization]")
{
LocalEchoDesc d1{
"some-txn-id",
json{
{"content", {{"lol", "lol"}}},
{"type", "m.room.message"},
},
LocalEchoDesc::Sending,
};
LocalEchoDesc d2;
std::stringstream stream;
{
auto ar = OAr(stream);
ar << d1;
}
{
auto ar = IAr(stream);
ar >> d2;
}
REQUIRE(d2.status == LocalEchoDesc::Failed);
}
TEST_CASE("Serialize from Client to archive", "[client][serialization]")
{
boost::asio::io_context io;
AsioPromiseHandler ph{io.get_executor()};
auto store = createTestClientStore(ph);
auto c = Client(store.reader().map([](auto c) { return SdkModel{c}; }), store,
std::nullopt);
std::stringstream stream;
{
auto ar = OAr(stream);
c.serializeTo(ar);
}
}

File Metadata

Mime Type
text/x-c
Expires
Thu, Oct 2, 2:28 AM (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
471326
Default Alt Text
serialization-test.cpp (2 KB)

Event Timeline