Update datapack test plugin
This commit is contained in:
parent
2166c32047
commit
081b683e03
|
@ -41,51 +41,57 @@ public datapacktest()
|
||||||
{
|
{
|
||||||
failcount = 0;
|
failcount = 0;
|
||||||
passcount = 0;
|
passcount = 0;
|
||||||
|
|
||||||
new DataPack:pack = CreateDataPack();
|
new DataPack:pack = CreateDataPack();
|
||||||
new DataPack:oldPack = pack; // Makes sure that the trie handle system recycles old handles
|
new DataPack:oldPack = pack; // Makes sure that the trie handle system recycles old handles
|
||||||
|
|
||||||
new refCell = 23;
|
new refCell = 23;
|
||||||
new Float:refFloat = 42.42;
|
new Float:refFloat = 42.42;
|
||||||
new refString[] = "I'm a little teapot.";
|
new refString[] = "I'm a little teapot.";
|
||||||
|
|
||||||
// Write
|
// Write
|
||||||
WritePackCell(pack, refCell); // 8
|
new cellPos = GetPackPosition(pack);
|
||||||
WritePackString(pack, refString); // 25 (sizeof string + 4)
|
WritePackCell(pack, refCell);
|
||||||
WritePackFloat(pack, refFloat); // 8
|
new floatPos = GetPackPosition(pack);
|
||||||
|
WritePackFloat(pack, refFloat);
|
||||||
test("Position #1 test", .pass = GetPackPosition(pack) == 41);
|
new strPos = GetPackPosition(pack);
|
||||||
test("Readable #1 test", .pass = !IsPackReadable(pack, 41));
|
WritePackString(pack, refString);
|
||||||
|
new endPos = GetPackPosition(pack);
|
||||||
|
|
||||||
|
test("Write position test",
|
||||||
|
.pass = (cellPos != floatPos && cellPos != strPos && cellPos != endPos
|
||||||
|
&& floatPos != strPos && floatPos != endPos && strPos != endPos));
|
||||||
|
|
||||||
//resets the index to the beginning, necessary for read.
|
//resets the index to the beginning, necessary for read.
|
||||||
ResetPack(pack);
|
ResetPack(pack);
|
||||||
|
|
||||||
test("Position #2 test", .pass = GetPackPosition(pack) == 0 );
|
test("Position #1 test", .pass = (GetPackPosition(pack) == cellPos));
|
||||||
test("Readable #2 test", .pass = IsPackReadable(pack, 15));
|
test("Readable #1 test", .pass = !IsPackEnded(pack));
|
||||||
|
|
||||||
// Read
|
|
||||||
new cellValue = ReadPackCell(pack);
|
new cellValue = ReadPackCell(pack);
|
||||||
|
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));
|
||||||
|
|
||||||
new buffer[1024];
|
new buffer[1024];
|
||||||
ReadPackString(pack, buffer, 1024);
|
ReadPackString(pack, buffer, 1024);
|
||||||
new Float:floatvalue = ReadPackFloat(pack);
|
test("String test #1", .pass = bool:equal(buffer, refString));
|
||||||
|
|
||||||
test("Cell test", .pass = cellValue == refCell);
|
test("End test", .pass = IsPackEnded(pack));
|
||||||
test("String test", .pass = bool:equal(buffer, refString));
|
|
||||||
test("Float test #1", .pass = floatvalue == refFloat);
|
|
||||||
|
|
||||||
SetPackPosition(pack, 33);
|
|
||||||
test("Set Position test", .pass = GetPackPosition(pack) == 33);
|
|
||||||
|
|
||||||
WritePackFloat(pack, refFloat + 1);
|
|
||||||
SetPackPosition(pack, 33);
|
|
||||||
test("Float test #2", .pass = ReadPackFloat(pack) == refFloat + 1);
|
|
||||||
|
|
||||||
ResetPack(pack, .clear = true);
|
ResetPack(pack, .clear = true);
|
||||||
test("Clear test", .pass = !IsPackReadable(pack, 15));
|
test("Clear test", .pass = IsPackEnded(pack));
|
||||||
|
|
||||||
DestroyDataPack(pack);
|
DestroyDataPack(pack);
|
||||||
|
|
||||||
test("Recycle handles", CreateDataPack() == oldPack);
|
test("Recycle handles", CreateDataPack() == oldPack);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user