|
| 1 | +#include <gtest/gtest.h> |
| 2 | +#include <wasmtime.h> |
| 3 | + |
| 4 | +TEST(component, instantiate) { |
| 5 | + static constexpr auto bytes = std::string_view{ |
| 6 | + R"END( |
| 7 | + (component |
| 8 | + (core module) |
| 9 | + ) |
| 10 | + )END", |
| 11 | + }; |
| 12 | + |
| 13 | + const auto engine = wasm_engine_new(); |
| 14 | + EXPECT_NE(engine, nullptr); |
| 15 | + |
| 16 | + const auto store = wasmtime_store_new(engine, nullptr, nullptr); |
| 17 | + EXPECT_NE(store, nullptr); |
| 18 | + const auto context = wasmtime_store_context(store); |
| 19 | + EXPECT_NE(context, nullptr); |
| 20 | + |
| 21 | + wasmtime_component_t *component = nullptr; |
| 22 | + |
| 23 | + auto error = wasmtime_component_new( |
| 24 | + engine, reinterpret_cast<const uint8_t *>(bytes.data()), bytes.size(), |
| 25 | + &component); |
| 26 | + |
| 27 | + EXPECT_EQ(error, nullptr); |
| 28 | + EXPECT_NE(component, nullptr); |
| 29 | + |
| 30 | + const auto linker = wasmtime_component_linker_new(engine); |
| 31 | + EXPECT_NE(linker, nullptr); |
| 32 | + |
| 33 | + wasmtime_component_linker_instance_t *linker_instance = nullptr; |
| 34 | + error = wasmtime_component_linker_instance(linker, "a:b/c", &linker_instance); |
| 35 | + |
| 36 | + EXPECT_EQ(error, nullptr); |
| 37 | + EXPECT_NE(linker_instance, nullptr); |
| 38 | + |
| 39 | + wasmtime_component_linker_instance_delete(linker_instance); |
| 40 | + |
| 41 | + wasmtime_component_instance_t *instance = nullptr; |
| 42 | + error = wasmtime_component_linker_instantiate(linker, context, component, |
| 43 | + &instance); |
| 44 | + EXPECT_EQ(error, nullptr); |
| 45 | + EXPECT_NE(instance, nullptr); |
| 46 | + |
| 47 | + wasmtime_component_instance_delete(instance); |
| 48 | + |
| 49 | + wasmtime_component_linker_delete(linker); |
| 50 | + |
| 51 | + wasmtime_store_delete(store); |
| 52 | + wasm_engine_delete(engine); |
| 53 | +} |
0 commit comments