2014-08-04 12:12:15 +00:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
|
|
|
|
2014-04-11 20:57:42 +00:00
|
|
|
#include <amxmodx>
|
|
|
|
|
|
|
|
new failcount;
|
|
|
|
new passcount;
|
|
|
|
|
|
|
|
public plugin_init()
|
|
|
|
{
|
|
|
|
register_plugin("Datapack Test", AMXX_VERSION_STR, "AMXX Dev Team");
|
|
|
|
register_srvcmd("datapacktest", "datapacktest");
|
|
|
|
}
|
|
|
|
|
|
|
|
test(const testname[], bool:pass)
|
|
|
|
{
|
|
|
|
if (!pass)
|
|
|
|
{
|
|
|
|
server_print("[FAIL] %s", testname);
|
|
|
|
failcount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
server_print("[PASS] %s", testname);
|
|
|
|
passcount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stock done()
|
|
|
|
{
|
|
|
|
server_print("Finished. %d tests, %d failed", failcount + passcount, failcount);
|
|
|
|
}
|
|
|
|
|
|
|
|
public datapacktest()
|
|
|
|
{
|
|
|
|
failcount = 0;
|
|
|
|
passcount = 0;
|
2015-03-15 23:28:40 +00:00
|
|
|
|
2014-04-11 20:57:42 +00:00
|
|
|
new DataPack:pack = CreateDataPack();
|
|
|
|
new DataPack:oldPack = pack; // Makes sure that the trie handle system recycles old handles
|
2015-03-15 23:28:40 +00:00
|
|
|
|
2014-04-11 20:57:42 +00:00
|
|
|
new refCell = 23;
|
|
|
|
new Float:refFloat = 42.42;
|
|
|
|
new refString[] = "I'm a little teapot.";
|
2015-03-15 23:28:40 +00:00
|
|
|
|
2014-04-11 20:57:42 +00:00
|
|
|
// Write
|
2015-03-15 23:28:40 +00:00
|
|
|
new cellPos = GetPackPosition(pack);
|
|
|
|
WritePackCell(pack, refCell);
|
|
|
|
new floatPos = GetPackPosition(pack);
|
|
|
|
WritePackFloat(pack, refFloat);
|
|
|
|
new strPos = GetPackPosition(pack);
|
|
|
|
WritePackString(pack, refString);
|
|
|
|
new endPos = GetPackPosition(pack);
|
|
|
|
|
|
|
|
test("Write position test",
|
|
|
|
.pass = (cellPos != floatPos && cellPos != strPos && cellPos != endPos
|
|
|
|
&& floatPos != strPos && floatPos != endPos && strPos != endPos));
|
|
|
|
|
2014-04-11 20:57:42 +00:00
|
|
|
//resets the index to the beginning, necessary for read.
|
|
|
|
ResetPack(pack);
|
2015-03-15 23:28:40 +00:00
|
|
|
|
|
|
|
test("Position #1 test", .pass = (GetPackPosition(pack) == cellPos));
|
|
|
|
test("Readable #1 test", .pass = !IsPackEnded(pack));
|
|
|
|
|
2014-04-11 20:57:42 +00:00
|
|
|
new cellValue = ReadPackCell(pack);
|
2015-03-15 23:28:40 +00:00
|
|
|
test("Cell test", .pass = (cellValue == refCell));
|
|
|
|
|
|
|
|
test("Position #2 test", .pass = (GetPackPosition(pack) == floatPos));
|
|
|
|
test("Readable #2 test", .pass = !IsPackEnded(pack));
|
|
|
|
|
|
|
|
new Float:floatValue = ReadPackFloat(pack);
|
|
|
|
test("Float test", .pass = (floatValue == refFloat));
|
|
|
|
|
|
|
|
test("Position #3 test", .pass = (GetPackPosition(pack) == strPos));
|
|
|
|
test("Readable #3 test", .pass = !IsPackEnded(pack));
|
|
|
|
|
2014-04-11 20:57:42 +00:00
|
|
|
new buffer[1024];
|
|
|
|
ReadPackString(pack, buffer, 1024);
|
2015-03-15 23:28:40 +00:00
|
|
|
test("String test #1", .pass = bool:equal(buffer, refString));
|
|
|
|
|
|
|
|
test("End test", .pass = IsPackEnded(pack));
|
2014-04-11 20:57:42 +00:00
|
|
|
|
|
|
|
ResetPack(pack, .clear = true);
|
2015-03-15 23:28:40 +00:00
|
|
|
test("Clear test", .pass = IsPackEnded(pack));
|
|
|
|
|
2014-04-11 20:57:42 +00:00
|
|
|
DestroyDataPack(pack);
|
2015-03-15 23:28:40 +00:00
|
|
|
|
2014-04-11 20:57:42 +00:00
|
|
|
test("Recycle handles", CreateDataPack() == oldPack);
|
2015-03-15 23:28:40 +00:00
|
|
|
|
2014-04-11 20:57:42 +00:00
|
|
|
done();
|
|
|
|
}
|