MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / TEST

Function TEST

crates/c-api/tests/component/values.cc:103–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103TEST(component, value_record) {
104 static const auto check = [](const Val &v, uint64_t x, uint64_t y) {
105 EXPECT_TRUE(v.is_record());
106 const Record &r = v.get_record();
107 EXPECT_EQ(r.size(), 2);
108
109 const auto &x_field = *r.begin();
110 EXPECT_EQ(x_field.name(), "x");
111 const auto &x_field_val = x_field.value();
112 EXPECT_TRUE(x_field_val.is_u64());
113 EXPECT_EQ(x_field_val.get_u64(), x);
114
115 const auto &y_field = *(r.begin() + 1);
116 EXPECT_EQ(y_field.name(), "y");
117 const auto &y_field_val = y_field.value();
118 EXPECT_TRUE(y_field_val.is_u64());
119 EXPECT_EQ(y_field_val.get_u64(), y);
120 };
121
122 static const auto make = [](uint64_t x, uint64_t y) -> Val {
123 return Record({
124 {"x", x},
125 {"y", y},
126 });
127 };
128
129 auto ctx = create(
130 R"((record (field "x" u64) (field "y" u64)))", R"(
131(param $x i64)
132(param $y i64)
133(result i32)
134(local $res i32)
135local.get $x
136local.get $y
137(call $realloc
138 (i32.const 0)
139 (i32.const 0)
140 (i32.const 4)
141 (i32.const 16))
142local.tee $res
143call $do
144local.get $res
145 )",
146 "(param i64 i64 i32)",
147 +[](Store::Context, const FuncType &_ty, Span<const Val> args,
148 Span<Val> rets) -> Result<std::monostate> {
149 EXPECT_EQ(args.size(), 1);
150 check(args[0], 1, 2);
151
152 EXPECT_EQ(rets.size(), 1);
153 rets[0] = make(3, 4);
154
155 return std::monostate();
156 });
157
158 auto arg = make(1, 2);
159 auto res = Val(false);
160

Callers

nothing calls this directly

Calls 15

WitOptionClass · 0.85
ResourceHostClass · 0.85
get_stringMethod · 0.80
get_enumMethod · 0.80
is_okMethod · 0.80
get_resourceMethod · 0.80
to_hostMethod · 0.80
to_anyMethod · 0.80
add_resourceMethod · 0.80
createFunction · 0.70
RecordClass · 0.50
checkFunction · 0.50

Tested by

no test coverage detected