ds@621: #include ds@621: ds@621: public Plugin:myinfo = ds@621: { ds@621: name = "Forward Testing Lab #1", ds@621: author = "AlliedModders LLC", ds@621: description = "Tests suite #1 for forwards created by plugins", ds@621: version = "1.0.0.0", ds@621: url = "http://www.sourcemod.net/" ds@621: }; ds@621: ds@621: new Handle:g_GlobalFwd = INVALID_HANDLE; ds@621: new Handle:g_PrivateFwd = INVALID_HANDLE; ds@621: ds@621: public OnPluginStart() ds@624: { ds@621: RegServerCmd("test_create_gforward", Command_CreateGlobalForward); ds@621: RegServerCmd("test_create_pforward", Command_CreatePrivateForward); ds@621: RegServerCmd("test_exec_gforward", Command_ExecGlobalForward); ds@621: RegServerCmd("test_exec_pforward", Command_ExecPrivateForward); ds@621: } ds@621: ds@621: public OnPluginEnd() ds@621: { ds@621: CloseHandle(g_GlobalFwd); ds@621: CloseHandle(g_PrivateFwd); ds@621: } ds@621: ds@621: public Action:Command_CreateGlobalForward(args) ds@621: { ds@621: if (g_GlobalFwd != INVALID_HANDLE) ds@621: { ds@621: CloseHandle(g_GlobalFwd); ds@621: } ds@621: ds@621: g_GlobalFwd = CreateGlobalForward("OnGlobalForward", ET_Ignore, Param_Any, Param_Cell, Param_Float, Param_String, Param_Array, Param_CellByRef, Param_FloatByRef); ds@621: ds@621: if (g_GlobalFwd == INVALID_HANDLE) ds@621: { ds@621: PrintToServer("Failed to create global forward!"); ds@621: } ds@621: ds@621: return Plugin_Handled; ds@621: } ds@621: ds@621: public Action:Command_CreatePrivateForward(args) ds@621: { ds@621: new Handle:pl; ds@621: new Function:func; ds@621: ds@621: if (g_PrivateFwd != INVALID_HANDLE) ds@621: { ds@621: CloseHandle(g_PrivateFwd); ds@621: } ds@621: ds@621: g_PrivateFwd = CreateForward(ET_Hook, Param_Cell, Param_String, Param_VarArgs); ds@621: ds@621: if (g_PrivateFwd == INVALID_HANDLE) ds@621: { ds@621: PrintToServer("Failed to create private forward!") ds@621: } ds@621: ds@621: pl = FindPluginByFile("fwdtest2.smx"); ds@621: ds@621: if (!pl) ds@621: { ds@621: PrintToServer("Could not find fwdtest2.smx!"); ds@621: return Plugin_Handled; ds@621: } ds@621: ds@621: func = GetFunctionByName(pl, "OnPrivateForward"); ds@621: ds@621: /* This shouldn't happen, but oh well */ ds@621: if (func == INVALID_FUNCTION) ds@621: { ds@621: PrintToServer("Could not find \"OnPrivateForward\" in fwdtest2.smx!"); ds@621: return Plugin_Handled; ds@621: } ds@621: ds@621: if (!AddToForward(g_PrivateFwd, pl, func) || !AddToForward(g_PrivateFwd, GetMyHandle(), ZohMyGod)) ds@621: { ds@621: PrintToServer("Failed to add functions to private forward!"); ds@621: return Plugin_Handled; ds@621: } ds@621: ds@621: return Plugin_Handled; ds@621: } ds@621: ds@621: public Action:Command_ExecGlobalForward(args) ds@621: { ds@621: new a = 99; ds@621: new Float:b = 4.215; ds@621: new err, ret; ds@621: ds@621: if (g_GlobalFwd == INVALID_HANDLE) ds@621: { ds@621: PrintToServer("Failed to execute global forward. Create it first."); ds@621: return Plugin_Handled; ds@621: } ds@621: ds@621: PrintToServer("Beginning call to %d functions in global forward \"OnGlobalForward\"", GetForwardFunctionCount(g_GlobalFwd)); ds@621: ds@621: Call_StartForward(g_GlobalFwd); ds@621: Call_PushCell(OnPluginStart); ds@621: Call_PushCell(7); ds@621: Call_PushFloat(-8.5); ds@621: Call_PushString("Anata wa doko desu ka?"); ds@621: Call_PushArray({0.0, 1.1, 2.2}, 3); ds@621: Call_PushCellRef(a); ds@621: Call_PushFloatRef(b); ds@621: err = Call_Finish(ret); ds@621: ds@621: PrintToServer("Call to global forward \"OnGlobalForward\" completed"); ds@621: PrintToServer("Error code = %d (expected: %d)", err, 0); ds@621: PrintToServer("Return value = %d (expected: %d)", ret, Plugin_Continue); ds@621: ds@621: PrintToServer("a = %d (expected: %d)", a, 777); ds@621: PrintToServer("b = %f (expected: %f)", b, -0.782); ds@621: ds@621: return Plugin_Handled; ds@621: } ds@621: ds@621: public Action:Command_ExecPrivateForward(args) ds@621: { ds@621: new err, ret; ds@621: ds@621: if (g_PrivateFwd == INVALID_HANDLE) ds@621: { ds@621: PrintToServer("Failed to execute private forward. Create it first."); ds@621: return Plugin_Handled; ds@621: } ds@621: ds@621: PrintToServer("Beginning call to %d functions in private forward", GetForwardFunctionCount(g_PrivateFwd)); ds@621: ds@621: Call_StartForward(g_PrivateFwd); ds@621: Call_PushCell(24); ds@621: Call_PushString("I am a format string: %d %d %d %d %d %d"); ds@621: Call_PushCell(0); ds@621: Call_PushCell(1); ds@621: Call_PushCell(2); ds@621: Call_PushCell(3); ds@621: Call_PushCell(4); ds@621: Call_PushCell(5); ds@621: err = Call_Finish(ret); ds@621: ds@621: PrintToServer("Call to private forward completed"); ds@621: PrintToServer("Error code = %d (expected: %d)", err, 0); ds@621: PrintToServer("Return value = %d (expected: %d)", ret, Plugin_Handled); ds@621: ds@621: return Plugin_Handled; ds@621: } ds@621: ds@621: public Action:ZohMyGod(num, const String:format[], ...) ds@621: { ds@621: decl String:buffer[128]; ds@621: ds@621: PrintToServer("Inside private forward #1"); ds@621: ds@621: PrintToServer("num = %d (expected: %d)", num, 24); ds@621: ds@621: VFormat(buffer, sizeof(buffer), format, 3); ds@621: PrintToServer("buffer = \"%s\" (expected: \"%s\")", buffer, "I am a format string: 0 1 2 3 4 5"); ds@621: ds@621: PrintToServer("End private forward #1"); ds@621: ds@621: return Plugin_Continue; ds@621: }