Files
EchoionCore/tests/test_extension_state.cpp
faumaray 39aff68d8d Update
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-15 19:49:57 +03:00

35 lines
1.1 KiB
C++

#include "echoion/core/state/StateSerializer.hpp"
#include <iostream>
#include <string>
int main()
{
Echoion::Core::StateV1 state;
state.extensionPlugins.push_back({.name = "example", .json = "{\"v\":1}",
.version = 3});
auto blob = Echoion::Core::StateSerializer::serialize(state);
std::string json{blob.data.begin(), blob.data.end()};
// State written by the removed experimental rooms build must remain safe to
// load during a hot reload. Void reflection intentionally ignores unknown
// root fields, so the obsolete payload is discarded rather than rejected.
json.insert(json.rfind('}'),
R"(,"listeningRooms":[{"name":"legacy","subscribers":["uid"]}])");
blob.data.assign(json.begin(), json.end());
const auto restored = Echoion::Core::StateSerializer::deserialize(blob);
if (!restored) {
std::cerr << "extension state did not deserialize: "
<< restored.error().message << '\n';
return 1;
}
if (restored->extensionPlugins.size() != 1 ||
restored->extensionPlugins.front().name != "example" ||
restored->extensionPlugins.front().version != 3) {
std::cerr << "extension plugin state did not round-trip\n";
return 1;
}
return 0;
}