sourcemod/plugins/testsuite/keyvalues.sp

59 lines
1.1 KiB
SourcePawn
Raw Normal View History

2014-07-05 19:01:17 +02:00
#include <sourcemod>
public Plugin:myinfo =
{
name = "KeyValues test",
author = "AlliedModders LLC",
description = "KeyValues test",
version = SOURCEMOD_VERSION,
url = "http://www.sourcemod.net/"
};
public OnPluginStart()
{
RegServerCmd("test_keyvalues", RunTests);
}
public Action:RunTests(argc)
{
new String:validKv[] =
"\"root\" \
{ \
\"child\" \"value\" \
\"subkey\" { \
subchild subvalue \
subfloat 1.0 \
} \
}";
KeyValues kv = CreateKeyValues("");
2014-07-05 19:01:17 +02:00
if (!kv.ImportFromString(validKv))
2014-07-05 19:01:17 +02:00
ThrowError("Valid kv not read correctly!");
char value[128];
kv.GetString("child", value, sizeof(value));
2014-07-05 19:01:17 +02:00
if (!StrEqual(value, "value"))
ThrowError("Child kv should have 'value' but has: '%s'", value);
if (!kv.JumpToKey("subkey"))
2014-07-05 19:01:17 +02:00
ThrowError("No sub kv subkey exists!");
kv.GetString("subchild", value, sizeof(value));
2014-07-05 19:01:17 +02:00
if (!StrEqual(value, "subvalue"))
ThrowError("Subkv subvalue should have 'subvalue' but has: '%s'", value);
float subfloat = kv.GetFloat("subfloat");
2014-07-05 19:01:17 +02:00
if (subfloat != 1.0)
ThrowError( "Subkv subfloat should have 1.0 but has: %f", subfloat)
delete kv;
2014-07-05 19:01:17 +02:00
PrintToServer("KeyValue tests passed!");
}