sourcemod/plugins/testsuite/filetest.sp

74 lines
1.7 KiB
SourcePawn
Raw Normal View History

2008-11-30 05:44:11 +01:00
#include <sourcemod>
public Plugin:myinfo =
{
name = "File test",
author = "AlliedModders LLC",
description = "Tests file functions",
version = "1.0.0.0",
url = "http://www.sourcemod.net/"
};
2014-11-01 02:49:15 +01:00
public void OnPluginStart()
2008-11-30 05:44:11 +01:00
{
RegServerCmd("test_fread1", Test_ReadBinStr);
}
2014-11-01 02:49:15 +01:00
File OpenFile2(const String:path[], const String:mode[])
2008-11-30 05:44:11 +01:00
{
2014-11-01 02:49:15 +01:00
File file = OpenFile(path, mode);
if (!file)
2008-11-30 05:44:11 +01:00
PrintToServer("Failed to open file %s for %s", path, mode);
else
PrintToServer("Opened file handle %x: %s", file, path);
return file;
}
2014-11-01 02:49:15 +01:00
public Action Test_ReadBinStr(args)
2008-11-30 05:44:11 +01:00
{
2014-11-01 02:49:15 +01:00
int items[] = {1, 3, 5, 7, 0, 92, 193, 26, 0, 84, 248, 2};
File of = OpenFile2("smbintest", "wb");
if (!of)
2008-11-30 05:44:11 +01:00
return Plugin_Handled;
2014-11-01 02:49:15 +01:00
of.Write(items, sizeof(items), 1);
of.Close();
2008-11-30 05:44:11 +01:00
2014-11-01 02:49:15 +01:00
File inf = OpenFile2("smbintest", "rb");
char buffer[sizeof(items)];
inf.ReadString(buffer, sizeof(items), sizeof(items));
inf.Seek(0, SEEK_SET);
int items2[sizeof(items)];
inf.Read(items2, sizeof(items), 1);
inf.Close();
2008-11-30 05:44:11 +01:00
for (new i = 0; i < sizeof(items); i++)
{
if (buffer[i] != items[i])
{
PrintToServer("FAILED ON INDEX %d: %d != %d", i, buffer[i], items[i]);
return Plugin_Handled;
}
else if (items2[i] != items[i])
{
PrintToServer("FAILED ON INDEX %d: %d != %d", i, items2[i], items[i]);
return Plugin_Handled;
}
}
2014-11-01 02:49:15 +01:00
inf = OpenFile2("smbintest", "rb");
for (new i = 0; i < sizeof(items); i++)
{
new item;
if (!inf.ReadInt8(item) || item != items[i])
{
PrintToServer("FAILED ON INDEX %d: %d != %d", i, item, items[i]);
return Plugin_Handled;
}
}
2008-11-30 05:44:11 +01:00
PrintToServer("Test passed!");
return Plugin_Handled;
}