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