jit refactoring branch

--HG--
branch : refac-jit
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/branches/refac-jit%402369
This commit is contained in:
David Anderson
2008-07-06 04:49:55 +00:00
commit 2e7b6b5ba5
879 changed files with 297155 additions and 0 deletions
+157
View File
@@ -0,0 +1,157 @@
#include <sourcemod>
#include <profiler>
public Plugin:myinfo =
{
name = "Benchmarks",
author = "AlliedModders LLC",
description = "Basic benchmarks",
version = "1.0.0.0",
url = "http://www.sourcemod.net/"
};
#define MATH_INT_LOOPS 2000
#define MATH_FLOAT_LOOPS 2000
#define STRING_OP_LOOPS 2000
#define STRING_FMT_LOOPS 2000
#define STRING_ML_LOOPS 2000
#define STRING_RPLC_LOOPS 2000
new Float:g_dict_time
new Handle:g_Prof = INVALID_HANDLE
public OnPluginStart()
{
RegServerCmd("bench", Benchmark);
g_Prof = CreateProfiler();
StartProfiling(g_Prof);
LoadTranslations("fakedict-sourcemod.cfg");
StopProfiling(g_Prof);
g_dict_time = GetProfilerTime(g_Prof);
}
public Action:Benchmark(args)
{
PrintToServer("dictionary time: %f seconds", g_dict_time);
StringBench();
MathBench();
return Plugin_Handled;
}
MathBench()
{
StartProfiling(g_Prof);
new iter = MATH_INT_LOOPS;
new a, b, c;
while(iter--)
{
a = iter * 7;
b = 5 + iter;
c = 6 / (iter + 3);
a = 6 * (iter);
b = a * 185;
a = b / 25;
c = b - a + 3;
b = b*b;
a = (a + c) / (b - c);
b = 6;
c = 1;
b = a * 128 - c;
c = b * (a + 16) * b;
if (!a)
{
a = 5;
}
a = c + (28/a) - c;
}
StopProfiling(g_Prof);
PrintToServer("int benchmark: %f seconds", GetProfilerTime(g_Prof));
StartProfiling(g_Prof);
new Float:fa, Float:fb, Float:fc
new int1
iter = MATH_FLOAT_LOOPS;
while (iter--)
{
fa = iter * 0.7;
fb = 5.1 + iter;
fc = 6.1 / (float(iter) + 2.5);
fa = 6.1 * (iter);
fb = fa * 185.26;
fa = fb / 25.56;
fc = fb - a + float(3);
fb = fb*fb;
fa = (fa + fc) / (fb - fc);
fb = 6.2;
fc = float(1);
int1 = RoundToNearest(fa);
fb = fa * float(128) - int1;
fc = fb * (a + 16.85) * float(RoundToCeil(fb));
if (fa == 0.0)
{
fa = 5.0;
}
fa = fc + (float(28)/fa) - RoundToFloor(fc);
}
StopProfiling(g_Prof);
PrintToServer("float benchmark: %f seconds", GetProfilerTime(g_Prof));
}
#define KEY1 "LVWANBAGVXSXUGB"
#define KEY2 "IDYCVNWEOWNND"
#define KEY3 "UZWTRNHY"
#define KEY4 "EPRHAFCIUOIG"
#define KEY5 "RMZCVWIEY"
#define KEY6 "ZHPU"
StringBench()
{
new i = STRING_FMT_LOOPS;
new String:buffer[255];
StartProfiling(g_Prof);
new end
while (i--)
{
end = 0;
Format(buffer, sizeof(buffer), "%d", i);
Format(buffer, sizeof(buffer), "%d %s %d %f %d %-3.4s %s", i, "gaben", 30, 10.0, 20, "hello", "What a gaben");
end = Format(buffer, sizeof(buffer), "Well, that's just %-17.18s!", "what. this isn't a valid string! wait it is");
end += Format(buffer[end], sizeof(buffer)-end, "There are %d in this %d", i, end);
end += Format(buffer[end], sizeof(buffer)-end, "There are %d in this %d", i, end);
}
StopProfiling(g_Prof);
PrintToServer("format() benchmark: %f seconds", GetProfilerTime(g_Prof));
StartProfiling(g_Prof);
i = STRING_ML_LOOPS;
new String:fmtbuf[2048]; /* don't change to decl, amxmodx doesn't use it */
while (i--)
{
Format(fmtbuf, 2047, "%T %T %d %s %f %T", KEY1, LANG_SERVER, KEY2, LANG_SERVER, 50, "what the", 50.0, KEY3, LANG_SERVER);
Format(fmtbuf, 2047, "%s %T %s %T %T", "gaben", KEY4, LANG_SERVER, "what TIME is it", KEY5, LANG_SERVER, KEY6, LANG_SERVER);
}
StopProfiling(g_Prof);
PrintToServer("ml benchmark: %f seconds", GetProfilerTime(g_Prof));
StartProfiling(g_Prof);
i = STRING_OP_LOOPS;
while (i--)
{
StringToInt(fmtbuf)
}
StopProfiling(g_Prof);
PrintToServer("str benchmark: %f seconds", GetProfilerTime(g_Prof));
StartProfiling(g_Prof);
i = STRING_RPLC_LOOPS;
while (i--)
{
strcopy(fmtbuf, 2047, "This is a test string for you.");
ReplaceString(fmtbuf, sizeof(fmtbuf), " ", "ASDF")
ReplaceString(fmtbuf, sizeof(fmtbuf), "SDF", "")
ReplaceString(fmtbuf, sizeof(fmtbuf), "string", "gnirts")
}
StopProfiling(g_Prof);
PrintToServer("replace benchmark: %f seconds", GetProfilerTime(g_Prof));
}
+169
View File
@@ -0,0 +1,169 @@
#include <sourcemod>
public Plugin:myinfo =
{
name = "Function Call Testing Lab",
author = "AlliedModders LLC",
description = "Tests basic function calls",
version = "1.0.0.0",
url = "http://www.sourcemod.net/"
};
public OnPluginStart()
{
RegServerCmd("test_callfunc", Command_CallFunc);
RegServerCmd("test_callfunc_reentrant", Command_ReentrantCallFunc);
}
public OnCallFuncReceived(num, Float:fnum, String:str[], String:str2[], &val, &Float:fval, array[], array2[], size, hello2[1])
{
PrintToServer("Inside OnCallFuncReceived...");
PrintToServer("num = %d (expected: %d)", num, 5);
PrintToServer("fnum = %f (expected: %f)", fnum, 7.17);
PrintToServer("str[] = \"%s\" (expected: \"%s\")", str, "Gaben");
PrintToServer("str2[] = \"%s\" (expected: \"%s\")", str2, ".taf si nebaG");
PrintToServer("val = %d (expected %d, setting to %d)", val, 62, 15);
val = 15;
PrintToServer("fval = %f (expected: %f, setting to %f)", fval, 6.25, 1.5);
fval = 1.5;
PrintToServer("Printing %d elements of array[] (expected: %d)", size, 6);
for (new i = 0; i < size; i++)
{
PrintToServer("array[%d] = %d (expected: %d)", i, array[i], i);
}
for (new i = 0; i < size; i++)
{
PrintToServer("array2[%d] = %d (expected: %d)", i, array[i], i);
}
/* This shouldn't get copied back */
strcopy(str, strlen(str) + 1, "Yeti");
/* This should get copied back */
strcopy(str2, strlen(str2) + 1, "Gaben is fat.");
/* This should get copied back */
array[0] = 5;
array[1] = 6;
/* This shouldn't get copied back */
hello2[0] = 25;
return 42;
}
public OnReentrantCallReceived(num, String:str[])
{
new err, ret;
PrintToServer("Inside OnReentrantCallReceived...");
PrintToServer("num = %d (expected: %d)", num, 7);
PrintToServer("str[] = \"%s\" (expected: \"%s\")", str, "nana");
new Function:func = GetFunctionByName(INVALID_HANDLE, "OnReentrantCallReceivedTwo");
if (func == INVALID_FUNCTION)
{
PrintToServer("Failed to get the function id of OnReentrantCallReceivedTwo");
return 0;
}
PrintToServer("Calling OnReentrantCallReceivedTwo...");
Call_StartFunction(INVALID_HANDLE, func);
Call_PushFloat(8.0);
err = Call_Finish(ret);
PrintToServer("Call to OnReentrantCallReceivedTwo has finished!");
PrintToServer("Error code = %d (expected: %d)", err, 0);
PrintToServer("Return value = %d (expected: %d)", ret, 707);
return 11;
}
public OnReentrantCallReceivedTwo(Float:fnum)
{
PrintToServer("Inside OnReentrantCallReceivedTwo...");
PrintToServer("fnum = %f (expected: %f)", fnum, 8.0);
return 707;
}
public Action:Command_CallFunc(args)
{
new a = 62;
new Float:b = 6.25;
new const String:what[] = "Gaben";
new String:truth[] = ".taf si nebaG";
new hello[] = {0, 1, 2, 3, 4, 5};
new hello2[] = {9};
new pm = 6;
new err;
new ret;
new Function:func = GetFunctionByName(INVALID_HANDLE, "OnCallFuncReceived");
if (func == INVALID_FUNCTION)
{
PrintToServer("Failed to get the function id of OnCallFuncReceived");
return Plugin_Handled;
}
PrintToServer("Calling OnCallFuncReceived...");
Call_StartFunction(INVALID_HANDLE, func);
Call_PushCell(5);
Call_PushFloat(7.17);
Call_PushString(what);
Call_PushStringEx(truth, sizeof(truth), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
Call_PushCellRef(a);
Call_PushFloatRef(b);
Call_PushArrayEx(hello, pm, SM_PARAM_COPYBACK);
Call_PushArray(hello, pm);
Call_PushCell(pm);
Call_PushArray(hello2, 1);
err = Call_Finish(ret);
PrintToServer("Call to OnCallFuncReceived has finished!");
PrintToServer("Error code = %d (expected: %d)", err, 0);
PrintToServer("Return value = %d (expected: %d)", ret, 42);
PrintToServer("a = %d (expected: %d)", a, 15);
PrintToServer("b = %f (expected: %f)", b, 1.5);
PrintToServer("what = \"%s\" (expected: \"%s\")", what, "Gaben");
PrintToServer("truth = \"%s\" (expected: \"%s\")", truth, "Gaben is fat.");
PrintToServer("hello[0] = %d (expected: %d)", hello[0], 5);
PrintToServer("hello[1] = %d (expected: %d)", hello[1], 6);
PrintToServer("hello2[0] = %d (expected: %d)", hello2[0], 9);
return Plugin_Handled;
}
public Action:Command_ReentrantCallFunc(args)
{
new err, ret;
new Function:func = GetFunctionByName(INVALID_HANDLE, "OnReentrantCallReceived");
if (func == INVALID_FUNCTION)
{
PrintToServer("Failed to get the function id of OnReentrantCallReceived");
return Plugin_Handled;
}
PrintToServer("Calling OnReentrantCallReceived...");
Call_StartFunction(INVALID_HANDLE, func);
Call_PushCell(7);
Call_PushString("nana");
err = Call_Finish(ret);
PrintToServer("Call to OnReentrantCallReceived has finished!");
PrintToServer("Error code = %d (expected: %d)", err, 0);
PrintToServer("Return value = %d (expected: %d)", ret, 11);
return Plugin_Handled;
}
+59
View File
@@ -0,0 +1,59 @@
#include <sourcemod>
#include <clientprefs.inc>
new Handle:g_Cookie;
new Handle:g_Cookie2;
new Handle:g_Cookie3;
new Handle:g_Cookie4;
new Handle:g_Cookie5;
public OnPluginStart()
{
g_Cookie = RegClientCookie("test-cookie", "A basic testing cookie", CookieAccess_Public);
g_Cookie2 = RegClientCookie("test-cookie2", "A basic testing cookie", CookieAccess_Protected);
g_Cookie3 = RegClientCookie("test-cookie3", "A basic testing cookie", CookieAccess_Public);
g_Cookie4 = RegClientCookie("test-cookie4", "A basic testing cookie", CookieAccess_Private);
g_Cookie5 = RegClientCookie("test-cookie5", "A basic testing cookie", CookieAccess_Public);
SetCookiePrefabMenu(g_Cookie, CookieMenu_YesNo, "Cookie 1", CookieSelected, any:g_Cookie);
SetCookiePrefabMenu(g_Cookie2, CookieMenu_YesNo_Int, "Cookie 2");
SetCookiePrefabMenu(g_Cookie3, CookieMenu_OnOff, "Cookie 3");
SetCookiePrefabMenu(g_Cookie4, CookieMenu_OnOff_Int, "Cookie 4");
SetCookieMenuItem(CookieSelected, g_Cookie5, "Get Cookie 5 value");
}
public CookieSelected(client, CookieMenuAction:action, any:info, String:buffer[], maxlen)
{
if (action == CookieMenuAction_DisplayOption)
{
PrintToChat(client, "About to draw item. Current text is : %s", buffer);
Format(buffer, maxlen, "HELLLLLLLLLLO");
}
else
{
LogMessage("SELECTED!");
new String:value[100];
GetClientCookie(client, info, value, sizeof(value));
PrintToChat(client, "Value is : %s", value);
}
}
public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
{
LogMessage("Connect Cookie state: %s", AreClientCookiesCached(client) ? "YES" : "NO");
}
public OnClientCookiesCached(client)
{
LogMessage("Loaded Cookie state: %s", AreClientCookiesCached(client) ? "YES" : "NO");
new String:hi[100];
GetClientCookie(client, g_Cookie, hi, sizeof(hi));
LogMessage("Test: %s",hi);
SetClientCookie(client, g_Cookie, "somethingsomething");
GetClientCookie(client, g_Cookie, hi, sizeof(hi));
LogMessage("Test: %s",hi);
}
+85
View File
@@ -0,0 +1,85 @@
#include <sourcemod>
public Plugin:myinfo =
{
name = "FakeNative Testing Lab #1",
author = "AlliedModders LLC",
description = "Test suite #1 for dynamic natives",
version = "1.0.0.0",
url = "http://www.sourcemod.net/"
};
public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max)
{
CreateNative("TestNative1", __TestNative1);
CreateNative("TestNative2", __TestNative2);
CreateNative("TestNative3", __TestNative3);
CreateNative("TestNative4", __TestNative4);
CreateNative("TestNative5", __TestNative5);
return true;
}
public __TestNative1(Handle:plugin, numParams)
{
PrintToServer("TestNative1: Plugin: %x params: %d", plugin, numParams);
if (numParams == 4)
{
ThrowNativeError(SP_ERROR_NATIVE, "Four parameters ARE NOT ALLOWED lol");
}
return 5;
}
public __TestNative2(Handle:plugin, numParams)
{
new String:buffer[512];
new bytes;
GetNativeString(1, buffer, sizeof(buffer), bytes);
for (new i=0; i<bytes; i++)
{
buffer[i] = buffer[i] + 1;
}
SetNativeString(1, buffer, bytes+1);
}
public __TestNative3(Handle:plugin, numParams)
{
new val1 = GetNativeCell(1);
new val2 = GetNativeCellRef(2);
SetNativeCellRef(2, val1+val2);
}
public __TestNative4(Handle:plugin, numParams)
{
new size = GetNativeCell(3);
new local[size];
GetNativeArray(1, local, size);
SetNativeArray(2, local, size);
}
public __TestNative5(Handle:plugin, numParams)
{
new local = GetNativeCell(1);
if (local)
{
FormatNativeString(2, 4, 5, GetNativeCell(3));
} else {
new len = GetNativeCell(3);
new fmt_len;
new String:buffer[len];
GetNativeStringLength(4, fmt_len);
new String:format[fmt_len];
GetNativeString(2, buffer, len);
GetNativeString(4, format, fmt_len);
FormatNativeString(0, 0, 5, len, _, buffer, format);
}
}
+87
View File
@@ -0,0 +1,87 @@
#include <sourcemod>
native TestNative1(gaben, ...);
native TestNative2(String:buffer[]);
native TestNative3(value1, &value2);
native TestNative4(const input[], output[], size);
native TestNative5(bool:local, String:buffer[], maxlength, const String:fmt[], {Handle,Float,String,_}:...);
public Plugin:myinfo =
{
name = "FakeNative Testing Lab #2",
author = "AlliedModders LLC",
description = "Test suite #2 for dynamic natives",
version = "1.0.0.0",
url = "http://www.sourcemod.net/"
};
public OnPluginStart()
{
RegServerCmd("test_native1", Test_Native1);
RegServerCmd("test_native2", Test_Native2);
RegServerCmd("test_native3", Test_Native3);
RegServerCmd("test_native4", Test_Native4);
RegServerCmd("test_native5", Test_Native5);
}
public Action:Test_Native1(args)
{
PrintToServer("Returned: %d", TestNative1(1));
PrintToServer("Returned: %d", TestNative1(1,2));
PrintToServer("Returned: %d", TestNative1(1,2,3,4));
return Plugin_Handled;
}
public Action:Test_Native2(args)
{
new String:buffer[] = "IBM";
PrintToServer("Before: %s", buffer);
TestNative2(buffer);
PrintToServer("AfteR: %s", buffer);
return Plugin_Handled;
}
public Action:Test_Native3(args)
{
new value1 = 5, value2 = 6
PrintToServer("Before: %d, %d", value1, value2);
TestNative3(value1, value2);
PrintToServer("After: %d, %d", value1, value2);
return Plugin_Handled;
}
public Action:Test_Native4(args)
{
new input[5] = {0, 1, 2, 3, 4};
new output[5];
TestNative4(input, output, 5);
PrintToServer("[0=%d] [1=%d] [2=%d] [3=%d] [4=%d]", input[0], input[1], input[2], input[3], input[4]);
PrintToServer("[0=%d] [1=%d] [2=%d] [3=%d] [4=%d]", output[0], output[1], output[2], output[3], output[4]);
return Plugin_Handled;
}
public Action:Test_Native5(args)
{
new String:buffer1[512];
new String:buffer2[512];
TestNative5(true, buffer1, sizeof(buffer1), "%d gabens in the %s", 50, "gabpark");
TestNative5(true, buffer2, sizeof(buffer2), "%d gabens in the %s", 50, "gabpark");
PrintToServer("Test 1: %s", buffer1);
PrintToServer("Test 2: %s", buffer2);
return Plugin_Handled;
}
+167
View File
@@ -0,0 +1,167 @@
#include <sourcemod>
public Plugin:myinfo =
{
name = "Forward Testing Lab #1",
author = "AlliedModders LLC",
description = "Tests suite #1 for forwards created by plugins",
version = "1.0.0.0",
url = "http://www.sourcemod.net/"
};
new Handle:g_GlobalFwd = INVALID_HANDLE;
new Handle:g_PrivateFwd = INVALID_HANDLE;
public OnPluginStart()
{
RegServerCmd("test_create_gforward", Command_CreateGlobalForward);
RegServerCmd("test_create_pforward", Command_CreatePrivateForward);
RegServerCmd("test_exec_gforward", Command_ExecGlobalForward);
RegServerCmd("test_exec_pforward", Command_ExecPrivateForward);
}
public OnPluginEnd()
{
CloseHandle(g_GlobalFwd);
CloseHandle(g_PrivateFwd);
}
public Action:Command_CreateGlobalForward(args)
{
if (g_GlobalFwd != INVALID_HANDLE)
{
CloseHandle(g_GlobalFwd);
}
g_GlobalFwd = CreateGlobalForward("OnGlobalForward", ET_Ignore, Param_Any, Param_Cell, Param_Float, Param_String, Param_Array, Param_CellByRef, Param_FloatByRef);
if (g_GlobalFwd == INVALID_HANDLE)
{
PrintToServer("Failed to create global forward!");
}
return Plugin_Handled;
}
public Action:Command_CreatePrivateForward(args)
{
new Handle:pl;
new Function:func;
if (g_PrivateFwd != INVALID_HANDLE)
{
CloseHandle(g_PrivateFwd);
}
g_PrivateFwd = CreateForward(ET_Hook, Param_Cell, Param_String, Param_VarArgs);
if (g_PrivateFwd == INVALID_HANDLE)
{
PrintToServer("Failed to create private forward!")
}
pl = FindPluginByFile("fwdtest2.smx");
if (!pl)
{
PrintToServer("Could not find fwdtest2.smx!");
return Plugin_Handled;
}
func = GetFunctionByName(pl, "OnPrivateForward");
/* This shouldn't happen, but oh well */
if (func == INVALID_FUNCTION)
{
PrintToServer("Could not find \"OnPrivateForward\" in fwdtest2.smx!");
return Plugin_Handled;
}
if (!AddToForward(g_PrivateFwd, pl, func) || !AddToForward(g_PrivateFwd, GetMyHandle(), ZohMyGod))
{
PrintToServer("Failed to add functions to private forward!");
return Plugin_Handled;
}
return Plugin_Handled;
}
public Action:Command_ExecGlobalForward(args)
{
new a = 99;
new Float:b = 4.215;
new err, ret;
if (g_GlobalFwd == INVALID_HANDLE)
{
PrintToServer("Failed to execute global forward. Create it first.");
return Plugin_Handled;
}
PrintToServer("Beginning call to %d functions in global forward \"OnGlobalForward\"", GetForwardFunctionCount(g_GlobalFwd));
Call_StartForward(g_GlobalFwd);
Call_PushCell(OnPluginStart);
Call_PushCell(7);
Call_PushFloat(-8.5);
Call_PushString("Anata wa doko desu ka?");
Call_PushArray({0.0, 1.1, 2.2}, 3);
Call_PushCellRef(a);
Call_PushFloatRef(b);
err = Call_Finish(ret);
PrintToServer("Call to global forward \"OnGlobalForward\" completed");
PrintToServer("Error code = %d (expected: %d)", err, 0);
PrintToServer("Return value = %d (expected: %d)", ret, Plugin_Continue);
PrintToServer("a = %d (expected: %d)", a, 777);
PrintToServer("b = %f (expected: %f)", b, -0.782);
return Plugin_Handled;
}
public Action:Command_ExecPrivateForward(args)
{
new err, ret;
if (g_PrivateFwd == INVALID_HANDLE)
{
PrintToServer("Failed to execute private forward. Create it first.");
return Plugin_Handled;
}
PrintToServer("Beginning call to %d functions in private forward", GetForwardFunctionCount(g_PrivateFwd));
Call_StartForward(g_PrivateFwd);
Call_PushCell(24);
Call_PushString("I am a format string: %d %d %d %d %d %d");
Call_PushCell(0);
Call_PushCell(1);
Call_PushCell(2);
Call_PushCell(3);
Call_PushCell(4);
Call_PushCell(5);
err = Call_Finish(ret);
PrintToServer("Call to private forward completed");
PrintToServer("Error code = %d (expected: %d)", err, 0);
PrintToServer("Return value = %d (expected: %d)", ret, Plugin_Handled);
return Plugin_Handled;
}
public Action:ZohMyGod(num, const String:format[], ...)
{
decl String:buffer[128];
PrintToServer("Inside private forward #1");
PrintToServer("num = %d (expected: %d)", num, 24);
VFormat(buffer, sizeof(buffer), format, 3);
PrintToServer("buffer = \"%s\" (expected: \"%s\")", buffer, "I am a format string: 0 1 2 3 4 5");
PrintToServer("End private forward #1");
return Plugin_Continue;
}
+43
View File
@@ -0,0 +1,43 @@
#include <sourcemod>
public Plugin:myinfo =
{
name = "Forward Testing Lab #2",
author = "AlliedModders LLC",
description = "Tests suite #2 for forwards created by plugins",
version = "1.0.0.0",
url = "http://www.sourcemod.net/"
};
public Action:OnPrivateForward(num, const String:format[], ...)
{
decl String:buffer[128];
PrintToServer("Inside private forward #2");
PrintToServer("num = %d (expected: %d)", num, 24);
VFormat(buffer, sizeof(buffer), format, 3);
PrintToServer("buffer = \"%s\" (expected: \"%s\")", buffer, "I am a format string: 0 1 2 3 4 5");
PrintToServer("End private forward #2");
return Plugin_Handled;
}
public OnGlobalForward(Function:a, b, Float:c, const String:d[], Float:e[3], &f, &Float:g)
{
PrintToServer("Inside global forward \"OnGlobalForward\"");
PrintToServer("a = %d (expected: %d)", a, 11);
PrintToServer("b = %d (expected: %d)", b, 7);
PrintToServer("c = %f (expected: %f)", c, -8.5);
PrintToServer("d = \"%s\" (expected: \"%s\")", d, "Anata wa doko desu ka?");
PrintToServer("e = %f %f %f (expected: %f %f %f)", e[0], e[1], e[2], 0.0, 1.1, 2.2);
PrintToServer("f = %d (expected %d, setting to %d)", f, 99, 777);
f = 777;
PrintToServer("g = %f (expected %f, setting to %f)", g, 4.215, -0.782);
g = -0.782;
}
+28
View File
@@ -0,0 +1,28 @@
#include <sourcemod>
public OnPluginStart()
{
RegServerCmd("test_goto", Test_Goto);
}
public Action:Test_Goto(args)
{
new bool:hello = false;
new String:crab[] = "space crab";
sample_label:
new String:yam[] = "yams";
PrintToServer("%s %s", crab, yam);
if (!hello)
{
new bool:what = true;
hello = what
goto sample_label;
}
return Plugin_Handled;
}
+59
View File
@@ -0,0 +1,59 @@
#include <sourcemod>
#include <sdktools>
public Plugin:myinfo =
{
name = "Entity Output Hook Testing",
author = "AlliedModders LLC",
description = "Test suite for Entity Output Hooks",
version = "1.0.0.0",
url = "http://www.sourcemod.net/"
};
public OnPluginStart()
{
HookEntityOutput("point_spotlight", "OnLightOn", OutputHook);
HookEntityOutput("func_door", "OnOpen", OutputHook);
HookEntityOutput("func_door_rotating", "OnOpen", OutputHook);
HookEntityOutput("func_door", "OnClose", OutputHook);
HookEntityOutput("func_door_rotating", "OnClose", OutputHook);
}
public OutputHook(const String:name[], caller, activator, Float:delay)
{
LogMessage("[ENTOUTPUT] %s", name);
}
public OnMapStart()
{
new ent = FindEntityByClassname(-1, "point_spotlight");
if (ent == -1)
{
LogError("Could not find a point_spotlight");
ent = CreateEntityByName("point_spotlight");
DispatchSpawn(ent);
}
HookSingleEntityOutput(ent, "OnLightOn", OutputHook, true);
HookSingleEntityOutput(ent, "OnLightOff", OutputHook, true);
AcceptEntityInput(ent, "LightOff", ent, ent);
AcceptEntityInput(ent, "LightOn", ent, ent);
AcceptEntityInput(ent, "LightOff", ent, ent);
AcceptEntityInput(ent, "LightOn", ent, ent);
HookSingleEntityOutput(ent, "OnLightOn", OutputHook, false);
HookSingleEntityOutput(ent, "OnLightOff", OutputHook, false);
AcceptEntityInput(ent, "LightOff", ent, ent);
AcceptEntityInput(ent, "LightOn", ent, ent);
AcceptEntityInput(ent, "LightOff", ent, ent);
AcceptEntityInput(ent, "LightOn", ent, ent);
//Comment these out (and reload the plugin heaps) to test for leaks on plugin unload
UnhookSingleEntityOutput(ent, "OnLightOn", OutputHook);
UnhookSingleEntityOutput(ent, "OnLightOff", OutputHook);
}
+331
View File
@@ -0,0 +1,331 @@
#include <sourcemod>
public Plugin:myinfo =
{
name = "Sorting Test",
author = "AlliedModders LLC",
description = "Tests sorting functions",
version = "1.0.0.0",
url = "http://www.sourcemod.net/"
};
public OnPluginStart()
{
RegServerCmd("test_sort_ints", Command_TestSortInts)
RegServerCmd("test_sort_floats", Command_TestSortFloats)
RegServerCmd("test_sort_strings", Command_TestSortStrings)
RegServerCmd("test_sort_1d", Command_TestSort1D)
RegServerCmd("test_sort_2d", Command_TestSort2D)
RegServerCmd("test_adtsort_ints", Command_TestSortADTInts)
RegServerCmd("test_adtsort_floats", Command_TestSortADTFloats)
RegServerCmd("test_adtsort_strings", Command_TestSortADTStrings)
RegServerCmd("test_adtsort_custom", Command_TestSortADTCustom)
}
/*****************
* INTEGER TESTS *
*****************/
// Note that integer comparison is just int1-int2 (or a variation therein)
PrintIntegers(const array[], size)
{
for (new i=0; i<size; i++)
{
PrintToServer("array[%d] = %d", i, array[i])
}
}
public Action:Command_TestSortInts(args)
{
new array[10] = {6, 7, 3, 2, 8, 5, 0, 1, 4, 9}
PrintToServer("Testing ascending sort:")
SortIntegers(array, 10, Sort_Ascending)
PrintIntegers(array, 10)
PrintToServer("Testing descending sort:")
SortIntegers(array, 10, Sort_Descending)
PrintIntegers(array, 10)
PrintToServer("Testing random sort:")
SortIntegers(array, 10, Sort_Random)
PrintIntegers(array, 10)
return Plugin_Handled
}
/**************************
* Float comparison tests *
**************************/
PrintFloats(const Float:array[], size)
{
for (new i=0; i<size; i++)
{
PrintToServer("array[%d] = %f", i, array[i])
}
}
public Action:Command_TestSortFloats(args)
{
new Float:array[10] = {6.3, 7.6, 3.2, 2.1, 8.5, 5.2, 0.4, 1.7, 4.8, 8.2}
PrintToServer("Testing ascending sort:")
SortFloats(array, 10, Sort_Ascending)
PrintFloats(array, 10)
PrintToServer("Testing descending sort:")
SortFloats(array, 10, Sort_Descending)
PrintFloats(array, 10)
PrintToServer("Testing random sort:")
SortFloats(array, 10, Sort_Random)
PrintFloats(array, 10)
return Plugin_Handled
}
public Custom1DSort(elem1, elem2, const array[], Handle:hndl)
{
new Float:f1 = Float:elem1
new Float:f2 = Float:elem2
if (f1 > f2)
{
return -1;
} else if (f1 < f2) {
return 1;
}
return 0;
}
public Action:Command_TestSort1D(args)
{
new Float:array[10] = {6.3, 7.6, 3.2, 2.1, 8.5, 5.2, 0.4, 1.7, 4.8, 8.2}
SortCustom1D(_:array, 10, Custom1DSort)
PrintFloats(array, 10)
return Plugin_Handled
}
/***************************
* String comparison tests *
***************************/
PrintStrings(const String:array[][], size)
{
for (new i=0; i<size; i++)
{
PrintToServer("array[%d] = %s", i, array[i])
}
}
public Action:Command_TestSortStrings(args)
{
new String:strarray[][] =
{
"faluco",
"bailopan",
"pm onoto",
"damaged soul",
"sniperbeamer",
"sidluke",
"johnny got his gun",
"gabe newell",
"pRED*'s awesome",
"WHAT?!"
}
PrintToServer("Testing ascending sort:")
SortStrings(strarray, 10, Sort_Ascending)
PrintStrings(strarray, 10)
PrintToServer("Testing descending sort:")
SortStrings(strarray, 10, Sort_Descending)
PrintStrings(strarray, 10)
PrintToServer("Testing random sort:")
SortStrings(strarray, 10, Sort_Random)
PrintStrings(strarray, 10)
return Plugin_Handled
}
public Custom2DSort(String:elem1[], String:elem2[], String:array[][], Handle:hndl)
{
return strcmp(elem1, elem2)
}
public Action:Command_TestSort2D(args)
{
new String:array[][] =
{
"faluco",
"bailopan",
"pm onoto",
"damaged soul",
"sniperbeamer",
"sidluke",
"johnny got his gun",
"gabe newell",
"pred is a crab",
"WHAT?!"
}
SortCustom2D(_:array, 10, Custom2DSort)
PrintStrings(array, 10)
return Plugin_Handled
}
/*******************
* ADT ARRAY TESTS *
*******************/
// Int and floats work the same as normal comparisions. Strings are direct
// comparisions with no hacky memory stuff like Pawn arrays.
PrintADTArrayIntegers(Handle:array)
{
new size = GetArraySize(array);
for (new i=0; i<size;i++)
{
PrintToServer("array[%d] = %d", i, GetArrayCell(array, i));
}
}
public Action:Command_TestSortADTInts(args)
{
new Handle:array = CreateArray();
PushArrayCell(array, 6);
PushArrayCell(array, 7);
PushArrayCell(array, 3);
PushArrayCell(array, 2);
PushArrayCell(array, 8);
PushArrayCell(array, 5);
PushArrayCell(array, 0);
PushArrayCell(array, 1);
PushArrayCell(array, 4);
PushArrayCell(array, 9);
PrintToServer("Testing ascending sort:")
SortADTArray(array, Sort_Ascending, Sort_Integer)
PrintADTArrayIntegers(array)
PrintToServer("Testing descending sort:")
SortADTArray(array, Sort_Descending, Sort_Integer)
PrintADTArrayIntegers(array)
PrintToServer("Testing random sort:")
SortADTArray(array, Sort_Random, Sort_Integer)
PrintADTArrayIntegers(array)
return Plugin_Handled
}
PrintADTArrayFloats(Handle:array)
{
new size = GetArraySize(array);
for (new i=0; i<size;i++)
{
PrintToServer("array[%d] = %f", i, float:GetArrayCell(array, i));
}
}
public Action:Command_TestSortADTFloats(args)
{
new Handle:array = CreateArray();
PushArrayCell(array, 6.0);
PushArrayCell(array, 7.0);
PushArrayCell(array, 3.0);
PushArrayCell(array, 2.0);
PushArrayCell(array, 8.0);
PushArrayCell(array, 5.0);
PushArrayCell(array, 0.0);
PushArrayCell(array, 1.0);
PushArrayCell(array, 4.0);
PushArrayCell(array, 9.0);
PrintToServer("Testing ascending sort:")
SortADTArray(array, Sort_Ascending, Sort_Float)
PrintADTArrayFloats(array)
PrintToServer("Testing descending sort:")
SortADTArray(array, Sort_Descending, Sort_Float)
PrintADTArrayFloats(array)
PrintToServer("Testing random sort:")
SortADTArray(array, Sort_Random, Sort_Float)
PrintADTArrayFloats(array)
return Plugin_Handled
}
PrintADTArrayStrings(Handle:array)
{
new size = GetArraySize(array);
decl String:buffer[64];
for (new i=0; i<size;i++)
{
GetArrayString(array, i, buffer, sizeof(buffer));
PrintToServer("array[%d] = %s", i, buffer);
}
}
public Action:Command_TestSortADTStrings(args)
{
new Handle:array = CreateArray(ByteCountToCells(64));
PushArrayString(array, "faluco");
PushArrayString(array, "bailopan");
PushArrayString(array, "pm onoto");
PushArrayString(array, "damaged soul");
PushArrayString(array, "sniperbeamer");
PushArrayString(array, "sidluke");
PushArrayString(array, "johnny got his gun");
PushArrayString(array, "gabe newell");
PushArrayString(array, "Hello pRED*");
PushArrayString(array, "WHAT?!");
PrintToServer("Testing ascending sort:")
SortADTArray(array, Sort_Ascending, Sort_String)
PrintADTArrayStrings(array)
PrintToServer("Testing descending sort:")
SortADTArray(array, Sort_Descending, Sort_String)
PrintADTArrayStrings(array)
PrintToServer("Testing random sort:")
SortADTArray(array, Sort_Random, Sort_String)
PrintADTArrayStrings(array)
return Plugin_Handled
}
public ArrayADTCustomCallback(index1, index2, Handle:array, Handle:hndl)
{
decl String:buffer1[64], String:buffer2[64];
GetArrayString(array, index1, buffer1, sizeof(buffer1));
GetArrayString(array, index2, buffer2, sizeof(buffer2));
return strcmp(buffer1, buffer2);
}
public Action:Command_TestSortADTCustom(args)
{
new Handle:array = CreateArray(ByteCountToCells(64));
PushArrayString(array, "faluco");
PushArrayString(array, "bailopan");
PushArrayString(array, "pm onoto");
PushArrayString(array, "damaged soul");
PushArrayString(array, "sniperbeamer");
PushArrayString(array, "sidluke");
PushArrayString(array, "johnny got his gun");
PushArrayString(array, "gabe newell");
PushArrayString(array, "pRED*'s running out of ideas");
PushArrayString(array, "WHAT?!");
PrintToServer("Testing custom sort:")
SortADTArrayCustom(array, ArrayADTCustomCallback)
PrintADTArrayStrings(array);
}
+178
View File
@@ -0,0 +1,178 @@
#include <sourcemod>
public Plugin:myinfo =
{
name = "SQL Testing Lab",
author = "AlliedModders LLC",
description = "Tests basic function calls",
version = "1.0.0.0",
url = "http://www.sourcemod.net/"
};
public OnPluginStart()
{
RegServerCmd("sql_test_normal", Command_TestSql1)
RegServerCmd("sql_test_stmt", Command_TestSql2)
RegServerCmd("sql_test_thread1", Command_TestSql3)
RegServerCmd("sql_test_thread2", Command_TestSql4)
RegServerCmd("sql_test_thread3", Command_TestSql5)
}
PrintQueryData(Handle:query)
{
if (!SQL_HasResultSet(query))
{
PrintToServer("Query Handle %x has no results", query)
return
}
new rows = SQL_GetRowCount(query)
new fields = SQL_GetFieldCount(query)
decl String:fieldNames[fields][32]
PrintToServer("Fields: %d", fields)
for (new i=0; i<fields; i++)
{
SQL_FieldNumToName(query, i, fieldNames[i], 32)
PrintToServer("-> Field %d: \"%s\"", i, fieldNames[i])
}
PrintToServer("Rows: %d", rows)
decl String:result[255]
new row
while (SQL_FetchRow(query))
{
row++
PrintToServer("Row %d:", row)
for (new i=0; i<fields; i++)
{
SQL_FetchString(query, i, result, sizeof(result))
PrintToServer(" [%s] %s", fieldNames[i], result)
}
}
}
public Action:Command_TestSql1(args)
{
new String:error[255]
new Handle:db = SQL_DefConnect(error, sizeof(error))
if (db == INVALID_HANDLE)
{
PrintToServer("Failed to connect: %s", error)
return Plugin_Handled
}
new Handle:query = SQL_Query(db, "SELECT * FROM gaben")
if (query == INVALID_HANDLE)
{
SQL_GetError(db, error, sizeof(error))
PrintToServer("Failed to query: %s", error)
} else {
PrintQueryData(query)
CloseHandle(query)
}
CloseHandle(db)
return Plugin_Handled;
}
public Action:Command_TestSql2(args)
{
new String:error[255]
new Handle:db = SQL_DefConnect(error, sizeof(error))
if (db == INVALID_HANDLE)
{
PrintToServer("Failed to connect: %s", error)
return Plugin_Handled
}
new Handle:stmt = SQL_PrepareQuery(db, "SELECT * FROM gaben WHERE gaben > ?", error, sizeof(error))
if (stmt == INVALID_HANDLE)
{
PrintToServer("Failed to prepare query: %s", error)
} else {
SQL_BindParamInt(stmt, 0, 1)
if (!SQL_Execute(stmt))
{
SQL_GetError(stmt, error, sizeof(error))
PrintToServer("Failed to execute query: %s", error)
} else {
PrintQueryData(stmt)
}
CloseHandle(stmt)
}
CloseHandle(db)
return Plugin_Handled;
}
new Handle:g_ThreadedHandle = INVALID_HANDLE;
public CallbackTest3(Handle:owner, Handle:hndl, const String:error[], any:data)
{
PrintToServer("CallbackTest1() (owner %x) (hndl %x) (error \"%s\") (data %d)", owner, hndl, error, data);
if (g_ThreadedHandle != INVALID_HANDLE && hndl != INVALID_HANDLE)
{
CloseHandle(hndl);
} else {
g_ThreadedHandle = hndl;
}
}
public Action:Command_TestSql3(args)
{
if (g_ThreadedHandle != INVALID_HANDLE)
{
PrintToServer("A threaded connection already exists, run the next test");
return Plugin_Handled;
}
new String:name[32];
GetCmdArg(1, name, sizeof(name));
SQL_TConnect(CallbackTest3, name);
return Plugin_Handled;
}
public Action:Command_TestSql4(args)
{
SQL_LockDatabase(g_ThreadedHandle);
new Handle:query = SQL_Query(g_ThreadedHandle, "SELECT * FROM gaben")
if (query == INVALID_HANDLE)
{
new String:error[255];
SQL_GetError(g_ThreadedHandle, error, sizeof(error))
PrintToServer("Failed to query: %s", error)
} else {
PrintQueryData(query)
CloseHandle(query)
}
SQL_UnlockDatabase(g_ThreadedHandle);
return Plugin_Handled;
}
public CallbackTest5(Handle:owner, Handle:hndl, const String:error[], any:data)
{
if (hndl == INVALID_HANDLE)
{
PrintToServer("Failed to query: %s", error)
} else {
PrintQueryData(hndl)
}
}
public Action:Command_TestSql5(args)
{
SQL_TQuery(g_ThreadedHandle, CallbackTest5, "SELECT * FROM gaben", 52)
SQL_TQuery(g_ThreadedHandle, CallbackTest5, "SELECT * FROM gaben", 52)
SQL_TQuery(g_ThreadedHandle, CallbackTest5, "SELECT * FROM gaben", 52)
SQL_TQuery(g_ThreadedHandle, CallbackTest5, "SELECT * FROM gaben", 52)
return Plugin_Handled;
}
+7
View File
@@ -0,0 +1,7 @@
CREATE TABLE gaben (gaben int primary key, fat varchar(32));
INSERT INTO gaben VALUES(1, 'what the');
INSERT INTO gaben VALUES(2, 'Bee''s Knees!');
INSERT INTO gaben VALUES(3, 'newell');
INSERT INTO gaben VALUES(4, 'CRAB CAKE.');
+53
View File
@@ -0,0 +1,53 @@
#include <sourcemod>
public Plugin:myinfo =
{
name = "Stack Tests",
author = "AlliedModders LLC",
description = "Tests stack functions",
version = "1.0.0.0",
url = "http://www.sourcemod.net/"
};
public OnPluginStart()
{
RegServerCmd("test_stack", Test_Stack);
}
public Action:Test_Stack(args)
{
new Handle:stack;
new test[20]
decl String:buffer[42];
test[0] = 5
test[1] = 7
stack = CreateStack(30);
PushStackCell(stack, 50);
PushStackArray(stack, test, 2);
PushStackArray(stack, test, 2);
PushStackString(stack, "space craaab");
PushStackCell(stack, 12);
PrintToServer("empty? %d", IsStackEmpty(stack));
PopStack(stack);
PopStackString(stack, buffer, sizeof(buffer));
PrintToServer("popped: \"%s\"", buffer);
test[0] = 0
test[1] = 0
PrintToServer("values: %d, %d", test[0], test[1]);
PopStackArray(stack, test, 2);
PrintToServer("popped: %d, %d", test[0], test[1]);
PopStackCell(stack, test[0], 1);
PrintToServer("popped: x, %d", test[0]);
PopStackCell(stack, test[0]);
PrintToServer("popped: %d", test[0]);
PrintToServer("empty? %d", IsStackEmpty(stack));
CloseHandle(stack);
return Plugin_Handled;
}
+167
View File
@@ -0,0 +1,167 @@
#include <sourcemod>
#include <sdktools>
#include <tf2>
#include <tf2_stocks>
public Plugin:myinfo =
{
name = "TF2 Test",
author = "pRED*",
description = "Test of Tf2 functions",
version = "1.0",
url = "www.sourcemod.net"
}
public OnPluginStart()
{
RegConsoleCmd("sm_burnme", Command_Burn);
RegConsoleCmd("sm_invuln", Command_Invuln);
RegConsoleCmd("sm_respawn", Command_Respawn);
RegConsoleCmd("sm_disguise", Command_Disguise);
RegConsoleCmd("sm_remdisguise", Command_RemDisguise);
RegConsoleCmd("sm_class", Command_Class);
RegConsoleCmd("sm_remove", Command_Remove);
RegConsoleCmd("sm_changeclass", Command_ChangeClass);
}
public Action:Command_Class(client, args)
{
TF2_RemoveAllWeapons(client);
decl String:text[10];
GetCmdArg(1, text, sizeof(text));
new one = StringToInt(text);
TF2_EquipPlayerClassWeapons(client, TFClassType:one);
PrintToChat(client, "Test: sniper's classnum is %i (should be %i)", TF2_GetClass("sniper"), TFClass_Sniper);
return Plugin_Handled;
}
public Action:Command_Remove(client, args)
{
decl String:text[10];
GetCmdArg(1, text, sizeof(text));
new one = StringToInt(text);
TF2_RemoveWeaponSlot(client, one);
PrintToChat(client, "Test: heavy's classnum is %i (should be %i)", TF2_GetClass("heavy"), TFClass_Heavy);
new doms = TF2_GetPlayerResourceData(client, TFResource_Dominations);
PrintToChat(client, "Dominations read test: %i", doms);
TF2_SetPlayerResourceData(client, TFResource_Dominations, doms + 10);
doms = TF2_GetPlayerResourceData(client, TFResource_Dominations);
PrintToChat(client, "Dominations write test: %i", doms);
/* Note: This didn't appear to change my dominations value when I pressed tab. */
return Plugin_Handled;
}
public Action:Command_ChangeClass(client, args)
{
decl String:text[10];
GetCmdArg(1, text, sizeof(text));
new one = StringToInt(text);
PrintToChat(client, "Current class is :%i", TF2_GetPlayerClass(client));
TF2_SetPlayerClass(client, TFClassType:one);
PrintToChat(client, "New class is :%i", TF2_GetPlayerClass(client));
return Plugin_Handled;
}
public Action:Command_Burn(client, args)
{
if (client == 0)
{
return Plugin_Handled;
}
TF2_IgnitePlayer(client, client);
return Plugin_Handled;
}
public Action:Command_Invuln(client, args)
{
if (client == 0)
{
return Plugin_Handled;
}
if (args < 1)
{
return Plugin_Handled;
}
decl String:text[10];
GetCmdArg(1, text, sizeof(text));
new bool:one = !!StringToInt(text);
TF2_SetPlayerInvuln(client, one)
return Plugin_Handled;
}
public Action:Command_Disguise(client, args)
{
if (client == 0)
{
return Plugin_Handled;
}
if (args < 2)
{
return Plugin_Handled;
}
decl String:text[10];
decl String:text2[10];
GetCmdArg(1, text, sizeof(text));
GetCmdArg(2, text2, sizeof(text2));
new one = StringToInt(text);
new two = StringToInt(text2);
TF2_DisguisePlayer(client, TFTeam:one, TFClassType:two);
return Plugin_Handled;
}
public Action:Command_RemDisguise(client, args)
{
if (client == 0)
{
return Plugin_Handled;
}
TF2_RemovePlayerDisguise(client);
return Plugin_Handled;
}
public Action:Command_Respawn(client, args)
{
if (client == 0)
{
return Plugin_Handled;
}
TF2_RespawnPlayer(client);
return Plugin_Handled;
}