Beispiel #1
0
void test_setDirectionMatch()
{
	Key *parentKey = keyNew ("user/tests/glob", KEY_END);
	KeySet *conf = ksNew (20,
			keyNew ("user/glob/set/#1", KEY_VALUE, "/*",
					KEY_META, "testmetakey1", "testvalue1",
					KEY_META, "testmetakey2", "testvalue2",
					KEY_END),
			keyNew ("user/glob/get/#1", KEY_VALUE, "/*/*",
					KEY_META, "testmetakey1", "testvalue1",
					KEY_META, "testmetakey2", "testvalue2",
					KEY_END),
			KS_END);
	PLUGIN_OPEN("glob");

	KeySet* ks = createKeys ();

	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");

	testKeys (ks);
	ksDel(ks);
	keyDel(parentKey);

	PLUGIN_CLOSE();
}
Beispiel #2
0
void test_readline(){

	char * filename = srcdir_file("line/linetest");
	Key * parentKey = keyNew ("user/tests/line", KEY_VALUE, filename, KEY_END);
	KeySet *conf = 0;
	PLUGIN_OPEN("line");
	printf("%s\n", filename);

	KeySet *ks=ksNew(0, KS_END);
	succeed_if (plugin->kdbGet(plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
	Key *key = ksLookupByName(ks, "user/tests/line/#0", 0);
	exit_if_fail (key, "line1 key not found");
	succeed_if (strcmp("test1", keyValue(key)) == 0, "line ´ does not match");

	key = ksLookupByName(ks, "user/tests/line/#_10", 0);
	exit_if_fail (key, "line11 key not found");
	succeed_if (strcmp("", keyValue(key)) == 0, "line 10 should be blank");

	key = ksLookupByName(ks, "user/tests/line/#_13", 0);
	exit_if_fail (key, "line14 key not found");
	succeed_if (strcmp("printf(\"hello world\\n\");", keyValue(key)) == 0, "line 13 not correct");

	ksDel (ks);
	keyDel(parentKey);

	PLUGIN_CLOSE();
}
void test_readfstab (const char * file)
{
	Key * parentKey = keyNew ("user/tests/fstab", KEY_VALUE, srcdir_file (file), KEY_END);
	KeySet * conf = 0;
	PLUGIN_OPEN ("fstab");

	KeySet * ks = ksNew (0, KS_END);

	printf ("Reading fstab using file: %s\n", file);

	succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");

	// output_keyset(ks);

	Key * key = ksLookupByName (ks, "user/tests/fstab/\\//device", 0);
	exit_if_fail (key, "rootfs device not found");
	succeed_if (strcmp ("/dev/sda1", keyValue (key)) == 0, "device not correct");

	key = ksLookupByName (ks, "user/tests/fstab/\\/media\\/ext4/device", 0);
	exit_if_fail (key, "media device not found");
	succeed_if (strcmp ("/dev/sdg1", keyValue (key)) == 0, "device not correct");

	exit_if_fail (key = ksLookupByName (ks, "user/tests/fstab/\\/media\\/ext4/dumpfreq", 0), "rootfs device not found");
	succeed_if (strcmp ("0", keyValue (key)) == 0, "dumpfreq not correct");

	ksDel (ks);
	keyDel (parentKey);

	PLUGIN_CLOSE ();
}
static void test_mmap_ksCopy (const char * tmpFile)
{
	Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	PLUGIN_OPEN ("mmapstorage");

	KeySet * ks = simpleTestKeySet ();
	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
	succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");
	succeed_if ((ks->flags & KS_FLAG_MMAP_ARRAY) == KS_FLAG_MMAP_ARRAY, "KeySet array not in mmap");

	KeySet * copyKs = ksNew (0, KS_END);
	if (ksCopy (copyKs, ks) == 1)
	{
		compare_keyset (copyKs, ks);
		compare_keyset (ks, copyKs);
	}
	else
	{
		yield_error ("ksCopy failed");
	}

	ksDel (copyKs);
	keyDel (parentKey);
	ksDel (ks);
	PLUGIN_CLOSE ();
}
Beispiel #5
0
void test_structure (void)
{
	printf ("Test structure of keys returned from uname plugin");

	Key * parentKey = keyNew ("user/test/key", KEY_END);
	KeySet * keys = ksNew (0, KS_END);
	KeySet * conf = 0;

	PLUGIN_OPEN ("uname");

	succeed_if (plugin->kdbGet (plugin, keys, parentKey) == 1, "could not call kdbGet");

	succeed_if (ksGetSize (keys) == 6, "size not correct");
	succeed_if (ksLookupByName (keys, "user/test/key", 0), "parentkey not found");
	succeed_if (ksLookupByName (keys, "user/test/key/sysname", 0), "sysname key not found");
	succeed_if (ksLookupByName (keys, "user/test/key/nodename", 0), "nodename key not found");
	succeed_if (ksLookupByName (keys, "user/test/key/release", 0), "release key not found");
	succeed_if (ksLookupByName (keys, "user/test/key/version", 0), "version key not found");
	succeed_if (ksLookupByName (keys, "user/test/key/machine", 0), "machine key not found");

	ksDel (keys);
	keyDel (parentKey);

	PLUGIN_CLOSE ();
}
static void test_mmap_opmphm (const char * tmpFile)
{
	Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	PLUGIN_OPEN ("mmapstorage");
	KeySet * ks = largeTestKeySet ();

	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
	ksDel (ks);

	ks = ksNew (0, KS_END);
	succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");

	const char * name = "user/tests/mmapstorage/dir7/key3";
	Key * found = ksLookupByName (ks, name, KDB_O_OPMPHM);

	if (!found)
	{
		yield_error ("Key not found.")
	}

	// write keyset with OPMPHM structures
	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");

	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
static void test_mmap_ks_copy_with_meta (const char * tmpFile)
{
	Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	PLUGIN_OPEN ("mmapstorage");
	KeySet * ks = metaTestKeySet ();
	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");
	ksDel (ks);

	KeySet * returned = ksNew (0, KS_END);

	succeed_if (plugin->kdbGet (plugin, returned, parentKey) == 1, "kdbGet was not successful");

	KeySet * expected = metaTestKeySet ();
	compare_keyset (expected, returned);

	KeySet * copiedKs = ksNew (0, KS_END);
	ksCopy (copiedKs, returned);
	compare_keyset (expected, copiedKs);

	ksDel (copiedKs);
	ksDel (expected);
	ksDel (returned);

	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
static void test_mmap_metacopy (const char * tmpFile)
{
	Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	PLUGIN_OPEN ("mmapstorage");
	KeySet * ks = metaTestKeySet ();

	Key * shareMeta = keyNew (0);
	keySetMeta (shareMeta, "sharedmeta", "shared meta key test");

	Key * current;
	ksRewind (ks);
	while ((current = ksNext (ks)) != 0)
	{
		keyCopyMeta (current, shareMeta, "sharedmeta");
	}
	KeySet * expected = ksDeepDup (ks);


	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");

	KeySet * returned = ksNew (0, KS_END);
	succeed_if (plugin->kdbGet (plugin, returned, parentKey) == 1, "kdbGet was not successful");


	compare_keyset (expected, returned);

	ksDel (expected);
	ksDel (returned);

	keyDel (parentKey);
	keyDel (shareMeta);
	ksDel (ks);
	PLUGIN_CLOSE ();
}
Beispiel #9
0
void test_hostLensFormatting(char *fileName)
{
	Key *parentKey = keyNew ("user/tests/augeas-hosts", KEY_VALUE,
			srcdir_file (fileName), KEY_END);
	KeySet *conf = ksNew (20,
			keyNew ("system/lens", KEY_VALUE, "Hosts.lns", KEY_END), KS_END);
	PLUGIN_OPEN("augeas");

	KeySet *ks = ksNew(0, KS_END);

	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");

	keySetString (parentKey, elektraFilename());

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

	succeed_if(
			compare_line_files (srcdir_file (fileName), keyString (parentKey)),
			"files do not match as expected");

	elektraUnlink(keyString (parentKey));
	keyDel (parentKey);
	ksDel (ks);


	PLUGIN_CLOSE ()
	;

}
Beispiel #10
0
void test_differentMetaNames () {
	Key *parentKey = keyNew ("user/tests/keytometa", KEY_END);
	KeySet *conf = ksNew (0);
	PLUGIN_OPEN("keytometa");

	KeySet *ks = createDifferentMetaNameTestKeys();
	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/normalkey1", 0);
	succeed_if (key, "normalkey1 was removed");

	const Key *metaKey1 = keyGetMeta(key, "testmeta1");
	succeed_if (metaKey1, "normalkey1 contained no meta testmeta1");
	const char *expected1 = "meta line1";
	succeed_if (!strcmp (keyString(metaKey1), expected1), "metakey testmeta1 of normalkey1 contained incorrect data");

	const Key *metaKey2= keyGetMeta(key, "testmeta2");
	succeed_if (metaKey2, "normalkey1 contained no meta testmeta1");
	const char *expected2 = "meta line2";
	succeed_if (!strcmp (keyString(metaKey2), expected2), "metakey testmeta1 of normalkey1 contained incorrect data");

	keyDel (parentKey);
	ksDel(ks);
	PLUGIN_CLOSE ();
}
Beispiel #11
0
void test_hostLensDelete(char *sourceFile, char *compFile)
{
	Key *parentKey = keyNew ("user/tests/augeas-hosts", KEY_VALUE,
			srcdir_file (sourceFile), KEY_END);
	KeySet *conf = ksNew (20,
			keyNew ("system/lens", KEY_VALUE, "Hosts.lns", KEY_END), KS_END);
	PLUGIN_OPEN("augeas");

	KeySet *ks = ksNew(0, KS_END);

	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/tests/augeas-hosts/1", 0);
	exit_if_fail(key, "localhost not found");
	ksPopAtCursor(ks, ksGetCursor(ks));
	keyDel (key);

	key = ksLookupByName (ks, "user/tests/augeas-hosts/1/ipaddr", 0);
	exit_if_fail(key, "ip address of localhost not found");
	ksPopAtCursor(ks, ksGetCursor(ks));
	keyDel (key);

	key = ksLookupByName (ks, "user/tests/augeas-hosts/1/canonical", 0);
	exit_if_fail(key, "canonical of localhost not found");
	ksPopAtCursor(ks, ksGetCursor(ks));
	keyDel (key);

	key = ksLookupByName (ks, "user/tests/augeas-hosts/1/#comment", 0);
	exit_if_fail(key, "comment of localhost not found");
	ksPopAtCursor(ks, ksGetCursor(ks));
	keyDel (key);

	keySetString (parentKey, elektraFilename());

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

	succeed_if(
			compare_line_files (srcdir_file (compFile), keyString (parentKey)),
			"files do not match as expected");

	ksDel (ks);

	elektraUnlink(keyString (parentKey));
	keyDel (parentKey);

	PLUGIN_CLOSE ()
	;

}
void testinvalid (const char * file)
{
	Key * parentKey = keyNew ("user/tests/lineendings", KEY_VALUE, srcdir_file (file), KEY_END);
	KeySet * conf = ksNew (20, keyNew ("system/valid", KEY_VALUE, "CRLF", KEY_END), KS_END);
	PLUGIN_OPEN ("lineendings");
	KeySet * ks = ksNew (0, KS_END);
	succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbget failed");
	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == (-1), "should have failed");
	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
void testvalid (const char * file)
{
	Key * parentKey = keyNew ("user/tests/lineendings", KEY_VALUE, srcdir_file (file), KEY_END);
	KeySet * conf = 0;
	PLUGIN_OPEN ("lineendings");
	KeySet * ks = ksNew (0, KS_END);
	succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbget failed");
	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbset failed");
	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
Beispiel #14
0
void test_metaMerging ()
{
	Key *parentKey = keyNew ("user/tests/keytometa", KEY_END);
	KeySet *conf = ksNew(0, KS_END);
	PLUGIN_OPEN("keytometa");

	KeySet* ks = createMergeTestkeys ();
	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/normalkey1", 0);
	succeed_if (key, "normalkey1 was removed");

	const Key *metaKey1 = keyGetMeta(key, "testmeta");
	succeed_if (metaKey1, "normalkey1 contained no metakey");
	const char *expected1 = "meta line 1\nmeta line 2\nmeta line 3";
	succeed_if (!strcmp (keyString(metaKey1), expected1), "metakey of normalkey1 contained incorrect data");

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

	const Key *metaKey2 = keyGetMeta(key, "testmeta");
	succeed_if (metaKey2, "normalkey2 contained no metakey");
	const char *expected2 = "meta line 30\nmeta line 31\nmeta line 32";
	succeed_if (!strcmp (keyString(metaKey2), expected2), "metakey of normalkey2 contained incorrect data");

	/* change the value of the middle key */
	keySetMeta(key, "testmeta", "meta line 30\nchanged meta line\nmeta line 32");

	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/convertkey30", 0);
	succeed_if (key, "convertkey30 was not restored");
	succeed_if (!strcmp (keyString(key), "meta line 30"), "value of convertkey30 was modified");

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

	key = ksLookupByName (ks, "user/convertkey32", 0);
	succeed_if (key, "convertkey32 was not restored");
	succeed_if (!strcmp (keyString(key), "meta line 32"), "value of convertkey32 was modified");

	keyDel (parentKey);
	ksDel(ks);
	PLUGIN_CLOSE ();
}
static void clearStorage (const char * tmpFile)
{
	Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	PLUGIN_OPEN ("mmapstorage");
	KeySet * ks = ksNew (0, KS_END);

	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "kdbSet was not successful");

	keyDel (parentKey);
	ksDel (ks);
	PLUGIN_CLOSE ();
}
Beispiel #16
0
void test_hostLensWrite(char *fileName)
{
	Key *parentKey = keyNew ("user/tests/augeas-hosts", KEY_VALUE,
			elektraFilename(), KEY_END);
	KeySet *conf = ksNew (20,
			keyNew ("system/lens", KEY_VALUE, "Hosts.lns", KEY_END), KS_END);
	PLUGIN_OPEN("augeas");

	KeySet *ks = ksNew (30, keyNew ("user/tests/augeas-hosts/1", KEY_END),
			keyNew ("user/tests/augeas-hosts/1/ipaddr", KEY_VALUE, "127.0.0.1",
					KEY_META, "order", "10", KEY_END),
			keyNew ("user/tests/augeas-hosts/1/canonical", KEY_VALUE,
					"localhost", KEY_META, "order", "20", KEY_END),
			keyNew ("user/tests/augeas-hosts/1/#comment", KEY_VALUE,
					"hostcomment", KEY_META, "order", "21", KEY_END),
			keyNew ("user/tests/augeas-hosts/#comment", KEY_VALUE,
					"linecomment", KEY_META, "order", "22", KEY_END),
			keyNew ("user/tests/augeas-hosts/2/ipaddr", KEY_VALUE,
					"192.168.0.1", KEY_META, "order", "30", KEY_END),
			keyNew ("user/tests/augeas-hosts/2/canonical", KEY_VALUE, "host1",
					KEY_META, "order", "40", KEY_END),
			keyNew ("user/tests/augeas-hosts/2/alias[1]", KEY_VALUE,
					"host1alias1", KEY_META, "order", "50", KEY_END),
			keyNew ("user/tests/augeas-hosts/2/alias[2]", KEY_VALUE,
					"host1alias2", KEY_META, "order", "60", KEY_END),
			keyNew ("user/tests/augeas-hosts/3/ipaddr", KEY_VALUE,
					"fd00::4711:4712:2::1", KEY_META, "order", "70", KEY_END),
			keyNew ("user/tests/augeas-hosts/3/canonical", KEY_VALUE, "host2",
					KEY_META, "order", "80", KEY_END),
			keyNew ("user/tests/augeas-hosts/3/alias[1]", KEY_VALUE,
					"host2alias1", KEY_META, "order", "90", KEY_END),
			keyNew ("user/tests/augeas-hosts/3/alias[2]", KEY_VALUE,
					"host2alias2", KEY_META, "order", "100", KEY_END), KS_END);

	ksAppendKey (ks, parentKey);

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

	succeed_if(
			compare_line_files (srcdir_file (fileName), keyString (parentKey)),
			"files do not match as expected");

	elektraUnlink(keyString (parentKey));

	ksDel (ks);

	PLUGIN_CLOSE ();
}
Beispiel #17
0
static void test_formatNotAccepted (const char * format)
{
	Key * parentKey = keyNew ("user/tests/simpleini", KEY_VALUE, elektraFilename (), KEY_END);
	KeySet * conf = ksNew (1, keyNew ("system/format", KEY_VALUE, format, KEY_END), KS_END);
	PLUGIN_OPEN ("simpleini");

	KeySet * ks = ksNew (0, KS_END);

	succeed_if (plugin->kdbGet (plugin, ks, parentKey) != 1, "kdbGet was successful for an invalid format");

	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
Beispiel #18
0
static void testreadwriteinvalid (const char * file)
{
	Key * parentKey = keyNew ("user/tests/csvstorage", KEY_VALUE, srcdir_file (file), KEY_END);
	KeySet * conf = ksNew (10, keyNew ("system/delimiter", KEY_VALUE, ";", KEY_END), KS_END);
	KeySet * ks = ksNew (0, KS_END);
	PLUGIN_OPEN ("csvstorage");
	succeed_if (plugin->kdbGet (plugin, ks, parentKey) > 0, "call to kdbGet was not successful");
	succeed_if (!output_warnings (parentKey), "no warnings in kdbGet");
	keySetString (parentKey, elektraFilename ());
	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == (-1), "error: wrote invalid data");
	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
Beispiel #19
0
void test_hostLensRead(char *fileName)
{
	Key *parentKey = keyNew ("user/tests/augeas-hosts", KEY_VALUE,
			srcdir_file (fileName), KEY_END);
	KeySet *conf = ksNew (20,
			keyNew ("system/lens", KEY_VALUE, "Hosts.lns", KEY_END), KS_END);
	PLUGIN_OPEN("augeas");

	KeySet *ks = ksNew(0, KS_END);

	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/tests/augeas-hosts/1/ipaddr", 0);
	exit_if_fail(key, "ip address of localhost not found");
	succeed_if(strcmp ("127.0.0.1", keyValue (key)) == 0,
			"address of localhost not correct");

	key = ksLookupByName (ks, "user/tests/augeas-hosts/1/canonical", 0);
	exit_if_fail(key, "name of localhost not found");
	succeed_if(strcmp ("localhost", keyValue (key)) == 0,
			"name of localhost not correct");

	key = ksLookupByName (ks, "user/tests/augeas-hosts/2/ipaddr", 0);
	exit_if_fail(key, "ip address of host1 not found");
	succeed_if(strcmp ("192.168.0.1", keyValue (key)) == 0,
			"address of host1 not correct");

	key = ksLookupByName (ks, "user/tests/augeas-hosts/2/canonical", 0);
	exit_if_fail(key, "name of host1 not found");
	succeed_if(strcmp ("host1", keyValue (key)) == 0,
			"name of host1 not correct");

	key = ksLookupByName (ks, "user/tests/augeas-hosts/2/alias[1]", 0);
	exit_if_fail(key, "alias1 of host1 not found");
	succeed_if(strcmp ("alias1", keyValue (key)) == 0,
			"name of alias1 of host1 not correct");

	key = ksLookupByName (ks, "user/tests/augeas-hosts/2/alias[2]", 0);
	exit_if_fail(key, "alias2 of host1 not found");
	succeed_if(strcmp ("alias2", keyValue (key)) == 0,
			"name of alias2 of host1 not correct");

	PLUGIN_CLOSE();

	ksDel (ks);
	keyDel(parentKey);
}
Beispiel #20
0
void test_onlyFirstMatchIsApplied (void)
{
	Key * parentKey = keyNew ("user/tests/glob", KEY_END);
	// clang-format off
	KeySet * conf = ksNew (20,
				keyNew ("user/glob/#1",
						KEY_VALUE, "user/tests/glob/test1*",
						KEY_META, "testmetakey1", "testvalue1",
						KEY_END),
				keyNew ("user/glob/#2",
						KEY_VALUE, "user/tests/glob/*",
						KEY_META, "testmetakey2", "testvalue2",
						KEY_END),
			       /* disable all flags */
			    keyNew ("user/glob/#1/flags",
			    		KEY_VALUE, "",
						KEY_END),
				keyNew ("user/glob/#2/flags",
				   		KEY_VALUE, "",
						KEY_END),
				KS_END);
	// clang-format on
	PLUGIN_OPEN ("glob");

	KeySet * ks = createKeys ();

	succeed_if (plugin->kdbGet (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 * key = ksLookupByName (ks, "user/tests/glob/test1", 0);
	exit_if_fail (key, "key user/tests/glob/test1 not found");
	const Key * firstMatchKey = keyGetMeta (key, "testmetakey1");
	exit_if_fail (firstMatchKey, "testmetakey1 not found");
	const Key * secondMatchKey = keyGetMeta (key, "testmetakey2");
	exit_if_fail (!secondMatchKey, "testmetakey2 was applied to testmetakey1 although another match was already applied")

		key = ksLookupByName (ks, "user/tests/glob/test2/subtest1", 0);
	exit_if_fail (key, "user/tests/glob/test2/subtest1 not found");
	exit_if_fail (keyGetMeta (key, "testmetakey2"), "testmetakey2 not found");

	key = ksLookupByName (ks, "user/tests/glob/test3", 0);
	exit_if_fail (key, "user/tests/glob/test3 not found");
	exit_if_fail (keyGetMeta (key, "testmetakey2"), "testmetakey2 not found");

	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
Beispiel #21
0
static void testreadfixcolcount (const char * file)
{
	Key * parentKey = keyNew ("user/tests/csvstorage", KEY_VALUE, srcdir_file (file), KEY_END);
	KeySet * conf =
		ksNew (20, keyNew ("system/delimiter", KEY_VALUE, ";", KEY_END), keyNew ("system/header", KEY_VALUE, "colname", KEY_END),
		       keyNew ("system/columns", KEY_VALUE, "4", KEY_END), KS_END);
	PLUGIN_OPEN ("csvstorage");
	KeySet * ks = ksNew (0, KS_END);
	int ret = plugin->kdbGet (plugin, ks, parentKey);
	succeed_if (ret == (-1), "call to kdbGet was successful but shouldn't have been");
	ksDel (ks);
	keyDel (parentKey);

	PLUGIN_CLOSE ();
}
static void test_mmap_empty_after_clear (const char * tmpFile)
{
	Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	PLUGIN_OPEN ("mmapstorage");
	KeySet * returned = ksNew (0, KS_END);

	succeed_if (plugin->kdbGet (plugin, returned, parentKey) == 1, "kdbGet was not successful");

	succeed_if (ksGetSize (returned) == 0, "KeySet not empty after clear (or nullptr)");

	ksDel (returned);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
Beispiel #23
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 ()
	;
}
Beispiel #24
0
static void test_sectionRead (char * fileName)
{
	Key * parentKey = keyNew ("user/tests/ini-section-read", KEY_VALUE, srcdir_file (fileName), KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	PLUGIN_OPEN ("ini");

	KeySet * ks = ksNew (0, KS_END);

	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/tests/ini-section-read/akey/looking/like/sections", KDB_O_NONE);
	exit_if_fail (key, "section like key not found not found");
	succeed_if (!strcmp ("value", keyString (key)), "section like key contained invalid data");

	key = ksLookupByName (ks, "user/tests/ini-section-read/emptysection", KDB_O_NONE);
	exit_if_fail (key, "empty section key not found");
	succeed_if (keyIsBinary (key), "empty section key is not a binary key");
	succeed_if (!keyValue (key), "section key contains non null data");

	key = ksLookupByName (ks, "user/tests/ini-section-read/section1", KDB_O_NONE);
	exit_if_fail (key, "section1 key not found");
	succeed_if (keyIsBinary (key), "section1 key is not a binary key");
	succeed_if (!keyValue (key), "section1 contains non null data");

	key = ksLookupByName (ks, "user/tests/ini-section-read/section1/key1", KDB_O_NONE);
	exit_if_fail (key, "key1 not found not found");
	succeed_if (!strcmp ("value1", keyString (key)), "key1 contained invalid data");

	key = ksLookupByName (ks, "user/tests/ini-section-read/section1/key/with/subkey", KDB_O_NONE);
	exit_if_fail (key, "key with subkey not found not found");
	succeed_if (!strcmp ("value2", keyString (key)), "key with subkey contained invalid data");

	key = ksLookupByName (ks, "user/tests/ini-section-read/section2/with/subkey", KDB_O_NONE);
	exit_if_fail (key, "section2 key not found");
	succeed_if (keyIsBinary (key), "section2 key is not a binary key");
	succeed_if (!keyValue (key), "section2 contains non null data");

	key = ksLookupByName (ks, "user/tests/ini-section-read/section2/with/subkey/key2", KDB_O_NONE);
	exit_if_fail (key, "key2 not found not found");
	succeed_if (!strcmp ("value2", keyString (key)), "key2 contained invalid data");

	ksDel (ks);
	keyDel (parentKey);

	PLUGIN_CLOSE ();
}
Beispiel #25
0
static void test_commentIniRead (char * fileName)
{
	Key * parentKey = keyNew ("user/tests/ini-read", KEY_VALUE, srcdir_file (fileName), KEY_END);

	KeySet * conf = ksNew (0, KS_END);
	PLUGIN_OPEN ("ini");

	KeySet * ks = ksNew (0, KS_END);

	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/tests/ini-read/nosectionkey", KDB_O_NONE);
	exit_if_fail (key, "nosectionkey not found");
	const Key * noSectionComment = keyGetMeta (key, "comments/#0");
	exit_if_fail (noSectionComment, "nosectionkey contained no comment");
	succeed_if (!strcmp (";nosection comment1", keyString (noSectionComment)), "nosectionkey contained an invalid comment");
	noSectionComment = keyGetMeta (key, "comments/#1");
	exit_if_fail (noSectionComment, "nosectionkey contained no comment");
	succeed_if (!strcmp (";nosection comment2", keyString (noSectionComment)), "nosectionkey contained an invalid comment");


	key = ksLookupByName (ks, "user/tests/ini-read/section1", KDB_O_NONE);
	exit_if_fail (key, "section1 not found");
	const Key * sectionComment = keyGetMeta (key, "comments/#0");
	exit_if_fail (sectionComment, "sectionkey contained no comment");
	succeed_if (!strcmp (";section comment1", keyString (sectionComment)), "sectionkey contained an invalid comment");
	sectionComment = keyGetMeta (key, "comments/#1");
	exit_if_fail (sectionComment, "sectionkey contained no comment");
	succeed_if (!strcmp (";section comment2", keyString (sectionComment)), "sectionkey contained an invalid comment");


	key = ksLookupByName (ks, "user/tests/ini-read/section1/key1", KDB_O_NONE);
	exit_if_fail (key, "key1 not found");
	const Key * keyComment_ = keyGetMeta (key, "comments/#0");
	exit_if_fail (keyComment_, "key1 contained no comment");
	succeed_if (!strcmp (";key comment1", keyString (keyComment_)), "key1 contained an invalid comment");
	keyComment_ = keyGetMeta (key, "comments/#1");
	exit_if_fail (keyComment_, "key1 contained no comment");
	succeed_if (!strcmp (";key comment2", keyString (keyComment_)), "key1 contained an invalid comment");


	ksDel (ks);
	keyDel (parentKey);

	PLUGIN_CLOSE ();
}
Beispiel #26
0
static void test_basics (void)
{
	printf ("• Test basic functionality of plugin\n");

	Key * parentKey = keyNew ("system/elektra/modules/camel", KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	PLUGIN_OPEN ("camel");

	KeySet * ks = ksNew (0, KS_END);

	succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_SUCCESS, "Could not retrieve plugin contract");

	keyDel (parentKey);
	ksDel (ks);
	PLUGIN_CLOSE ();
}
Beispiel #27
0
static void testreadunescapedDQuote (const char * file)
{
	Key * parentKey = keyNew ("user/tests/csvstorage", KEY_VALUE, srcdir_file (file), KEY_END);
	KeySet * conf = ksNew (10, keyNew ("system/delimiter", KEY_VALUE, ";", KEY_END),
			       keyNew ("system/header", KEY_VALUE, "colname", KEY_END), KS_END);
	KeySet * ks = ksNew (0, KS_END);
	PLUGIN_OPEN ("csvstorage");
	succeed_if (plugin->kdbGet (plugin, ks, parentKey) > 0, "call to kdbGet was not successful");
	succeed_if (!output_warnings (parentKey), "no warnings in kdbGet");
	succeed_if (!strcmp (keyString (ksLookupByName (ks, "user/tests/csvstorage/#3/col3", KDB_O_NONE)), "l3\"c3"),
		    "key value doesn't match expected value");

	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
Beispiel #28
0
static void testwritevalidemptycol (const char * file)
{

	Key * parentKey = keyNew ("user/tests/csvstorage", KEY_VALUE, srcdir_file (file), KEY_END);
	KeySet * conf = ksNew (20, keyNew ("system/delimiter", KEY_VALUE, ";", KEY_END),
			       keyNew ("system/header", KEY_VALUE, "colname", KEY_END), KS_END);

	KeySet * ks = ksNew (0, KS_END);
	PLUGIN_OPEN ("csvstorage");
	succeed_if (plugin->kdbGet (plugin, ks, parentKey) > 0, "call to kdbGet was not successful");
	keySetString (parentKey, elektraFilename ());
	succeed_if (plugin->kdbSet (plugin, ks, parentKey) >= 0, "error: couldn't write data");
	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
Beispiel #29
0
static void test_array (char * fileName)
{
	Key * parentKey = keyNew ("user/tests/ini-read", KEY_VALUE, srcdir_file (fileName), KEY_END);
	KeySet * conf = ksNew (10, keyNew ("system/array", KEY_VALUE, "1", KEY_END), KS_END);
	KeySet * ks = ksNew (30, KS_END);
	PLUGIN_OPEN ("ini");
	succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 0, "call to kdbGet was not successful");
	Key * lookupKey;
	lookupKey = ksLookupByName (ks, "user/tests/ini-read/sec/a/#0", KDB_O_NONE);
	succeed_if (!strcmp (keyString (lookupKey), "1"), "key sec/a/#0 has the wrong value");
	lookupKey = ksLookupByName (ks, "user/tests/ini-read/sec/a/#3", KDB_O_NONE);
	succeed_if (!strcmp (keyString (lookupKey), "4"), "key sec/a/#3 has the wrong value");
	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
Beispiel #30
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 ()
	;
}