mirror of
https://github.com/logos-co/logos-test-modules.git
synced 2026-08-27 18:21:07 +00:00
test universal modules with LogosModuleContext (#19)
* test universal modules with LogosModuleContext * pr comments * bump dependencies
This commit is contained in:
@@ -191,19 +191,29 @@ std::string TestBasicModuleCppImpl::fiveArgs(const std::string& a, int64_t b,
|
||||
}
|
||||
|
||||
// ── Events ───────────────────────────────────────────────────────────────
|
||||
// The driver methods fire the typed events declared in `logos_events:`.
|
||||
// Bodies for `testEvent` / `multiArgEvent` themselves live in the
|
||||
// codegen-emitted `test_basic_module_cpp_events.cpp`, which marshals
|
||||
// the typed args into a QVariantList and routes them through
|
||||
// LogosModuleContext::emitEventImpl_ → LogosProviderBase::emitEvent.
|
||||
|
||||
void TestBasicModuleCppImpl::emitTestEvent(const std::string& data) {
|
||||
if (emitEvent) emitEvent("testEvent", data);
|
||||
testEvent(data);
|
||||
}
|
||||
|
||||
void TestBasicModuleCppImpl::emitMultiArgEvent(const std::string& name, int64_t count) {
|
||||
// The generator-wired emitEvent takes (name, data). Pack the multi-arg
|
||||
// payload as a JSON string so the wire shape is lossless (Python test
|
||||
// just asserts both fragments appear in the stringified event).
|
||||
if (emitEvent) {
|
||||
nlohmann::json payload;
|
||||
payload["name"] = name;
|
||||
payload["count"] = count;
|
||||
emitEvent("multiArgEvent", payload.dump());
|
||||
}
|
||||
multiArgEvent(name, count);
|
||||
}
|
||||
|
||||
// Bool-returning siblings for `logoscore -c` chaining (the void twins
|
||||
// above can't be chained — logoscore exits non-zero on `void → invalid
|
||||
// QVariant`). Used by the context-cpp event round-trip tests.
|
||||
bool TestBasicModuleCppImpl::triggerTestEvent(const std::string& data) {
|
||||
testEvent(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestBasicModuleCppImpl::triggerMultiArgEvent(const std::string& name, int64_t count) {
|
||||
multiArgEvent(name, count);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -14,29 +14,26 @@
|
||||
// QVariant ↔ std conversion. See spec.md in logos-cpp-sdk/cpp-generator/docs/
|
||||
// for the full conversion table.
|
||||
//
|
||||
// Event emission: the generator detects the `std::function emitEvent`
|
||||
// member by name and wires it to LogosProviderBase::emitEvent in the
|
||||
// generated glue layer, so the impl can fire events without touching Qt.
|
||||
// Event emission: declare events in the `logos_events:` section below
|
||||
// (Qt-`signals:`-style). The generator parses each prototype, emits a
|
||||
// `<name>_events.cpp` defining the body (which routes the typed args
|
||||
// through LogosModuleContext::emitEventImpl_ → LogosProviderBase
|
||||
// → QRO `eventResponse`), and a `<name>.lidl` sidecar so consumer-side
|
||||
// codegen can expose typed `on<EventName>(callback)` accessors.
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <logos_json.h> // LogosMap, LogosList (nlohmann::json aliases)
|
||||
#include <logos_result.h> // StdLogosResult
|
||||
#include <logos_json.h> // LogosMap, LogosList (nlohmann::json aliases)
|
||||
#include <logos_module_context.h> // LogosModuleContext base; pulls in `logos_events`
|
||||
#include <logos_result.h> // StdLogosResult
|
||||
|
||||
class TestBasicModuleCppImpl {
|
||||
class TestBasicModuleCppImpl : public LogosModuleContext {
|
||||
public:
|
||||
TestBasicModuleCppImpl() = default;
|
||||
~TestBasicModuleCppImpl() = default;
|
||||
|
||||
// Generated glue wires this in its ctor — call it to emit events. The
|
||||
// two-string signature (name, json-serialised data) is the one the
|
||||
// parser recognises; the generator emits a shim that dispatches to
|
||||
// LogosProviderBase::emitEvent with a QVariantList payload.
|
||||
std::function<void(const std::string& eventName, const std::string& data)> emitEvent;
|
||||
|
||||
// ── Return type: void ────────────────────────────────────────────────
|
||||
void doNothing();
|
||||
void doNothingWithArgs(const std::string& a, int64_t b);
|
||||
@@ -106,6 +103,27 @@ public:
|
||||
std::string fiveArgs(const std::string& a, int64_t b, bool c, const std::string& d, int64_t e);
|
||||
|
||||
// ── Events ──────────────────────────────────────────────────────────
|
||||
// Driver methods called from logoscore — they fire the typed events
|
||||
// declared in `logos_events:` below. Mirrors test_basic_module's
|
||||
// Qt-side `emitTestEvent` / `emitMultiArgEvent` Q_INVOKABLE pair so
|
||||
// the integration tests can use the same test_event_system.cpp
|
||||
// harness against both modules.
|
||||
void emitTestEvent(const std::string& data);
|
||||
void emitMultiArgEvent(const std::string& name, int64_t count);
|
||||
|
||||
// Bool-returning variants of the emit drivers. Same semantic, but
|
||||
// safe to chain via `logoscore -c` (the void-returning twins above
|
||||
// can't be — logoscore needs a value to format as `Result:`).
|
||||
// Used by the context-cpp round-trip tests, which chain
|
||||
// subscribe → trigger → read
|
||||
// in a single logoscore invocation.
|
||||
bool triggerTestEvent(const std::string& data);
|
||||
bool triggerMultiArgEvent(const std::string& name, int64_t count);
|
||||
|
||||
// Typed events. Codegen emits bodies in test_basic_module_cpp_events.cpp
|
||||
// and exposes typed `onTestEvent(...)` / `onMultiArgEvent(...)`
|
||||
// accessors on the consumer-side wrapper.
|
||||
logos_events:
|
||||
void testEvent(const std::string& data);
|
||||
void multiArgEvent(const std::string& name, int64_t count);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user