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); }
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 (); }
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 (); }
static void test_file_faulty_signature (void) { Plugin * plugin = NULL; Key * parentKey = keyNew ("system", KEY_END); KeySet * modules = ksNew (0, KS_END); KeySet * config = newPluginConfigurationWithTextmodeEnabled (); 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 writeFaultySignatureFile (tmpFile); keySetString (parentKey, tmpFile); // try to decrypt/verify the file -- should fail succeed_if (plugin->kdbGet (plugin, data, parentKey) == -1, "kdb get succeeded on a faulty signature"); remove (tmpFile); } ksDel (data); elektraPluginClose (plugin, 0); } elektraModulesClose (modules, 0); ksDel (modules); keyDel (parentKey); }
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 (); }
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 (); }
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 () ; }
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 (); }
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 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 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 (); }
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 (); }
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 (); }
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 testWriteMultiLine (const char * compareTo) { Key * parentKey = keyNew ("user/tests/file", KEY_VALUE, elektraFilename (), KEY_END); KeySet * conf = ksNew (0, KS_END); PLUGIN_OPEN ("file"); KeySet * ks = ksNew (3, keyNew ("user/tests/file", KEY_VALUE, "\nthis\n\n\tis a\n multi line test-\nfile\n\n", KEY_END), KS_END); succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "call to kdbSet was not successful"); succeed_if (compare_line_files (srcdir_file (compareTo), keyString (parentKey)), "files do not match as expected"); ksDel (ks); keyDel (parentKey); PLUGIN_CLOSE (); }
static void test_readFormat (const char * format, const char * fileContent, int numKeys, const char ** keys, const char ** values) { const char * tmpFile = elektraFilename (); FILE * fh = fopen (tmpFile, "w"); if (fh) { fputs (fileContent, fh); fclose (fh); } Key * parentKey = keyNew ("user/tests/simpleini", KEY_VALUE, tmpFile, KEY_END); KeySet * conf = 0; if (format) { conf = ksNew (1, keyNew ("system/format", KEY_VALUE, format, KEY_END), KS_END); } else { conf = ksNew (0, KS_END); } PLUGIN_OPEN ("simpleini"); KeySet * ks = ksNew (numKeys, KS_END); Key * key = 0; succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful"); Key * lookup = 0; for (int i = 0; i < numKeys; i++) { lookup = keyNew ("user/tests/simpleini", KEY_END); keyAddBaseName (lookup, keys[i]); printf ("testing key '%s'\n", keyBaseName (lookup)); succeed_if ((key = ksLookup (ks, lookup, 0)) != NULL, "key not found"); succeed_if (strcmp (values[i], keyString (key)) == 0, "value of key did not match"); keyDel (lookup); } keyDel (key); ksDel (ks); keyDel (parentKey); PLUGIN_CLOSE (); }
static void test_file_crypto_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 the file again (simulating the pregetstorage call) succeed_if (plugin->kdbGet (plugin, data, parentKey) == 1, "kdb get (pregetstorage) failed"); succeed_if (isTestFileCorrect (keyString (parentKey)) == 1, "file content could not be restored during decryption"); // a second call to kdb get (the postgetstorage call) should re-encrypt the file again succeed_if (plugin->kdbGet (plugin, data, parentKey) == 1, "kdb get (postgetstorage) failed"); succeed_if (isTestFileCorrect (tmpFile) == -1, "postgetstorage did not encrypt the file again"); remove (tmpFile); } ksDel (data); elektraPluginClose (plugin, 0); } elektraModulesClose (modules, 0); ksDel (modules); keyDel (parentKey); }
static void test_emptySectionBug (char * fileName) { Key * parentKey = keyNew ("user/tests/ini-write", KEY_VALUE, elektraFilename (), KEY_END); KeySet * conf = ksNew (0, KS_END); KeySet * ks = ksNew (30, keyNew ("user/tests/ini-write/MyApp/mykey", KEY_VALUE, "new_value", KEY_END), keyNew ("user/tests/ini-write/binarytest", KEY_BINARY, KEY_END), keyNew ("user/tests/ini-write/debienna/test", KEY_VALUE, "value", KEY_END), KS_END); PLUGIN_OPEN ("ini"); 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 (); }
void test_writefstab (const char * file) { KeySet * conf = 0; PLUGIN_OPEN ("fstab"); printf ("Writing fstab using file: %s\n", file); KeySet * ks = ksNew ( 22, keyNew ("user/tests/filesystems", KEY_VALUE, "filesystems", KEY_COMMENT, "", KEY_END), keyNew ("user/tests/filesystems/\\/", KEY_VALUE, "the root fs", KEY_COMMENT, "pseudo name", KEY_END), keyNew ("user/tests/filesystems/\\//device", KEY_VALUE, "/dev/sda6", KEY_COMMENT, "Device or Label", KEY_END), keyNew ("user/tests/filesystems/\\//dumpfreq", KEY_VALUE, "0", KEY_COMMENT, "Dump frequency in days", KEY_END), keyNew ("user/tests/filesystems/\\//mpoint", KEY_VALUE, "/", KEY_COMMENT, "Moint point", KEY_END), keyNew ("user/tests/filesystems/\\//options", KEY_VALUE, "defaults,errors=remount-ro", KEY_COMMENT, "Fileuser/tests specific options. See mount(8)", KEY_END), keyNew ("user/tests/filesystems/\\//passno", KEY_VALUE, "1", KEY_COMMENT, "Pass number on parallel fsck", KEY_END), keyNew ("user/tests/filesystems/\\//type", KEY_VALUE, "jfs", KEY_COMMENT, "Fileuser/tests type. See fs(5)", KEY_END), keyNew ("user/tests/filesystems/swap00", KEY_VALUE, "non-swapfs", KEY_COMMENT, "pseudo name", KEY_END), keyNew ("user/tests/filesystems/swap00/device", KEY_VALUE, "/dev/sda10", KEY_COMMENT, "Device or Label", KEY_END), keyNew ("user/tests/filesystems/swap00/dumpfreq", KEY_VALUE, "0", KEY_COMMENT, "Dump frequency in days", KEY_END), keyNew ("user/tests/filesystems/swap00/mpoint", KEY_VALUE, "none", KEY_COMMENT, "Moint point", KEY_END), keyNew ("user/tests/filesystems/swap00/options", KEY_VALUE, "sw", KEY_COMMENT, "Fileuser/tests specific options. See mount(8)", KEY_END), keyNew ("user/tests/filesystems/swap00/passno", KEY_VALUE, "0", KEY_COMMENT, "Pass number on parallel fsck", KEY_END), keyNew ("user/tests/filesystems/swap00/type", KEY_VALUE, "swap", KEY_COMMENT, "Fileuser/tests type. See fs(5)", KEY_END), KS_END); Key * parentKey = keyNew ("user/tests/filesystems", KEY_VALUE, elektraFilename (), KEY_END); 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 (file), keyString (parentKey)), "files do not match as expected"); elektraUnlink (keyString (parentKey)); keyDel (parentKey); ksDel (ks); PLUGIN_CLOSE (); }
static void test_writePref (char * fileName) { Key * parentKey = keyNew ("user/tests/pref-write", KEY_VALUE, elektraFilename (), KEY_END); KeySet * conf = ksNew (0, KS_END); PLUGIN_OPEN ("mozprefs"); KeySet * ks = ksNew ( 30, keyNew ("user/tests/pref-write/user/a/user/key", KEY_VALUE, "usertest", KEY_META, "type", "string", KEY_END), keyNew ("user/tests/pref-write/lock/a/lock/key", KEY_VALUE, "true", KEY_META, "type", "boolean", KEY_END), keyNew ("user/tests/pref-write/pref/a/default/key", KEY_VALUE, "1", KEY_META, "type", "integer", KEY_END), keyNew ("user/tests/pref-write/sticky/a/sticky/key", KEY_VALUE, "false", KEY_META, "type", "boolean", KEY_END), KS_END); 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 (); }
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_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); }
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); }
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 (); }
static void test_multilineIniInvalidConfigWrite () { Key * parentKey = keyNew ("user/tests/ini-multiline-write", KEY_VALUE, elektraFilename (), KEY_END); KeySet * conf = ksNew (30, keyNew ("system/multiline", KEY_VALUE, "0", 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), KS_END); succeed_if (plugin->kdbSet (plugin, ks, parentKey) < 0, "call to kdbSet was successful, but should fail"); const Key * metaError = keyGetMeta (parentKey, "error"); exit_if_fail (metaError, "No error was produced on the parentKey"); succeed_if (!strcmp (keyString (keyGetMeta (parentKey, "error/number")), "97"), "The plugin threw the wrong error"); ksDel (ks); keyDel (parentKey); PLUGIN_CLOSE (); }
int main (int argc, char ** argv) { printf ("MMAPSTORAGE TESTS\n"); printf ("==================\n\n"); init (argc, argv); testDynArray (); const char * tmpFile = elektraFilename (); // call once before clearStorage, to test non existent file test_mmap_get_set (tmpFile); clearStorage (tmpFile); test_mmap_truncated_file (tmpFile); test_mmap_wrong_magic_number (tmpFile); test_mmap_wrong_format_version (tmpFile); test_mmap_wrong_magic_keyset (tmpFile); clearStorage (tmpFile); test_mmap_get_set_empty (tmpFile); clearStorage (tmpFile); test_mmap_get_set (tmpFile); clearStorage (tmpFile); test_mmap_set_get (tmpFile); test_mmap_get_after_reopen (tmpFile); test_mmap_set_get_large_keyset (tmpFile); test_mmap_ks_copy (tmpFile); clearStorage (tmpFile); test_mmap_empty_after_clear (tmpFile); test_mmap_meta (tmpFile); test_mmap_meta_get_after_reopen (tmpFile); test_mmap_metacopy (tmpFile); clearStorage (tmpFile); test_mmap_ks_copy_with_meta (tmpFile); clearStorage (tmpFile); test_mmap_opmphm (tmpFile); clearStorage (tmpFile); test_mmap_ksDupFun (tmpFile, ksDup); clearStorage (tmpFile); test_mmap_ksDupFun (tmpFile, ksDeepDup); clearStorage (tmpFile); test_mmap_ksCopy (tmpFile); test_mmap_open_pipe (); test_mmap_bad_file_permissions (tmpFile); test_mmap_unlink (tmpFile); printf ("\ntestmod_mmapstorage RESULTS: %d test(s) done. %d error(s).\n", nbTest, nbError); return nbError; }
int main (int argc, char ** argv) { printf ("STORAGE TESTS\n"); printf ("==================\n\n"); init (argc, argv); initPlugins (); for (size_t plugin = 0; plugin < numPlugins; ++plugin) { const char * tmpFile = elektraFilename (); printf ("Testing plugin %s\n", pluginNames[plugin]); fprintf (stdout, "Tmp-file: %s\n", tmpFile); // KeySet API tests clearStorage (plugin, tmpFile); test_ksDupFun (plugin, tmpFile, ksDup); clearStorage (plugin, tmpFile); test_ksDupFun (plugin, tmpFile, ksDeepDup); clearStorage (plugin, tmpFile); test_ksCopy (plugin, tmpFile); clearStorage (plugin, tmpFile); test_ksGetSize (plugin, tmpFile); clearStorage (plugin, tmpFile); test_double_get (plugin, tmpFile); // regression test clearStorage (plugin, tmpFile); test_ksAppendKey (plugin, tmpFile); clearStorage (plugin, tmpFile); test_ksAppend (plugin, tmpFile); clearStorage (plugin, tmpFile); test_ksCut (plugin, tmpFile); clearStorage (plugin, tmpFile); test_ksPop (plugin, tmpFile); clearStorage (plugin, tmpFile); test_ksLookup (plugin, tmpFile, 0); clearStorage (plugin, tmpFile); test_ksLookup (plugin, tmpFile, KDB_O_POP); clearStorage (plugin, tmpFile); test_ksLookupByName (plugin, tmpFile, 0); clearStorage (plugin, tmpFile); test_ksLookupByName (plugin, tmpFile, KDB_O_POP); // Key API tests clearStorage (plugin, tmpFile); test_keyFlags (plugin, tmpFile); clearStorage (plugin, tmpFile); test_keyDup (plugin, tmpFile); clearStorage (plugin, tmpFile); test_keyCopy_newKey (plugin, tmpFile); clearStorage (plugin, tmpFile); test_keyCopy_clearOverwriteKey (plugin, tmpFile); clearStorage (plugin, tmpFile); test_keyDel (plugin, tmpFile); clearStorage (plugin, tmpFile); test_keyClear (plugin, tmpFile); // Key Name API tests clearStorage (plugin, tmpFile); test_keyName (plugin, tmpFile); clearStorage (plugin, tmpFile); test_keySetName (plugin, tmpFile); clearStorage (plugin, tmpFile); test_keyGetFullName (plugin, tmpFile); clearStorage (plugin, tmpFile); test_keyGetBaseName (plugin, tmpFile); // Key Value API tests clearStorage (plugin, tmpFile); test_keyValue (plugin, tmpFile); clearStorage (plugin, tmpFile); test_keyString (plugin, tmpFile); clearStorage (plugin, tmpFile); test_keyGetBinary (plugin, tmpFile); clearStorage (plugin, tmpFile); test_keyGetString (plugin, tmpFile); clearStorage (plugin, tmpFile); test_keySetBinary (plugin, tmpFile); clearStorage (plugin, tmpFile); test_keySetString (plugin, tmpFile); } printf ("\ntest_storage RESULTS: %d test(s) done. %d error(s).\n", nbTest, nbError); return nbError; }