Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/c-api/tests/component/instantiate.cc
1692 views
1
#include "utils.h"
2
3
#include <gtest/gtest.h>
4
#include <wasmtime.h>
5
6
TEST(component, instantiate) {
7
static constexpr auto bytes = std::string_view{
8
R"END(
9
(component
10
(core module)
11
)
12
)END",
13
};
14
15
const auto engine = wasm_engine_new();
16
EXPECT_NE(engine, nullptr);
17
18
const auto store = wasmtime_store_new(engine, nullptr, nullptr);
19
EXPECT_NE(store, nullptr);
20
const auto context = wasmtime_store_context(store);
21
EXPECT_NE(context, nullptr);
22
23
wasmtime_component_t *component = nullptr;
24
25
auto error = wasmtime_component_new(
26
engine, reinterpret_cast<const uint8_t *>(bytes.data()), bytes.size(),
27
&component);
28
29
CHECK_ERR(error);
30
31
const auto linker = wasmtime_component_linker_new(engine);
32
EXPECT_NE(linker, nullptr);
33
34
wasmtime_component_instance_t instance = {};
35
error = wasmtime_component_linker_instantiate(linker, context, component,
36
&instance);
37
38
CHECK_ERR(error);
39
40
wasmtime_component_linker_delete(linker);
41
42
wasmtime_store_delete(store);
43
wasm_engine_delete(engine);
44
}
45
46