Files
logos-protocol/tests/protocol/test_mock_transport.cpp
Dario Lipicar 29afbac532 Extract the Logos protocol layer from logos-cpp-sdk (lp_* C ABI + protocol semver) (#2)
* Extract the Logos protocol layer from logos-cpp-sdk

Transports (plain TCP/TLS, qt_local, qt_remote/QRO, mock), token manager,
consumer core (LogosAPIClient/LogosAPIConsumer incl. the capability
auto-requestModule flow), ModuleProxy, the abstract LogosProviderObject
interface, and the canonical QVariant<->JSON conversion — now behind the
language-neutral lp_* C ABI (logos_protocol.h) carrying the protocol
semver (LOGOS_PROTOCOL_VERSION_*, lp_protocol_version()).

Bytes crossing the ABI use the lossless {"_bytes": base64url} tagging
(NUL-safe), matching the plain wire encoding.

Provider lp_* surface is compiled groundwork; serving lands with module
authoring.

* consumer: typed requestModule for the capability flow

Port of logos-cpp-sdk master f5a127dd ('use updated capability module',
cpp-sdk#85, Iuri Matias) — the touched files (logos_api_client.cpp,
logos_api_consumer.{h,cpp}) moved into this repo in the P1 extraction.
The capability auto-requestModule path now calls a typed std::string
helper on the consumer (which acquires the capability object directly)
instead of a stringly invokeRemoteMethod round-trip. 111/111 tests.
2026-06-12 18:59:01 -03:00

107 lines
2.5 KiB
C++

#include <gtest/gtest.h>
#include "mock_transport.h"
#include "mock_store.h"
class MockTransportTest : public ::testing::Test {
protected:
void SetUp() override
{
MockStore::instance().reset();
}
};
// -- MockTransportHost --
TEST_F(MockTransportTest, HostPublishObjectIsNoOp)
{
MockTransportHost host;
EXPECT_TRUE(host.publishObject("module", nullptr));
}
TEST_F(MockTransportTest, HostUnpublishObjectIsNoOp)
{
MockTransportHost host;
// Should not crash
host.unpublishObject("module");
}
// -- MockTransportConnection --
TEST_F(MockTransportTest, ConnectionAlwaysConnected)
{
MockTransportConnection conn;
EXPECT_TRUE(conn.isConnected());
}
TEST_F(MockTransportTest, ConnectToHostReturnsTrue)
{
MockTransportConnection conn;
EXPECT_TRUE(conn.connectToHost());
}
TEST_F(MockTransportTest, ReconnectReturnsTrue)
{
MockTransportConnection conn;
EXPECT_TRUE(conn.reconnect());
}
TEST_F(MockTransportTest, RequestObjectReturnsMockObject)
{
MockTransportConnection conn;
LogosObject* obj = conn.requestObject("test_mod", 5000);
ASSERT_NE(obj, nullptr);
obj->release();
}
// -- MockLogosObject --
TEST_F(MockTransportTest, CallMethodDelegatesToMockStore)
{
MockStore::instance().when("test_mod", "fn").thenReturn(QVariant(42));
MockLogosObject obj("test_mod");
QVariant r = obj.callMethod("auth", "fn", {}, 5000);
EXPECT_EQ(r.toInt(), 42);
EXPECT_TRUE(MockStore::instance().wasCalled("test_mod", "fn"));
}
TEST_F(MockTransportTest, CallMethodRecordsArgs)
{
MockLogosObject obj("mod");
obj.callMethod("auth", "fn", {QVariant("a"), QVariant("b")}, 5000);
EXPECT_TRUE(MockStore::instance().wasCalledWith("mod", "fn", {QVariant("a"), QVariant("b")}));
}
TEST_F(MockTransportTest, InformModuleTokenReturnsTrue)
{
MockLogosObject obj("mod");
EXPECT_TRUE(obj.informModuleToken("auth", "target", "tok", 5000));
}
TEST_F(MockTransportTest, EventOperationsAreNoOps)
{
MockLogosObject obj("mod");
// Should not crash
obj.onEvent("event", [](const QString&, const QVariantList&) {});
obj.disconnectEvents();
obj.emitEvent("event", {QVariant(1)});
}
TEST_F(MockTransportTest, GetMethodsReturnsEmptyArray)
{
MockLogosObject obj("mod");
EXPECT_TRUE(obj.getMethods().isEmpty());
}
TEST_F(MockTransportTest, IdReturnsNonZero)
{
MockLogosObject obj("mod");
EXPECT_NE(obj.id(), quintptr(0));
}
TEST_F(MockTransportTest, ModuleName)
{
MockLogosObject obj("my_module");
EXPECT_EQ(obj.moduleName(), "my_module");
}