plugins/testsuite/callfunctest.sp
author Scott Ehlert <ds@alliedmods.net>
Thu Jun 07 02:04:05 2007 +0000 (2007-06-07)
changeset 898 f8ff0a7cd037
parent 621 5a0f5014aac1
child 1082 bb923439d570
permissions -rw-r--r--
Yikes, fixed PrintToChatAll() and PrintCenterTextAll()
     1 #include <sourcemod>
     2 
     3 public Plugin:myinfo = 
     4 {
     5 	name = "Function Call Testing Lab",
     6 	author = "AlliedModders LLC",
     7 	description = "Tests basic function calls",
     8 	version = "1.0.0.0",
     9 	url = "http://www.sourcemod.net/"
    10 };
    11 
    12 public OnPluginStart()
    13 {
    14 	RegServerCmd("test_callfunc", Command_CallFunc);
    15 }
    16 
    17 public OnCallFuncReceived(num, Float:fnum, String:str[], String:str2[], &val, &Float:fval, array[], array2[], size, hello2[1])
    18 {
    19 	PrintToServer("Inside OnCallFuncReceived...");
    20 
    21 	PrintToServer("num = %d (expected: %d)", num, 5);
    22 	PrintToServer("fnum = %f (expected: %f)", fnum, 7.17);
    23 	PrintToServer("str[] = \"%s\" (expected: \"%s\")", str, "Gaben");
    24 	PrintToServer("str2[] = \"%s\" (expected: \"%s\")", str2, ".taf si nebaG");
    25 	
    26 	PrintToServer("val = %d (expected %d, setting to %d)", val, 62, 15);
    27 	val = 15;
    28 	
    29 	PrintToServer("fval = %f (expected: %f, setting to %f)", fval, 6.25, 1.5);
    30 	fval = 1.5; 
    31 	
    32 	PrintToServer("Printing %d elements of array[] (expected: %d)", size, 6);
    33 	for (new i = 0; i < size; i++)
    34 	{
    35 		PrintToServer("array[%d] = %d (expected: %d)", i, array[i], i);
    36 	}
    37 	for (new i = 0; i < size; i++)
    38 	{
    39 		PrintToServer("array2[%d] = %d (expected: %d)", i, array[i], i);
    40 	}
    41 	
    42 	/* This shouldn't get copied back */
    43 	StrCopy(str, strlen(str) + 1, "Yeti");
    44 	/* This should get copied back */
    45 	StrCopy(str2, strlen(str2) + 1, "Gaben is fat.");
    46 	
    47 	/* This should get copied back */
    48 	array[0] = 5;
    49 	array[1] = 6;
    50 	/* This shouldn't get copied back */
    51 	hello2[0] = 25;
    52 	
    53 	return 42;
    54 }
    55 
    56 public Action:Command_CallFunc(args)
    57 {
    58 	new a = 62;
    59 	new Float:b = 6.25;
    60 	new const String:what[] = "Gaben";
    61 	new String:truth[] = ".taf si nebaG";
    62 	new hello[] = {0, 1, 2, 3, 4, 5};
    63 	new hello2[] = {9};
    64 	new pm = 6;
    65 	new err;
    66 	new ret;
    67 	
    68 	new Function:func = GetFunctionByName(INVALID_HANDLE, "OnCallFuncReceived");
    69 	
    70 	if (func == INVALID_FUNCTION)
    71 	{
    72 		PrintToServer("Failed to get the function id of OnCallFuncReceived");
    73 		return Plugin_Handled;
    74 	}
    75 	
    76 	PrintToServer("Calling OnCallFuncReceived...");
    77 	
    78 	Call_StartFunction(INVALID_HANDLE, func);
    79 	Call_PushCell(5);
    80 	Call_PushFloat(7.17);
    81 	Call_PushString(what);
    82 	Call_PushStringEx(truth, sizeof(truth), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
    83 	Call_PushCellRef(a);
    84 	Call_PushFloatRef(b);
    85 	Call_PushArrayEx(hello, pm, SM_PARAM_COPYBACK);
    86 	Call_PushArray(hello, pm);
    87 	Call_PushCell(pm);
    88 	Call_PushArray(hello2, 1);
    89 	err = Call_Finish(ret);
    90 	
    91 	PrintToServer("Call to OnCallFuncReceived has finished!");
    92 	PrintToServer("Error code = %d (expected: %d)", err, 0);
    93 	PrintToServer("Return value = %d (expected: %d)", ret, 42);
    94 	
    95 	PrintToServer("a = %d (expected: %d)", a, 15);
    96 	PrintToServer("b = %f (expected: %f)", b, 1.5);
    97 	PrintToServer("what = \"%s\" (expected: \"%s\")", what, "Gaben");
    98 	PrintToServer("truth = \"%s\" (expected: \"%s\")", truth, "Gaben is fat.");
    99 	PrintToServer("hello[0] = %d (expected: %d)", hello[0], 5);
   100 	PrintToServer("hello[1] = %d (expected: %d)", hello[1], 6);
   101 	PrintToServer("hello2[0] = %d (expected: %d)", hello2[0], 9);
   102 	
   103 	return Plugin_Handled;
   104 }