Skip to content
Merged
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
8 changes: 7 additions & 1 deletion test/mp/test/foo.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,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 @@ -81,3 +82,8 @@ struct Pair(T1, T2) {
first @0 :T1;
second @1 :T2;
}

struct StringIntPair {
first @0 :Text;
second @1 :Int32;
}
3 changes: 2 additions & 1 deletion 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
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