LCOV - code coverage report
Current view: top level - tests/ctest - test_splitget.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 559 559 100.0 %
Date: 2019-09-12 12:28:41 Functions: 14 14 100.0 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief
       5             :  *
       6             :  * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
       7             :  */
       8             : 
       9             : #include <../../src/libs/elektra/backend.c>
      10             : #include <../../src/libs/elektra/mount.c>
      11             : #include <../../src/libs/elektra/split.c>
      12             : #include <../../src/libs/elektra/trie.c>
      13             : #include <tests_internal.h>
      14             : 
      15          16 : KeySet * modules_config (void)
      16             : {
      17          16 :         return ksNew (5, keyNew ("system/elektra/modules", KEY_END), KS_END);
      18             : }
      19             : 
      20           8 : KeySet * simple_config (void)
      21             : {
      22           8 :         return ksNew (5, keyNew ("system/elektra/mountpoints", KEY_END), keyNew ("system/elektra/mountpoints/root", KEY_END),
      23             :                       keyNew ("system/elektra/mountpoints/root/mountpoint", KEY_VALUE, "/", KEY_END),
      24             :                       keyNew ("system/elektra/mountpoints/simple", KEY_END),
      25             :                       keyNew ("system/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "user/tests/simple", KEY_END), KS_END);
      26             : }
      27             : 
      28           2 : KeySet * simple_cascading (void)
      29             : {
      30           2 :         return ksNew (5, keyNew ("system/elektra/mountpoints", KEY_END), keyNew ("system/elektra/mountpoints/root", KEY_END),
      31             :                       keyNew ("system/elektra/mountpoints/root/mountpoint", KEY_VALUE, "/", KEY_END),
      32             :                       keyNew ("system/elektra/mountpoints/simple", KEY_END),
      33             :                       keyNew ("system/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "/cascading/simple", KEY_END), KS_END);
      34             : }
      35             : 
      36             : 
      37           2 : KeySet * set_realworld (void)
      38             : {
      39           2 :         return ksNew (50, keyNew ("system/elektra/mountpoints", KEY_END), keyNew ("system/elektra/mountpoints/root", KEY_END),
      40             :                       keyNew ("system/elektra/mountpoints/root/mountpoint", KEY_VALUE, "/", KEY_END),
      41             :                       keyNew ("system/elektra/mountpoints/users", KEY_END),
      42             :                       keyNew ("system/elektra/mountpoints/users/mountpoint", KEY_VALUE, "system/users", KEY_END),
      43             :                       keyNew ("system/elektra/mountpoints/groups", KEY_END),
      44             :                       keyNew ("system/elektra/mountpoints/groups/mountpoint", KEY_VALUE, "system/groups", KEY_END),
      45             :                       keyNew ("system/elektra/mountpoints/hosts", KEY_END),
      46             :                       keyNew ("system/elektra/mountpoints/hosts/mountpoint", KEY_VALUE, "system/hosts", KEY_END),
      47             :                       keyNew ("system/elektra/mountpoints/kde", KEY_END),
      48             :                       keyNew ("system/elektra/mountpoints/kde/mountpoint", KEY_VALUE, "user/sw/kde/default", KEY_END),
      49             :                       keyNew ("system/elektra/mountpoints/app1", KEY_END),
      50             :                       keyNew ("system/elektra/mountpoints/app1/mountpoint", KEY_VALUE, "user/sw/apps/app1/default", KEY_END),
      51             :                       keyNew ("system/elektra/mountpoints/app2", KEY_END),
      52             :                       keyNew ("system/elektra/mountpoints/app2/mountpoint", KEY_VALUE, "user/sw/apps/app2", KEY_END), KS_END);
      53             : }
      54             : 
      55             : 
      56           2 : static void test_simple (void)
      57             : {
      58           2 :         printf ("Test simple trie\n");
      59             : 
      60           2 :         KDB * handle = elektraCalloc (sizeof (struct _KDB));
      61           2 :         KeySet * modules = modules_config ();
      62             :         Backend * backend;
      63             : 
      64           2 :         handle->split = splitNew ();
      65           2 :         handle->defaultBackend = elektraCalloc (sizeof (struct _Backend));
      66           2 :         mountOpen (handle, simple_config (), modules, 0);
      67             : 
      68           2 :         KeySet * ks = ksNew (15, keyNew ("user/testkey1/below/here", KEY_END), keyNew ("user/testkey/below1/here", KEY_END),
      69             :                              keyNew ("user/testkey/below2/here", KEY_END), keyNew ("user/tests/simple/testkey/b1/b2/down", KEY_END),
      70             :                              keyNew ("user/tests/simple/testkey/b1/b2/up", KEY_END), KS_END);
      71             : 
      72             :         Split * split;
      73             :         Key * parentKey;
      74             :         Key * mp;
      75             : 
      76           2 :         split = splitNew ();
      77             : 
      78           2 :         parentKey = keyNew ("user/tests/simple/below", KEY_END);
      79           2 :         succeed_if (splitBuildup (split, handle, parentKey) == 1, "we add the default backend for user");
      80           2 :         succeed_if (split->size == 1, "user root + simple");
      81             : 
      82           2 :         succeed_if (split->handles[0]->specsize == -1, "spec size wrong");
      83           2 :         succeed_if (split->handles[0]->usersize == -1, "user size wrong");
      84           2 :         succeed_if (split->handles[0]->systemsize == -1, "system size wrong");
      85           2 :         succeed_if (split->handles[0]->dirsize == -1, "dir size wrong");
      86             : 
      87             :         // elektraGetCheckUpdateNeeded(split, parentKey)
      88             : 
      89           2 :         succeed_if (ksGetSize (split->keysets[0]) == 0, "wrong size");
      90             : 
      91           2 :         mp = keyNew ("user/tests/simple", KEY_VALUE, "simple", KEY_END);
      92           2 :         compare_key (split->parents[0], mp);
      93           2 :         succeed_if (split->handles[0] != handle->defaultBackend, "should be not the default backend");
      94           2 :         keyDel (mp);
      95             : 
      96           2 :         backend = trieLookup (handle->trie, parentKey);
      97           2 :         succeed_if (split->handles[0] == backend, "should be user backend");
      98             : 
      99           2 :         succeed_if (splitAppoint (split, handle, ks) == 1, "could not appoint keys");
     100           2 :         succeed_if (split->size == 2, "not correct size after appointing");
     101             : 
     102           2 :         succeed_if (split->handles[0] != -0, "no backend");
     103           2 :         if (split->handles[0] != -0)
     104             :         {
     105           2 :                 succeed_if (split->handles[0]->specsize == -1, "spec size wrong");
     106           2 :                 succeed_if (split->handles[0]->usersize == -1, "user size wrong");
     107           2 :                 succeed_if (split->handles[0]->systemsize == -1, "system size wrong");
     108           2 :                 succeed_if (split->handles[0]->dirsize == -1, "dir size wrong");
     109             :         }
     110             : 
     111           2 :         succeed_if (split->handles[1] == -0, "backend at bypass?");
     112             : 
     113           2 :         succeed_if (ksGetSize (split->keysets[0]) == 2, "wrong size");
     114           2 :         succeed_if (ksGetSize (split->keysets[1]) == 3, "wrong size");
     115           2 :         succeed_if (split->handles[0] == backend, "should be user backend");
     116           2 :         succeed_if (split->handles[1] == 0, "should be default backend");
     117             : 
     118           2 :         splitDel (split);
     119           2 :         keyDel (parentKey);
     120             : 
     121           2 :         ksDel (ks);
     122           2 :         splitDel (handle->split);
     123           2 :         trieClose (handle->trie, 0);
     124           2 :         elektraFree (handle->defaultBackend);
     125           2 :         elektraFree (handle);
     126           2 :         ksDel (modules);
     127           2 : }
     128             : 
     129             : 
     130           2 : static void test_cascading (void)
     131             : {
     132             :         // TODO: test not fully done
     133           2 :         printf ("Test simple cascading\n");
     134             : 
     135           2 :         KDB * handle = elektraCalloc (sizeof (struct _KDB));
     136           2 :         KeySet * modules = modules_config ();
     137             :         Backend * backend;
     138             : 
     139           2 :         handle->split = splitNew ();
     140           2 :         handle->defaultBackend = elektraCalloc (sizeof (struct _Backend));
     141           2 :         mountOpen (handle, simple_cascading (), modules, 0);
     142             : 
     143           2 :         KeySet * ks = ksNew (15, keyNew ("user/testkey1/below/here", KEY_END), keyNew ("user/testkey/below1/here", KEY_END),
     144             :                              keyNew ("user/testkey/below2/here", KEY_END), keyNew ("user/tests/simple/testkey/b1/b2/down", KEY_END),
     145             :                              keyNew ("user/tests/simple/testkey/b1/b2/up", KEY_END), KS_END);
     146             : 
     147             :         Split * split;
     148             :         Key * parentKey;
     149             :         Key * mp;
     150             : 
     151           2 :         split = splitNew ();
     152             : 
     153           2 :         parentKey = keyNew ("user/tests/simple/below", KEY_END);
     154           2 :         succeed_if (splitBuildup (split, handle, parentKey) == 1, "we add the default backend for user");
     155           2 :         succeed_if (split->size == 1, "user root + simple");
     156             : 
     157           2 :         succeed_if (split->handles[0]->specsize == -1, "spec size wrong");
     158           2 :         succeed_if (split->handles[0]->usersize == -1, "user size wrong");
     159           2 :         succeed_if (split->handles[0]->systemsize == -1, "system size wrong");
     160           2 :         succeed_if (split->handles[0]->dirsize == -1, "dir size wrong");
     161             : 
     162             :         // elektraGetCheckUpdateNeeded(split, parentKey)
     163             : 
     164           2 :         succeed_if (ksGetSize (split->keysets[0]) == 0, "wrong size");
     165             : 
     166           2 :         mp = keyNew ("user", KEY_VALUE, "root", KEY_END);
     167           2 :         compare_key (split->parents[0], mp);
     168           2 :         succeed_if (split->handles[0] != handle->defaultBackend, "should be not the default backend");
     169           2 :         keyDel (mp);
     170             : 
     171           2 :         backend = trieLookup (handle->trie, parentKey);
     172           2 :         succeed_if (split->handles[0] == backend, "should be user backend");
     173             : 
     174           2 :         keySetName (parentKey, "user/cascading/simple/below");
     175           2 :         /*backend = */ trieLookup (handle->trie, parentKey);
     176             :         // succeed_if (split->handles[1] == backend, "should be cascading backend");
     177             : 
     178           2 :         succeed_if (splitAppoint (split, handle, ks) == 1, "could not appoint keys");
     179           2 :         succeed_if (split->size == 2, "not correct size after appointing");
     180             : 
     181           2 :         succeed_if (split->handles[0] != -0, "no backend");
     182           2 :         if (split->handles[0] != -0)
     183             :         {
     184           2 :                 succeed_if (split->handles[0]->specsize == -1, "spec size wrong");
     185           2 :                 succeed_if (split->handles[0]->usersize == -1, "user size wrong");
     186           2 :                 succeed_if (split->handles[0]->systemsize == -1, "system size wrong");
     187           2 :                 succeed_if (split->handles[0]->dirsize == -1, "dir size wrong");
     188             :         }
     189             : 
     190           2 :         succeed_if (split->handles[1] == -0, "backend at bypass?");
     191             : 
     192             :         // output_split (split);
     193           2 :         succeed_if (ksGetSize (split->keysets[0]) == 5, "wrong size");
     194           2 :         succeed_if (ksGetSize (split->keysets[1]) == 0, "wrong size");
     195             :         // succeed_if (split->handles[0] == backend, "should be user backend");
     196           2 :         succeed_if (split->handles[1] == 0, "should be default backend");
     197             : 
     198           2 :         splitDel (split);
     199           2 :         keyDel (parentKey);
     200             : 
     201           2 :         ksDel (ks);
     202           2 :         splitDel (handle->split);
     203           2 :         trieClose (handle->trie, 0);
     204           2 :         elektraFree (handle->defaultBackend);
     205           2 :         elektraFree (handle);
     206           2 :         ksDel (modules);
     207           2 : }
     208             : 
     209             : 
     210           2 : static void test_get (void)
     211             : {
     212           2 :         printf ("Test basic get\n");
     213           2 :         KDB * handle = elektraCalloc (sizeof (struct _KDB));
     214           2 :         handle->split = splitNew ();
     215           2 :         KeySet * modules = modules_config ();
     216             :         /* So we had 2 keys before in the keyset */
     217             : 
     218           2 :         KeySet * ks = ksNew (15, keyNew ("user/testkey1/below/here", KEY_END), keyNew ("user/testkey/below1/here", KEY_END),
     219             :                              keyNew ("user/testkey/below2/here", KEY_END), KS_END);
     220             : 
     221           2 :         Split * split = splitNew ();
     222           2 :         Key * parentKey = keyNew ("user", KEY_VALUE, "default", KEY_END);
     223             : 
     224           2 :         succeed_if (mountDefault (handle, modules, 1, 0) == 0, "could not mount default backends");
     225           2 :         succeed_if (splitBuildup (split, handle, parentKey) == 1, "we add the default backend for user");
     226           2 :         succeed_if (output_error (parentKey), "error found");
     227           2 :         succeed_if (output_warnings (parentKey), "warning(s) found");
     228             : 
     229           2 :         succeed_if (split->size == 1, "size of split wrong");
     230           2 :         succeed_if (split->handles[0]->specsize == -1, "spec size wrong");
     231           2 :         succeed_if (split->handles[0]->usersize == -1, "user size wrong");
     232           2 :         succeed_if (split->handles[0]->systemsize == -1, "system size wrong");
     233           2 :         succeed_if (split->handles[0]->dirsize == -1, "dir size wrong");
     234             : 
     235           2 :         succeed_if (splitAppoint (split, handle, ks) == 1, "could not appoint keys to split");
     236             : 
     237           2 :         succeed_if (split->size == 2, "not correct size after appointing");
     238           2 :         succeed_if (split->handles[0] != -0, "no backend");
     239           2 :         if (split->handles[0] != -0)
     240             :         {
     241           2 :                 succeed_if (split->handles[0]->specsize == -1, "spec size wrong");
     242           2 :                 succeed_if (split->handles[0]->usersize == -1, "user size wrong");
     243           2 :                 succeed_if (split->handles[0]->systemsize == -1, "system size wrong");
     244           2 :                 succeed_if (split->handles[0]->dirsize == -1, "dir size wrong");
     245             :         }
     246           2 :         succeed_if (split->handles[1] == -0, "backend at bypass?");
     247             : 
     248           2 :         split->syncbits[0] = 3; /* Simulate a kdbGet() */
     249           2 :         succeed_if (splitGet (split, parentKey, handle) == 1, "could not postprocess get");
     250           2 :         succeed_if (output_error (parentKey), "error found");
     251           2 :         succeed_if (output_warnings (parentKey), "warning(s) found");
     252           2 :         succeed_if (split->size == 2, "not correct size after get");
     253           2 :         succeed_if (split->handles[0] != -0, "no backend");
     254           2 :         if (split->handles[0] != -0)
     255             :         {
     256           2 :                 succeed_if (split->handles[0]->specsize == -1, "spec size wrong");
     257           2 :                 succeed_if (split->handles[0]->usersize == 3, "user size wrong");
     258           2 :                 succeed_if (split->handles[0]->systemsize == -1, "system size wrong");
     259           2 :                 succeed_if (split->handles[0]->dirsize == -1, "dir size wrong");
     260             :         }
     261             : 
     262           2 :         succeed_if (split->size == 2, "there is an empty keset");
     263           2 :         succeed_if (ksGetSize (split->keysets[0]) == 3, "wrong size");
     264           2 :         succeed_if (keyNeedSync (split->keysets[0]->array[0]) == 0, "key should not need sync");
     265           2 :         succeed_if (keyNeedSync (split->keysets[0]->array[1]) == 0, "key should not need sync");
     266           2 :         succeed_if (keyNeedSync (split->keysets[0]->array[2]) == 0, "key should not need sync");
     267           2 :         compare_keyset (split->keysets[0], ks);
     268           2 :         succeed_if (ksGetSize (split->keysets[1]) == 0, "wrong size");
     269           2 :         compare_key (split->parents[0], parentKey);
     270           2 :         succeed_if (split->parents[1] == 0, "parentKey for default not correct");
     271           2 :         succeed_if (split->handles[0] == handle->defaultBackend, "not correct backend");
     272           2 :         succeed_if (split->syncbits[0] == 3, "should be marked as sync");
     273             : 
     274           2 :         splitDel (split);
     275           2 :         keyDel (parentKey);
     276             : 
     277             : 
     278           2 :         split = splitNew ();
     279           2 :         parentKey = keyNew ("system", KEY_VALUE, "default", KEY_END);
     280             : 
     281           2 :         succeed_if (splitBuildup (split, handle, parentKey) == 1, "system backend should be added");
     282           2 :         succeed_if (output_error (parentKey), "error found");
     283           2 :         succeed_if (output_warnings (parentKey), "warning(s) found");
     284             : 
     285           2 :         succeed_if (splitAppoint (split, handle, ks) == 1, "could not appoint keys to split");
     286           2 :         succeed_if (splitGet (split, parentKey, handle) == 1, "could not postprocess get");
     287           2 :         succeed_if (output_error (parentKey), "error found");
     288           2 :         succeed_if (output_warnings (parentKey), "warning(s) found");
     289             : 
     290           2 :         succeed_if (split->size == 2, "there is an empty keset");
     291           2 :         succeed_if (ksGetSize (split->keysets[0]) == 0, "wrong size");
     292           2 :         succeed_if (ksGetSize (split->keysets[1]) == 3, "keys with other domain should go to default keyset");
     293           2 :         compare_keyset (split->keysets[1], ks);
     294           2 :         compare_key (split->parents[0], parentKey);
     295           2 :         succeed_if (split->parents[1] == 0, "parentKey for default not correct");
     296           2 :         succeed_if (split->handles[0] == handle->defaultBackend, "not correct backend");
     297           2 :         succeed_if (split->syncbits[0] == 2, "should be marked as root");
     298             : 
     299             : 
     300           2 :         splitDel (split);
     301           2 :         keyDel (parentKey);
     302             : 
     303           2 :         ksDel (ks);
     304           2 :         kdbClose (handle, 0);
     305           2 :         ksDel (modules);
     306           2 : }
     307             : 
     308           2 : static void test_limit (void)
     309             : {
     310           2 :         printf ("Test limit\n");
     311           2 :         KDB * handle = elektraCalloc (sizeof (struct _KDB));
     312           2 :         handle->split = splitNew ();
     313             :         /* So we had 2 keys before in the keyset */
     314           2 :         KeySet * modules = modules_config ();
     315             : 
     316           2 :         KeySet * ks = ksNew (15, keyNew ("user/testkey1/below/here", KEY_END), keyNew ("user/testkey/below1/here", KEY_END),
     317             :                              keyNew ("user/testkey/below2/here", KEY_END), KS_END);
     318             : 
     319           2 :         Split * split = splitNew ();
     320           2 :         Key * parentKey = keyNew ("user", KEY_VALUE, "default", KEY_END);
     321             : 
     322           2 :         succeed_if (mountDefault (handle, modules, 1, 0) == 0, "could not mount default backends");
     323           2 :         succeed_if (splitBuildup (split, handle, parentKey) == 1, "we add the default backend for user");
     324           2 :         succeed_if (output_error (parentKey), "error found");
     325           2 :         succeed_if (output_warnings (parentKey), "warning(s) found");
     326             : 
     327           2 :         succeed_if (splitAppoint (split, handle, ks) == 1, "could not appoint keys to split");
     328           2 :         split->syncbits[0] = 3; /* Simulate a kdbGet() */
     329           2 :         ksAppendKey (split->keysets[0], keyNew ("system/wrong", KEY_END));
     330           2 :         succeed_if (splitGet (split, parentKey, handle) == 1, "could not postprocess get");
     331             : 
     332           2 :         succeed_if (split->size == 2, "there is an empty keset");
     333           2 :         succeed_if (ksGetSize (split->keysets[0]) == 3, "wrong size");
     334           2 :         succeed_if (keyNeedSync (split->keysets[0]->array[0]) == 0, "key should not need sync");
     335           2 :         succeed_if (keyNeedSync (split->keysets[0]->array[1]) == 0, "key should not need sync");
     336           2 :         succeed_if (keyNeedSync (split->keysets[0]->array[2]) == 0, "key should not need sync");
     337           2 :         compare_keyset (split->keysets[0], ks);
     338           2 :         succeed_if (ksGetSize (split->keysets[1]) == 0, "wrong size");
     339             : 
     340             :         // we know that system/wrong will produce a warning
     341           2 :         compare_key_name (split->parents[0], parentKey);
     342           2 :         succeed_if (split->parents[1] == 0, "parentKey for default not correct");
     343           2 :         succeed_if (split->handles[0] == handle->defaultBackend, "not correct backend");
     344           2 :         succeed_if (split->syncbits[0] == 3, "should be marked as root");
     345             : 
     346           2 :         splitDel (split);
     347           2 :         keyDel (parentKey);
     348             : 
     349             : 
     350           2 :         split = splitNew ();
     351           2 :         parentKey = keyNew ("system", KEY_VALUE, "default", KEY_END);
     352             : 
     353           2 :         succeed_if (splitBuildup (split, handle, parentKey) == 1, "system backend should be added");
     354           2 :         succeed_if (output_error (parentKey), "error found");
     355           2 :         succeed_if (output_warnings (parentKey), "warning(s) found");
     356             : 
     357           2 :         succeed_if (splitAppoint (split, handle, ks) == 1, "could not appoint keys to split");
     358           2 :         split->syncbits[1] = 1; /* Simulate a kdbGet() */
     359           2 :         ksAppendKey (split->keysets[1], keyNew ("user/wrong", KEY_END));
     360           2 :         succeed_if (splitGet (split, parentKey, handle) == 1, "could not postprocess get");
     361           2 :         succeed_if (output_error (parentKey), "error found");
     362           2 :         succeed_if (output_warnings (parentKey), "warning(s) found");
     363             : 
     364           2 :         succeed_if (split->size == 2, "there is an empty keset");
     365           2 :         succeed_if (ksGetSize (split->keysets[0]) == 0, "wrong size");
     366           2 :         succeed_if (ksGetSize (split->keysets[1]) == 4, "default should stay untouched");
     367           2 :         succeed_if (keyNeedSync (split->keysets[1]->array[0]) == 0, "key should not need sync");
     368           2 :         succeed_if (keyNeedSync (split->keysets[1]->array[1]) == 0, "key should not need sync");
     369           2 :         succeed_if (keyNeedSync (split->keysets[1]->array[2]) == 0, "key should not need sync");
     370           2 :         compare_key (split->parents[0], parentKey);
     371           2 :         succeed_if (split->parents[1] == 0, "parentKey for default not correct");
     372           2 :         succeed_if (split->handles[0] == handle->defaultBackend, "not correct backend");
     373           2 :         succeed_if (split->syncbits[0] == 2, "should be marked as root");
     374             : 
     375           2 :         splitDel (split);
     376           2 :         keyDel (parentKey);
     377             : 
     378             : 
     379           2 :         ksDel (ks);
     380           2 :         kdbClose (handle, 0);
     381           2 :         ksDel (modules);
     382           2 : }
     383             : 
     384             : 
     385           2 : static void test_nobackend (void)
     386             : {
     387           2 :         printf ("Test keys without backends in split\n");
     388             : 
     389           2 :         KDB * handle = elektraCalloc (sizeof (struct _KDB));
     390           2 :         handle->split = splitNew ();
     391           2 :         KeySet * modules = modules_config ();
     392             :         Backend * backend;
     393             : 
     394           2 :         mountOpen (handle, simple_config (), modules, 0);
     395             : 
     396           2 :         KeySet * ks = ksNew (15, keyNew ("user/testkey1/below/here", KEY_END), keyNew ("user/testkey/below1/here", KEY_END),
     397             :                              keyNew ("user/testkey/below2/here", KEY_END), keyNew ("user/tests/simple/testkey/b1/b2/down", KEY_END),
     398             :                              keyNew ("user/tests/simple/testkey/b1/b2/up", KEY_END), KS_END);
     399             : 
     400             :         Split * split;
     401             :         Key * parentKey;
     402             :         Key * mp;
     403             : 
     404           2 :         split = splitNew ();
     405             : 
     406           2 :         parentKey = keyNew ("user/tests/simple/below", KEY_END);
     407           2 :         mp = keyNew ("user/tests/simple", KEY_VALUE, "simple", KEY_END);
     408           2 :         succeed_if (splitBuildup (split, handle, parentKey) == 1, "we add the default backend for user");
     409           2 :         succeed_if (output_error (parentKey), "error found");
     410           2 :         succeed_if (output_warnings (parentKey), "warning(s) found");
     411             : 
     412           2 :         succeed_if (splitAppoint (split, handle, ks) == 1, "could not appoint keys");
     413           2 :         split->syncbits[0] = 1; /* Simulate a kdbGet() */
     414           2 :         ksAppendKey (split->keysets[0], keyNew ("system/wrong", KEY_END));
     415             : 
     416           2 :         succeed_if (splitGet (split, parentKey, handle) == 1, "could not postprocess get");
     417           2 :         succeed_if (output_error (parentKey), "error found");
     418             :         // there will be a warning
     419             :         // succeed_if (output_warnings(parentKey), "warning(s) found");
     420             : 
     421           2 :         succeed_if (split->size == 2, "not correct size after appointing");
     422           2 :         succeed_if (ksGetSize (split->keysets[0]) == 2, "wrong size");
     423           2 :         succeed_if (ksGetSize (split->keysets[1]) == 3, "wrong size");
     424           2 :         compare_key (split->parents[0], mp);
     425           2 :         backend = trieLookup (handle->trie, parentKey);
     426           2 :         succeed_if (split->handles[0] == backend, "should be user backend");
     427           2 :         succeed_if (split->handles[1] == 0, "should be default backend");
     428             : 
     429             : 
     430           2 :         splitDel (split);
     431           2 :         keyDel (parentKey);
     432           2 :         keyDel (mp);
     433             : 
     434             :         // output_trie(trie);
     435             : 
     436           2 :         ksDel (ks);
     437           2 :         kdbClose (handle, 0);
     438           2 :         ksDel (modules);
     439           2 : }
     440             : 
     441             : 
     442           2 : static void test_sizes (void)
     443             : {
     444           2 :         printf ("Test sizes\n");
     445           2 :         KDB * handle = elektraCalloc (sizeof (struct _KDB));
     446           2 :         handle->split = splitNew ();
     447           2 :         KeySet * modules = modules_config ();
     448             : 
     449           2 :         KeySet * ks = ksNew (15, keyNew ("user/testkey1/below/here", KEY_END), keyNew ("user/testkey/below1/here", KEY_END),
     450             :                              keyNew ("user/testkey/below2/here", KEY_END), KS_END);
     451             : 
     452             : 
     453           2 :         succeed_if (mountDefault (handle, modules, 1, 0) == 0, "could not mount default backends");
     454           2 :         succeed_if (handle->defaultBackend->specsize == -1, "specsize not initialized correct");
     455           2 :         succeed_if (handle->defaultBackend->dirsize == -1, "dirsize not initialized correct");
     456           2 :         succeed_if (handle->defaultBackend->usersize == -1, "usersize not initialized correct");
     457           2 :         succeed_if (handle->defaultBackend->systemsize == -1, "systemsize not initialized correct");
     458             : 
     459           2 :         Split * split = splitNew ();
     460           2 :         Key * parentKey = keyNew ("user", KEY_VALUE, "default", KEY_END);
     461             : 
     462           2 :         succeed_if (splitBuildup (split, handle, parentKey) == 1, "we add the default backend for user");
     463           2 :         succeed_if (output_error (parentKey), "error found");
     464           2 :         succeed_if (output_warnings (parentKey), "warning(s) found");
     465             : 
     466           2 :         succeed_if (splitAppoint (split, handle, ks) == 1, "could not appoint keys to split");
     467           2 :         split->syncbits[0] = 3; /* Simulate a kdbGet() */
     468           2 :         ksAppendKey (split->keysets[0], keyNew ("system/wrong", KEY_END));
     469           2 :         succeed_if (splitGet (split, parentKey, handle) == 1, "could not postprocess get");
     470           2 :         succeed_if (output_error (parentKey), "error found");
     471             :         // there will be a warning
     472             :         // succeed_if (output_warnings(parentKey), "warning(s) found");
     473           2 :         succeed_if_same_string (keyString (keyGetMeta (parentKey, "warnings/#00/number")), ELEKTRA_ERROR_INTERFACE) // drop key
     474             : 
     475           2 :                 succeed_if (handle->defaultBackend->usersize == 3, "usersize not updated by splitGet");
     476           2 :         succeed_if (handle->defaultBackend->specsize == -1, "specsize not initialized correct");
     477           2 :         succeed_if (handle->defaultBackend->dirsize == -1, "dirsize not initialized correct");
     478           2 :         succeed_if (handle->defaultBackend->systemsize == -1, "systemsize not initialized correct");
     479           2 :         succeed_if (split->size == 2, "there is an empty keset");
     480           2 :         succeed_if (ksGetSize (split->keysets[0]) == 3, "wrong size");
     481           2 :         succeed_if (keyNeedSync (split->keysets[0]->array[0]) == 0, "key should not need sync");
     482           2 :         succeed_if (keyNeedSync (split->keysets[0]->array[1]) == 0, "key should not need sync");
     483           2 :         succeed_if (keyNeedSync (split->keysets[0]->array[2]) == 0, "key should not need sync");
     484           2 :         compare_keyset (split->keysets[0], ks);
     485           2 :         succeed_if (ksGetSize (split->keysets[1]) == 0, "wrong size");
     486           2 :         compare_key_name (split->parents[0], parentKey);
     487           2 :         succeed_if (split->parents[1] == 0, "parentKey for default not correct");
     488           2 :         succeed_if (split->handles[0] == handle->defaultBackend, "not correct backend");
     489           2 :         succeed_if (split->syncbits[0] == 3, "should be marked as root");
     490             : 
     491           2 :         splitDel (split);
     492           2 :         keyDel (parentKey);
     493             : 
     494             : 
     495           2 :         split = splitNew ();
     496           2 :         parentKey = keyNew ("system", KEY_VALUE, "default", KEY_END);
     497             : 
     498           2 :         succeed_if (splitBuildup (split, handle, parentKey) == 1, "system backend should be added");
     499           2 :         succeed_if (output_error (parentKey), "error found");
     500           2 :         succeed_if (output_warnings (parentKey), "warning(s) found");
     501             : 
     502           2 :         succeed_if (splitAppoint (split, handle, ks) == 1, "could not appoint keys to split");
     503           2 :         split->syncbits[1] = 1; /* Simulate a kdbGet() */
     504           2 :         ksAppendKey (split->keysets[1], keyNew ("user/wrong", KEY_END));
     505           2 :         succeed_if (splitGet (split, parentKey, handle) == 1, "could not postprocess get");
     506           2 :         succeed_if (output_error (parentKey), "error found");
     507           2 :         succeed_if (output_warnings (parentKey), "warning(s) found");
     508             : 
     509           2 :         succeed_if (handle->defaultBackend->usersize == 3, "usersize should not be updated");
     510           2 :         succeed_if (handle->defaultBackend->systemsize == 0, "systemsize not set to zero");
     511           2 :         succeed_if (handle->defaultBackend->specsize == -1, "specsize not initialized correct");
     512           2 :         succeed_if (handle->defaultBackend->dirsize == -1, "dirsize not initialized correct");
     513           2 :         succeed_if (split->size == 2, "there is an empty keset");
     514           2 :         succeed_if (ksGetSize (split->keysets[0]) == 0, "wrong size");
     515           2 :         succeed_if (ksGetSize (split->keysets[1]) == 4, "default should stay untouched");
     516           2 :         succeed_if (keyNeedSync (split->keysets[1]->array[0]) == 0, "key should not need sync");
     517           2 :         succeed_if (keyNeedSync (split->keysets[1]->array[1]) == 0, "key should not need sync");
     518           2 :         succeed_if (keyNeedSync (split->keysets[1]->array[2]) == 0, "key should not need sync");
     519           2 :         compare_key (split->parents[0], parentKey);
     520           2 :         succeed_if (split->parents[1] == 0, "parentKey for default not correct");
     521           2 :         succeed_if (split->handles[0] == handle->defaultBackend, "not correct backend");
     522           2 :         succeed_if (split->syncbits[0] == 2, "should be marked as root");
     523             : 
     524           2 :         splitDel (split);
     525           2 :         keyDel (parentKey);
     526             : 
     527             : 
     528           2 :         ksDel (ks);
     529           2 :         kdbClose (handle, 0);
     530           2 :         ksDel (modules);
     531           2 : }
     532             : 
     533             : 
     534           2 : static void test_triesizes (void)
     535             : {
     536           2 :         printf ("Test sizes in backends with trie\n");
     537             : 
     538           2 :         KDB * handle = elektraCalloc (sizeof (struct _KDB));
     539           2 :         handle->split = splitNew ();
     540           2 :         KeySet * modules = modules_config ();
     541           2 :         Backend * backend = 0;
     542           2 :         Backend * rootBackend = 0;
     543             : 
     544           2 :         mountOpen (handle, simple_config (), modules, 0);
     545           2 :         succeed_if (mountDefault (handle, modules, 1, 0) == 0, "could not mount default backends");
     546           2 :         succeed_if (handle->defaultBackend->specsize == -1, "specsize not initialized correct");
     547           2 :         succeed_if (handle->defaultBackend->dirsize == -1, "dirsize not initialized correct");
     548           2 :         succeed_if (handle->defaultBackend->usersize == -1, "usersize  not initialized correct");
     549           2 :         succeed_if (handle->defaultBackend->systemsize == -1, "systemsize not initialized correct");
     550             : 
     551           2 :         KeySet * ks = ksNew (15, keyNew ("user/testkey1/below/here", KEY_END), keyNew ("user/testkey/below1/here", KEY_END),
     552             :                              keyNew ("user/testkey/below2/here", KEY_END), keyNew ("user/tests/simple/testkey/b1/b2/down", KEY_END),
     553             :                              keyNew ("user/tests/simple/testkey/b1/b2/up", KEY_END), KS_END);
     554             : 
     555             :         Split * split;
     556             :         Key * parentKey;
     557             : 
     558           2 :         split = splitNew ();
     559             : 
     560           2 :         parentKey = keyNew ("user", KEY_END);
     561             : 
     562           2 :         rootBackend = trieLookup (handle->trie, parentKey);
     563           2 :         keySetName (parentKey, "user/tests/simple/below");
     564           2 :         backend = trieLookup (handle->trie, parentKey);
     565             : 
     566             :         // now clear name so that we process all backends
     567           2 :         succeed_if (keySetName (parentKey, 0) == 0, "could not delete name of parentKey");
     568           2 :         succeed_if (handle->defaultBackend->specsize == -1, "specsize not initialized correct");
     569           2 :         succeed_if (handle->defaultBackend->dirsize == -1, "dirsize not initialized correct");
     570           2 :         succeed_if (handle->defaultBackend->usersize == -1, "usersize  not initialized correct");
     571           2 :         succeed_if (handle->defaultBackend->systemsize == -1, "systemsize not initialized correct");
     572             : 
     573           2 :         succeed_if (splitBuildup (split, handle, parentKey) == 1, "we add the default backend for user");
     574           2 :         succeed_if (output_error (parentKey), "error found");
     575           2 :         succeed_if (output_warnings (parentKey), "warning(s) found");
     576             : 
     577           2 :         succeed_if (splitAppoint (split, handle, ks) == 1, "could not appoint keys");
     578           2 :         split->syncbits[2] = 3; /* Simulate a kdbGet() */
     579           2 :         split->syncbits[4] = 3; /* Simulate a kdbGet() */
     580           2 :         split->syncbits[5] = 1; /* Simulate a kdbGet() */
     581             : 
     582           2 :         succeed_if (handle->defaultBackend->specsize == -1, "specsize not initialized correct");
     583           2 :         succeed_if (handle->defaultBackend->dirsize == -1, "dirsize not initialized correct");
     584           2 :         succeed_if (handle->defaultBackend->usersize == -1, "usersize  not initialized correct");
     585           2 :         succeed_if (handle->defaultBackend->systemsize == -1, "systemsize not initialized correct");
     586             : 
     587           2 :         succeed_if (splitGet (split, parentKey, handle) == 1, "could not postprocess get");
     588           2 :         succeed_if (output_error (parentKey), "error found");
     589           2 :         succeed_if (output_warnings (parentKey), "warning(s) found");
     590             : 
     591           2 :         succeed_if (backend->usersize == 2, "usersize should be updated");
     592           2 :         succeed_if (backend->systemsize == -1, "systemsize should not change");
     593           2 :         succeed_if (backend->dirsize == -1, "dirsize should not change");
     594           2 :         succeed_if (backend->specsize == -1, "specsize should not change");
     595             : 
     596           2 :         succeed_if (rootBackend->usersize == 3, "usersize of rootBackend should be updated");
     597           2 :         succeed_if (rootBackend->systemsize == 0, "systemsize of rootBackend should be updated");
     598           2 :         succeed_if (rootBackend->dirsize == 0, "dirsize of rootBackend should be updated");
     599           2 :         succeed_if (rootBackend->specsize == 0, "specsize of rootBackend should be updated");
     600             : 
     601           2 :         succeed_if (handle->defaultBackend->specsize == -1, "specsize not initialized correct");
     602           2 :         succeed_if (handle->defaultBackend->dirsize == -1, "dirsize not initialized correct");
     603           2 :         succeed_if (handle->defaultBackend->usersize == -1, "usersize  not initialized correct");
     604           2 :         succeed_if (handle->defaultBackend->systemsize == 0, "systemsize should be updated");
     605             : 
     606           2 :         succeed_if (split->size == 7, "not correct size after appointing");
     607           2 :         succeed_if (ksGetSize (split->keysets[2]) == 3, "wrong size");
     608           2 :         succeed_if (ksGetSize (split->keysets[4]) == 2, "wrong size");
     609             : 
     610           2 :         succeed_if (split->handles[0] == rootBackend, "should be root backend");
     611           2 :         succeed_if (split->handles[1] == rootBackend, "should be root backend");
     612           2 :         succeed_if (split->handles[2] == rootBackend, "should be root backend");
     613           2 :         succeed_if (split->handles[3] == rootBackend, "should be root backend");
     614           2 :         succeed_if (split->handles[4] == backend, "should be mountedbackend");
     615           2 :         succeed_if (split->handles[5] == handle->defaultBackend, "should be defaultBackend");
     616             : 
     617           2 :         Key * mp = keyNew ("user/tests/simple", KEY_VALUE, "simple", KEY_END);
     618           2 :         compare_key (split->parents[4], mp);
     619           2 :         keyDel (mp);
     620             : 
     621           2 :         splitDel (split);
     622           2 :         keyDel (parentKey);
     623             : 
     624           2 :         ksDel (ks);
     625           2 :         kdbClose (handle, 0);
     626           2 :         ksDel (modules);
     627           2 : }
     628             : 
     629             : 
     630           2 : static void test_merge (void)
     631             : {
     632           2 :         printf ("Test sizes in backends with trie\n");
     633             : 
     634           2 :         KDB * handle = elektraCalloc (sizeof (struct _KDB));
     635           2 :         handle->split = splitNew ();
     636           2 :         KeySet * modules = modules_config ();
     637           2 :         Backend * backend = 0;
     638           2 :         Backend * rootBackend = 0;
     639             : 
     640           2 :         mountOpen (handle, simple_config (), modules, 0);
     641           2 :         succeed_if (mountDefault (handle, modules, 1, 0) == 0, "could not mount default backends");
     642           2 :         succeed_if (handle->defaultBackend->specsize == -1, "specsize not initialized correct");
     643           2 :         succeed_if (handle->defaultBackend->dirsize == -1, "dirsize not initialized correct");
     644           2 :         succeed_if (handle->defaultBackend->usersize == -1, "usersize  not initialized correct");
     645           2 :         succeed_if (handle->defaultBackend->systemsize == -1, "systemsize not initialized correct");
     646             : 
     647           2 :         KeySet * ks = ksNew (15, keyNew ("user/testkey1/below/here", KEY_END), keyNew ("user/testkey/below1/here", KEY_END),
     648             :                              keyNew ("user/testkey/below2/here", KEY_END), keyNew ("user/tests/simple/testkey/b1/b2/down", KEY_END),
     649             :                              keyNew ("user/tests/simple/testkey/b1/b2/up", KEY_END), KS_END);
     650             : 
     651             :         Split * split;
     652             :         Key * parentKey;
     653             :         Key * mp;
     654             : 
     655           2 :         split = splitNew ();
     656             : 
     657           2 :         parentKey = keyNew ("user", KEY_END);
     658             : 
     659           2 :         rootBackend = trieLookup (handle->trie, parentKey);
     660           2 :         keySetName (parentKey, "user/tests/simple/below");
     661           2 :         backend = trieLookup (handle->trie, parentKey);
     662           2 :         succeed_if (keySetName (parentKey, 0) == 0, "could not delete name of parentKey");
     663           2 :         succeed_if (backend->specsize == -1, "specsize not initialized correct");
     664           2 :         succeed_if (backend->dirsize == -1, "dirsize not initialized correct");
     665           2 :         succeed_if (backend->usersize == -1, "usersize  not initialized correct");
     666           2 :         succeed_if (backend->systemsize == -1, "systemsize not initialized correct");
     667             : 
     668           2 :         mp = keyNew ("user/tests/simple", KEY_VALUE, "simple", KEY_END);
     669             : 
     670           2 :         succeed_if (splitBuildup (split, handle, parentKey) == 1, "we add the default backend for user");
     671           2 :         succeed_if (output_error (parentKey), "error found");
     672           2 :         succeed_if (output_warnings (parentKey), "warning(s) found");
     673             : 
     674           2 :         succeed_if (splitAppoint (split, handle, ks) == 1, "could not appoint keys");
     675           2 :         split->syncbits[2] = 3; /* Simulate a kdbGet() */
     676           2 :         split->syncbits[4] = 3; /* Simulate a kdbGet() */
     677           2 :         split->syncbits[5] = 1; /* Simulate a kdbGet() */
     678             : 
     679           2 :         succeed_if (splitGet (split, parentKey, handle) == 1, "could not postprocess get");
     680           2 :         succeed_if (output_error (parentKey), "error found");
     681           2 :         succeed_if (output_warnings (parentKey), "warning(s) found");
     682             : 
     683           2 :         succeed_if (backend->usersize == 2, "usersize should be updated");
     684           2 :         succeed_if (backend->systemsize == -1, "systemsize should not change");
     685             : 
     686           2 :         succeed_if (rootBackend->usersize == 3, "usersize of rootBackend should be updated");
     687           2 :         succeed_if (rootBackend->systemsize == 0, "systemsize  of rootBackend should not change");
     688             : 
     689           2 :         succeed_if (handle->defaultBackend->specsize == -1, "specsize not initialized correct");
     690           2 :         succeed_if (handle->defaultBackend->dirsize == -1, "dirsize not initialized correct");
     691           2 :         succeed_if (handle->defaultBackend->usersize == -1, "usersize  not initialized correct");
     692           2 :         succeed_if (handle->defaultBackend->systemsize == 0, "systemsize not initialized correct");
     693             : 
     694             :         // output_split(split);
     695           2 :         succeed_if (split->size == 7, "not correct size after appointing");
     696           2 :         succeed_if (ksGetSize (split->keysets[2]) == 3, "wrong size");
     697           2 :         succeed_if (ksGetSize (split->keysets[4]) == 2, "wrong size");
     698           2 :         compare_key (split->parents[4], mp);
     699           2 :         succeed_if (split->handles[0] == rootBackend, "should be root backend");
     700           2 :         succeed_if (split->handles[1] == rootBackend, "should be root backend");
     701           2 :         succeed_if (split->handles[2] == rootBackend, "should be root backend");
     702           2 :         succeed_if (split->handles[3] == rootBackend, "should be root backend");
     703           2 :         succeed_if (split->handles[4] == backend, "should be backend");
     704             : 
     705           2 :         KeySet * nks = ksNew (0, KS_END);
     706           4 :         succeed_if (splitMergeBackends (split, nks) == 1, "could not merge together keysets from backend");
     707           4 :         succeed_if (splitMergeDefault (split, nks) == 1, "could not merge together keysets from default split");
     708           2 :         compare_keyset (ks, nks);
     709             :         // output_keyset (nks);
     710           2 :         ksDel (nks);
     711             : 
     712             : 
     713           2 :         splitDel (split);
     714           2 :         keyDel (parentKey);
     715           2 :         keyDel (mp);
     716             : 
     717           2 :         ksDel (ks);
     718           2 :         kdbClose (handle, 0);
     719           2 :         ksDel (modules);
     720           2 : }
     721             : 
     722             : 
     723           2 : static void test_realworld (void)
     724             : {
     725           2 :         printf ("Test real world example\n");
     726             : 
     727           2 :         Key * parent = 0;
     728           2 :         KDB * handle = elektraCalloc (sizeof (struct _KDB));
     729           2 :         handle->split = splitNew ();
     730           2 :         KeySet * modules = ksNew (0, KS_END);
     731           2 :         elektraModulesInit (modules, 0);
     732             : 
     733           2 :         mountOpen (handle, set_realworld (), modules, 0);
     734           2 :         succeed_if (mountDefault (handle, modules, 1, 0) == 0, "could not mount default backends");
     735             : 
     736           2 :         KeySet * ks =
     737           2 :                 ksNew (18, keyNew ("system/elektra/mountpoints", KEY_END), keyNew ("system/elektra/mountpoints/new", KEY_END),
     738             :                        keyNew ("system/elektra/mountpoints/new/mountpoint", KEY_VALUE, "something", KEY_END),
     739             :                        keyNew ("system/users", KEY_END), keyNew ("system/users/markus", KEY_END), keyNew ("system/users/harald", KEY_END),
     740             :                        keyNew ("system/users/n", KEY_END), keyNew ("system/users/albert", KEY_END), keyNew ("system/hosts", KEY_END),
     741             :                        keyNew ("system/hosts/markusbyte", KEY_VALUE, "127.0.0.1", KEY_END), keyNew ("system/hosts/mobilebyte", KEY_END),
     742             :                        keyNew ("system/hosts/n900", KEY_END), keyNew ("user/sw/apps/app1/default", KEY_END),
     743             :                        keyNew ("user/sw/apps/app1/default/maximize", KEY_VALUE, "1", KEY_END),
     744             :                        keyNew ("user/sw/apps/app1/default/download", KEY_VALUE, "0", KEY_END),
     745             :                        keyNew ("user/sw/apps/app1/default/keys/a", KEY_VALUE, "a", KEY_END),
     746             :                        keyNew ("user/sw/apps/app1/default/keys/b", KEY_VALUE, "b", KEY_END),
     747             :                        keyNew ("user/sw/apps/app1/default/keys/c", KEY_VALUE, "c", KEY_END),
     748             :                        keyNew ("user/outside", KEY_VALUE, "test", KEY_END), KS_END);
     749           2 :         KeySet * split0 = ksNew (9, keyNew ("user/sw/apps/app1/default", KEY_END),
     750             :                                  keyNew ("user/sw/apps/app1/default/maximize", KEY_VALUE, "1", KEY_END),
     751             :                                  keyNew ("user/sw/apps/app1/default/download", KEY_VALUE, "0", KEY_END),
     752             :                                  keyNew ("user/sw/apps/app1/default/keys/a", KEY_VALUE, "a", KEY_END),
     753             :                                  keyNew ("user/sw/apps/app1/default/keys/b", KEY_VALUE, "b", KEY_END),
     754             :                                  keyNew ("user/sw/apps/app1/default/keys/c", KEY_VALUE, "c", KEY_END), KS_END);
     755           2 :         KeySet * split3 = ksNew (9, keyNew ("system/hosts", KEY_END), keyNew ("system/hosts/markusbyte", KEY_VALUE, "127.0.0.1", KEY_END),
     756             :                                  keyNew ("system/hosts/mobilebyte", KEY_END), keyNew ("system/hosts/n900", KEY_END), KS_END);
     757           2 :         KeySet * split7 = ksNew (3, keyNew ("user/outside", KEY_VALUE, "test", KEY_END), KS_END);
     758           2 :         KeySet * split9 = ksNew (9, keyNew ("system/users", KEY_END), keyNew ("system/users/markus", KEY_END),
     759             :                                  keyNew ("system/users/harald", KEY_END), keyNew ("system/users/n", KEY_END),
     760             :                                  keyNew ("system/users/albert", KEY_END), KS_END);
     761           2 :         KeySet * split10 = ksNew (9, keyNew ("system/elektra/mountpoints", KEY_END), keyNew ("system/elektra/mountpoints/new", KEY_END),
     762             :                                   keyNew ("system/elektra/mountpoints/new/mountpoint", KEY_VALUE, "something", KEY_END), KS_END);
     763             : 
     764             : 
     765           2 :         Split * split = splitNew ();
     766             : 
     767           2 :         succeed_if (splitBuildup (split, handle, parent) == 1, "should need sync");
     768           2 :         succeed_if (output_error (parent), "error found");
     769           2 :         succeed_if (output_warnings (parent), "warning(s) found");
     770             : 
     771           2 :         succeed_if (split->size == 11, "size not correct");
     772           2 :         succeed_if (split->handles[5] == split->handles[6], "root backends have same handle");
     773           2 :         succeed_if (split->syncbits[5] == 2, "sync state for root not correct");
     774           2 :         succeed_if (split->syncbits[6] == 2, "sync state for root not correct");
     775           2 :         succeed_if_same_string (keyName (split->parents[0]), "user/sw/apps/app1/default");
     776           2 :         succeed_if_same_string (keyName (split->parents[1]), "user/sw/apps/app2");
     777           2 :         succeed_if_same_string (keyName (split->parents[2]), "system/groups");
     778           2 :         succeed_if_same_string (keyName (split->parents[3]), "system/hosts");
     779           2 :         succeed_if_same_string (keyName (split->parents[4]), "user/sw/kde/default");
     780           2 :         succeed_if_same_string (keyName (split->parents[5]), "spec");
     781           2 :         succeed_if_same_string (keyName (split->parents[6]), "dir");
     782           2 :         succeed_if_same_string (keyName (split->parents[7]), "user");
     783           2 :         succeed_if_same_string (keyName (split->parents[8]), "system");
     784           2 :         succeed_if_same_string (keyName (split->parents[9]), "system/users");
     785           2 :         succeed_if_same_string (keyName (split->parents[10]), "system/elektra");
     786             : 
     787           2 :         succeed_if (splitAppoint (split, handle, ks) == 1, "should need sync");
     788             : 
     789           2 :         succeed_if (split->size == 12, "size not correct (def not added)");
     790           2 :         succeed_if (split->syncbits[0] == 0, "sync state not correct");
     791           2 :         succeed_if (split->syncbits[1] == 0, "sync state not correct");
     792           2 :         succeed_if (split->syncbits[2] == 0, "sync state not correct");
     793           2 :         succeed_if (split->syncbits[3] == 0, "sync state not correct");
     794           2 :         succeed_if (split->syncbits[4] == 0, "sync state not correct");
     795           2 :         succeed_if (split->syncbits[5] == 2, "sync state not correct");
     796           2 :         succeed_if (split->syncbits[6] == 2, "sync state not correct");
     797           2 :         succeed_if (split->syncbits[7] == 2, "sync state not correct");
     798           2 :         succeed_if (split->syncbits[8] == 2, "sync state not correct");
     799           2 :         succeed_if (split->syncbits[9] == 0, "sync state not correct");
     800           2 :         succeed_if (split->syncbits[10] == 2, "sync state not correct");
     801           2 :         compare_keyset (split->keysets[0], split0);
     802           2 :         compare_keyset (split->keysets[3], split3);
     803           2 :         compare_keyset (split->keysets[7], split7);
     804           2 :         compare_keyset (split->keysets[9], split9);
     805           2 :         compare_keyset (split->keysets[10], split10);
     806             : 
     807           2 :         split->syncbits[0] |= 1;
     808           2 :         split->syncbits[3] |= 1;
     809           2 :         split->syncbits[6] |= 1;
     810           2 :         split->syncbits[7] |= 1;
     811           2 :         succeed_if (splitGet (split, parent, handle) == 1, "postprocessing failed");
     812           2 :         succeed_if (output_error (parent), "error found");
     813           2 :         succeed_if (output_warnings (parent), "warning(s) found");
     814             : 
     815           2 :         succeed_if (split->handles[0]->usersize == 6, "wrong size");
     816           2 :         succeed_if (split->handles[3]->systemsize == 4, "wrong size");
     817           2 :         succeed_if (split->handles[6]->usersize == 1, "wrong size");
     818           2 :         succeed_if (split->handles[9]->systemsize == 5, "wrong size");
     819             : 
     820             : 
     821           2 :         KeySet * dest = ksNew (5, keyNew ("user/test", KEY_VALUE, "should be gone", KEY_END), KS_END);
     822           2 :         ksClear (dest);
     823           4 :         succeed_if (splitMergeBackends (split, dest) == 1, "split merge backends");
     824           4 :         succeed_if (splitMergeDefault (split, dest) == 1, "split merge default");
     825           2 :         compare_keyset (dest, ks);
     826           2 :         ksDel (dest);
     827             : 
     828           2 :         splitDel (split);
     829             : 
     830             : 
     831           2 :         ksDel (ks);
     832           2 :         ksDel (split0);
     833           2 :         ksDel (split3);
     834           2 :         ksDel (split7);
     835           2 :         ksDel (split9);
     836           2 :         ksDel (split10);
     837           2 :         elektraModulesClose (modules, 0);
     838           2 :         ksDel (modules);
     839             : 
     840           2 :         kdbClose (handle, parent);
     841           2 :         keyDel (parent);
     842           2 : }
     843             : 
     844             : 
     845           2 : int main (int argc, char ** argv)
     846             : {
     847           2 :         printf ("SPLIT GET   TESTS\n");
     848           2 :         printf ("==================\n\n");
     849             : 
     850           2 :         init (argc, argv);
     851             : 
     852           2 :         test_simple ();
     853           2 :         test_cascading ();
     854           2 :         test_get ();
     855           2 :         test_limit ();
     856           2 :         test_nobackend ();
     857           2 :         test_sizes ();
     858           2 :         test_triesizes ();
     859           2 :         test_merge ();
     860           2 :         test_realworld ();
     861             : 
     862             : 
     863           2 :         printf ("\ntest_splitget RESULTS: %d test(s) done. %d error(s).\n", nbTest, nbError);
     864             : 
     865           2 :         return nbError;
     866             : }

Generated by: LCOV version 1.13