| 48 | } // namespace |
| 49 | |
| 50 | TEST(wasmedgePluginTests, C_Run) { |
| 51 | auto *ExecCxt = WasmEdge_ExecutorCreate(nullptr, nullptr); |
| 52 | auto *StoreCxt = WasmEdge_StoreCreate(); |
| 53 | WasmEdge_Result Res; |
| 54 | WasmEdge_FunctionInstanceContext *FuncCxt; |
| 55 | WasmEdge_String FuncName; |
| 56 | WasmEdge_Value Params[2], Returns[1]; |
| 57 | |
| 58 | // Create the wasmedge_plugintest_c_module module instance. |
| 59 | auto *ModInstC = createModuleC(); |
| 60 | EXPECT_FALSE(ModInstC == nullptr); |
| 61 | int32_t *HostData = |
| 62 | static_cast<int32_t *>(WasmEdge_ModuleInstanceGetHostData(ModInstC)); |
| 63 | EXPECT_FALSE(HostData == nullptr); |
| 64 | |
| 65 | // Create the wasmedge_plugintest_cpp_module module instance. |
| 66 | auto *ModInstCPP = createModuleCPP(); |
| 67 | EXPECT_FALSE(ModInstCPP == nullptr); |
| 68 | |
| 69 | // Test: Run the function "wasmedge_plugintest_c.add". |
| 70 | FuncName = WasmEdge_StringCreateByCString("add"); |
| 71 | FuncCxt = WasmEdge_ModuleInstanceFindFunction(ModInstC, FuncName); |
| 72 | WasmEdge_StringDelete(FuncName); |
| 73 | EXPECT_NE(FuncCxt, nullptr); |
| 74 | Params[0] = WasmEdge_ValueGenI32(111); |
| 75 | Params[1] = WasmEdge_ValueGenI32(333); |
| 76 | Res = WasmEdge_ExecutorInvoke(ExecCxt, FuncCxt, Params, 2, Returns, 1); |
| 77 | EXPECT_TRUE(WasmEdge_ResultOK(Res)); |
| 78 | EXPECT_EQ(WasmEdge_ValueGetI32(Returns[0]), 444); |
| 79 | EXPECT_EQ(*HostData, 444); |
| 80 | |
| 81 | // Test: Run the function "wasmedge_plugintest_c.sub". |
| 82 | FuncName = WasmEdge_StringCreateByCString("sub"); |
| 83 | FuncCxt = WasmEdge_ModuleInstanceFindFunction(ModInstC, FuncName); |
| 84 | WasmEdge_StringDelete(FuncName); |
| 85 | EXPECT_NE(FuncCxt, nullptr); |
| 86 | Params[0] = WasmEdge_ValueGenI32(666); |
| 87 | Params[1] = WasmEdge_ValueGenI32(555); |
| 88 | Res = WasmEdge_ExecutorInvoke(ExecCxt, FuncCxt, Params, 2, Returns, 1); |
| 89 | EXPECT_TRUE(WasmEdge_ResultOK(Res)); |
| 90 | EXPECT_EQ(WasmEdge_ValueGetI32(Returns[0]), 111); |
| 91 | EXPECT_EQ(*HostData, 555); |
| 92 | |
| 93 | // Test: Run the function "wasmedge_plugintest_cpp.add". |
| 94 | FuncName = WasmEdge_StringCreateByCString("add"); |
| 95 | FuncCxt = WasmEdge_ModuleInstanceFindFunction(ModInstCPP, FuncName); |
| 96 | WasmEdge_StringDelete(FuncName); |
| 97 | EXPECT_NE(FuncCxt, nullptr); |
| 98 | Params[0] = WasmEdge_ValueGenI32(111); |
| 99 | Params[1] = WasmEdge_ValueGenI32(333); |
| 100 | Res = WasmEdge_ExecutorInvoke(ExecCxt, FuncCxt, Params, 2, Returns, 1); |
| 101 | EXPECT_TRUE(WasmEdge_ResultOK(Res)); |
| 102 | EXPECT_EQ(WasmEdge_ValueGetI32(Returns[0]), 444); |
| 103 | |
| 104 | // Test: Run the function "wasmedge_plugintest_cpp.sub". |
| 105 | FuncName = WasmEdge_StringCreateByCString("sub"); |
| 106 | FuncCxt = WasmEdge_ModuleInstanceFindFunction(ModInstCPP, FuncName); |
| 107 | WasmEdge_StringDelete(FuncName); |
nothing calls this directly
no test coverage detected