amxmodx/plugins/testsuite/stacktest.sma
2014-08-01 23:14:44 +02:00

74 lines
1.4 KiB
Plaintext

#include <amxmodx>
new FailCount;
new PassCount;
public plugin_init()
{
register_plugin("Stack Tests", AMXX_VERSION_STR, "AMXX Dev Team");
register_srvcmd("test_stack", "ServerCommand_TestStack");
}
assertEqual(const testname[], bool:pass)
{
if (!pass)
{
server_print("[FAIL] %s", testname);
FailCount++;
}
else
{
server_print("[PASS] %s", testname);
PassCount++;
}
}
done()
{
server_print("Finished. %d tests, %d failed", FailCount + PassCount, FailCount);
}
public ServerCommand_TestStack()
{
new Stack:stack;
new test[20];
new 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);
}
assertEqual("Size test #1", IsStackEmpty(stack) == false);
PopStack(stack);
PopStackString(stack, buffer, charsmax(buffer));
assertEqual("String test", bool:equal(buffer, "space craaab"));
test[0] = 0;
test[1] = 0;
assertEqual("Array test #1", test[0] == 0 && test[1] == 0);
PopStackArray(stack, test, 2);
assertEqual("Array test #1", test[0] == 5 && test[1] == 7);
PopStackCell(stack, test[0], 1);
assertEqual("Value test #1", test[0] == 7);
PopStackCell(stack, test[0]);
assertEqual("Value test #2", test[0] == 50);
assertEqual("Size test #2", IsStackEmpty(stack) == true);
DestroyStack(stack);
done();
}