diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-11-07 17:30:41 +0100 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-11-07 17:30:41 +0100 |
| commit | 55fb3a9221ea91453573453288ecedb6ea79b7ba (patch) | |
| tree | 128945e3e15ae03a11c46f9e490f4dbaafa5de67 /modules/remote/tests/remote_loopback.cpp | |
| parent | c90823bde9aea6b8f4c9737a0d8d5cd17560e8b9 (diff) | |
| download | forstio-forstio-55fb3a9221ea91453573453288ecedb6ea79b7ba.tar.gz | |
Creating out of source doc files
Diffstat (limited to 'modules/remote/tests/remote_loopback.cpp')
| -rw-r--r-- | modules/remote/tests/remote_loopback.cpp | 82 |
1 files changed, 81 insertions, 1 deletions
diff --git a/modules/remote/tests/remote_loopback.cpp b/modules/remote/tests/remote_loopback.cpp index dbdd0f1..4460ad1 100644 --- a/modules/remote/tests/remote_loopback.cpp +++ b/modules/remote/tests/remote_loopback.cpp @@ -65,6 +65,85 @@ SAW_TEST("Remote Loopback RPC"){ } } +SAW_TEST("Remote Loopback RPC Runtime Dispatch"){ + using namespace saw; + + event_loop loop; + wait_scope wait{loop}; + + remote<rmt::Loopback> rmt; + + auto eov = rmt.parse_address(0u); + SAW_EXPECT(eov.is_value(), "Didn't parse correctly"); + auto& addr = eov.get_value(); + + auto eo_u32_srv = rmt.template data_listen<sch::UInt32, encode::Native>(*addr); + SAW_EXPECT(eo_u32_srv.is_value(), std::string{"Couldn't listen: "} + std::string{eo_u32_srv.get_error().get_category()}); + auto& u32_srv = eo_u32_srv.get_value(); + + auto eo_i64_srv = rmt.template data_listen<sch::Int64, encode::Native>(*addr); + SAW_EXPECT(eo_i64_srv.is_value(), std::string{"Couldn't listen: "} + std::string{eo_i64_srv.get_error().get_category()}); + auto& i64_srv = eo_i64_srv.get_value(); + + auto foo_func = [](data<sch::UInt32, encode::Native> input) -> error_or<data<sch::Int64, encode::Native>> { + data<sch::Int64, encode::Native> rv; + rv.set(input.get() * 2); + return rv; + }; + + auto iface = interface_factory<sch::TestInterface, encode::Native>::create(std::move(foo_func)); + + auto eo_rpc_srv = rmt.template rpc_listen<sch::TestInterface, encode::Native>(*addr, std::move(iface)); + SAW_EXPECT(eo_rpc_srv.is_value(), std::string{"Couldn't listen: "} + std::string{eo_rpc_srv.get_error().get_category()}); + auto& rpc_srv = eo_rpc_srv.get_value(); + + id<sch::UInt32> id32{0u}; + /** + * Deliberately not 0, since the server picks that one for the first + * response below. + */ + id<sch::Int64> id64{7u}; + + data<sch::UInt32, encode::Native> inp{21}; + + { + auto eo_send = u32_srv->send(inp, id32); + SAW_EXPECT(eo_send.is_value(), "Failed send."); + } + + /** + * This is the path a backend takes which transports the call itself. + * Only the function id and the raw parameter id are known. The id the + * server picked for the response is meant to travel back in the reply. + */ + { + auto eo_called = rpc_srv->call_by_id(rpc_function_id<"foo">::value, id32.get_value()); + SAW_EXPECT(eo_called.is_value(), (std::string{"Failed call: "} + std::string{eo_called.get_error().get_category()})); + + id<sch::Int64> resp_id{eo_called.get_value()}; + auto eo_recv = i64_srv->receive(resp_id); + SAW_EXPECT(eo_recv.is_value(), "Failed receive."); + auto& recv = eo_recv.get_value(); + SAW_EXPECT((recv.get() == 42), (std::string{"Wrong value received: "} + std::to_string(recv.get()))); + } + /** + * Calling into a slot the caller picked beforehand. + */ + { + auto eo_called = rpc_srv->call_by_id(rpc_function_id<"foo">::value, id32.get_value(), id64.get_value()); + SAW_EXPECT(eo_called.is_value(), (std::string{"Failed call: "} + std::string{eo_called.get_error().get_category()})); + + auto eo_recv = i64_srv->receive(id64); + SAW_EXPECT(eo_recv.is_value(), "Failed receive."); + auto& recv = eo_recv.get_value(); + SAW_EXPECT((recv.get() == 42), (std::string{"Wrong value received: "} + std::to_string(recv.get()))); + } + { + auto eo_called = rpc_srv->call_by_id(rpc_function_id<"foo">::value + 1u, id32.get_value()); + SAW_EXPECT(eo_called.is_error(), "An unknown function id should not be callable."); + } +} + SAW_TEST("Remote Loopback RPC Client"){ using namespace saw; @@ -101,7 +180,8 @@ SAW_TEST("Remote Loopback RPC Client"){ data<sch::UInt32, encode::Native> inp{21}; - auto eo_rmt_dat = client.template call<"foo">(std::move(inp)); + auto cvr_rmt_dat = client.template call<"foo">(std::move(inp)); + auto eo_rmt_dat = cvr_rmt_dat.take(); SAW_EXPECT(eo_rmt_dat.is_value(), (std::string{"Failed call: "} + std::string{eo_rmt_dat.get_error().get_category()})); auto& rmt_dat = eo_rmt_dat.get_value(); |
