1 parent
01362d2e51
commit
39aff68d8d
29 files changed
+2061
-1818
No files matched your search
@@ -0,0 +1,34 @@
|
||||
#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;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
#include "echoion/core/state/StateSerializer.hpp"
|
||||
#include "echoion/core/ListeningRoomName.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto normalized = Echoion::Core::validateListeningRoomName(" Focus Room ");
|
||||
if (!normalized || *normalized != "Focus Room" ||
|
||||
Echoion::Core::canonicalListeningRoomName(*normalized) != "focus room" ||
|
||||
Echoion::Core::validateListeningRoomName("\n\t") ||
|
||||
Echoion::Core::validateListeningRoomName(std::string(49, 'x'))) {
|
||||
std::cerr << "listening-room name validation failed\n";
|
||||
return 1;
|
||||
}
|
||||
Echoion::Core::StateV1 state;
|
||||
Echoion::Core::StateV1::ListeningRoomState room;
|
||||
room.name = "focus";
|
||||
room.ownerId = 17;
|
||||
room.members = {17, 23};
|
||||
room.playback.isPlaying = true;
|
||||
room.playback.position = std::chrono::milliseconds{42000};
|
||||
room.playbackPositionMs = 42000;
|
||||
room.autoplay = true;
|
||||
state.listeningRooms.push_back(std::move(room));
|
||||
|
||||
const auto blob = Echoion::Core::StateSerializer::serialize(state);
|
||||
const auto restored = Echoion::Core::StateSerializer::deserialize(blob);
|
||||
if (!restored || restored->listeningRooms.size() != 1) {
|
||||
std::cerr << "listening-room state did not round-trip\n";
|
||||
return 1;
|
||||
}
|
||||
const auto& actual = restored->listeningRooms.front();
|
||||
if (actual.name != "focus" || actual.ownerId != 17 ||
|
||||
actual.members != std::vector<uint64_t>({17, 23}) ||
|
||||
actual.playbackPositionMs != 42000 || !actual.autoplay) {
|
||||
std::cerr << "restored listening-room fields differ\n";
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
#include "echoion/core/TeamSpeakDirectoryService.hpp"
|
||||
#include "echoion/core/detail/RpcValidation.hpp"
|
||||
|
||||
#include <Void/Data/Json.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
class FakePlugin final : public Echoion::Api::IPluginInterface
|
||||
{
|
||||
public:
|
||||
|
||||
Echoion::Api::Result<void> initialize() override { return {}; }
|
||||
Echoion::Api::Result<void> shutdown() override { return {}; }
|
||||
Echoion::Api::Result<std::vector<Echoion::Api::ClientInfo>>
|
||||
getClients() override
|
||||
{
|
||||
return clients;
|
||||
}
|
||||
Echoion::Api::Result<std::optional<Echoion::Api::ClientInfo>>
|
||||
getClient(uint64_t id) override
|
||||
{
|
||||
for (const auto& client : clients) {
|
||||
if (client.id == id) {
|
||||
return client;
|
||||
}
|
||||
}
|
||||
return std::optional<Echoion::Api::ClientInfo>{};
|
||||
}
|
||||
Echoion::Api::Result<void> moveClient(uint64_t, uint64_t) override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
Echoion::Api::Result<void> kickClient(uint64_t,
|
||||
const std::string&) override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
Echoion::Api::Result<std::vector<Echoion::Api::ChannelInfo>>
|
||||
getChannels() const override
|
||||
{
|
||||
return channels;
|
||||
}
|
||||
Echoion::Api::Result<std::optional<Echoion::Api::ChannelInfo>>
|
||||
getChannel(uint64_t id) const override
|
||||
{
|
||||
for (const auto& channel : channels) {
|
||||
if (channel.id == id) {
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
return std::optional<Echoion::Api::ChannelInfo>{};
|
||||
}
|
||||
Echoion::Api::Result<void>
|
||||
sendTextMessage(uint64_t, const std::string&) override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
Echoion::Api::Result<void>
|
||||
sendChannelMessage(uint64_t, const std::string&) override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
Echoion::Api::Result<void>
|
||||
sendServerMessage(const std::string&) override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
Echoion::Api::Result<void>
|
||||
sendAudioData(const std::span<const short>&) override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
Echoion::Api::Result<void>
|
||||
setWhisperList(const std::vector<uint64_t>&) override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
Echoion::Api::Result<void>
|
||||
connectToServer(const Echoion::Api::ServerConfig&) override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
Echoion::Api::Result<void> disconnectFromServer() override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
bool isConnected() const override { return connected; }
|
||||
Echoion::Api::Result<void> reconnect() override { return {}; }
|
||||
void registerEventCallback(
|
||||
const Echoion::Api::EventCallback&) override
|
||||
{
|
||||
}
|
||||
void unregisterEventCallback(
|
||||
const Echoion::Api::EventCallback&) override
|
||||
{
|
||||
}
|
||||
Echoion::Api::Result<Echoion::Api::ServerInfo>
|
||||
getTeamSpeakServerInfo() override
|
||||
{
|
||||
return Echoion::Api::ServerInfo{
|
||||
.name = "Fixture", .welcomeMessage = "", .maxClients = 64};
|
||||
}
|
||||
|
||||
std::vector<Echoion::Api::ClientInfo> clients;
|
||||
std::vector<Echoion::Api::ChannelInfo> channels;
|
||||
bool connected = true;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
using Echoion::Api::ChannelInfo;
|
||||
using Echoion::Api::ClientInfo;
|
||||
using Echoion::Core::TeamSpeakDirectoryService;
|
||||
|
||||
const auto validId = Void::Json::parse(R"({"id":42})");
|
||||
const auto fractionalId = Void::Json::parse(R"({"id":1.5})");
|
||||
const auto negativeId = Void::Json::parse(R"({"id":-1})");
|
||||
const auto overflowingId =
|
||||
Void::Json::parse(R"({"id":18446744073709551616})");
|
||||
const auto enormousId = Void::Json::parse(R"({"id":1e100})");
|
||||
assert(validId && Echoion::Core::Detail::uintField(*validId, "id") == 42);
|
||||
assert(fractionalId &&
|
||||
!Echoion::Core::Detail::uintField(*fractionalId, "id"));
|
||||
assert(negativeId && !Echoion::Core::Detail::uintField(*negativeId, "id"));
|
||||
assert(overflowingId &&
|
||||
!Echoion::Core::Detail::uintField(*overflowingId, "id"));
|
||||
assert(enormousId && !Echoion::Core::Detail::uintField(*enormousId, "id"));
|
||||
|
||||
auto plugin = std::make_shared<FakePlugin>();
|
||||
plugin->channels = {
|
||||
ChannelInfo{.id = 2, .name = "Second", .parentId = 0, .order = 1},
|
||||
ChannelInfo{.id = 1, .name = "First", .parentId = 0, .order = 0},
|
||||
ChannelInfo{.id = 3, .name = "Child", .parentId = 1, .order = 0}};
|
||||
plugin->clients = {ClientInfo{.id = 10,
|
||||
.databaseId = 110,
|
||||
.nickname = "Visible",
|
||||
.uniqueIdentifier = "secret-uid",
|
||||
.channelId = 1,
|
||||
.isTalking = true,
|
||||
.serverGroups = {7}},
|
||||
ClientInfo{.id = 11,
|
||||
.databaseId = std::nullopt,
|
||||
.nickname = "Query Client",
|
||||
.uniqueIdentifier = "query-secret",
|
||||
.channelId = 1,
|
||||
.isQuery = true,
|
||||
.serverGroups = {}}};
|
||||
|
||||
TeamSpeakDirectoryService service;
|
||||
service.setPluginInterface(plugin);
|
||||
const auto publicJson = Void::Json::serialize(service.publicJson());
|
||||
assert(publicJson.contains("Visible"));
|
||||
assert(publicJson.find("First") < publicJson.find("Second"));
|
||||
assert(!publicJson.contains("Query Client"));
|
||||
assert(!publicJson.contains("secret-uid"));
|
||||
assert(!publicJson.contains("databaseId"));
|
||||
assert(!publicJson.contains("groups"));
|
||||
|
||||
const auto adminJson = Void::Json::serialize(service.adminJson());
|
||||
assert(adminJson.contains("secret-uid"));
|
||||
assert(adminJson.contains("databaseId"));
|
||||
assert(!adminJson.contains("Query Client"));
|
||||
|
||||
const auto ordered = TeamSpeakDirectoryService::orderChannels(
|
||||
{ChannelInfo{.id = 2, .name = "", .parentId = std::nullopt, .order = 1},
|
||||
ChannelInfo{.id = 1, .name = "", .parentId = std::nullopt, .order = 0},
|
||||
ChannelInfo{
|
||||
.id = 9, .name = "", .parentId = std::nullopt, .order = 99}});
|
||||
assert(ordered.size() == 3);
|
||||
assert(ordered[0].id == 1);
|
||||
assert(ordered[1].id == 2);
|
||||
assert(ordered[2].id == 9);
|
||||
|
||||
plugin->connected = false;
|
||||
plugin->clients.clear();
|
||||
plugin->channels.clear();
|
||||
service.handleEvent(Echoion::Api::PluginEventType::ChannelUpdated);
|
||||
const auto disconnected = Void::Json::serialize(service.publicJson());
|
||||
assert(disconnected.contains("\"connected\":false"));
|
||||
assert(!disconnected.contains("Visible"));
|
||||
}
|
||||
Reference in new issue
Block a user