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 (); }
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_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 (); }
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 () ; }
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_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 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_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_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 (); }
/**Compare two files line by line. * * Fails when there are any differences. * * The original file is passed as parameter. * It will be compared with the file -gen. * * file.xml -> file-gen.xml (xml comparator) * file.txt -> file-gen.txt (line comparator) * file.c -> file-gen.c (c comparator) * */ int compare_files (const char * filename) { char genfilename [KDB_MAX_PATH_LENGTH]; char * dot = strrchr (filename, '.'); exit_if_fail (dot != 0, "could not find extension in file"); strncpy (genfilename, filename, dot- filename); /* does not terminate string, but strcat need it, so: */ genfilename[dot-filename] = 0; strcat (genfilename, "-gen"); if (!strcmp (dot, ".xml")) { strcat (genfilename, ".xml"); } else if (!strcmp (dot, ".txt")) { strcat (genfilename, ".txt"); } else if (!strcmp (dot, ".c")) { strcat (genfilename, ".c"); } return compare_line_files (filename, genfilename); }