Esempio n. 1
0
void testReadMultiLine (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");

	const Key * key = ksLookupByName (ks, "user/tests/file", KDB_O_NONE);
	exit_if_fail (key, "key not found");

	succeed_if (!strcmp ("\nthis\n\n\tis a\n   multi line test-\nfile\n\n", keyString (key)),
		    "read multiline data doesn't match expected string");

	ksDel (ks);
	keyDel (parentKey);

	PLUGIN_CLOSE ();
}
Esempio n. 2
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 ();
}
static void test_mmap_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");

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

	ksDel (expected);
	ksDel (returned);

	keyDel (parentKey);
	ksDel (ks);
	PLUGIN_CLOSE ();
}
Esempio n. 4
0
void test_simpleAppendModes()
{
	Key *parentKey = keyNew ("user/tests/keytometa", KEY_END);
	KeySet *conf = ksNew (0);
	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, "normalkey1 contained no metakey");
	succeed_if (!strcmp (keyString(metaKey1), "testvalue1"), "metakey of normalkey1 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, "normalkey1 contained no metakey");
	succeed_if (!strcmp (keyString(metaKey2), "testvalue2"), "metakey of normalkey2 contained incorrect data");

	keyDel (parentKey);
	ksDel(ks);
	PLUGIN_CLOSE ()
	;
}
Esempio n. 5
0
int main (void)
{
	KeySet * myConfig = ksNew (0, KS_END);
	Key * key = keyNew ("/sw/MyApp", KEY_CASCADING_NAME, KEY_END);
	KDB * handle = kdbOpen (key);

	if (!handle) printError (key);


	printWarnings (key);

	if (kdbGet (handle, myConfig, key) < 0) printError (key);


	printWarnings (key);

	keyDel (key);

	// lookup
	Key * result = ksLookupByName (myConfig, "/sw/MyApp/Tests/TestKey1", 0);
	if (!result)
		printf ("Key not found in KeySet\n");
	else
	{
		// do something with the key
		const char * key_name = keyName (result);
		const char * key_value = keyString (result);
		const char * key_comment = keyString (keyGetMeta (result, "comment"));
		printf ("key: %s value: %s comment: %s\n", key_name, key_value, key_comment);
	}

	ksDel (myConfig); // delete the in-memory configuration


	// maybe you want kdbSet() myConfig here

	kdbClose (handle, 0); // no more affairs with the key database.
}
Esempio n. 6
0
static void test_file_signature_operations (void)
{
	Plugin * plugin = NULL;
	Key * parentKey = keyNew ("system", KEY_END);
	KeySet * modules = ksNew (0, KS_END);
	KeySet * config = newPluginConfiguration ();

	elektraModulesInit (modules, 0);
	plugin = elektraPluginOpen (PLUGIN_NAME, modules, config, 0);
	succeed_if (plugin, "failed to open plugin handle");
	if (plugin)
	{
		KeySet * data = ksNew (0, KS_END);
		const char * tmpFile = elektraFilename ();
		if (tmpFile)
		{
			// prepare test file to be encrypted
			writeTestFile (tmpFile);
			keySetString (parentKey, tmpFile);

			// try to encrypt the file
			succeed_if (plugin->kdbSet (plugin, data, parentKey) == 1, "kdb set failed");
			succeed_if (isTestFileCorrect (tmpFile) == -1, "file content did not change during encryption");

			// try to decrypt/verify the file
			succeed_if (plugin->kdbGet (plugin, data, parentKey) == 1, "kdb get failed");

			remove (tmpFile);
		}

		ksDel (data);
		elektraPluginClose (plugin, 0);
	}

	elektraModulesClose (modules, 0);
	ksDel (modules);
	keyDel (parentKey);
}
Esempio n. 7
0
int main()
{
	KeySet *myConfig = ksNew(0, KS_END);
	Key *key = keyNew("system/test/myapp",KEY_END);
	KDB *handle = kdbOpen(key);

	kdbGet(handle, myConfig, key);

	keySetName(key, "user/test/myapp");
	kdbGet(handle, myConfig, key);

	// check for errors in key
	keyDel(key);

	/*
	ksRewind(myConfig);
	while ((key = ksNext(myConfig)))
	{
		printf ("%s\n", keyName(key));
	}
	*/

	key = ksLookupByName(myConfig,"/test/myapp/key", 0);

	// check if key is not 0 and work with it...
	if (key)
	{
		printf("%s\n", keyString(key));
	}

	ksDel (myConfig); // delete the in-memory configuration


	// maybe you want kdbSet() myConfig here

	kdbClose(handle, 0); // no more affairs with the key database.
	return 0;
}
static void test_callbackCalledWithKey (void)
{
	printf ("test callback is called with changed key\n");

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

	char * value = "foobaroo!";
	Key * valueKey = keyNew ("user/test/internalnotification/value", KEY_VALUE, value, KEY_END);
	KeySet * ks = ksNew (1, valueKey, KS_END);

	succeed_if (internalnotificationRegisterCallback (plugin, valueKey, test_callback) == 1,
		    "call to elektraInternalnotificationRegisterCallback was not successful");

	elektraInternalnotificationUpdateRegisteredKeys (plugin, ks);

	succeed_if (callback_called, "registered value was not updated");
	succeed_if_same_string (callback_keyName, keyName (valueKey));
	succeed_if_same_string (callback_keyValue, value);

	ksDel (ks);
	PLUGIN_CLOSE ();
}
Esempio n. 9
0
void test_dup()
{
	Key *key;
	Key *dup;

	key = keyNew ("user/orig", KEY_END);
	succeed_if (keySetMeta (key, "test", "some_meta_test") == sizeof("some_meta_test"),
			"could not set meta");
	succeed_if (!strcmp(keyValue (keyGetMeta(key, "test")), "some_meta_test"), "could not set meta value");

	dup = keyDup (key);
	succeed_if (!strcmp(keyValue (keyGetMeta(dup, "test")), "some_meta_test"),
			"in duplicated key meta value was not copied");
	succeed_if (keySetMeta (dup, "test", "some_other_meta_test") == sizeof("some_other_meta_test"),
			"could not set meta");
	succeed_if (!strcmp(keyValue (keyGetMeta(dup, "test")), "some_other_meta_test"),
			"in duplicated key meta value was not changed");
	succeed_if (!strcmp(keyValue (keyGetMeta(key, "test")), "some_meta_test"),
			"in original key the value has changed");
	keyDel (dup);

	keyDel (key);
}
void test_name()
{
	printf ("Resolve Name\n");

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

	Plugin *plugin = elektraPluginOpen("resolver", modules, set_pluginconf(), 0);
	exit_if_fail (plugin, "could not load resolver plugin");

	KeySet *test_config = set_pluginconf();
	KeySet *config = elektraPluginGetConfig (plugin);
	succeed_if (config != 0, "there should be a config");
	compare_keyset(config, test_config);
	ksDel (test_config);

	succeed_if (plugin->kdbOpen != 0, "no open pointer");
	succeed_if (plugin->kdbClose != 0, "no open pointer");
	succeed_if (plugin->kdbGet != 0, "no open pointer");
	succeed_if (plugin->kdbSet != 0, "no open pointer");
	succeed_if (plugin->kdbError!= 0, "no open pointer");

	succeed_if (!strcmp(plugin->name, "resolver"), "got wrong name");

	resolverHandles *h = elektraPluginGetData(plugin);
	succeed_if (h != 0, "no plugin handle");

	Key *parentKey= keyNew("system", KEY_END);
	plugin->kdbGet(plugin, 0, parentKey);
	succeed_if (!strcmp(keyString(parentKey), KDB_DB_SYSTEM "/elektra.ecf"),
			"resulting filename not correct");

	keyDel (parentKey);
	elektraPluginClose(plugin, 0);
	elektraModulesClose(modules, 0);
	ksDel (modules);
}
Esempio n. 11
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, "comment");
	exit_if_fail (noSectionComment, "nosectionkey contained no comment");
	succeed_if (!strcmp ("nosection comment1\nnosection 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, "comment");
	exit_if_fail (sectionComment, "nosectionkey contained no comment");
	succeed_if (!strcmp ("section comment1\nsection comment2", keyString (sectionComment)), "section1 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, "comment");
	exit_if_fail (keyComment_, "key1 contained no comment");
	succeed_if (!strcmp ("key comment1\nkey comment2", keyString (keyComment_)), "key1 contained an invalid comment");

	ksDel (ks);
	keyDel (parentKey);

	PLUGIN_CLOSE ();
}
Esempio n. 12
0
void test_plainIniRead(char *fileName)
{
	Key *parentKey = keyNew ("user/tests/ini-read", KEY_VALUE,
			srcdir_file(fileName), KEY_END);

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

	KeySet *ks = ksNew (0);

	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 (keyIsDir(key), "section1 is not a directory key");

	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 ()
	;
}
Esempio n. 13
0
static void test_basics ()
{
	printf ("test basics\n");

	Key * parentKey = keyNew ("user/tests/template", KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	PLUGIN_OPEN ("template");

	KeySet * ks = ksNew (0, KS_END);

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

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

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

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

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

	keyDel (parentKey);
	ksDel (ks);
	PLUGIN_CLOSE ();
}
static void test_intNoUpdateWithInvalidValue (void)
{
	printf ("test no update with invalid value\n");

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

	Key * valueKey = keyNew ("user/test/internalnotification/value", KEY_END);
	KeySet * ks = ksNew (1, valueKey, KS_END);

	int value = 123;
	succeed_if (internalnotificationRegisterInt (plugin, valueKey, &value) == 1,
		    "call to elektraInternalnotificationRegisterInt was not successful");

	keySetString (valueKey, "42abcd");


	elektraInternalnotificationUpdateRegisteredKeys (plugin, ks);

	succeed_if (value == 123, "registered value was updated");

	ksDel (ks);
	PLUGIN_CLOSE ();
}
Esempio n. 15
0
static int elektraResolveEnvUser (ElektraResolved * handle)
{
	const char * user = getenv ("USER");

	if (!user || !strcmp (user, ""))
	{
		return 0;
	}

	Key * canonify = keyNew ("user", KEY_END);
	keyAddName (canonify, user);
	size_t homeSize = sizeof (KDB_DB_HOME "/") + keyGetNameSize (canonify) + sizeof ("/" KDB_DB_USER);

	char * homeBuf = elektraMalloc (homeSize);
	strcpy (homeBuf, KDB_DB_HOME "/");
	strcat (homeBuf, keyName (canonify) + 5); // cut user/
	if (handle->relPath[0] != '/')
	{
		strcat (homeBuf, "/" KDB_DB_USER);
	}
	keyDel (canonify);
	handle->dirname = homeBuf;
	return 1;
}
Esempio n. 16
0
static void test_mmap_open_pipe (void)
{
	// try writing to an invalid file, we simply use a pipe here
	int pipefd[2];
	if (pipe (pipefd) != 0)
	{
		yield_error ("pipe() error");
	}
	char pipeFile[1024];
	sprintf (pipeFile, "/dev/fd/%d", pipefd[1]);
	pipeFile[1023] = '\0';

	Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, pipeFile, KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	PLUGIN_OPEN ("mmapstorage");

	KeySet * ks = simpleTestKeySet ();
	// truncate inside mmap plugin should fail here, since the pipe cannot be truncated
	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_ERROR, "kdbSet did not detect error with the file");

	keyDel (parentKey);
	ksDel (ks);
	PLUGIN_CLOSE ();
}
Esempio n. 17
0
void test_comment()
{
	Key *key;
	char ret[10];

	succeed_if (key = keyNew(0), "could not create new key");
	succeed_if (strcmp (keyComment(key), "") == 0, "Empty comment problem");
	succeed_if (keyGetCommentSize(key) == 1, "Empty comment size problem");
	succeed_if (keyValue(keyGetMeta(key, "comment")) == 0, "No comment up to now");

	succeed_if (keySetComment (key,0) == 1, "could not remove comment");
	succeed_if (keyValue(keyGetMeta(key, "comment")) == 0, "There should be an no comment");
	succeed_if (!strcmp (keyComment(key), ""), "Empty comment problem");
	succeed_if (keyGetCommentSize(key) == 1, "Empty comment size problem");
	succeed_if (keyGetComment(key, ret, 0) == -1, "Could not get empty comment");
	succeed_if (keyGetComment(key, ret, 1) == 1, "Could not get empty comment");
	succeed_if (ret[0] == 0, "keyGetComment did not return empty comment");

	succeed_if (keySetComment (key,"") == 1, "could not remove comment");
	succeed_if (keyValue(keyGetMeta(key, "comment")) == 0, "There should be an no comment");
	succeed_if (!strcmp (keyComment(key), ""), "Empty comment problem");
	succeed_if (keyGetCommentSize(key) == 1, "Empty comment size problem");
	succeed_if (keyGetComment(key, ret, 0) == -1, "Could not get empty comment");
	succeed_if (keyGetComment(key, ret, 1) == 1, "Could not get empty comment");
	succeed_if (ret[0] == 0, "keyGetComment did not return empty comment");

	succeed_if (keySetComment (key,"mycom") == sizeof("mycom"), "could not set comment");
	succeed_if (!strcmp(keyValue(keyGetMeta(key, "comment")), "mycom"), "There should be my comment");
	succeed_if (!strcmp (keyComment(key), "mycom"), "My comment problem");
	succeed_if (keyGetCommentSize(key) == sizeof("mycom"), "My comment size problem");
	succeed_if (keyGetComment(key, ret, 0) == -1, "Could not get my comment");
	succeed_if (keyGetComment(key, ret, 1) == -1, "Could not get my comment");
	succeed_if (keyGetComment(key, ret, sizeof("mycom")) == sizeof("mycom"), "Could not get my comment");
	succeed_if (!strcmp (ret, "mycom"), "keyGetComment did not return my comment");
	succeed_if (keyDel (key) == 0, "could not delete key");
}
Esempio n. 18
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. 19
0
void test_encode (void)
{
	printf ("test encode\n");

	CHexData * hd = calloc (1, sizeof (CHexData));
	hd->hd['\0'] = 1;
	hd->hd['\n'] = 1;
	hd->hd['\\'] = 1;
	hd->hd[' '] = 1;
	hd->hd['='] = 1;
	hd->hd[';'] = 1;
	hd->hd['#'] = 1;
	hd->escape = '\\';

	char buf[1000];
	hd->buf = buf;

	Key * test = keyNew ("user/test", KEY_VALUE, decoded_string, KEY_END);
	elektraHexcodeEncode (test, hd);
	succeed_if (!memcmp (keyValue (test), encoded_string, sizeof (encoded_string) - 1), "string not correctly encoded");

	elektraFree (hd);
	keyDel (test);
}
Esempio n. 20
0
static int elektraResolveEnvUser (resolverHandle * p)
{
	const char * owner = getenv ("USER");

	if (!owner || !strcmp (owner, ""))
	{
		return 0;
	}

	Key * canonify = keyNew ("user", KEY_END);
	keyAddName (canonify, owner);
	size_t dirnameSize = sizeof (KDB_DB_HOME "/") + keyGetNameSize (canonify) + sizeof ("/" KDB_DB_USER);

	p->dirname = elektraMalloc (dirnameSize);
	strcpy (p->dirname, KDB_DB_HOME "/");
	strcat (p->dirname, keyName (canonify) + 5); // cut user/
	if (p->path[0] != '/')
	{
		strcat (p->dirname, "/" KDB_DB_USER);
	}
	keyDel (canonify);

	return 1;
}
Esempio n. 21
0
static void test_keyDel (const size_t storagePlugin, const char * tmpFile)
{
	Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
	open_storage_plugin (storagePlugin);
	Plugin * plugin = plugins[storagePlugin];

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

	Key * found = ksLookupByName (ks, "user/tests/storage/b", 0);
	succeed_if (found, "did not find key");

	succeed_if (keyDel (found) > 0, "Key was NULL or free()'d unexpectedly");

	// check that keyDel has not changed KeySet
	KeySet * expected = metaTestKeySet ();
	compare_keyset (ks, expected);

	ksDel (expected);
	keyDel (parentKey);
	ksDel (ks);
	closeStoragePlugin (storagePlugin);
}
Esempio n. 22
0
static int openStoragePlugin (const size_t storagePlugin)
{
	modules[storagePlugin] = ksNew (0, KS_END);
	elektraModulesInit (modules[storagePlugin], 0);
	KeySet * conf = ksNew (0, KS_END);
	Key * errorKey = keyNew ("", KEY_END);
	Plugin * plugin = elektraPluginOpen (pluginNames[storagePlugin], modules[storagePlugin], conf, errorKey);

	const Key * metaWarnings = keyGetMeta (errorKey, "warnings");
	if (metaWarnings) printf ("There are warnings for plugin: %s\n", pluginNames[storagePlugin]);
	const Key * metaError = keyGetMeta (errorKey, "error");
	if (metaError) printf ("There are errors for plugin: %s\n", pluginNames[storagePlugin]);

	if (plugin == 0)
	{
		printf ("Could not open plugin: %s\n", pluginNames[storagePlugin]);
		return -1;
	}

	plugins[storagePlugin] = plugin;
	keyDel (errorKey);

	return 0;
}
Esempio n. 23
0
static void test_lookupDoubleIndirect ()
{
	printf ("Test lookup by double indirect spec\n");

	Key * s;
	Key * p;
	Key * d;
	Key * u;
	Key * y;
	Key * se;
	Key * pe;
	KeySet * ks = ksNew (20, se = keyNew ("spec/first", KEY_END), pe = keyNew ("proc/first", KEY_END), s = keyNew ("spec/abc", KEY_END),
			     p = keyNew ("proc/abc", KEY_END), d = keyNew ("dir/abc", KEY_END), u = keyNew ("user/abc", KEY_END),
			     y = keyNew ("system/abc", KEY_END), KS_END);
	succeed_if (ksGetSize (ks) == 7, "wrong size");

	Key * k = ksLookupByName (ks, "/first", 0);
	succeed_if (k == pe, "did not find proc key");

	keySetMeta (se, "override/#0", "/abc");
	k = ksLookupByName (ks, "/first", 0);
	succeed_if (k == p, "did not find proc/abc");

	keySetMeta (s, "namespace/#0", "system");
	k = ksLookupByName (ks, "/first", 0);
	succeed_if (k == y, "did not find system key");

	keySetMeta (s, "namespace/#0", "system");
	keySetMeta (s, "namespace/#1", "user");
	k = ksLookupByName (ks, "/first", 0);
	succeed_if (k == y, "did not find system key");

	keySetMeta (s, "namespace/#0", "proc");
	keySetMeta (s, "namespace/#1", "user");
	k = ksLookupByName (ks, "/first", 0);
	succeed_if (k == p, "did not find proc key");

	keySetMeta (s, "override/#0", "proc/first");
	k = ksLookupByName (ks, "/first", 0);
	succeed_if (k == pe, "did not find override key (double indirect)");

	ksDel (ks);
}
Esempio n. 24
0
static KeySet * elektraNoresolverModules()
{
	return ksNew (50,
	keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME "",
			KEY_VALUE, "" ELEKTRA_PLUGIN_NAME " plugin waits for your orders", KEY_END),
		keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME "/exports", KEY_END),
		keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME "/exports/get",
			KEY_FUNC, elektraNoresolverGet,
			KEY_END),
		keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME "/exports/set",
			KEY_FUNC, elektraNoresolverSet,
			KEY_END),
		keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME "/exports/error",
			KEY_FUNC, elektraNoresolverError,
			KEY_END),
		keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME "/exports/checkfile",
			KEY_FUNC, elektraNoresolverCheckFile,
			KEY_END),
#include ELEKTRA_README(noresolver)
		keyNew ("system/elektra/modules/" ELEKTRA_PLUGIN_NAME "/infos/version",
			KEY_VALUE, PLUGINVERSION, KEY_END),
		KS_END);
}
Esempio n. 25
0
void test_config (void)
{
	KeySet * config =
		ksNew (20, keyNew ("user/chars", KEY_END), keyNew ("user/chars/20", KEY_END), keyNew ("user/chars/23", KEY_END),
		       keyNew ("user/chars/5C", KEY_END), keyNew ("user/chars/3D", KEY_END), keyNew ("user/chars/3B", KEY_END), KS_END);

	KeySet * returned = ksNew (20, keyNew ("user/something", KEY_VALUE, decoded_string, KEY_END), KS_END);

	Plugin * p = calloc (1, sizeof (Plugin));
	p->config = config;

	elektraHexcodeOpen (p, 0);

	elektraHexcodeSet (p, returned, 0);

	Key * test = ksLookupByName (returned, "user/something", 0);
	succeed_if (!memcmp (keyValue (test), encoded_string, sizeof (encoded_string) - 1), "string not correctly encoded");

	elektraHexcodeClose (p, 0);

	ksDel (returned);
	ksDel (p->config);
	elektraFree (p);
}
Esempio n. 26
0
static void testSetColnames (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, "2", KEY_END), keyNew ("system/columns/names", KEY_VALUE, "", KEY_END),
		       keyNew ("system/columns/names/#0", KEY_VALUE, "col0Name", KEY_END),
		       keyNew ("system/columns/names/#1", KEY_VALUE, "col1Name", KEY_END), KS_END);
	PLUGIN_OPEN ("csvstorage");
	KeySet * ks = ksNew (0, KS_END);
	succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
	Key * key;
	key = ksLookupByName (ks, "user/tests/csvstorage/#1/col0Name", 0);
	exit_if_fail (key, "key not found");
	succeed_if (strcmp (keyString (key), "l1c1") == 0, "wrong key");
	key = ksLookupByName (ks, "user/tests/csvstorage/#2/col1Name", 0);
	exit_if_fail (key, "key not found");
	succeed_if (strcmp (keyString (key), "l2c2") == 0, "wrong key");

	ksDel (ks);
	keyDel (parentKey);

	PLUGIN_CLOSE ();
}
Esempio n. 27
0
static void test_lookupNamespace ()
{
	printf ("Test lookup namespace\n");

	Key * specKey = keyNew ("/abc", KEY_CASCADING_NAME, KEY_META, "namespace/#0", "system", KEY_END);
	Key * k = 0;

	KeySet * ks = ksNew (20, k = keyNew ("user/abc", KEY_END), KS_END);
	succeed_if (ksLookup (ks, specKey, KDB_O_SPEC) == 0, "found wrong key of other namespace");
	keySetMeta (specKey, "namespace/#0", "user");
	succeed_if (ksLookup (ks, specKey, KDB_O_SPEC) == k, "did not find key in correct namespace");
	ksDel (ks);

	ks = ksNew (20, k = keyNew ("system/abc", KEY_END), KS_END);
	keySetMeta (specKey, "namespace/#0", "user");
	succeed_if (ksLookup (ks, specKey, KDB_O_SPEC) == 0, "found wrong key of other namespace");
	keySetMeta (specKey, "namespace/#0", "system");
	succeed_if (ksLookup (ks, specKey, KDB_O_SPEC) == k, "did not find key in correct namespace");
	ksDel (ks);


	ks = ksNew (20, keyNew ("system/abc", KEY_END), k = keyNew ("user/abc", KEY_END), KS_END);
	keySetMeta (specKey, "namespace/#0", "user");
	keySetMeta (specKey, "namespace/#1", "system");
	succeed_if (ksLookup (ks, specKey, KDB_O_SPEC) == k, "found wrong key of other namespace");
	ksDel (ks);


	ks = ksNew (20, k = keyNew ("system/abc", KEY_END), keyNew ("user/abc", KEY_END), KS_END);
	keySetMeta (specKey, "namespace/#0", "system");
	keySetMeta (specKey, "namespace/#1", "user");
	succeed_if (ksLookup (ks, specKey, KDB_O_SPEC) == k, "found wrong key of other namespace");
	ksDel (ks);

	keyDel (specKey);
}
Esempio n. 28
0
static void test_arrayInsert (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 (10, keyNew ("system/array", KEY_VALUE, "1", KEY_END), KS_END);
	KeySet * ks = ksNew (30, KS_END);
	KeySet * appendKS = ksNew (10, keyNew ("user/tests/ini-write/a/section/array/#0", KEY_VALUE, "0", KEY_END),
				   keyNew ("user/tests/ini-write/a/section/array/#1", KEY_VALUE, "1", KEY_END),
				   keyNew ("user/tests/ini-write/a/section/array/#2", KEY_VALUE, "2", KEY_END),
				   keyNew ("user/tests/ini-write/a/section/array/#3", 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 ();
}
Esempio n. 29
0
static void test_relative_generic ()
{
	printf ("Get relative name of key with generic mountpoint\n");

	Key * parent = keyNew ("system/", KEY_END);
	Key * child = keyNew ("system/key/🔑/🗝", KEY_END);

	test_relative ("key/🔑/🗝", child, parent);
	keyDel (child);
	child = keyNew ("system/Käfer/K", KEY_END);
	test_relative ("Käfer/K", child, parent);
	keyDel (child);
	keyDel (parent);
	parent = keyNew ("user", KEY_END);
	child = keyNew ("user/K", KEY_END);
	test_relative ("K", child, parent);
	keyDel (child);
	child = keyNew ("user/KK\\/Kitchens/What/Were/You/Thinking?", KEY_END);
	test_relative ("KK\\/Kitchens/What/Were/You/Thinking?", child, parent);
	keyDel (child);
	keyDel (parent);
}
Esempio n. 30
0
static void test_relative_cascading ()
{
	printf ("Get relative name of key with cascading mountpoint\n");

	Key * parent = keyNew ("/cascading", KEY_END);
	Key * child = keyNew ("/cascading/k", KEY_END);

	test_relative ("k", child, parent);
	keyDel (child);
	child = keyNew ("system/cascading/deep/deeper/deepest", KEY_END);
	test_relative ("deep/deeper/deepest", child, parent);
	keyDel (parent);
	keyDel (child);
	parent = keyNew ("/cascading\\/mountpoint/", KEY_END);
	child = keyNew ("user/cascading\\/mountpoint/\\/dot", KEY_END);
	test_relative ("\\/dot", child, parent);
	keyDel (child);
	child = keyNew ("user/second_level/cascading\\/mountpoint/\\/dot", KEY_END);
	test_relative ("\\/dot", child, parent);
	keyDel (child);
	keyDel (parent);
}