1 #include <gtest/gtest.h>
2 #include <wasmtime/instance.hh>
3
4 using namespace wasmtime;
5
TEST(Instance,Smoke)6 TEST(Instance, Smoke) {
7 Engine engine;
8 Store store(engine);
9 Memory m = Memory::create(store, MemoryType(1)).unwrap();
10 Global g = Global::create(store, GlobalType(ValKind::I32, false), 1).unwrap();
11 Table t = Table::create(store, TableType(ValKind::FuncRef, 1),
12 std::optional<Func>())
13 .unwrap();
14 Func f(store, FuncType({}, {}),
15 [](auto caller, auto params, auto results) -> auto {
16 return std::monostate();
17 });
18
19 Module mod =
20 Module::compile(engine, "(module"
21 "(import \"\" \"\" (func))"
22 "(import \"\" \"\" (global i32))"
23 "(import \"\" \"\" (table 1 funcref))"
24 "(import \"\" \"\" (memory 1))"
25
26 "(func (export \"f\"))"
27 "(global (export \"g\") i32 (i32.const 0))"
28 "(export \"m\" (memory 0))"
29 "(export \"t\" (table 0))"
30 ")")
31 .unwrap();
32 Instance::create(store, mod, {}).err();
33 Instance i = Instance::create(store, mod, {f, g, t, m}).unwrap();
34 EXPECT_FALSE(i.get(store, "not-present"));
35 f = std::get<Func>(*i.get(store, "f"));
36 m = std::get<Memory>(*i.get(store, "m"));
37 t = std::get<Table>(*i.get(store, "t"));
38 g = std::get<Global>(*i.get(store, "g"));
39
40 EXPECT_TRUE(i.get(store, 0));
41 EXPECT_TRUE(i.get(store, 1));
42 EXPECT_TRUE(i.get(store, 2));
43 EXPECT_TRUE(i.get(store, 3));
44 EXPECT_FALSE(i.get(store, 4));
45 auto [name, func] = *i.get(store, 0);
46 EXPECT_EQ(name, "f");
47 }
48