MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / TEST

Function TEST

test/plugins/unittest/unittest_cpp.cpp:56–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54} // namespace
55
56TEST(wasmedgePluginTests, CPP_Run) {
57 // Create the wasmedge_plugintest_cpp_module module instance.
58 auto TestModCPP = createModuleCPP();
59 ASSERT_TRUE(TestModCPP);
60
61 WasmEdge::Runtime::Instance::ModuleInstance Mod("");
62 WasmEdge::Runtime::CallingFrame CallFrame(nullptr, &Mod);
63 std::array<WasmEdge::ValVariant, 1> RetVal;
64
65 // Get the function "arg_len".
66 auto *FuncInst1 = TestModCPP->findFuncExports("arg_len");
67 EXPECT_NE(FuncInst1, nullptr);
68 EXPECT_TRUE(FuncInst1->isHostFunction());
69 auto &HostFuncInst1 = FuncInst1->getHostFunc();
70
71 // Test: Run function successfully.
72 EXPECT_TRUE(HostFuncInst1.run(CallFrame, {}, RetVal));
73 EXPECT_EQ(RetVal[0].get<int32_t>(), 4);
74
75 // Get the function "name_size".
76 auto *FuncInst2 = TestModCPP->findFuncExports("name_size");
77 EXPECT_NE(FuncInst2, nullptr);
78 EXPECT_TRUE(FuncInst2->isHostFunction());
79 auto &HostFuncInst2 = FuncInst2->getHostFunc();
80
81 // Test: Run function successfully.
82 EXPECT_TRUE(HostFuncInst2.run(CallFrame, {}, RetVal));
83 EXPECT_EQ(RetVal[0].get<int32_t>(), 9);
84
85 // Get the function "opt".
86 auto *FuncInst3 = TestModCPP->findFuncExports("opt");
87 EXPECT_NE(FuncInst3, nullptr);
88 EXPECT_TRUE(FuncInst3->isHostFunction());
89 auto &HostFuncInst3 = FuncInst3->getHostFunc();
90
91 // Test: Run function successfully.
92 EXPECT_TRUE(HostFuncInst3.run(CallFrame, {}, RetVal));
93 EXPECT_EQ(RetVal[0].get<int32_t>(), 1);
94
95 // Create the wasmedge_plugintest_c_module module instance.
96 auto TestModC = createModuleC();
97 ASSERT_TRUE(TestModC);
98 // The host functions are implemented in the C API.
99 // Therefore not test to invoke them here.
100}
101
102TEST(wasmedgePluginTests, CPP_Module) {
103 // Create the wasmedge_plugintest_cpp_module module instance.

Callers

nothing calls this directly

Calls 6

findFuncExportsMethod · 0.80
isHostFunctionMethod · 0.80
getFuncExportNumMethod · 0.80
createModuleCPPFunction · 0.70
createModuleCFunction · 0.70
runMethod · 0.45

Tested by

no test coverage detected