1 #include <gtest/gtest.h>
2 #include <wasmtime/component.hh>
3 #include <wasmtime/store.hh>
4
5 using namespace wasmtime::component;
6
TEST(component,lookup_func)7 TEST(component, lookup_func) {
8 static constexpr auto component_text = std::string_view{
9 R"END(
10 (component
11 (core module $m
12 (func (export "f"))
13 )
14 (core instance $i (instantiate $m))
15 (func (export "f")
16 (canon lift (core func $i "f")))
17 )
18 )END",
19 };
20
21 wasmtime::Engine engine;
22 wasmtime::Store store(engine);
23 auto context = store.context();
24 Component component = Component::compile(engine, component_text).unwrap();
25 auto f = component.export_index(nullptr, "ff");
26
27 EXPECT_FALSE(f);
28
29 f = component.export_index(nullptr, "f");
30
31 EXPECT_TRUE(f);
32
33 Linker linker(engine);
34
35 auto instance = linker.instantiate(context, component).unwrap();
36
37 *instance.get_func(context, *f);
38
39 auto f2 = instance.get_export_index(context, nullptr, "f");
40 EXPECT_TRUE(f2);
41 }
42