plugins/testsuite/fwdtest1.sp
author Borja Ferrer <faluco@alliedmods.net>
Fri Sep 28 20:13:42 2007 +0000 (2007-09-28)
changeset 1499 e55ac4555a2b
parent 624 c38674238f45
permissions -rw-r--r--
synced linux build
ds@621
     1
#include <sourcemod>
ds@621
     2
ds@621
     3
public Plugin:myinfo = 
ds@621
     4
{
ds@621
     5
	name = "Forward Testing Lab #1",
ds@621
     6
	author = "AlliedModders LLC",
ds@621
     7
	description = "Tests suite #1 for forwards created by plugins",
ds@621
     8
	version = "1.0.0.0",
ds@621
     9
	url = "http://www.sourcemod.net/"
ds@621
    10
};
ds@621
    11
ds@621
    12
new Handle:g_GlobalFwd = INVALID_HANDLE;
ds@621
    13
new Handle:g_PrivateFwd = INVALID_HANDLE;
ds@621
    14
ds@621
    15
public OnPluginStart()
ds@624
    16
{	
ds@621
    17
	RegServerCmd("test_create_gforward", Command_CreateGlobalForward);
ds@621
    18
	RegServerCmd("test_create_pforward", Command_CreatePrivateForward);
ds@621
    19
	RegServerCmd("test_exec_gforward", Command_ExecGlobalForward);
ds@621
    20
	RegServerCmd("test_exec_pforward", Command_ExecPrivateForward);
ds@621
    21
}
ds@621
    22
ds@621
    23
public OnPluginEnd()
ds@621
    24
{
ds@621
    25
	CloseHandle(g_GlobalFwd);
ds@621
    26
	CloseHandle(g_PrivateFwd);
ds@621
    27
}
ds@621
    28
ds@621
    29
public Action:Command_CreateGlobalForward(args)
ds@621
    30
{
ds@621
    31
	if (g_GlobalFwd != INVALID_HANDLE)
ds@621
    32
	{
ds@621
    33
		CloseHandle(g_GlobalFwd);
ds@621
    34
	}
ds@621
    35
	
ds@621
    36
	g_GlobalFwd = CreateGlobalForward("OnGlobalForward", ET_Ignore, Param_Any, Param_Cell, Param_Float, Param_String, Param_Array, Param_CellByRef, Param_FloatByRef);
ds@621
    37
	
ds@621
    38
	if (g_GlobalFwd == INVALID_HANDLE)
ds@621
    39
	{
ds@621
    40
		PrintToServer("Failed to create global forward!");
ds@621
    41
	}
ds@621
    42
	
ds@621
    43
	return Plugin_Handled;
ds@621
    44
}
ds@621
    45
ds@621
    46
public Action:Command_CreatePrivateForward(args)
ds@621
    47
{
ds@621
    48
	new Handle:pl;
ds@621
    49
	new Function:func;
ds@621
    50
	
ds@621
    51
	if (g_PrivateFwd != INVALID_HANDLE)
ds@621
    52
	{
ds@621
    53
		CloseHandle(g_PrivateFwd);
ds@621
    54
	}
ds@621
    55
	
ds@621
    56
	g_PrivateFwd = CreateForward(ET_Hook, Param_Cell, Param_String, Param_VarArgs);
ds@621
    57
	
ds@621
    58
	if (g_PrivateFwd == INVALID_HANDLE)
ds@621
    59
	{
ds@621
    60
		PrintToServer("Failed to create private forward!")
ds@621
    61
	}
ds@621
    62
	
ds@621
    63
	pl = FindPluginByFile("fwdtest2.smx");
ds@621
    64
	
ds@621
    65
	if (!pl)
ds@621
    66
	{
ds@621
    67
		PrintToServer("Could not find fwdtest2.smx!");
ds@621
    68
		return Plugin_Handled;
ds@621
    69
	}
ds@621
    70
	
ds@621
    71
	func = GetFunctionByName(pl, "OnPrivateForward");
ds@621
    72
	
ds@621
    73
	/* This shouldn't happen, but oh well */
ds@621
    74
	if (func == INVALID_FUNCTION)
ds@621
    75
	{
ds@621
    76
		PrintToServer("Could not find \"OnPrivateForward\" in fwdtest2.smx!");
ds@621
    77
		return Plugin_Handled;
ds@621
    78
	}
ds@621
    79
	
ds@621
    80
	if (!AddToForward(g_PrivateFwd, pl, func) || !AddToForward(g_PrivateFwd, GetMyHandle(), ZohMyGod))
ds@621
    81
	{
ds@621
    82
		PrintToServer("Failed to add functions to private forward!");
ds@621
    83
		return Plugin_Handled;
ds@621
    84
	}
ds@621
    85
	
ds@621
    86
	return Plugin_Handled;
ds@621
    87
}
ds@621
    88
ds@621
    89
public Action:Command_ExecGlobalForward(args)
ds@621
    90
{
ds@621
    91
	new a = 99;
ds@621
    92
	new Float:b = 4.215;
ds@621
    93
	new err, ret;
ds@621
    94
	
ds@621
    95
	if (g_GlobalFwd == INVALID_HANDLE)
ds@621
    96
	{
ds@621
    97
		PrintToServer("Failed to execute global forward. Create it first.");
ds@621
    98
		return Plugin_Handled;
ds@621
    99
	}
ds@621
   100
	
ds@621
   101
	PrintToServer("Beginning call to %d functions in global forward \"OnGlobalForward\"", GetForwardFunctionCount(g_GlobalFwd));
ds@621
   102
	
ds@621
   103
	Call_StartForward(g_GlobalFwd);
ds@621
   104
	Call_PushCell(OnPluginStart);
ds@621
   105
	Call_PushCell(7);
ds@621
   106
	Call_PushFloat(-8.5);
ds@621
   107
	Call_PushString("Anata wa doko desu ka?");
ds@621
   108
	Call_PushArray({0.0, 1.1, 2.2}, 3);
ds@621
   109
	Call_PushCellRef(a);
ds@621
   110
	Call_PushFloatRef(b);
ds@621
   111
	err = Call_Finish(ret);
ds@621
   112
	
ds@621
   113
	PrintToServer("Call to global forward \"OnGlobalForward\" completed");
ds@621
   114
	PrintToServer("Error code = %d (expected: %d)", err, 0);
ds@621
   115
	PrintToServer("Return value = %d (expected: %d)", ret, Plugin_Continue);
ds@621
   116
	
ds@621
   117
	PrintToServer("a = %d (expected: %d)", a, 777);
ds@621
   118
	PrintToServer("b = %f (expected: %f)", b, -0.782);
ds@621
   119
	
ds@621
   120
	return Plugin_Handled;
ds@621
   121
}
ds@621
   122
ds@621
   123
public Action:Command_ExecPrivateForward(args)
ds@621
   124
{
ds@621
   125
	new err, ret;
ds@621
   126
	
ds@621
   127
	if (g_PrivateFwd == INVALID_HANDLE)
ds@621
   128
	{
ds@621
   129
		PrintToServer("Failed to execute private forward. Create it first.");
ds@621
   130
		return Plugin_Handled;
ds@621
   131
	}
ds@621
   132
	
ds@621
   133
	PrintToServer("Beginning call to %d functions in private forward", GetForwardFunctionCount(g_PrivateFwd));
ds@621
   134
	
ds@621
   135
	Call_StartForward(g_PrivateFwd);
ds@621
   136
	Call_PushCell(24);
ds@621
   137
	Call_PushString("I am a format string: %d %d %d %d %d %d");
ds@621
   138
	Call_PushCell(0);
ds@621
   139
	Call_PushCell(1);
ds@621
   140
	Call_PushCell(2);
ds@621
   141
	Call_PushCell(3);
ds@621
   142
	Call_PushCell(4);
ds@621
   143
	Call_PushCell(5);
ds@621
   144
	err = Call_Finish(ret);
ds@621
   145
	
ds@621
   146
	PrintToServer("Call to private forward completed");
ds@621
   147
	PrintToServer("Error code = %d (expected: %d)", err, 0);
ds@621
   148
	PrintToServer("Return value = %d (expected: %d)", ret, Plugin_Handled);
ds@621
   149
ds@621
   150
	return Plugin_Handled;
ds@621
   151
}
ds@621
   152
ds@621
   153
public Action:ZohMyGod(num, const String:format[], ...)
ds@621
   154
{
ds@621
   155
	decl String:buffer[128];
ds@621
   156
	
ds@621
   157
	PrintToServer("Inside private forward #1");
ds@621
   158
	
ds@621
   159
	PrintToServer("num = %d (expected: %d)", num, 24);
ds@621
   160
	
ds@621
   161
	VFormat(buffer, sizeof(buffer), format, 3);
ds@621
   162
	PrintToServer("buffer = \"%s\" (expected: \"%s\")", buffer, "I am a format string: 0 1 2 3 4 5");
ds@621
   163
	
ds@621
   164
	PrintToServer("End private forward #1");
ds@621
   165
	
ds@621
   166
	return Plugin_Continue;
ds@621
   167
}