44#include " generated/echo_ipc_client.hpp"
55
66#include < array>
7- #include < cassert>
87#include < iostream>
98#include < string_view>
109
10+ // Explicit check (not assert): verification must survive NDEBUG builds.
11+ #define CHECK (cond, label ) \
12+ do { \
13+ if (!(cond)) { \
14+ std::cerr << " echo_client(cpp): " << (label) << " FAIL\n " ; \
15+ return 1 ; \
16+ } \
17+ } while (0 )
18+
1119namespace {
1220echo::Fr test_hash (uint8_t base) {
1321 echo::Fr hash{};
@@ -33,24 +41,26 @@ int main(int argc, char **argv) {
3341
3442 {
3543 auto resp = client.bytes ({.data = {0xDE , 0xAD , 0xBE , 0xEF , 0x42 }});
36- assert ((resp.data == std::vector<uint8_t >{0xDE , 0xAD , 0xBE , 0xEF , 0x42 }));
44+ CHECK ((resp.data == std::vector<uint8_t >{0xDE , 0xAD , 0xBE , 0xEF , 0x42 }),
45+ " EchoBytes" );
3746 std::cerr << " echo_client(cpp): EchoBytes OK\n " ;
3847 }
3948
4049 {
4150 auto resp =
4251 client.fields ({.a = 42 , .b = 999999 , .name = " hello wire compat" });
43- assert (resp.a == 42 && resp.b == 999999 &&
44- resp. name == " hello wire compat " );
52+ CHECK (resp.a == 42 && resp.b == 999999 && resp. name == " hello wire compat " ,
53+ " EchoFields " );
4554 std::cerr << " echo_client(cpp): EchoFields OK\n " ;
4655 }
4756
4857 {
4958 auto resp =
5059 client.nested ({.inner = {.values = {{1 , 2 , 3 }, {4 , 5 }}, .flag = true }});
51- assert ((resp.inner .values ==
52- std::vector<std::vector<uint8_t >>{{1 , 2 , 3 }, {4 , 5 }}));
53- assert (resp.inner .flag == true );
60+ CHECK ((resp.inner .values ==
61+ std::vector<std::vector<uint8_t >>{{1 , 2 , 3 }, {4 , 5 }}),
62+ " EchoNested values" );
63+ CHECK (resp.inner .flag == true , " EchoNested flag" );
5464 std::cerr << " echo_client(cpp): EchoNested OK\n " ;
5565 }
5666
@@ -61,13 +71,63 @@ int main(int argc, char **argv) {
6171 .hash = hash,
6272 .maybeHash = second,
6373 .hashes = {hash, second}});
64- assert (resp.treeId == 7 );
65- assert (resp.hash == hash);
66- assert (resp.maybeHash == second);
67- assert ((resp.hashes == std::vector<echo::Fr>{hash, second}));
74+ CHECK (resp.treeId == 7 , " EchoAliases treeId" );
75+ CHECK (resp.hash == hash, " EchoAliases hash" );
76+ CHECK (resp.maybeHash == second, " EchoAliases maybeHash" );
77+ CHECK ((resp.hashes == std::vector<echo::Fr>{hash, second}),
78+ " EchoAliases hashes" );
6879 std::cerr << " echo_client(cpp): EchoAliases OK\n " ;
6980 }
7081
82+ // Optional-absent over live IPC.
83+ {
84+ auto hash = test_hash (0x10 );
85+ auto resp = client.aliases ({.treeId = 7 ,
86+ .hash = hash,
87+ .maybeHash = std::nullopt ,
88+ .hashes = {hash}});
89+ CHECK (!resp.maybeHash .has_value (), " EchoAliases none" );
90+ std::cerr << " echo_client(cpp): EchoAliases none OK\n " ;
91+ }
92+
93+ // uint64 wire encoding above 2^32 over live IPC.
94+ {
95+ const uint64_t big = (1ULL << 53 ) - 1 ;
96+ auto resp = client.fields ({.a = 42 , .b = big, .name = " big" });
97+ CHECK (resp.b == big, " EchoFields u64" );
98+ std::cerr << " echo_client(cpp): EchoFields u64 OK\n " ;
99+ }
100+
101+ // Optional bytes Some/None and fixed [bytes; 2].
102+ {
103+ auto resp = client.blobs ({.maybeData = std::vector<uint8_t >{0xAA , 0xBB },
104+ .parts = {{{1 , 2 , 3 }, {4 }}}});
105+ CHECK ((resp.maybeData == std::vector<uint8_t >{0xAA , 0xBB }),
106+ " EchoBlobs maybeData" );
107+ CHECK ((resp.parts == std::array<std::vector<uint8_t >, 2 >{{{1 , 2 , 3 }, {4 }}}),
108+ " EchoBlobs parts" );
109+ auto resp_none =
110+ client.blobs ({.maybeData = std::nullopt , .parts = {{{}, {9 }}}});
111+ CHECK (!resp_none.maybeData .has_value (), " EchoBlobs none" );
112+ std::cerr << " echo_client(cpp): EchoBlobs OK\n " ;
113+ }
114+
115+ // Server error surfaces with its message.
116+ {
117+ bool threw = false ;
118+ std::string message;
119+ try {
120+ client.fail ({.message = " deliberate failure" });
121+ } catch (const std::exception &e) {
122+ threw = true ;
123+ message = e.what ();
124+ }
125+ CHECK (threw, " EchoFail threw" );
126+ CHECK (message.find (" deliberate failure" ) != std::string::npos,
127+ " EchoFail message" );
128+ std::cerr << " echo_client(cpp): EchoFail OK\n " ;
129+ }
130+
71131 std::cerr << " echo_client(cpp): all tests passed\n " ;
72132 return 0 ;
73133}
0 commit comments