Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions test/mp/test/foo.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ interface FooInterface $Proxy.wrap("mp::test::FooImplementation") {
add @0 (a :Int32, b :Int32) -> (result :Int32);
addOut @19 (a :Int32, b :Int32) -> (ret :Int32);
addInOut @20 (x :Int32, sum :Int32) -> (sum :Int32);
mapSize @1 (map :List(Pair(Text, Text))) -> (result :Int32);
pass @2 (arg :FooStruct) -> (result :FooStruct);
raise @3 (arg :FooStruct) -> (error :FooStruct $Proxy.exception("mp::test::FooStruct"));
initThreadMap @4 (threadMap: Proxy.ThreadMap) -> (threadMap :Proxy.ThreadMap);
Expand All @@ -30,7 +29,7 @@ interface FooInterface $Proxy.wrap("mp::test::FooImplementation") {
passMessage @13 (arg :FooMessage) -> (result :FooMessage);
passMutable @14 (arg :FooMutable) -> (arg :FooMutable);
passEnum @15 (arg :Int32) -> (result :Int32);
passDouble @23 (arg :Float64) -> (result :Float64);
passDouble @1 (arg :Float64) -> (result :Float64);
passFn @16 (context :Proxy.Context, fn :FooFn) -> (result :Int32);
callFn @17 () -> ();
callFnAsync @18 (context :Proxy.Context) -> ();
Expand All @@ -55,10 +54,11 @@ interface FooFn $Proxy.wrap("ProxyCallback<std::function<int()>>") {
struct FooStruct $Proxy.wrap("mp::test::FooStruct") {
name @0 :Text;
setInt @1 :List(Int32) $Proxy.name("set_int");
vBool @2 :List(Bool) $Proxy.name("v_bool");
vectorBool @2 :List(Bool) $Proxy.name("vector_bool");
optionalInt @3 :Int32 $Proxy.name("optional_int");
hasOptionalInt @4 :Bool;
unorderedSetInt @5 :List(Int32) $Proxy.name("unordered_set_int");
mapStringInt @6 :List(StringIntPair) $Proxy.name("map_string_int");
}

struct FooCustom $Proxy.wrap("mp::test::FooCustom") {
Expand All @@ -77,7 +77,7 @@ struct FooMutable {
message @0 :Text;
}

struct Pair(T1, T2) {
first @0 :T1;
second @1 :T2;
struct StringIntPair {
first @0 :Text;
second @1 :Int32;
}
4 changes: 2 additions & 2 deletions test/mp/test/foo.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ struct FooStruct
{
std::string name;
std::set<int> set_int;
std::vector<bool> v_bool;
std::vector<bool> vector_bool;
std::optional<int> optional_int;
std::unordered_set<int> unordered_set_int;
std::map<std::string, int> map_string_int;
};

enum class FooEnum : uint8_t { ONE = 1, TWO = 2, };
Expand Down Expand Up @@ -71,7 +72,6 @@ class FooImplementation
int add(int a, int b) { return a + b; }
void addOut(int a, int b, int& out) { out = a + b; }
void addInOut(int x, int& sum) { sum += x; }
int mapSize(const std::map<std::string, std::string>& map) { return map.size(); }
FooStruct pass(FooStruct foo) { return foo; }
void raise(FooStruct foo) { throw foo; }
void initThreadMap() {}
Expand Down
20 changes: 14 additions & 6 deletions test/mp/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <kj/debug.h>
#include <kj/memory.h>
#include <kj/test.h>
#include <map>
#include <memory>
#include <mp/proxy.h>
#include <mp/proxy.capnp.h>
Expand Down Expand Up @@ -146,10 +147,12 @@ KJ_TEST("Call FooInterface methods")
in.set_int.insert(1);
in.unordered_set_int.insert(2);
in.unordered_set_int.insert(1);
in.v_bool.push_back(false);
in.v_bool.push_back(true);
in.v_bool.push_back(false);
in.vector_bool.push_back(false);
in.vector_bool.push_back(true);
in.vector_bool.push_back(false);
in.optional_int = 3;
in.map_string_int.emplace("a", 1);
in.map_string_int.emplace("b", 2);
FooStruct out = foo->pass(in);
KJ_EXPECT(in.name == out.name);
KJ_EXPECT(in.set_int.size() == out.set_int.size());
Expand All @@ -160,11 +163,16 @@ KJ_TEST("Call FooInterface methods")
for (const auto& elem : in.unordered_set_int) {
KJ_EXPECT(out.unordered_set_int.count(elem) == 1);
}
KJ_EXPECT(in.v_bool.size() == out.v_bool.size());
for (size_t i = 0; i < in.v_bool.size(); ++i) {
KJ_EXPECT(in.v_bool[i] == out.v_bool[i]);
KJ_EXPECT(in.vector_bool.size() == out.vector_bool.size());
for (size_t i = 0; i < in.vector_bool.size(); ++i) {
KJ_EXPECT(in.vector_bool[i] == out.vector_bool[i]);
}
KJ_EXPECT(in.optional_int == out.optional_int);
KJ_EXPECT(in.map_string_int.size() == out.map_string_int.size());
for (auto init{in.map_string_int.begin()}, outit{out.map_string_int.begin()}; init != in.map_string_int.end() && outit != out.map_string_int.end(); ++init, ++outit) {
KJ_EXPECT(init->first == outit->first);
KJ_EXPECT(init->second == outit->second);
}

// Additional checks for std::optional member
KJ_EXPECT(foo->pass(in).optional_int == 3);
Expand Down
Loading