Esempio n. 1
0
static void test_withoutConfig()
{
	Key *parentKey = keyNew ("user/tests/rename", KEY_END);
	Key *parentKeyCopy = keyDup(parentKey);
	KeySet *conf = ksNew (0, KS_END);
	PLUGIN_OPEN("rename");

	KeySet *ks = createSimpleTestKeys();
	ksAppendKey(ks, parentKey);

	succeed_if(plugin->kdbGet (plugin, ks, parentKey) >= 1,
			"call to kdbGet was not successful");
	succeed_if(output_error (parentKey), "error in kdbGet");
	succeed_if(output_warnings (parentKey), "warnings in kdbGet");

	KeySet *expected = createSimpleTestKeys();
	ksAppendKey(expected, parentKeyCopy);

	compareKeySets(ks, expected);
	keyDel (parentKey);
	keyDel (parentKeyCopy);
	ksDel(expected);
	ksDel(ks);
	PLUGIN_CLOSE ();
}
Esempio n. 2
0
static void test_simpleCutOnGet () 
{
	Key *parentKey = keyNew ("user/tests/rename", KEY_END);
	KeySet *conf = ksNew (20,
			keyNew ("system/cut", KEY_VALUE, "will/be/stripped", KEY_END), KS_END);
	PLUGIN_OPEN("rename");

	KeySet *ks = createSimpleTestKeys();
	ksAppendKey(ks, parentKey);

	succeed_if(plugin->kdbGet (plugin, ks, parentKey) >= 1,
			"call to kdbGet was not successful");
	succeed_if(output_error (parentKey), "error in kdbGet");
	succeed_if(output_warnings (parentKey), "warnings in kdbGet");

	
	checkSimpleTestKeys (ks);
	ksDel(ks);

	/*
	 * this has to be done because the parentKey is not
	 * part of ks anymore due to renaming
	 */
	keyDel(parentKey);
	PLUGIN_CLOSE ();
}
Esempio n. 3
0
static void test_replaceString()
{
	Key *parentKey = keyNew("user/tests/rename", KEY_END);
	KeySet *conf = ksNew(20, 
			keyNew("system/cut", KEY_VALUE, "will/be/stripped", KEY_END),
			keyNew("system/replacewith", KEY_VALUE, "stripped/it/is", KEY_END),
			KS_END);
	
	KeySet *ks = createSimpleTestKeys();
	ksAppendKey(ks, parentKey);

	PLUGIN_OPEN("rename");

	succeed_if(plugin->kdbGet(plugin, ks, parentKey) >= 1,
			"call to kdbGet was not successful");
	Key *key = ksLookupByName(ks, "user/tests/rename/stripped/it/is/key1", KDB_O_NONE);
	succeed_if(key, "key1 was not correctly rename");
	key = ksLookupByName(ks, "user/tests/rename/stripped/it/is/key2", KDB_O_NONE);
	succeed_if(key, "key2 was not correctly rename");
	key = ksLookupByName(ks, "user/tests/rename/will/not/be/stripped/key4", KDB_O_NONE);
	succeed_if(key, "key4 was not correctly rename");
	
	keyDel(parentKey);
	ksDel(ks);
	PLUGIN_CLOSE();

}
Esempio n. 4
0
static void test_simpleCutRestoreOnSet () {
	Key *parentKey = keyNew ("user/tests/rename", KEY_END);
	Key *parentKeyCopy = keyDup(parentKey);
	KeySet *conf = ksNew (20,
			keyNew ("system/cut", KEY_VALUE, "will/be/stripped", KEY_END), KS_END);
	PLUGIN_OPEN("rename");

	KeySet *ks = createSimpleTestKeys();
	ksAppendKey(ks, parentKey);

	succeed_if(plugin->kdbGet (plugin, ks, parentKey) >= 1,
			"call to kdbGet was not successful");
	succeed_if(output_error (parentKey), "error in kdbGet");
	succeed_if(output_warnings (parentKey), "warnings in kdbGet");

	succeed_if(plugin->kdbSet (plugin, ks, parentKey) >= 1,
			"call to kdbSet was not successful");
	succeed_if(output_error (parentKey), "error in kdbSet");
	succeed_if(output_warnings (parentKey), "warnings in kdbSet");

	/* test that the keys have been correctly restored */
	KeySet *expected = createSimpleTestKeys();

	/* the parent key is restored from user/tests/rename/will/be/stripped
	 * and therefore will have its key value
	 */
	keySetString (parentKeyCopy, "value3");
	ksAppendKey (expected, parentKeyCopy);

	compareKeySets (ks, expected);
	ksDel(expected);
	ksDel(ks);

	/*
	 * this has to be done because the parentKey is not
	 * part of ks anymore due to renaming
	 */
	keyDel(parentKey);
	PLUGIN_CLOSE ();
}
Esempio n. 5
0
void test_simpleAppendModes()
{
	Key *parentKey = keyNew ("user/tests/keytometa", KEY_END);
	KeySet *conf = ksNew(0, KS_END);
	PLUGIN_OPEN("keytometa");


	KeySet *ks = createSimpleTestKeys ();

	succeed_if(plugin->kdbGet (plugin, ks, parentKey) >= 1,
			"call to kdbGet was not successful");
	succeed_if(output_error (parentKey), "error in kdbGet");
	succeed_if(output_warnings (parentKey), "warnings in kdbGet");

	/* converted keys must be removed from the result */
	succeed_if (!ksLookupByName(ks, "user/convertkey1", 0), "convertkey1 was not converted");
	succeed_if (!ksLookupByName(ks, "user/convertkey2", 0), "convertkey2 was not converted");

	/* normalkey2 must contain meta information generated from convertkey1 (via next) */
	Key *key = ksLookupByName(ks, "user/normalkey2", 0);
	succeed_if (key, "normalkey2 was removed");

	const Key *metaKey1 = keyGetMeta(key, "testmeta");
	succeed_if (metaKey1, "normalkey2 contained no metakey");
	succeed_if (!strcmp (keyString(metaKey1), "testvalue1"), "metakey of normalkey2 contained incorrect data");

	/* normalkey3 must contain meta information generated from convertkey2 (via previous) */
	key = ksLookupByName (ks, "user/normalkey3", 0);
	succeed_if (key, "normalkey3 was removed");

	const Key *metaKey2 = keyGetMeta(key, "testmeta");
	succeed_if (metaKey2, "normalkey3 contained no metakey");
	succeed_if (!strcmp (keyString(metaKey2), "testvalue2"), "metakey of normalkey3 contained incorrect data");

	/* normalkey1 must contain meta information generated from subkey (via parent) */
	key = ksLookupByName (ks, "user/normalkey1", 0);
	succeed_if (key, "normalkey1 was removed");

	const Key *metaKey3 = keyGetMeta(key, "testmeta");
	succeed_if (metaKey3, "normalkey1 contained no metakey");
	succeed_if (!strcmp (keyString(metaKey3), "testvalue3"), "metakey of normalkey1 contained incorrect data");


	keyDel (parentKey);
	ksDel(ks);
	PLUGIN_CLOSE ()
	;
}
Esempio n. 6
0
void test_restoreOnSet () {
	Key *parentKey = keyNew ("user/tests/keytometa", KEY_END);
	KeySet *conf = ksNew(0, KS_END);
	PLUGIN_OPEN("keytometa");

	KeySet *ks = createSimpleTestKeys ();

	succeed_if(plugin->kdbGet (plugin, ks, parentKey) >= 1,
			"call to kdbGet was not successful");
	succeed_if(output_error (parentKey), "error in kdbGet");
	succeed_if(output_warnings (parentKey), "warnings in kdbGet");

	Key *key = ksLookupByName(ks, "user/normalkey2", 0);
	succeed_if (key, "normalkey2 was removed");

	/* change the meta information stored in normalkey2
	 * (was generated from convertkey1)
	 */
	keySetMeta(key, "testmeta", "changedtestvalue");

	/* do not touch the meta information of normalkey3
	 * (was generated from convertkey2)
	 */

	succeed_if(plugin->kdbSet (plugin, ks, parentKey) >= 1,
			"call to kdbSet was not successful");
	succeed_if(output_error (parentKey), "error in kdbSet");
	succeed_if(output_warnings (parentKey), "warnings in kdbSet");

	key = ksLookupByName(ks, "user/convertkey1", 0);
	succeed_if (key, "convertkey1 was not restored");
	succeed_if (!strcmp (keyString(key), "changedtestvalue"), "meta information was not written back to convertkey1");

	key = ksLookupByName (ks, "user/convertkey2", 0);
	succeed_if (key, "convertkey2 was not restored");
	succeed_if (!strcmp (keyString(key), "testvalue2"), " value of convertkey2 was modified");

	key = ksLookupByName (ks, "user/normalkey1/subkey", 0);
	succeed_if (key, "subkey was not restored");
	succeed_if (!strcmp (keyString(key), "testvalue3"), " value of subkey was modified");


	keyDel (parentKey);
	ksDel(ks);
	PLUGIN_CLOSE ()
	;
}
Esempio n. 7
0
static void test_toUpper ()
{
	Key * parentKey = keyNew ("user/tests/rename", KEY_END);
	KeySet * conf = ksNew (20, keyNew ("system/toupper", KEY_VALUE, "0", KEY_END), KS_END);
	KeySet * ks = createSimpleTestKeys ();
	ksAppendKey (ks, parentKey);
	PLUGIN_OPEN ("rename");
	succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
	Key * key = ksLookupByName (ks, "user/tests/rename/WILL/BE/STRIPPED/KEY1", KDB_O_NONE);
	succeed_if (key, "key1 was not correctly rename");
	key = ksLookupByName (ks, "user/tests/rename/WILL/BE/STRIPPED/KEY2", KDB_O_NONE);
	succeed_if (key, "key2 was not correctly rename");
	key = ksLookupByName (ks, "user/tests/rename/WILL/NOT/BE/STRIPPED/KEY4", KDB_O_NONE);
	succeed_if (key, "key4 was not correctly rename");

	keyDel (parentKey);
	ksDel (ks);
	PLUGIN_CLOSE ();
}