mirror of
https://github.com/logos-co/logos-protocol.git
synced 2026-08-30 13:31:12 +00:00
* 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.
112 lines
3.4 KiB
C++
112 lines
3.4 KiB
C++
#include <gtest/gtest.h>
|
|
#include "mock_store.h"
|
|
|
|
class MockStoreTest : public ::testing::Test {
|
|
protected:
|
|
void SetUp() override
|
|
{
|
|
MockStore::instance().reset();
|
|
}
|
|
};
|
|
|
|
TEST_F(MockStoreTest, WhenThenReturn)
|
|
{
|
|
MockStore::instance().when("mod", "method").thenReturn(QVariant(42));
|
|
|
|
QVariant result = MockStore::instance().recordAndReturn("mod", "method", {});
|
|
EXPECT_EQ(result.toInt(), 42);
|
|
}
|
|
|
|
TEST_F(MockStoreTest, WithArgsMatching)
|
|
{
|
|
MockStore::instance().when("mod", "greet")
|
|
.withArgs({QVariant("hello")})
|
|
.thenReturn(QVariant("world"));
|
|
|
|
QVariant hit = MockStore::instance().recordAndReturn("mod", "greet", {QVariant("hello")});
|
|
EXPECT_EQ(hit.toString(), "world");
|
|
|
|
QVariant miss = MockStore::instance().recordAndReturn("mod", "greet", {QVariant("bye")});
|
|
EXPECT_FALSE(miss.isValid());
|
|
}
|
|
|
|
TEST_F(MockStoreTest, MatchAnyArgsByDefault)
|
|
{
|
|
MockStore::instance().when("mod", "fn").thenReturn(QVariant(true));
|
|
|
|
QVariant r = MockStore::instance().recordAndReturn("mod", "fn", {QVariant(1), QVariant(2)});
|
|
EXPECT_TRUE(r.toBool());
|
|
}
|
|
|
|
TEST_F(MockStoreTest, LIFOOrder)
|
|
{
|
|
MockStore::instance().when("mod", "fn").thenReturn(QVariant("first"));
|
|
MockStore::instance().when("mod", "fn").thenReturn(QVariant("second"));
|
|
|
|
QVariant r = MockStore::instance().recordAndReturn("mod", "fn", {});
|
|
EXPECT_EQ(r.toString(), "second");
|
|
}
|
|
|
|
TEST_F(MockStoreTest, NoMatchReturnsInvalid)
|
|
{
|
|
QVariant r = MockStore::instance().recordAndReturn("mod", "noSuchMethod", {});
|
|
EXPECT_FALSE(r.isValid());
|
|
}
|
|
|
|
TEST_F(MockStoreTest, WasCalled)
|
|
{
|
|
EXPECT_FALSE(MockStore::instance().wasCalled("mod", "fn"));
|
|
|
|
MockStore::instance().recordAndReturn("mod", "fn", {});
|
|
EXPECT_TRUE(MockStore::instance().wasCalled("mod", "fn"));
|
|
}
|
|
|
|
TEST_F(MockStoreTest, WasCalledWith)
|
|
{
|
|
MockStore::instance().recordAndReturn("mod", "fn", {QVariant(10)});
|
|
EXPECT_TRUE(MockStore::instance().wasCalledWith("mod", "fn", {QVariant(10)}));
|
|
EXPECT_FALSE(MockStore::instance().wasCalledWith("mod", "fn", {QVariant(20)}));
|
|
}
|
|
|
|
TEST_F(MockStoreTest, CallCount)
|
|
{
|
|
EXPECT_EQ(MockStore::instance().callCount("mod", "fn"), 0);
|
|
MockStore::instance().recordAndReturn("mod", "fn", {});
|
|
MockStore::instance().recordAndReturn("mod", "fn", {});
|
|
MockStore::instance().recordAndReturn("mod", "fn", {});
|
|
EXPECT_EQ(MockStore::instance().callCount("mod", "fn"), 3);
|
|
}
|
|
|
|
TEST_F(MockStoreTest, LastArgs)
|
|
{
|
|
MockStore::instance().recordAndReturn("mod", "fn", {QVariant("a")});
|
|
MockStore::instance().recordAndReturn("mod", "fn", {QVariant("b")});
|
|
|
|
QVariantList last = MockStore::instance().lastArgs("mod", "fn");
|
|
EXPECT_EQ(last.size(), 1);
|
|
EXPECT_EQ(last.at(0).toString(), "b");
|
|
}
|
|
|
|
TEST_F(MockStoreTest, AllCalls)
|
|
{
|
|
MockStore::instance().recordAndReturn("m1", "f1", {});
|
|
MockStore::instance().recordAndReturn("m2", "f2", {QVariant(1)});
|
|
|
|
auto calls = MockStore::instance().allCalls();
|
|
EXPECT_EQ(calls.size(), 2);
|
|
EXPECT_EQ(calls.at(0).module, "m1");
|
|
EXPECT_EQ(calls.at(1).module, "m2");
|
|
}
|
|
|
|
TEST_F(MockStoreTest, ResetClearsEverything)
|
|
{
|
|
MockStore::instance().when("mod", "fn").thenReturn(QVariant(1));
|
|
MockStore::instance().recordAndReturn("mod", "fn", {});
|
|
|
|
MockStore::instance().reset();
|
|
|
|
EXPECT_FALSE(MockStore::instance().wasCalled("mod", "fn"));
|
|
QVariant r = MockStore::instance().recordAndReturn("mod", "fn", {});
|
|
EXPECT_FALSE(r.isValid());
|
|
}
|