| 54 | } // namespace |
| 55 | |
| 56 | TEST(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 | |
| 102 | TEST(wasmedgePluginTests, CPP_Module) { |
| 103 | // Create the wasmedge_plugintest_cpp_module module instance. |
nothing calls this directly
no test coverage detected