MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / Run

Method Run

tests/runtime/cpp/param-ownership/runner-owning.cpp:6–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include <array>
5
6void exports::runner::Run() {
7 std::array<std::string_view, 2> a1 = {"value1", "value2"};
8 std::array<std::string_view, 2> a2 = {"value3", "value4"};
9 std::array<std::span<std::string_view const>, 2> as = {
10 std::span<std::string_view const>(a1.data(), a1.size()),
11 std::span<std::string_view const>(a2.data(), a2.size())};
12 std::span<std::span<std::string_view const> const> input(as.data(),
13 as.size());
14 auto res = test::ownership::Foo(input);
15 assert(res.size() == 2);
16 assert(res[0].size() == 2);
17 assert(res[0][0].get_view() == "VALUE1");
18 assert(res[0][1].get_view() == "VALUE2");
19 assert(res[1].size() == 2);
20 assert(res[1][0].get_view() == "VALUE3");
21 assert(res[1][1].get_view() == "VALUE4");
22
23 test::ownership::Thing thing1 {
24 wit::string::from_view("thing"),
25 wit::vector<wit::string>::allocate(2)
26 };
27 thing1.value.initialize(0, wit::string::from_view("value1"));
28 thing1.value.initialize(1, wit::string::from_view("value2"));
29 test::ownership::Bar(std::move(thing1));
30
31 test::ownership::Thing thing2 {
32 wit::string::from_view("thing"),
33 wit::vector<wit::string>::allocate(2)
34 };
35 thing2.value.initialize(0, wit::string::from_view("value1"));
36 thing2.value.initialize(1, wit::string::from_view("value2"));
37 auto result = test::ownership::Baz(std::move(thing2));
38 assert(result.name.get_view() == "THING");
39 assert(result.value.size() == 2);
40 assert(result.value[0].get_view() == "VALUE1");
41 assert(result.value[1].get_view() == "VALUE2");
42
43 auto v1 = wit::vector<wit::string>::allocate(2);
44 v1.initialize(0, wit::string::from_view("value1"));
45 v1.initialize(1, wit::string::from_view("value2"));
46 std::array<std::string_view, 2> v2 = {"value1", "value2"};
47 test::ownership::both_list_and_resource::Thing resource_thing {
48 std::move(v1),
49 test::ownership::both_list_and_resource::TheResource(std::span<std::string_view const>(v2.data(), v2.size()))
50 };
51 test::ownership::both_list_and_resource::ListAndResource(
52 std::move(resource_thing));
53}

Callers

nothing calls this directly

Calls 10

BazFunction · 0.85
TheResourceClass · 0.85
ListAndResourceFunction · 0.85
FooFunction · 0.70
BarFunction · 0.70
assertFunction · 0.50
dataMethod · 0.45
sizeMethod · 0.45
get_viewMethod · 0.45
initializeMethod · 0.45

Tested by

no test coverage detected