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