plugins/testsuite/filetest.sp
changeset 2446 46bfcd5b47a1
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/testsuite/filetest.sp	Sat Nov 29 22:44:11 2008 -0600
     1.3 @@ -0,0 +1,62 @@
     1.4 +#include <sourcemod>
     1.5 +
     1.6 +public Plugin:myinfo = 
     1.7 +{
     1.8 +	name = "File test",
     1.9 +	author = "AlliedModders LLC",
    1.10 +	description = "Tests file functions",
    1.11 +	version = "1.0.0.0",
    1.12 +	url = "http://www.sourcemod.net/"
    1.13 +};
    1.14 +
    1.15 +public OnPluginStart()
    1.16 +{
    1.17 +	RegServerCmd("test_fread1", Test_ReadBinStr);
    1.18 +}
    1.19 +
    1.20 +Handle:OpenFile2(const String:path[], const String:mode[])
    1.21 +{
    1.22 +	new Handle:file = OpenFile(path, mode);
    1.23 +	if (file == INVALID_HANDLE)
    1.24 +		PrintToServer("Failed to open file %s for %s", path, mode);
    1.25 +	else
    1.26 +		PrintToServer("Opened file handle %x: %s", file, path);
    1.27 +	return file;
    1.28 +}
    1.29 +
    1.30 +public Action:Test_ReadBinStr(args)
    1.31 +{
    1.32 +	new items[] = {1, 3, 5, 7, 0, 92, 193, 26, 0, 84, 248, 2};
    1.33 +	new Handle:of = OpenFile2("smbintest", "wb");
    1.34 +	if (of == INVALID_HANDLE)
    1.35 +		return Plugin_Handled;
    1.36 +	WriteFile(of, items, sizeof(items), 1);
    1.37 +	CloseHandle(of);
    1.38 +
    1.39 +	new Handle:inf = OpenFile2("smbintest", "rb");
    1.40 +	new String:buffer[sizeof(items)];
    1.41 +	ReadFileString(inf, buffer, sizeof(items), sizeof(items));
    1.42 +	FileSeek(inf, 0, SEEK_SET);
    1.43 +	new items2[sizeof(items)];
    1.44 +	ReadFile(inf, items2, sizeof(items), 1);
    1.45 +	CloseHandle(inf);
    1.46 +
    1.47 +	for (new i = 0; i < sizeof(items); i++)
    1.48 +	{
    1.49 +		if (buffer[i] != items[i])
    1.50 +		{
    1.51 +			PrintToServer("FAILED ON INDEX %d: %d != %d", i, buffer[i], items[i]);
    1.52 +			return Plugin_Handled;
    1.53 +		}
    1.54 +		else if (items2[i] != items[i])
    1.55 +		{
    1.56 +			PrintToServer("FAILED ON INDEX %d: %d != %d", i, items2[i], items[i]);
    1.57 +			return Plugin_Handled;
    1.58 +		}
    1.59 +	}
    1.60 +
    1.61 +	PrintToServer("Test passed!");
    1.62 +
    1.63 +	return Plugin_Handled;
    1.64 +}
    1.65 +