Exemple #1
0
static void testreadwritecomplicated (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 (!strcmp (keyString (ksLookupByName (ks, "user/tests/csvstorage/#1/col3", KDB_O_NONE)), "l1;c3"),
		    "key value doesn't match expected value");
	succeed_if (!strcmp (keyString (ksLookupByName (ks, "user/tests/csvstorage/#1/col4", KDB_O_NONE)), "l1\"\"c4"),
		    "key value doesn't match expected value");
	succeed_if (!strcmp (keyString (ksLookupByName (ks, "user/tests/csvstorage/#2/col3", KDB_O_NONE)), "l2\nc3"),
		    "key value doesn't match expected value");
	succeed_if (!strcmp (keyString (ksLookupByName (ks, "user/tests/csvstorage/#4/col4", KDB_O_NONE)), "l4\"\"c4"),
		    "key value doesn't match expected value");
	succeed_if (!strcmp (keyString (ksLookupByName (ks, "user/tests/csvstorage/#5/col3", KDB_O_NONE)), "l5\"\"\nc3"),
		    "key value doesn't match expected value");

	keySetString (parentKey, elektraFilename ());
	succeed_if (plugin->kdbSet (plugin, ks, parentKey) >= 0, "error: wrote invalid data");
	succeed_if (compare_line_files (srcdir_file (file), keyString (parentKey)), "files do not match as expected");

	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
Exemple #2
0
// test loading lua twice
static void test_two_scripts (void)
{
	printf ("Testing loading of two active lua plugins...\n");

	KeySet * modules = ksNew (0, KS_END);
	elektraModulesInit (modules, 0);

	KeySet * conf = ksNew (2, keyNew ("user/script", KEY_VALUE, srcdir_file ("lua/lua_plugin.lua"), KEY_END),
			       keyNew ("user/print", KEY_END), KS_END);

	KeySet * conf2 = ksNew (2, keyNew ("user/script", KEY_VALUE, srcdir_file ("lua/lua_plugin2.lua"), KEY_END),
				keyNew ("user/print", KEY_END), KS_END);

	Key * errorKey = keyNew ("", KEY_END);
	Plugin * plugin = elektraPluginOpen ("lua", modules, conf, errorKey);
	succeed_if (output_warnings (errorKey), "warnings in kdbOpen");
	succeed_if (output_error (errorKey), "errors in kdbOpen");
	exit_if_fail (plugin != NULL, "unable to load lua plugin");
	keyDel (errorKey);

	Key * errorKey2 = keyNew ("", KEY_END);
	Plugin * plugin2 = elektraPluginOpen ("lua", modules, conf2, errorKey2);
	succeed_if (output_warnings (errorKey2), "warnings in kdbOpen");
	succeed_if (output_error (errorKey2), "errors in kdbOpen");
	exit_if_fail (plugin2 != NULL, "unable to load lua plugin again");
	keyDel (errorKey2);

	elektraPluginClose (plugin2, 0);
	elektraPluginClose (plugin, 0);
	elektraModulesClose (modules, 0);
	ksDel (modules);
}
Exemple #3
0
void test_readWrite (const char * fileName, KeySet * conf)
{
	printf ("Test read write with %s\n", srcdir_file (fileName));

	Plugin * plugin = elektraPluginOpen ("yajl", modules, conf, 0);
	exit_if_fail (plugin != 0, "could not open plugin");
	// printf ("Test with %s\n", srcdir_file(fileName));

	Key * parentKey = keyNew ("user/tests/yajl", KEY_VALUE, srcdir_file (fileName), KEY_END);
	KeySet * keys = ksNew (0, KS_END);
	succeed_if (plugin->kdbGet (plugin, keys, parentKey) == 1, "kdbGet was not successful");
	succeed_if (output_error (parentKey), "error in kdbGet");
	succeed_if (output_warnings (parentKey), "warnings in kdbGet");

	// output_keyset(keys);

	keySetString (parentKey, elektraFilename ());
	// keySetString(parentKey, "/proc/self/fd/1");
	// printf("File name is: %s\n", keyString(parentKey));

	succeed_if (plugin->kdbSet (plugin, keys, 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 (keys);

	elektraPluginClose (plugin, 0);
}
Exemple #4
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 ()
	;

}
Exemple #5
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 ()
	;

}
static void test_plainIniEmptyWrite (char * fileName)
{
	Key * parentKey = keyNew ("user/tests/ini-write", KEY_VALUE, elektraFilename (), KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	PLUGIN_OPEN ("ini");

	KeySet * ks = ksNew (30, keyNew ("user/tests/ini-write/nosectionkey", KEY_VALUE, "nosectionvalue", KEY_END),
			     keyNew ("user/tests/ini-write/section1", KEY_BINARY,

				     KEY_END),
			     keyNew ("user/tests/ini-write/section1/key1", KEY_VALUE, "value1", KEY_END),
			     keyNew ("user/tests/ini-write/section1/key2", KEY_VALUE, "value2", KEY_END),
			     keyNew ("user/tests/ini-write/section2", KEY_BINARY, KEY_END),
			     keyNew ("user/tests/ini-write/section2/key3", KEY_VALUE, "value3", KEY_END),
			     keyNew ("user/tests/ini-write/section2/emptykey", KEY_META, "ini/empty", "", KEY_END), KS_END);

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

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

	KeySet * readKS = ksNew (0, KS_END);
	succeed_if (plugin->kdbGet (plugin, readKS, parentKey) >= 0, "kdbGet failed");
	const Key * meta;
	Key * searchKey = keyNew ("user/tests/ini-write/section2/emptykey", KEY_META, "ini/empty", "", KEY_END);
	Key * key = ksLookup (readKS, searchKey, KDB_O_NONE);
	meta = keyGetMeta (key, "ini/empty");
	succeed_if (meta != NULL, "reading empty key again failed");
	ksDel (readKS);
	keyDel (parentKey);
	keyDel (searchKey);
	ksDel (ks);
	PLUGIN_CLOSE ();
}
Exemple #7
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();
}
static void test_plainIniRead (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");
	succeed_if (!strcmp ("nosectionvalue", keyString (key)), "nosectionkey contained invalid data");

	key = ksLookupByName (ks, "user/tests/ini-read/section1", KDB_O_NONE);
	exit_if_fail (key, "section1 not found");
	succeed_if (!keyValue (key), "section value was not empty");

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

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

	ksDel (ks);
	keyDel (parentKey);

	PLUGIN_CLOSE ();
}
static void test_plainIniWrite (char * fileName)
{
	Key * parentKey = keyNew ("user/tests/ini-write", KEY_VALUE, elektraFilename (), KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	PLUGIN_OPEN ("ini");

	KeySet * ks = ksNew (30, keyNew ("user/tests/ini-write/nosectionkey", KEY_VALUE, "nosectionvalue", KEY_END),
			     keyNew ("user/tests/ini-write/section1", KEY_BINARY, KEY_END),
			     keyNew ("user/tests/ini-write/section1/key1", KEY_VALUE, "value1", KEY_END),
			     keyNew ("user/tests/ini-write/section1/key2", KEY_VALUE, "value2", KEY_END),
			     keyNew ("user/tests/ini-write/section2", KEY_BINARY, KEY_END),
			     keyNew ("user/tests/ini-write/section2/key3", KEY_VALUE, "value3", KEY_END),
			     keyNew ("user/tests/ini-write/section2/emptykey", KEY_END), KS_END);

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

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

	keyDel (parentKey);
	ksDel (ks);

	PLUGIN_CLOSE ();
}
Exemple #10
0
static void test_multilineIniWrite (char * fileName)
{
	Key * parentKey = keyNew ("user/tests/ini-multiline-write", KEY_VALUE, elektraFilename (), KEY_END);
	KeySet * conf = ksNew (30, keyNew ("system/multiline", KEY_VALUE, "1", KEY_END),
			       keyNew ("system/linecont", KEY_VALUE, "\t", KEY_END), KS_END);
	PLUGIN_OPEN ("ini");

	KeySet * ks = ksNew (
		30, keyNew ("user/tests/ini-multiline-write/multilinesection", KEY_BINARY, KEY_END),
		keyNew ("user/tests/ini-multiline-write/multilinesection/key1", KEY_VALUE, "value1\nwith continuation\nlines", KEY_END),
		keyNew ("user/tests/ini-multiline-write/singlelinesection", KEY_BINARY, KEY_END),
		keyNew ("user/tests/ini-multiline-write/singlelinesection/key2", KEY_VALUE, "", KEY_END),
		keyNew ("user/tests/ini-multiline-write/singlelinesection/key3", KEY_VALUE, "value3", KEY_END), KS_END);

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

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

	ksDel (ks);
	keyDel (parentKey);

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

	KeySet * conf = ksNew (30, keyNew ("system/multiline", KEY_VALUE, "1", KEY_END),
			       keyNew ("system/linecont", KEY_VALUE, "\t", KEY_END), 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-multiline-read/multilinesection/key1", KDB_O_NONE);
	exit_if_fail (key, "key1 not found");
	succeed_if (!strcmp ("value1\nwith continuation\nlines", keyString (key)), "key1 contained invalid data");

	key = ksLookupByName (ks, "user/tests/ini-multiline-read/singlelinesection/key2", KDB_O_NONE);
	exit_if_fail (key, "key2 not found");
	succeed_if (!strcmp ("", keyString (key)), "key2 contained invalid data");

	key = ksLookupByName (ks, "user/tests/ini-multiline-read/singlelinesection/key3", KDB_O_NONE);
	exit_if_fail (key, "key3 not found");
	succeed_if (!strcmp ("value3", keyString (key)), "key3 contained invalid data");

	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();
}
Exemple #13
0
static void test_sectionWrite (char * fileName)
{
	Key * parentKey = keyNew ("user/tests/ini-section-write", KEY_VALUE, elektraFilename (), KEY_END);
	KeySet * conf = ksNew (10, keyNew ("system/section", KEY_VALUE, "NULL", KEY_END), KS_END);
	PLUGIN_OPEN ("ini");

	KeySet * ks = ksNew (30, keyNew ("user/tests/ini-section-write/akey/looking/like/sections", KEY_VALUE, "value", KEY_END),
			     keyNew ("user/tests/ini-section-write/emptysection", KEY_BINARY, KEY_END),
			     keyNew ("user/tests/ini-section-write/section1", KEY_BINARY, KEY_END),
			     keyNew ("user/tests/ini-section-write/section1/key1", KEY_VALUE, "value1", KEY_END),
			     keyNew ("user/tests/ini-section-write/section1/key/with/subkey", KEY_VALUE, "value2", KEY_END),
			     keyNew ("user/tests/ini-section-write/section2/with/subkey", KEY_BINARY, KEY_END),
			     keyNew ("user/tests/ini-section-write/section2/with/subkey/key2", KEY_VALUE, "value2", KEY_END), KS_END);

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

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

	ksDel (ks);
	keyDel (parentKey);

	PLUGIN_CLOSE ();
}
Exemple #14
0
static void test_readPref (char * fileName)
{
	Key * parentKey = keyNew ("user/tests/pref-read", KEY_VALUE, srcdir_file (fileName), KEY_END);
	KeySet * conf = ksNew (0, KS_END);

	PLUGIN_OPEN ("mozprefs");

	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/pref-read/user/a/user/key", KDB_O_NONE);
	exit_if_fail (key, "Key a.user.key not found");
	succeed_if (!strcmp (keyString (key), "usertest"), "Key a.user.key contains invalid data");
	key = ksLookupByName (ks, "user/tests/pref-read/lock/a/lock/key", KDB_O_NONE);
	exit_if_fail (key, "Key a.lock.key not found");
	succeed_if (!strcmp (keyString (key), "true"), "Key a.lock.key contains invalid data");
	key = ksLookupByName (ks, "user/tests/pref-read/pref/a/default/key", KDB_O_NONE);
	exit_if_fail (key, "Key a.default.key not found");
	succeed_if (!strcmp (keyString (key), "1"), "Key a.default.key contains invalid data");
	key = ksLookupByName (ks, "user/tests/pref-read/sticky/a/sticky/key", KDB_O_NONE);
	exit_if_fail (key, "Key a.sticky.key not found");
	succeed_if (!strcmp (keyString (key), "false"), "Key a.sticky.key contains invalid data");
	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
Exemple #15
0
static void test_preserveEmptyLines (char * fileName)
{
	Key * parentKey = keyNew ("user/tests/ini-write", KEY_VALUE, srcdir_file (fileName), KEY_END);
	Key * writeParentKey = keyNew ("user/tests/ini-write", KEY_VALUE, elektraFilename (), KEY_END);
	KeySet * conf = ksNew (0, 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");
	keyDel (ksLookup (ks, parentKey, KDB_O_POP));
	keyDel (parentKey);
	succeed_if (plugin->kdbSet (plugin, ks, writeParentKey) >= 1, "call to kdbSet was not successful");
	succeed_if (compare_line_files (srcdir_file (fileName), keyString (writeParentKey)), "files do not match as expected");
	keyDel (ksLookup (ks, writeParentKey, KDB_O_POP));
	keyDel (writeParentKey);
	ksDel (ks);
	PLUGIN_CLOSE ();
}
void test_readwrite_hier ()
{
	KeySet * ks;
	FILE * fout;

	printf ("Testing Read and write xml\n");

	fout = fopen (srcdir_file ("xmltool/key-gen.xml"), "w");
	ks = ksNew (0, KS_END);
	exit_if_fail (ksFromXMLfile (ks, srcdir_file ("xmltool/key.xml")) == 0, "ksFromXMLfile(key.xml) failed.");
	ksToStream (ks, fout, KDB_O_HIER | KDB_O_HEADER);
	fclose (fout);

	compare_files (srcdir_file ("xmltool/key.xml"));
	unlink (srcdir_file ("xmltool/key-gen.xml"));

	ksDel (ks);
}
void test_keyset()
{
	KeySet		*ks;
	Key     	*cur;
	int		counter;

	printf("Testing KeySet from xml\n");

	ks = ksNew(0, KS_END);
	exit_if_fail( ksFromXMLfile(ks, srcdir_file("xmltool/keyset.xml")) == 0, "ksFromXMLfile(key.xml) failed.");
	counter = 0;
	ksRewind(ks);
	while ( (cur = ksNext(ks)) ) {
		counter ++;

		/* Make tests ... */	
		// printf ("counter: %d - %s\n", counter, keyName(cur));
		switch (counter) {
			// <key type="43" basename="0-27042916" value="0 216905227"><comment>2551516588474823843</comment></key>
		case 1:	succeed_if (strcmp (keyName(cur),"user/tests/filesys/0-27042916") == 0,"name of first key not correct");
			succeed_if (strcmp (keyValue(cur),"0 216905227") == 0,"value of first key not correct");
			succeed_if (strcmp (keyComment(cur),"2551516588474823843") == 0,"comment of first key not correct");
			break;
			// <key type="253" basename="1-2449524622" value="1 1679328197"><comment>3246436893195629244</comment></key>
		case 2:	succeed_if (strcmp (keyName(cur),"user/tests/filesys/1-2449524622") == 0,"name of 2. key not correct");
			succeed_if (strcmp (keyValue(cur),"1 1679328197") == 0,"value of 2. key not correct");
			succeed_if (strcmp (keyComment(cur),"3246436893195629244") == 0,"comment of 2. key not correct");
			break;
			// <key type="string" basename="dir-1-0">
		case 3:	succeed_if (strcmp (keyName(cur),"user/tests/filesys/dir-1-0") == 0,"name of 3. key not correct");
			break;
			// <key type="114" basename="0-294164813" value="0 216245011"><comment>18454108762891828026</comment></key>
		case 4:	succeed_if (strcmp (keyName(cur),"user/tests/filesys/dir-1-0/0-294164813") == 0,"name of 4. key not correct");
			succeed_if (strcmp (keyValue(cur),"0 216245011") == 0,"value of 4. key not correct");
			succeed_if (strcmp (keyComment(cur),"18454108762891828026") == 0,"comment of 4. key not correct");
			break;
			// <key type="135" basename="1-1479930365" value="1 2732423037"><comment>24597295372375238</comment></key>
		case 5:	succeed_if (strcmp (keyName(cur),"user/tests/filesys/dir-1-0/1-1479930365") == 0,"name of 4. key not correct");
			succeed_if (strcmp (keyValue(cur),"1 2732423037") == 0,"value of 4. key not correct");
			succeed_if (strcmp (keyComment(cur),"24597295372375238") == 0,"comment of 4. key not correct");
			break;
			// <key type="string" basename="dir-2-0">
		case 6:	succeed_if (strcmp (keyName(cur),"user/tests/filesys/dir-1-0/dir-2-0") == 0,"name of 3. key not correct");
			break;
			// <key type="144" basename="0-215571059" value="0 264857705"><comment>2188631490667217086</comment></key>
		case 7:	succeed_if (strcmp (keyName(cur),"user/tests/filesys/dir-1-0/dir-2-0/0-215571059") == 0,"name of 4. key not correct");
			succeed_if (strcmp (keyValue(cur),"0 264857705") == 0,"value of 4. key not correct");
			succeed_if (strcmp (keyComment(cur),"2188631490667217086") == 0,"comment of 4. key not correct");
			break;
		}
	}
	
	ksDel(ks);
}
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 ();
}
Exemple #20
0
void testRoundTrip (const char * fileName)
{
	Key * parentKey = keyNew ("user/tests/file", KEY_VALUE, srcdir_file (fileName), KEY_END);

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

	KeySet * ks = ksNew (0, KS_END);

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

	keySetString (parentKey, elektraFilename ());

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

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

	ksDel (ks);
	keyDel (parentKey);

	PLUGIN_CLOSE ();
}
Exemple #21
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 ();
}
static void test_BlockresolverWrite (char * fileName, char * compareName)
{
	FILE * fin = fopen (srcdir_file (fileName), "r");
	char buffer[1024];
	const char * foutname = elektraFilename ();
	FILE * fout = fopen (foutname, "w");
	while (fgets (buffer, sizeof (buffer), fin))
	{
		fputs (buffer, fout);
	}
	fclose (fin);
	fclose (fout);

	Key * parentKey = keyNew ("system/test/blockresolver-write", KEY_VALUE, foutname, KEY_END);
	KeySet * conf = ksNew (10, keyNew ("system/path", KEY_VALUE, foutname, KEY_END),
			       keyNew ("system/identifier", KEY_VALUE, "### block config", KEY_END), KS_END);
	KeySet * modules = ksNew (0, KS_END);
	KeySet * ks = ksNew (0, KS_END);
	elektraModulesInit (modules, 0);
	Plugin * resolver = elektraPluginOpen ("blockresolver", modules, ksDup (conf), 0);
	succeed_if (resolver->kdbGet (resolver, ks, parentKey) >= 0, "blockresolver->kdbGet failed");
	Plugin * storage = elektraPluginOpen ("ini", modules, ksNew (0, KS_END), 0);
	succeed_if (storage->kdbGet (storage, ks, parentKey) >= 0, "storage->kdbGet failed");
	keySetString (ksLookupByName (ks, "system/test/blockresolver-write/section/key", 0), "only the inside has changed");
	succeed_if (storage->kdbSet (storage, ks, parentKey) >= 0, "storage->kdbSet failed");
	succeed_if (resolver->kdbSet (resolver, ks, parentKey) >= 0, "blockresolver->kdbSet failed");
	succeed_if (resolver->kdbSet (resolver, ks, parentKey) >= 0, "blockresolver->kdbSet failed");

	succeed_if (compare_line_files (srcdir_file (compareName), foutname), "files do not match as expected");

	elektraPluginClose (storage, 0);
	elektraPluginClose (resolver, 0);
	ksDel (conf);
	ksDel (ks);
	elektraModulesClose (modules, 0);
	ksDel (modules);
	keyDel (parentKey);
}
Exemple #23
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);
}
Exemple #24
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 ();
}
Exemple #25
0
static void test_complexInsert (char * source, char * compare)
{
	Key * parentKey = keyNew ("user/tests/ini-write", KEY_VALUE, srcdir_file (source), KEY_END);
	Key * writeParentKey = keyNew ("user/tests/ini-write", KEY_VALUE, elektraFilename (), KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	KeySet * ks = ksNew (30, KS_END);
	KeySet * appendKS = ksNew (10, keyNew ("user/tests/ini-write/section/subsection", KEY_BINARY, KEY_END),
				   keyNew ("user/tests/ini-write/section/subsection/subkey", KEY_VALUE, "subval", KEY_END),
				   keyNew ("user/tests/ini-write/section/zkey3", KEY_VALUE, "3", KEY_END), KS_END);

	PLUGIN_OPEN ("ini");
	succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 0, "call to kdbGet was not successful");
	keyDel (ksLookup (ks, parentKey, KDB_O_POP));
	keyDel (parentKey);
	ksAppend (ks, appendKS);
	succeed_if (plugin->kdbSet (plugin, ks, writeParentKey) >= 1, "call to kdbSet was not successful");
	succeed_if (compare_line_files (srcdir_file (compare), keyString (writeParentKey)), "files do not match as expected");
	keyDel (ksLookup (ks, writeParentKey, KDB_O_POP));
	keyDel (writeParentKey);
	ksDel (appendKS);
	ksDel (ks);
	PLUGIN_CLOSE ();
}
Exemple #26
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_BlockresolverRead (char * fileName)
{
	Key * parentKey = keyNew ("system/test/blockresolver-read", KEY_VALUE, srcdir_file (fileName), KEY_END);
	KeySet * conf = ksNew (10, keyNew ("system/path", KEY_VALUE, srcdir_file (fileName), KEY_END),
			       keyNew ("system/identifier", KEY_VALUE, "### block config", KEY_END), KS_END);
	KeySet * modules = ksNew (0, KS_END);
	KeySet * ks = ksNew (0, KS_END);
	elektraModulesInit (modules, 0);
	Plugin * resolver = elektraPluginOpen ("blockresolver", modules, ksDup (conf), 0);
	succeed_if (resolver->kdbGet (resolver, ks, parentKey) >= 0, "blockresolver->kdbGet failed");
	output_warnings (parentKey);
	output_error (parentKey);
	Plugin * storage = elektraPluginOpen ("ini", modules, ksNew (0, KS_END), 0);
	succeed_if (storage->kdbGet (storage, ks, parentKey) >= 0, "storage->kdbGet failed");
	succeed_if (!strcmp (keyString (ksLookupByName (ks, "system/test/blockresolver-read/section/key", 0)), "inside block"),
		    "blockresolver failed to resolve requested block");
	elektraPluginClose (storage, 0);
	elektraPluginClose (resolver, 0);
	ksDel (conf);
	ksDel (ks);
	elektraModulesClose (modules, 0);
	ksDel (modules);
	keyDel (parentKey);
}
Exemple #28
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 ();
}
Exemple #29
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 ();
}
Exemple #30
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 ();
}