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 \
|
|
|
|
} \
|
|
|
|
}";
|
|
|
|
|
2014-10-31 04:55:02 +01:00
|
|
|
KeyValues kv = CreateKeyValues("");
|
2014-07-05 19:01:17 +02:00
|
|
|
|
2014-10-31 04:55:02 +01:00
|
|
|
if (!kv.ImportFromString(validKv))
|
2014-07-05 19:01:17 +02:00
|
|
|
ThrowError("Valid kv not read correctly!");
|
|
|
|
|
2014-10-31 04:55:02 +01:00
|
|
|
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);
|
|
|
|
|
2014-10-31 04:55:02 +01:00
|
|
|
if (!kv.JumpToKey("subkey"))
|
2014-07-05 19:01:17 +02:00
|
|
|
ThrowError("No sub kv subkey exists!");
|
|
|
|
|
2014-10-31 04:55:02 +01:00
|
|
|
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);
|
|
|
|
|
2014-10-31 04:55:02 +01:00
|
|
|
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)
|
|
|
|
|
2014-10-31 04:55:02 +01:00
|
|
|
delete kv;
|
2014-07-05 19:01:17 +02:00
|
|
|
|
|
|
|
PrintToServer("KeyValue tests passed!");
|
|
|
|
}
|