LCOV - code coverage report
Current view: top level - src/plugins/rename - testmod_rename.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 285 285 100.0 %
Date: 2019-09-12 12:28:41 Functions: 19 19 100.0 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief A plugin for renaming
       5             :  *
       6             :  * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
       7             :  *
       8             :  */
       9             : 
      10             : #ifdef HAVE_KDBCONFIG_H
      11             : #include "kdbconfig.h"
      12             : #endif
      13             : 
      14             : /* used for asprintf */
      15             : #define _GNU_SOURCE
      16             : 
      17             : #ifdef HAVE_STDLIB_H
      18             : #include <stdlib.h>
      19             : #endif
      20             : #ifdef HAVE_STRING_H
      21             : #include <string.h>
      22             : #endif
      23             : 
      24             : #include "rename.h"
      25             : #include <tests_plugin.h>
      26             : 
      27             : 
      28          14 : static KeySet * createSimpleTestKeys (void)
      29             : {
      30          14 :         return ksNew (20, keyNew ("user/tests/rename/will/be/stripped/key1", KEY_VALUE, "value1", KEY_END),
      31             :                       keyNew ("user/tests/rename/will/be/stripped/key2", KEY_VALUE, "value2", KEY_END),
      32             :                       keyNew ("user/tests/rename/will/be/stripped", KEY_VALUE, "value3", KEY_END),
      33             :                       keyNew ("user/tests/rename/will/not/be/stripped/key4", KEY_VALUE, "value4", KEY_END), KS_END);
      34             : }
      35             : 
      36           4 : static KeySet * createSimpleMetaTestKeys (void)
      37             : {
      38             :         // clang-format off
      39           4 :         return ksNew (20,
      40             :                         keyNew("user/tests/rename/will/be/stripped/key1",
      41             :                                         KEY_VALUE, "value1",
      42             :                                         KEY_META, "rename/cut", "will/be/stripped",
      43             :                                         KEY_END),
      44             :                         keyNew("user/tests/rename/will/be/stripped/key2",
      45             :                                         KEY_VALUE, "value2",
      46             :                                         KEY_META, "rename/cut", "will/be/stripped",
      47             :                                         KEY_END),
      48             :                         keyNew("user/tests/rename/will/be/stripped",
      49             :                                         KEY_VALUE, "value3",
      50             :                                         KEY_END),
      51             :                         keyNew("user/tests/rename/will/not/be/stripped/key4",
      52             :                                         KEY_VALUE, "value4",
      53             :                                         KEY_END),
      54             :                         KS_END);
      55             :         // clang-format on
      56             : }
      57             : 
      58           4 : static void checkSimpleTestKeys (KeySet * ks)
      59             : {
      60             :         /* the first two keys should have been renamed */
      61           4 :         Key * key = ksLookupByName (ks, "user/tests/rename/key1", KDB_O_NONE);
      62           4 :         succeed_if (key, "key1 was not correctly renamed");
      63           4 :         key = ksLookupByName (ks, "user/tests/rename/key2", KDB_O_NONE);
      64           4 :         succeed_if (key, "key2 was not correctly renamed");
      65             :         /* the fourth key was not renamed because the prefix did not match */
      66           4 :         key = ksLookupByName (ks, "user/tests/rename/will/not/be/stripped/key4", KDB_O_NONE);
      67           4 :         succeed_if (key, "key4 was renamed although its prefix did not match");
      68           4 : }
      69             : 
      70           4 : static void compareKeySets (KeySet * ks, KeySet * expected)
      71             : {
      72           4 :         succeed_if (ksGetSize (expected) == ksGetSize (ks), "KeySet on set does not contain the same amount of keys");
      73             :         Key * current;
      74           4 :         ksRewind (expected);
      75          28 :         while ((current = ksNext (expected)))
      76             :         {
      77          20 :                 Key * key = ksLookup (ks, current, KDB_O_NONE);
      78          20 :                 succeed_if (key, "Expected key was not found in KeySet");
      79          20 :                 succeed_if (!strcmp (keyString (key), keyString (current)), "Value of key was modified");
      80             :         }
      81           4 : }
      82             : 
      83           2 : static void test_simpleCutOnGet (void)
      84             : {
      85           2 :         Key * parentKey = keyNew ("user/tests/rename", KEY_END);
      86           2 :         KeySet * conf = ksNew (20, keyNew ("system/cut", KEY_VALUE, "will/be/stripped", KEY_END), KS_END);
      87           2 :         PLUGIN_OPEN ("rename");
      88             : 
      89           2 :         KeySet * ks = createSimpleTestKeys ();
      90           2 :         ksAppendKey (ks, parentKey);
      91             : 
      92           2 :         succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
      93           2 :         succeed_if (output_error (parentKey), "error in kdbGet");
      94           2 :         succeed_if (output_warnings (parentKey), "warnings in kdbGet");
      95             : 
      96             : 
      97           2 :         checkSimpleTestKeys (ks);
      98           2 :         ksDel (ks);
      99             : 
     100             :         /*
     101             :          * this has to be done because the parentKey is not
     102             :          * part of ks anymore due to renaming
     103             :          */
     104           2 :         keyDel (parentKey);
     105           2 :         PLUGIN_CLOSE ();
     106           2 : }
     107             : 
     108             : 
     109           2 : static void test_metaCutOnGet (void)
     110             : {
     111           2 :         Key * parentKey = keyNew ("user/tests/rename", KEY_END);
     112           2 :         KeySet * conf = ksNew (0, KS_END);
     113           2 :         PLUGIN_OPEN ("rename");
     114             : 
     115           2 :         KeySet * ks = createSimpleMetaTestKeys ();
     116           2 :         ksAppendKey (ks, parentKey);
     117             : 
     118           2 :         succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
     119           2 :         succeed_if (output_error (parentKey), "error in kdbGet");
     120           2 :         succeed_if (output_warnings (parentKey), "warnings in kdbGet");
     121             : 
     122           2 :         checkSimpleTestKeys (ks);
     123             : 
     124           2 :         keyDel (parentKey);
     125           2 :         ksDel (ks);
     126           2 :         PLUGIN_CLOSE ();
     127           2 : }
     128             : 
     129           2 : static void test_simpleCutRestoreOnSet (void)
     130             : {
     131           2 :         Key * parentKey = keyNew ("user/tests/rename", KEY_END);
     132           2 :         Key * parentKeyCopy = keyDup (parentKey);
     133           2 :         KeySet * conf = ksNew (20, keyNew ("system/cut", KEY_VALUE, "will/be/stripped", KEY_END), KS_END);
     134           2 :         PLUGIN_OPEN ("rename");
     135             : 
     136           2 :         KeySet * ks = createSimpleTestKeys ();
     137           2 :         ksAppendKey (ks, parentKey);
     138             : 
     139           2 :         succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
     140           2 :         succeed_if (output_error (parentKey), "error in kdbGet");
     141           2 :         succeed_if (output_warnings (parentKey), "warnings in kdbGet");
     142             : 
     143           2 :         succeed_if (plugin->kdbSet (plugin, ks, parentKey) >= 1, "call to kdbSet was not successful");
     144           2 :         succeed_if (output_error (parentKey), "error in kdbSet");
     145           2 :         succeed_if (output_warnings (parentKey), "warnings in kdbSet");
     146             : 
     147             :         /* test that the keys have been correctly restored */
     148           2 :         KeySet * expected = createSimpleTestKeys ();
     149             : 
     150             :         /* the parent key is restored from user/tests/rename/will/be/stripped
     151             :          * and therefore will have its key value
     152             :          */
     153           2 :         keySetString (parentKeyCopy, "value3");
     154           2 :         ksAppendKey (expected, parentKeyCopy);
     155             : 
     156           2 :         compareKeySets (ks, expected);
     157           2 :         ksDel (expected);
     158           2 :         ksDel (ks);
     159             : 
     160             :         /*
     161             :          * this has to be done because the parentKey is not
     162             :          * part of ks anymore due to renaming
     163             :          */
     164           2 :         keyDel (parentKey);
     165           2 :         PLUGIN_CLOSE ();
     166           2 : }
     167             : 
     168           2 : static void test_withoutConfig (void)
     169             : {
     170           2 :         Key * parentKey = keyNew ("user/tests/rename", KEY_END);
     171           2 :         Key * parentKeyCopy = keyDup (parentKey);
     172           2 :         KeySet * conf = ksNew (0, KS_END);
     173           2 :         PLUGIN_OPEN ("rename");
     174             : 
     175           2 :         KeySet * ks = createSimpleTestKeys ();
     176           2 :         ksAppendKey (ks, parentKey);
     177             : 
     178           2 :         succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
     179           2 :         succeed_if (output_error (parentKey), "error in kdbGet");
     180           2 :         succeed_if (output_warnings (parentKey), "warnings in kdbGet");
     181             : 
     182           2 :         KeySet * expected = createSimpleTestKeys ();
     183           2 :         ksAppendKey (expected, parentKeyCopy);
     184             : 
     185           2 :         compareKeySets (ks, expected);
     186           2 :         keyDel (parentKey);
     187           2 :         keyDel (parentKeyCopy);
     188           2 :         ksDel (expected);
     189           2 :         ksDel (ks);
     190           2 :         PLUGIN_CLOSE ();
     191           2 : }
     192             : 
     193           2 : static void test_metaConfigTakesPrecedence (void)
     194             : {
     195           2 :         Key * parentKey = keyNew ("user/tests/rename", KEY_END);
     196           2 :         KeySet * conf = ksNew (20, keyNew ("system/cut", KEY_VALUE, "will/be", KEY_END), KS_END);
     197           2 :         PLUGIN_OPEN ("rename");
     198             : 
     199           2 :         KeySet * ks = createSimpleMetaTestKeys ();
     200           2 :         ksAppendKey (ks, parentKey);
     201             : 
     202           2 :         succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
     203           2 :         succeed_if (output_error (parentKey), "error in kdbGet");
     204           2 :         succeed_if (output_warnings (parentKey), "warnings in kdbGet");
     205             : 
     206             :         /* the first two keys should have been renamed by their metadata */
     207           2 :         Key * key = ksLookupByName (ks, "user/tests/rename/key1", KDB_O_NONE);
     208           2 :         succeed_if (key, "key1 was not correctly renamed");
     209           2 :         key = ksLookupByName (ks, "user/tests/rename/key2", KDB_O_NONE);
     210           2 :         succeed_if (key, "key2 was not correctly renamed");
     211             : 
     212             :         /* the third key should have been renamed by the global config */
     213           2 :         key = ksLookupByName (ks, "user/tests/rename/stripped", KDB_O_NONE);
     214           2 :         succeed_if (key, "key3 was renamed but would replace the parent key");
     215             : 
     216             :         /* the fourth key was not renamed because the prefix did not match */
     217           2 :         key = ksLookupByName (ks, "user/tests/rename/will/not/be/stripped/key4", KDB_O_NONE);
     218           2 :         succeed_if (key, "key4 was renamed although its prefix did not match");
     219             : 
     220           2 :         keyDel (parentKey);
     221           2 :         ksDel (ks);
     222           2 :         PLUGIN_CLOSE ();
     223           2 : }
     224             : 
     225           2 : static void test_keyCutNamePart (void)
     226             : {
     227           2 :         Key * parentKey = keyNew ("user/tests/rename", KEY_END);
     228           2 :         Key * result = elektraKeyCreateNewName (parentKey, parentKey, "wont/cut/this", NULL, NULL, NULL, 0);
     229           2 :         succeed_if (!result, "parentKey was modified although it should have been ignored");
     230             : 
     231             :         /* cutting works correctly without trailing slash */
     232           2 :         Key * testKey = keyNew ("user/tests/rename/will/cut/this/key1", KEY_END);
     233           2 :         result = elektraKeyCreateNewName (testKey, parentKey, "will/cut/this", NULL, NULL, NULL, 0);
     234           2 :         succeed_if (result, "key1 was not cut")
     235           2 :                 succeed_if (!strcmp (keyName (result), "user/tests/rename/key1"), "cutting key1 did not yield the expected result");
     236           2 :         keyDel (testKey);
     237           2 :         keyDel (result);
     238             : 
     239             :         /* cutting works correctly with trailing slash */
     240           2 :         testKey = keyNew ("user/tests/rename/will/cut/this/key1", KEY_END);
     241           2 :         result = elektraKeyCreateNewName (testKey, parentKey, "will/cut/this/", NULL, NULL, NULL, 0);
     242           2 :         succeed_if (result, "key1 was not cut")
     243           2 :                 succeed_if (!strcmp (keyName (result), "user/tests/rename/key1"), "cutting key1 did not yield the expected result");
     244           2 :         keyDel (testKey);
     245           2 :         keyDel (result);
     246             : 
     247             :         /* disallow leading slashes */
     248           2 :         testKey = keyNew ("user/tests/rename/wont/cut/this/key1", KEY_END);
     249           2 :         result = elektraKeyCreateNewName (testKey, parentKey, "/wont/cut/this", NULL, NULL, NULL, 0);
     250           2 :         succeed_if (!result, "key was cut although it the cutpath contained a leading slash");
     251           2 :         keyDel (testKey);
     252           2 :         keyDel (parentKey);
     253           2 : }
     254             : 
     255           2 : static void test_rebaseOfNewKeys (void)
     256             : {
     257           2 :         Key * parentKey = keyNew ("user/tests/rename", KEY_END);
     258           2 :         KeySet * conf = ksNew (20, keyNew ("system/cut", KEY_VALUE, "new/base", KEY_END), KS_END);
     259           2 :         PLUGIN_OPEN ("rename");
     260             : 
     261             :         // clang-format off
     262           2 :         KeySet *ks = ksNew(20,
     263             :                         /* this key was seen by rename before and wont be changed */
     264             :                         keyNew("user/tests/rename/key1",
     265             :                                         KEY_VALUE, "value1",
     266             :                                         KEY_META, ELEKTRA_ORIGINAL_NAME_META, "user/tests/rename/key1",
     267             :                                         KEY_END),
     268             :                         /* this key was not seen by rename before and will be renamed */
     269             :                         keyNew("user/tests/rename/key2",
     270             :                                         KEY_VALUE, "value2",
     271             :                                         KEY_END),
     272             :                         KS_END);
     273             :         // clang-format on
     274             : 
     275           2 :         succeed_if (plugin->kdbSet (plugin, ks, parentKey) >= 1, "call to kdbSet was not successful");
     276           2 :         succeed_if (output_error (parentKey), "error in kdbSet");
     277           2 :         succeed_if (output_warnings (parentKey), "warnings in kdbSet");
     278             : 
     279           2 :         Key * key = ksLookupByName (ks, "user/tests/rename/key1", KDB_O_NONE);
     280           2 :         succeed_if (key, "key1 was not found anymore, but it should not have been renamed");
     281             : 
     282           2 :         key = ksLookupByName (ks, "user/tests/rename/new/base/key2", KDB_O_NONE);
     283           2 :         succeed_if (key, "key2 was not correctly renamed");
     284             : 
     285           2 :         keyDel (parentKey);
     286           2 :         ksDel (ks);
     287           2 :         PLUGIN_CLOSE ();
     288           2 : }
     289             : 
     290           2 : static void test_addNewBaseToParentKey (void)
     291             : {
     292           2 :         Key * parentKey = keyNew ("user/tests/rename", KEY_END);
     293           2 :         KeySet * conf = ksNew (20, keyNew ("system/cut", KEY_VALUE, "new/base", KEY_END), KS_END);
     294             : 
     295           2 :         PLUGIN_OPEN ("rename");
     296             : 
     297           2 :         KeySet * ks = ksNew (0, KS_END);
     298           2 :         keyIncRef (parentKey);
     299           2 :         ksAppendKey (ks, parentKey);
     300             : 
     301           2 :         succeed_if (plugin->kdbSet (plugin, ks, parentKey) >= 1, "call to kdbSet was not successful");
     302           2 :         succeed_if (output_error (parentKey), "error in kdbSet");
     303           2 :         succeed_if (output_warnings (parentKey), "warnings in kdbSet");
     304             : 
     305           2 :         Key * key = ksLookupByName (ks, "user/tests/rename/new/base", 0);
     306           2 :         succeed_if (key, "new base was not correctly appended to parent key");
     307             : 
     308           2 :         ksDel (ks);
     309           2 :         keyDecRef (parentKey);
     310           2 :         keyDel (parentKey);
     311           2 :         PLUGIN_CLOSE ();
     312           2 : }
     313             : 
     314           2 : static void test_replaceString (void)
     315             : {
     316           2 :         Key * parentKey = keyNew ("user/tests/rename", KEY_END);
     317           2 :         KeySet * conf = ksNew (20, keyNew ("system/cut", KEY_VALUE, "will/be/stripped", KEY_END),
     318             :                                keyNew ("system/replacewith", KEY_VALUE, "stripped/it/is", KEY_END), KS_END);
     319             : 
     320           2 :         KeySet * ks = createSimpleTestKeys ();
     321           2 :         ksAppendKey (ks, parentKey);
     322             : 
     323           2 :         PLUGIN_OPEN ("rename");
     324             : 
     325           2 :         succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
     326           2 :         Key * key = ksLookupByName (ks, "user/tests/rename/stripped/it/is/key1", KDB_O_NONE);
     327           2 :         succeed_if (key, "key1 was not correctly rename");
     328           2 :         key = ksLookupByName (ks, "user/tests/rename/stripped/it/is/key2", KDB_O_NONE);
     329           2 :         succeed_if (key, "key2 was not correctly rename");
     330           2 :         key = ksLookupByName (ks, "user/tests/rename/will/not/be/stripped/key4", KDB_O_NONE);
     331           2 :         succeed_if (key, "key4 was not correctly rename");
     332             : 
     333           2 :         keyDel (parentKey);
     334           2 :         ksDel (ks);
     335           2 :         PLUGIN_CLOSE ();
     336           2 : }
     337             : 
     338           2 : static void test_toUpper (void)
     339             : {
     340           2 :         Key * parentKey = keyNew ("user/tests/rename", KEY_END);
     341           2 :         KeySet * conf = ksNew (20, keyNew ("system/toupper", KEY_VALUE, "0", KEY_END), KS_END);
     342           2 :         KeySet * ks = createSimpleTestKeys ();
     343           2 :         ksAppendKey (ks, parentKey);
     344           2 :         PLUGIN_OPEN ("rename");
     345           2 :         succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
     346           2 :         Key * key = ksLookupByName (ks, "user/tests/rename/WILL/BE/STRIPPED/KEY1", KDB_O_NONE);
     347           2 :         succeed_if (key, "key1 was not correctly rename");
     348           2 :         key = ksLookupByName (ks, "user/tests/rename/WILL/BE/STRIPPED/KEY2", KDB_O_NONE);
     349           2 :         succeed_if (key, "key2 was not correctly rename");
     350           2 :         key = ksLookupByName (ks, "user/tests/rename/WILL/NOT/BE/STRIPPED/KEY4", KDB_O_NONE);
     351           2 :         succeed_if (key, "key4 was not correctly rename");
     352             : 
     353           2 :         keyDel (parentKey);
     354           2 :         ksDel (ks);
     355           2 :         PLUGIN_CLOSE ();
     356           2 : }
     357             : 
     358           2 : static void test_toLower (void)
     359             : {
     360           2 :         Key * parentKey = keyNew ("user/tests/rename", KEY_END);
     361           2 :         KeySet * conf = ksNew (20, keyNew ("system/tolower", KEY_VALUE, "0", KEY_END), KS_END);
     362           2 :         KeySet * ks = ksNew (20, keyNew ("user/tests/rename/AM/I/LOWERCASE", KEY_VALUE, "val1", KEY_END),
     363             :                              keyNew ("user/tests/rename/I/HOPE/IM/LOWERCASE/TOO", KEY_VALUE, "val2", KEY_END), KS_END);
     364           2 :         ksAppendKey (ks, parentKey);
     365           2 :         PLUGIN_OPEN ("rename");
     366           2 :         succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
     367           2 :         Key * key = ksLookupByName (ks, "user/tests/rename/am/i/lowercase", KDB_O_NONE);
     368           2 :         succeed_if (key, "key1 was not correctly rename");
     369           2 :         key = ksLookupByName (ks, "user/tests/rename/i/hope/im/lowercase/too", KDB_O_NONE);
     370           2 :         succeed_if (key, "key2 was not correctly rename");
     371             : 
     372           2 :         keyDel (parentKey);
     373           2 :         ksDel (ks);
     374           2 :         PLUGIN_CLOSE ();
     375           2 : }
     376             : 
     377           2 : static void test_mixCase (void)
     378             : {
     379           2 :         Key * parentKey = keyNew ("user/tests/rename", KEY_END);
     380           2 :         KeySet * conf =
     381           2 :                 ksNew (20, keyNew ("system/tolower", KEY_VALUE, "1", KEY_END), keyNew ("system/toupper", KEY_VALUE, "4", KEY_END), KS_END);
     382           2 :         KeySet * ks =
     383           2 :                 ksNew (20, keyNew ("user/tests/rename/am/i/LOWERCASE", KEY_VALUE, "val1", KEY_END),
     384             :                        keyNew ("user/tests/rename/hopefullystilllower/upper/upper/upper/LOWERCASE", KEY_VALUE, "val2", KEY_END), KS_END);
     385           2 :         ksAppendKey (ks, parentKey);
     386           2 :         PLUGIN_OPEN ("rename");
     387           2 :         succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
     388           2 :         Key * key = ksLookupByName (ks, "user/tests/rename/AM/I/lowercase", KDB_O_NONE);
     389           2 :         succeed_if (key, "key1 was not correctly rename");
     390           2 :         key = ksLookupByName (ks, "user/tests/rename/hopefullystilllower/UPPER/UPPER/UPPER/lowercase", KDB_O_NONE);
     391           2 :         succeed_if (key, "key2 was not correctly rename");
     392             : 
     393           2 :         keyDel (parentKey);
     394           2 :         ksDel (ks);
     395           2 :         PLUGIN_CLOSE ();
     396           2 : }
     397             : 
     398           2 : static void test_write (void)
     399             : {
     400           2 :         Key * parentKey = keyNew ("user/tests/rename", KEY_END);
     401           2 :         KeySet * conf =
     402           2 :                 ksNew (20, keyNew ("system/tolower", KEY_VALUE, "1", KEY_END), keyNew ("system/get/case", KEY_VALUE, "toupper", KEY_END),
     403             :                        keyNew ("system/set/case", KEY_VALUE, "keyname", KEY_END), KS_END);
     404           2 :         KeySet * ks = ksNew (20, keyNew ("user/tests/rename/uppercase/uppercase/uppercase/LOWERCASE", KEY_VALUE, "test", KEY_END), KS_END);
     405           2 :         ksAppendKey (ks, parentKey);
     406           2 :         PLUGIN_OPEN ("rename");
     407           2 :         succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
     408           2 :         Key * key = ksLookupByName (ks, "user/tests/rename/UPPERCASE/UPPERCASE/UPPERCASE/lowercase", KDB_O_NONE);
     409           2 :         succeed_if (key, "key1 was not correctly rename");
     410           2 :         succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "call to kdbSet was not successful");
     411           2 :         key = ksLookupByName (ks, "user/tests/rename/UPPERCASE/UPPERCASE/UPPERCASE/lowercase", KDB_O_NONE);
     412           2 :         succeed_if (key, "key1s name was not correctly saved");
     413           2 :         keyDel (parentKey);
     414           2 :         ksDel (ks);
     415           2 :         PLUGIN_CLOSE ();
     416           2 : }
     417             : 
     418           2 : static void test_write2 (void)
     419             : {
     420           2 :         Key * parentKey = keyNew ("user/tests/rename", KEY_END);
     421           2 :         KeySet * conf =
     422           2 :                 ksNew (20, keyNew ("system/tolower", KEY_VALUE, "1", KEY_END), keyNew ("system/get/case", KEY_VALUE, "tolower", KEY_END),
     423             :                        keyNew ("system/set/case", KEY_VALUE, "toupper", KEY_END), KS_END);
     424           2 :         KeySet * ks = ksNew (20, keyNew ("user/tests/rename/UPPERCASE/UPPERCASE/UPPERCASE/LOWERCASE", KEY_VALUE, "test", KEY_END), KS_END);
     425           2 :         ksAppendKey (ks, parentKey);
     426           2 :         PLUGIN_OPEN ("rename");
     427           2 :         succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
     428           2 :         Key * key = ksLookupByName (ks, "user/tests/rename/uppercase/uppercase/uppercase/lowercase", KDB_O_NONE);
     429           2 :         succeed_if (key, "key1 was not correctly rename");
     430           2 :         succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "call to kdbSet was not successful");
     431           2 :         key = ksLookupByName (ks, "user/tests/rename/UPPERCASE/UPPERCASE/UPPERCASE/LOWERCASE", KDB_O_NONE);
     432           2 :         succeed_if (key, "key1s name was not correctly saved");
     433           2 :         keyDel (parentKey);
     434           2 :         ksDel (ks);
     435           2 :         PLUGIN_CLOSE ();
     436           2 : }
     437           2 : int main (int argc, char ** argv)
     438             : {
     439           2 :         printf ("RENAME       TESTS\n");
     440           2 :         printf ("==================\n\n");
     441             : 
     442           2 :         init (argc, argv);
     443             : 
     444           2 :         test_withoutConfig ();
     445           2 :         test_simpleCutOnGet ();
     446           2 :         test_simpleCutRestoreOnSet ();
     447           2 :         test_metaCutOnGet ();
     448           2 :         test_metaConfigTakesPrecedence ();
     449           2 :         test_rebaseOfNewKeys ();
     450           2 :         test_addNewBaseToParentKey ();
     451             : 
     452           2 :         test_keyCutNamePart ();
     453           2 :         test_toUpper ();
     454           2 :         test_toLower ();
     455           2 :         test_mixCase ();
     456           2 :         test_replaceString ();
     457           2 :         test_write ();
     458           2 :         test_write2 ();
     459           2 :         print_result ("test_rename");
     460             : 
     461           2 :         return nbError;
     462             : }

Generated by: LCOV version 1.13