LCOV - code coverage report
Current view: top level - tests/ctest - test_mountsplit.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 459 461 99.6 %
Date: 2019-09-12 12:28:41 Functions: 18 19 94.7 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief Test suite for split buildup during mount.
       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           0 : KDB * kdb_new (void)
      16             : {
      17          18 :         KDB * kdb = elektraCalloc (sizeof (KDB));
      18          18 :         kdb->split = splitNew ();
      19           0 :         return kdb;
      20             : }
      21             : 
      22           4 : Backend * b_new (const char * name, const char * value)
      23             : {
      24           4 :         Backend * backend = elektraCalloc (sizeof (Backend));
      25           4 :         backend->refcounter = 1;
      26             : 
      27           4 :         backend->mountpoint = keyNew (name, KEY_VALUE, value, KEY_END);
      28           4 :         keyIncRef (backend->mountpoint);
      29             : 
      30           4 :         return backend;
      31             : }
      32             : 
      33          18 : static void kdb_del (KDB * kdb)
      34             : {
      35          18 :         backendClose (kdb->defaultBackend, 0);
      36          18 :         trieClose (kdb->trie, 0);
      37          18 :         splitDel (kdb->split);
      38             : 
      39          18 :         elektraFree (kdb);
      40          18 : }
      41             : 
      42           2 : static void test_mount (void)
      43             : {
      44           2 :         printf ("test mount backend\n");
      45             : 
      46           2 :         KDB * kdb = kdb_new ();
      47           2 :         mountBackend (kdb, b_new ("user", "user"), 0);
      48           2 :         succeed_if (kdb->trie, "there should be a trie");
      49             : 
      50           2 :         Key * mp = keyNew ("user", KEY_VALUE, "user", KEY_END);
      51           2 :         Key * sk = keyNew ("user", KEY_VALUE, "user", KEY_END);
      52             : 
      53           2 :         succeed_if (kdb->split->size == 1, "size of split not correct");
      54           2 :         compare_key (mp, kdb->split->parents[0]);
      55             : 
      56           2 :         compare_key (mountGetBackend (kdb, sk)->mountpoint, mp);
      57           4 :         compare_key (mountGetMountpoint (kdb, sk), mp);
      58             : 
      59           2 :         keySetName (sk, "user/below");
      60           2 :         compare_key (mountGetBackend (kdb, sk)->mountpoint, mp);
      61           4 :         compare_key (mountGetMountpoint (kdb, sk), mp);
      62             : 
      63           2 :         keySetName (sk, "system");
      64           2 :         kdb->defaultBackend = b_new ("", "default");
      65           2 :         succeed_if (mountGetBackend (kdb, sk) == kdb->defaultBackend, "did not return default backend");
      66             : 
      67           2 :         keySetName (mp, "");
      68           2 :         keySetString (mp, "default");
      69           2 :         compare_key (mountGetBackend (kdb, sk)->mountpoint, mp);
      70           4 :         compare_key (mountGetMountpoint (kdb, sk), mp);
      71             : 
      72           2 :         keyDel (sk);
      73           2 :         keyDel (mp);
      74             : 
      75           2 :         kdb_del (kdb);
      76           2 : }
      77             : 
      78          14 : KeySet * modules_config (void)
      79             : {
      80          14 :         return ksNew (5, keyNew ("system/elektra/modules", KEY_END), KS_END);
      81             : }
      82             : 
      83           4 : KeySet * minimal_config (void)
      84             : {
      85           4 :         return ksNew (5, keyNew ("system/elektra/mountpoints", KEY_END), KS_END);
      86             : }
      87             : 
      88             : 
      89           2 : static void test_minimaltrie (void)
      90             : {
      91           2 :         printf ("Test minimal mount\n");
      92             : 
      93           2 :         KDB * kdb = kdb_new ();
      94           2 :         Key * errorKey = keyNew (0);
      95           2 :         KeySet * modules = modules_config ();
      96           2 :         succeed_if (mountOpen (kdb, minimal_config (), modules, errorKey) == 0, "could not open minimal config");
      97             : 
      98           2 :         succeed_if (output_warnings (errorKey), "warnings found");
      99           2 :         succeed_if (output_error (errorKey), "error found");
     100             : 
     101           2 :         succeed_if (!kdb->trie, "minimal trie is null");
     102           2 :         succeed_if (kdb->split->size == 0, "minimal trie has size 0");
     103             : 
     104           2 :         keyDel (errorKey);
     105           2 :         ksDel (modules);
     106           2 :         kdb_del (kdb);
     107           2 : }
     108             : 
     109           2 : KeySet * simple_config (void)
     110             : {
     111           2 :         return ksNew (5, keyNew ("system/elektra/mountpoints", KEY_END), keyNew ("system/elektra/mountpoints/simple", KEY_END),
     112             :                       keyNew ("system/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "user/tests/simple", KEY_END), KS_END);
     113             : }
     114             : 
     115           2 : static void test_simple (void)
     116             : {
     117           2 :         printf ("Test simple mount\n");
     118             : 
     119           2 :         KDB * kdb = kdb_new ();
     120           2 :         Key * errorKey = keyNew (0);
     121           2 :         KeySet * modules = modules_config ();
     122           2 :         Key * mp = keyNew ("user/tests/simple", KEY_VALUE, "simple", KEY_END);
     123             : 
     124           2 :         succeed_if (mountOpen (kdb, simple_config (), modules, errorKey) == 0, "could not open trie");
     125             : 
     126           2 :         succeed_if (kdb->split->size == 1, "size of split not correct");
     127           2 :         compare_key (mp, kdb->split->parents[0]);
     128             : 
     129           2 :         succeed_if (output_warnings (errorKey), "warnings found");
     130           2 :         succeed_if (output_error (errorKey), "error found");
     131             : 
     132           2 :         exit_if_fail (kdb->trie, "kdb->trie was not build up successfully");
     133             : 
     134           2 :         Key * searchKey = keyNew ("user", KEY_END);
     135           2 :         Backend * backend = trieLookup (kdb->trie, searchKey);
     136           2 :         succeed_if (!backend, "there should be no backend");
     137             : 
     138             : 
     139           2 :         keySetName (searchKey, "user/tests/simple");
     140           2 :         backend = trieLookup (kdb->trie, searchKey);
     141           2 :         succeed_if (backend, "there should be a backend");
     142           2 :         if (backend) compare_key (backend->mountpoint, mp);
     143             : 
     144             : 
     145           2 :         keySetName (searchKey, "user/tests/simple/below");
     146           2 :         Backend * b2 = trieLookup (kdb->trie, searchKey);
     147           2 :         succeed_if (b2, "there should be a backend");
     148           2 :         succeed_if (backend == b2, "should be same backend");
     149           2 :         if (b2) compare_key (b2->mountpoint, mp);
     150             : 
     151             : 
     152           2 :         keySetName (searchKey, "user/tests/simple/deep/below");
     153           2 :         b2 = trieLookup (kdb->trie, searchKey);
     154           2 :         succeed_if (b2, "there should be a backend");
     155           2 :         succeed_if (backend == b2, "should be same backend");
     156           2 :         if (b2) compare_key (b2->mountpoint, mp);
     157             : 
     158           2 :         keyDel (errorKey);
     159           2 :         ksDel (modules);
     160           2 :         keyDel (mp);
     161           2 :         keyDel (searchKey);
     162           2 :         kdb_del (kdb);
     163           2 : }
     164             : 
     165           2 : KeySet * set_us (void)
     166             : {
     167           2 :         return ksNew (50, keyNew ("system/elektra/mountpoints", KEY_END), keyNew ("system/elektra/mountpoints/user", KEY_END),
     168             :                       keyNew ("system/elektra/mountpoints/user/mountpoint", KEY_VALUE, "user", KEY_END),
     169             :                       keyNew ("system/elektra/mountpoints/system", KEY_END),
     170             :                       keyNew ("system/elektra/mountpoints/system/mountpoint", KEY_VALUE, "system", KEY_END), KS_END);
     171             : }
     172             : 
     173           2 : static void test_us (void)
     174             : {
     175           2 :         printf ("Test mounting of user and system backends\n");
     176             : 
     177           2 :         KDB * kdb = kdb_new ();
     178           2 :         KeySet * modules = ksNew (0, KS_END);
     179           2 :         elektraModulesInit (modules, 0);
     180             :         Key * mp;
     181             : 
     182           2 :         KeySet * config = set_us ();
     183           2 :         ksAppendKey (config, keyNew ("system/elektra/mountpoints", KEY_END));
     184           2 :         succeed_if (mountOpen (kdb, config, modules, 0) == 0, "could not open mount");
     185           2 :         succeed_if (mountDefault (kdb, modules, 1, 0) == 0, "could not mount default backend");
     186             : 
     187           2 :         succeed_if (kdb->split->size == 5, "size of split not correct");
     188           2 :         mp = keyNew ("system", KEY_VALUE, "system", KEY_END);
     189           2 :         compare_key (mp, kdb->split->parents[0]);
     190           2 :         keySetName (mp, "user");
     191           2 :         keySetString (mp, "user");
     192           2 :         compare_key (mp, kdb->split->parents[1]);
     193           2 :         keySetName (mp, "system/elektra");
     194           2 :         keySetString (mp, "default");
     195           2 :         compare_key (mp, kdb->split->parents[4]);
     196           2 :         keyDel (mp);
     197             : 
     198           2 :         Key * key = keyNew ("user/anywhere/backend/simple", KEY_END);
     199           2 :         Backend * backend = trieLookup (kdb->trie, key);
     200             : 
     201           2 :         keyAddBaseName (key, "somewhere");
     202           2 :         keyAddBaseName (key, "deep");
     203           2 :         keyAddBaseName (key, "below");
     204           2 :         Backend * backend2 = trieLookup (kdb->trie, key);
     205           2 :         succeed_if (backend == backend2, "should be same backend");
     206           2 :         mp = backend->mountpoint;
     207           2 :         succeed_if (mp, "no mountpoint found");
     208           2 :         if (mp)
     209             :         {
     210           2 :                 succeed_if_same_string (keyName (mp), "user");
     211           2 :                 succeed_if_same_string (keyString (mp), "user");
     212             :         }
     213             : 
     214           2 :         keySetName (key, "system/anywhere/tests/backend/two");
     215           2 :         Backend * two = trieLookup (kdb->trie, key);
     216           2 :         succeed_if (two != backend, "should be differnt backend");
     217             : 
     218           2 :         succeed_if ((mp = two->mountpoint) != 0, "no mountpoint found");
     219           2 :         succeed_if_same_string (keyName (mp), "system");
     220           2 :         succeed_if_same_string (keyString (mp), "system");
     221             : 
     222           2 :         keyDel (key);
     223           2 :         kdb_del (kdb);
     224           2 :         elektraModulesClose (modules, 0);
     225           2 :         ksDel (modules);
     226           2 : }
     227             : 
     228             : 
     229           2 : KeySet * cascading_config (void)
     230             : {
     231           2 :         return ksNew (5, keyNew ("system/elektra/mountpoints", KEY_END), keyNew ("system/elektra/mountpoints/simple", KEY_END),
     232             :                       keyNew ("system/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "/tests/simple", KEY_END), KS_END);
     233             : }
     234             : 
     235           2 : static void test_cascading (void)
     236             : {
     237           2 :         printf ("Test simple mount with cascading\n");
     238             : 
     239           2 :         KDB * kdb = kdb_new ();
     240           2 :         Key * errorKey = keyNew (0);
     241           2 :         KeySet * modules = modules_config ();
     242           2 :         succeed_if (mountOpen (kdb, cascading_config (), modules, errorKey) == 0, "could not open trie");
     243           2 :         succeed_if (mountDefault (kdb, modules, 1, errorKey) == 0, "could not mount default backend");
     244             : 
     245           2 :         succeed_if (output_warnings (errorKey), "warnings found");
     246           2 :         succeed_if (output_error (errorKey), "error found");
     247             : 
     248           2 :         exit_if_fail (kdb->trie, "kdb->trie was not build up successfully");
     249             : 
     250           2 :         succeed_if (kdb->split->size == 7, "size of split not correct");
     251           2 :         Key * mp = keyNew ("dir/tests/simple", KEY_VALUE, "simple", KEY_END);
     252           2 :         compare_key (mp, kdb->split->parents[0]);
     253           2 :         keySetName (mp, "user/tests/simple");
     254           2 :         keySetString (mp, "simple");
     255           2 :         compare_key (mp, kdb->split->parents[1]);
     256           2 :         keySetName (mp, "system/tests/simple");
     257           2 :         keySetString (mp, "simple");
     258           2 :         compare_key (mp, kdb->split->parents[2]);
     259           2 :         keyDel (mp);
     260             : 
     261             :         // output_split (kdb->split);
     262             :         // output_trie (kdb->trie);
     263             : 
     264           2 :         Key * searchKey = keyNew ("user", KEY_END);
     265           2 :         Backend * backend = trieLookup (kdb->trie, searchKey);
     266           2 :         succeed_if (!backend, "there should be no backend");
     267             : 
     268           2 :         keySetName (searchKey, "system");
     269           2 :         backend = trieLookup (kdb->trie, searchKey);
     270           2 :         succeed_if (!backend, "there should be no backend");
     271             : 
     272             : 
     273           2 :         mp = keyNew ("", KEY_VALUE, "simple", KEY_END);
     274           2 :         elektraKeySetName (mp, "/tests/simple", KEY_CASCADING_NAME);
     275             : 
     276           2 :         keySetName (searchKey, "user/tests/simple");
     277           2 :         backend = trieLookup (kdb->trie, searchKey);
     278           2 :         succeed_if (backend, "there should be a backend");
     279           2 :         if (backend) compare_key (backend->mountpoint, mp);
     280             : 
     281             : 
     282           2 :         keySetName (searchKey, "user/tests/simple/below");
     283           2 :         Backend * b2 = trieLookup (kdb->trie, searchKey);
     284           2 :         succeed_if (b2, "there should be a backend");
     285           2 :         succeed_if (backend == b2, "should be same backend");
     286           2 :         if (b2) compare_key (b2->mountpoint, mp);
     287             : 
     288             : 
     289           2 :         keySetName (searchKey, "user/tests/simple/deep/below");
     290           2 :         b2 = trieLookup (kdb->trie, searchKey);
     291           2 :         succeed_if (b2, "there should be a backend");
     292           2 :         succeed_if (backend == b2, "should be same backend");
     293           2 :         if (b2) compare_key (b2->mountpoint, mp);
     294             : 
     295             : 
     296           2 :         keySetName (searchKey, "system/tests/simple");
     297           2 :         backend = trieLookup (kdb->trie, searchKey);
     298           2 :         succeed_if (backend, "there should be a backend");
     299           2 :         if (backend) compare_key (backend->mountpoint, mp);
     300             : 
     301           2 :         keySetName (searchKey, "system/tests/simple/below");
     302           2 :         b2 = trieLookup (kdb->trie, searchKey);
     303           2 :         succeed_if (b2, "there should be a backend");
     304           2 :         succeed_if (backend == b2, "should be same backend");
     305           2 :         if (b2) compare_key (b2->mountpoint, mp);
     306             : 
     307             : 
     308           2 :         keySetName (searchKey, "system/tests/simple/deep/below");
     309           2 :         b2 = trieLookup (kdb->trie, searchKey);
     310           2 :         succeed_if (b2, "there should be a backend");
     311           2 :         succeed_if (backend == b2, "should be same backend");
     312           2 :         if (b2) compare_key (b2->mountpoint, mp);
     313             : 
     314             : 
     315           2 :         keyDel (errorKey);
     316           2 :         ksDel (modules);
     317           2 :         keyDel (mp);
     318           2 :         keyDel (searchKey);
     319           2 :         kdb_del (kdb);
     320           2 : }
     321             : 
     322             : 
     323           6 : KeySet * root_config (void)
     324             : {
     325           6 :         return ksNew (5, keyNew ("system/elektra/mountpoints", KEY_END), keyNew ("system/elektra/mountpoints/root", KEY_END),
     326             :                       keyNew ("system/elektra/mountpoints/root/mountpoint", KEY_VALUE, "/", KEY_END),
     327             :                       keyNew ("system/elektra/mountpoints/simple", KEY_END),
     328             :                       keyNew ("system/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "user/tests/simple", KEY_END), KS_END);
     329             : }
     330             : 
     331           2 : static void test_root (void)
     332             : {
     333           2 :         printf ("Test mounting with root\n");
     334             : 
     335           2 :         KDB * kdb = kdb_new ();
     336           2 :         Key * errorKey = keyNew (0);
     337           2 :         KeySet * modules = modules_config ();
     338           2 :         succeed_if (mountOpen (kdb, root_config (), modules, errorKey) == 0, "could not buildup mount");
     339             : 
     340           2 :         succeed_if (output_warnings (errorKey), "warnings found");
     341           2 :         succeed_if (output_error (errorKey), "error found");
     342             : 
     343           2 :         exit_if_fail (kdb->trie, "trie was not build up successfully");
     344             : 
     345           2 :         succeed_if (kdb->split->size == 5, "size of split not correct");
     346           2 :         Key * mp = keyNew ("spec", KEY_VALUE, "root", KEY_END);
     347           2 :         compare_key (mp, kdb->split->parents[0]);
     348           2 :         keySetName (mp, "dir");
     349           2 :         keySetString (mp, "root");
     350           2 :         compare_key (mp, kdb->split->parents[1]);
     351           2 :         keySetName (mp, "user");
     352           2 :         keySetString (mp, "root");
     353           2 :         compare_key (mp, kdb->split->parents[2]);
     354           2 :         keySetName (mp, "system");
     355           2 :         keySetString (mp, "root");
     356           2 :         compare_key (mp, kdb->split->parents[3]);
     357           2 :         keySetName (mp, "user/tests/simple");
     358           2 :         keySetString (mp, "simple");
     359           2 :         compare_key (mp, kdb->split->parents[4]);
     360             : 
     361           2 :         Key * searchKey = keyNew ("", KEY_END);
     362           2 :         Key * rmp = keyNew ("", KEY_VALUE, "root", KEY_END);
     363           2 :         elektraKeySetName (rmp, "/", KEY_CASCADING_NAME);
     364           2 :         Backend * b2 = 0;
     365             : 
     366           2 :         keySetName (searchKey, "user");
     367           2 :         b2 = trieLookup (kdb->trie, searchKey);
     368           2 :         succeed_if (b2, "there should be a backend");
     369           2 :         if (b2) compare_key (b2->mountpoint, rmp);
     370             : 
     371             : 
     372           2 :         Backend * backend = 0;
     373           2 :         keySetName (searchKey, "user/tests/simple");
     374           2 :         backend = trieLookup (kdb->trie, searchKey);
     375           2 :         succeed_if (backend, "there should be a backend");
     376           2 :         if (backend) compare_key (backend->mountpoint, mp);
     377             : 
     378             : 
     379           2 :         keySetName (searchKey, "user/tests/simple/below");
     380           2 :         b2 = trieLookup (kdb->trie, searchKey);
     381           2 :         succeed_if (b2, "there should be a backend");
     382           2 :         succeed_if (backend == b2, "should be same backend");
     383           2 :         if (b2) compare_key (b2->mountpoint, mp);
     384             : 
     385             : 
     386           2 :         keySetName (searchKey, "user/tests/simple/deep/below");
     387           2 :         b2 = trieLookup (kdb->trie, searchKey);
     388           2 :         succeed_if (b2, "there should be a backend");
     389           2 :         succeed_if (backend == b2, "should be same backend");
     390           2 :         if (b2) compare_key (b2->mountpoint, mp);
     391             : 
     392           2 :         keyDel (mp);
     393           2 :         keyDel (rmp);
     394             : 
     395           2 :         keyDel (searchKey);
     396             : 
     397           2 :         kdb_del (kdb);
     398           2 :         keyDel (errorKey);
     399           2 :         ksDel (modules);
     400           2 : }
     401             : 
     402           2 : static void test_default (void)
     403             : {
     404           2 :         printf ("Test mounting with default\n");
     405             : 
     406           2 :         KDB * kdb = kdb_new ();
     407           2 :         Key * errorKey = keyNew (0);
     408           2 :         KeySet * modules = modules_config ();
     409           2 :         succeed_if (mountOpen (kdb, root_config (), modules, errorKey) == 0, "could not buildup mount");
     410           2 :         succeed_if (mountDefault (kdb, modules, 1, errorKey) == 0, "could not mount default backend");
     411             : 
     412           2 :         succeed_if (kdb->split->size == 6, "size of split not correct");
     413           2 :         Key * mp = keyNew ("spec", KEY_VALUE, "root", KEY_END);
     414           2 :         compare_key (mp, kdb->split->parents[0]);
     415           2 :         keySetName (mp, "dir");
     416           2 :         keySetString (mp, "root");
     417           2 :         compare_key (mp, kdb->split->parents[1]);
     418           2 :         keySetName (mp, "user");
     419           2 :         keySetString (mp, "root");
     420           2 :         compare_key (mp, kdb->split->parents[2]);
     421           2 :         keySetName (mp, "system");
     422           2 :         keySetString (mp, "root");
     423           2 :         compare_key (mp, kdb->split->parents[3]);
     424           2 :         keySetName (mp, "system/elektra");
     425           2 :         keySetString (mp, "default");
     426           2 :         compare_key (mp, kdb->split->parents[5]);
     427             : 
     428             :         // must be last, needed later
     429           2 :         keySetName (mp, "user/tests/simple");
     430           2 :         keySetString (mp, "simple");
     431           2 :         compare_key (mp, kdb->split->parents[4]);
     432             : 
     433           2 :         succeed_if (output_warnings (errorKey), "warnings found");
     434           2 :         succeed_if (output_error (errorKey), "error found");
     435             : 
     436           2 :         exit_if_fail (kdb->trie, "trie was not build up successfully");
     437             : 
     438             :         // output_trie (kdb->trie);
     439             : 
     440           2 :         Key * searchKey = keyNew ("", KEY_END);
     441           2 :         Key * rmp = keyNew ("", KEY_VALUE, "root", KEY_END);
     442           2 :         elektraKeySetName (rmp, "/", KEY_CASCADING_NAME);
     443           2 :         Backend * b2 = 0;
     444             : 
     445           2 :         keySetName (searchKey, "user");
     446           2 :         b2 = trieLookup (kdb->trie, searchKey);
     447           2 :         succeed_if (b2, "there should be a backend");
     448           2 :         if (b2) compare_key (b2->mountpoint, rmp);
     449             : 
     450             : 
     451           2 :         Backend * backend = 0;
     452           2 :         keySetName (searchKey, "user/tests/simple");
     453           2 :         backend = trieLookup (kdb->trie, searchKey);
     454           2 :         succeed_if (backend, "there should be a backend");
     455           2 :         if (backend) compare_key (backend->mountpoint, mp);
     456             : 
     457             : 
     458           2 :         keySetName (searchKey, "user/tests/simple/below");
     459           2 :         b2 = trieLookup (kdb->trie, searchKey);
     460           2 :         succeed_if (b2, "there should be a backend");
     461           2 :         succeed_if (backend == b2, "should be same backend");
     462           2 :         if (b2) compare_key (b2->mountpoint, mp);
     463             : 
     464             : 
     465           2 :         keySetName (searchKey, "user/tests/simple/deep/below");
     466           2 :         b2 = trieLookup (kdb->trie, searchKey);
     467           2 :         succeed_if (b2, "there should be a backend");
     468           2 :         succeed_if (backend == b2, "should be same backend");
     469           2 :         if (b2) compare_key (b2->mountpoint, mp);
     470             : 
     471           2 :         Key * dmp = keyNew ("", KEY_VALUE, "default", KEY_END);
     472           2 :         keySetName (searchKey, "system/elektra");
     473           2 :         b2 = trieLookup (kdb->trie, searchKey);
     474           2 :         succeed_if (b2, "there should be a backend");
     475           2 :         succeed_if (b2 == kdb->defaultBackend, "should be the default backend");
     476           2 :         if (b2) compare_key (b2->mountpoint, dmp);
     477             : 
     478           2 :         keySetName (searchKey, "system/elektra/below");
     479           2 :         b2 = trieLookup (kdb->trie, searchKey);
     480           2 :         succeed_if (b2, "there should be a backend");
     481           2 :         succeed_if (b2 == kdb->defaultBackend, "should be the default backend");
     482           2 :         if (b2) compare_key (b2->mountpoint, dmp);
     483             : 
     484           2 :         keyDel (dmp);
     485           2 :         keyDel (mp);
     486           2 :         keyDel (rmp);
     487             : 
     488           2 :         keyDel (searchKey);
     489             : 
     490           2 :         kdb_del (kdb);
     491           2 :         keyDel (errorKey);
     492           2 :         ksDel (modules);
     493           2 : }
     494             : 
     495           2 : static void test_modules (void)
     496             : {
     497           2 :         printf ("Test mounting with modules\n");
     498             : 
     499           2 :         KDB * kdb = kdb_new ();
     500           2 :         Key * errorKey = keyNew (0);
     501           2 :         KeySet * modules = modules_config ();
     502           2 :         succeed_if (mountOpen (kdb, root_config (), modules, errorKey) == 0, "could not buildup mount");
     503           2 :         succeed_if (mountDefault (kdb, modules, 1, errorKey) == 0, "could not mount default backend");
     504           2 :         succeed_if (mountModules (kdb, modules, errorKey) == 0, "could not mount modules");
     505             : 
     506           2 :         succeed_if (output_warnings (errorKey), "warnings found");
     507           2 :         succeed_if (output_error (errorKey), "error found");
     508             : 
     509             :         // output_split (kdb->split);
     510             : 
     511           2 :         succeed_if (kdb->split->size == 8, "size of split not correct");
     512           2 :         Key * mp = keyNew ("spec", KEY_VALUE, "root", KEY_END);
     513           2 :         compare_key (mp, kdb->split->parents[0]);
     514           2 :         keySetName (mp, "dir");
     515           2 :         keySetString (mp, "root");
     516           2 :         compare_key (mp, kdb->split->parents[1]);
     517           2 :         keySetName (mp, "user");
     518           2 :         keySetString (mp, "root");
     519           2 :         compare_key (mp, kdb->split->parents[2]);
     520           2 :         keySetName (mp, "system");
     521           2 :         keySetString (mp, "root");
     522           2 :         compare_key (mp, kdb->split->parents[3]);
     523             :         /* we cannot exactly know where resolver+dump is located
     524             :          *(depending on alphabet)
     525             :         keySetName(mp, "system/elektra/modules/"KDB_DEFAULT_RESOLVER); keySetString (mp, "modules");
     526             :         compare_key(mp, kdb->split->parents[4]);
     527             :         */
     528           2 :         keySetName (mp, "system/elektra");
     529           2 :         keySetString (mp, "default");
     530           2 :         compare_key (mp, kdb->split->parents[5]);
     531             : 
     532           2 :         keySetName (mp, "user/tests/simple");
     533           2 :         keySetString (mp, "simple");
     534           2 :         compare_key (mp, kdb->split->parents[4]);
     535             : 
     536           2 :         exit_if_fail (kdb->trie, "trie was not build up successfully");
     537             : 
     538             :         // output_trie (kdb->trie);
     539             : 
     540           2 :         Key * searchKey = keyNew ("", KEY_END);
     541           2 :         Key * rmp = keyNew ("", KEY_VALUE, "root", KEY_END);
     542           2 :         elektraKeySetName (rmp, "/", KEY_CASCADING_NAME);
     543           2 :         Backend * b2 = 0;
     544             : 
     545           2 :         keySetName (searchKey, "user");
     546           2 :         b2 = trieLookup (kdb->trie, searchKey);
     547           2 :         succeed_if (b2, "there should be a backend");
     548           2 :         if (b2) compare_key (b2->mountpoint, rmp);
     549             : 
     550             : 
     551           2 :         Backend * backend = 0;
     552           2 :         keySetName (searchKey, "user/tests/simple");
     553           2 :         backend = trieLookup (kdb->trie, searchKey);
     554           2 :         succeed_if (backend, "there should be a backend");
     555           2 :         if (backend) compare_key (backend->mountpoint, mp);
     556             : 
     557             : 
     558           2 :         keySetName (searchKey, "user/tests/simple/below");
     559           2 :         b2 = trieLookup (kdb->trie, searchKey);
     560           2 :         succeed_if (b2, "there should be a backend");
     561           2 :         succeed_if (backend == b2, "should be same backend");
     562           2 :         if (b2) compare_key (b2->mountpoint, mp);
     563             : 
     564             : 
     565           2 :         keySetName (searchKey, "user/tests/simple/deep/below");
     566           2 :         b2 = trieLookup (kdb->trie, searchKey);
     567           2 :         succeed_if (b2, "there should be a backend");
     568           2 :         succeed_if (backend == b2, "should be same backend");
     569           2 :         if (b2) compare_key (b2->mountpoint, mp);
     570             : 
     571           2 :         Key * dmp = keyNew ("", KEY_VALUE, "default", KEY_END);
     572           2 :         keySetName (searchKey, "system/elektra");
     573           2 :         b2 = trieLookup (kdb->trie, searchKey);
     574           2 :         succeed_if (b2, "there should be a backend");
     575           2 :         succeed_if (b2 == kdb->defaultBackend, "should be the default backend");
     576           2 :         if (b2) compare_key (b2->mountpoint, dmp);
     577             : 
     578           2 :         keySetName (searchKey, "system/elektra/below");
     579           2 :         b2 = trieLookup (kdb->trie, searchKey);
     580           2 :         succeed_if (b2, "there should be a backend");
     581           2 :         succeed_if (b2 == kdb->defaultBackend, "should be the default backend");
     582           2 :         if (b2) compare_key (b2->mountpoint, dmp);
     583             : 
     584           2 :         Key * mmp = keyNew ("system/elektra/modules", KEY_VALUE, "modules", KEY_END);
     585           2 :         keyAddBaseName (mmp, "default");
     586             : 
     587             :         /*
     588             :         keySetName(searchKey, "system/elektra/modules/default");
     589             :         b2 = trieLookup(kdb->trie, searchKey);
     590             :         succeed_if (b2, "there should be a backend");
     591             :         succeed_if (b2 != kdb->defaultBackend, "should not be the default backend");
     592             :         compare_key(b2->mountpoint, mmp);
     593             :         */
     594             : 
     595           2 :         keyDel (mmp);
     596           2 :         keyDel (dmp);
     597           2 :         keyDel (mp);
     598           2 :         keyDel (rmp);
     599             : 
     600           2 :         keyDel (searchKey);
     601             : 
     602           2 :         kdb_del (kdb);
     603           2 :         keyDel (errorKey);
     604           2 :         ksDel (modules);
     605           2 : }
     606             : 
     607           2 : static void test_defaultonly (void)
     608             : {
     609           2 :         printf ("Test mounting with default only\n");
     610             : 
     611           2 :         KDB * kdb = kdb_new ();
     612           2 :         Key * errorKey = keyNew (0);
     613           2 :         KeySet * modules = modules_config ();
     614           2 :         succeed_if (mountOpen (kdb, minimal_config (), modules, errorKey) == 0, "could not buildup mount");
     615           2 :         succeed_if (mountDefault (kdb, modules, 1, errorKey) == 0, "could not mount default backend");
     616             : 
     617             : 
     618             :         // output_split (kdb->split);
     619             : 
     620           2 :         succeed_if (kdb->split->size == 4, "size of split not correct");
     621           2 :         Key * mp = keyNew ("spec", KEY_VALUE, "default", KEY_END);
     622           2 :         compare_key (mp, kdb->split->parents[0]);
     623           2 :         keySetName (mp, "dir");
     624           2 :         keySetString (mp, "default");
     625           2 :         compare_key (mp, kdb->split->parents[1]);
     626           2 :         keySetName (mp, "user");
     627           2 :         keySetString (mp, "default");
     628           2 :         compare_key (mp, kdb->split->parents[2]);
     629           2 :         keySetName (mp, "system");
     630           2 :         keySetString (mp, "default");
     631           2 :         compare_key (mp, kdb->split->parents[3]);
     632             : 
     633           2 :         succeed_if (output_warnings (errorKey), "warnings found");
     634           2 :         succeed_if (output_error (errorKey), "error found");
     635             : 
     636           2 :         succeed_if (!kdb->trie, "trie should be empty");
     637             : 
     638           2 :         Key * searchKey = keyNew ("", KEY_END);
     639           2 :         Backend * b2 = 0;
     640             : 
     641           2 :         keySetName (searchKey, "user");
     642           2 :         b2 = trieLookup (kdb->trie, searchKey);
     643           2 :         succeed_if (b2 == 0, "should be default backend");
     644             : 
     645             : 
     646           2 :         keySetName (searchKey, "user/tests/simple");
     647           2 :         b2 = trieLookup (kdb->trie, searchKey);
     648           2 :         succeed_if (b2 == 0, "should be default backend");
     649             : 
     650             : 
     651           2 :         keySetName (searchKey, "user/tests/simple/below");
     652           2 :         b2 = trieLookup (kdb->trie, searchKey);
     653           2 :         succeed_if (b2 == 0, "should be default backend");
     654             : 
     655             : 
     656           2 :         keySetName (searchKey, "user/tests/simple/deep/below");
     657           2 :         b2 = trieLookup (kdb->trie, searchKey);
     658           2 :         succeed_if (b2 == 0, "should be default backend");
     659             : 
     660           2 :         keyDel (mp);
     661             : 
     662           2 :         keyDel (searchKey);
     663             : 
     664           2 :         kdb_del (kdb);
     665           2 :         keyDel (errorKey);
     666           2 :         ksDel (modules);
     667           2 : }
     668             : 
     669           2 : int main (int argc, char ** argv)
     670             : {
     671           2 :         printf ("MOUNTSPLIT    TESTS\n");
     672           2 :         printf ("===================\n\n");
     673             : 
     674           2 :         init (argc, argv);
     675             : 
     676           2 :         test_mount ();
     677           2 :         test_minimaltrie ();
     678           2 :         test_simple ();
     679           2 :         test_us ();
     680           2 :         test_cascading ();
     681           2 :         test_root ();
     682           2 :         test_default ();
     683           2 :         test_modules ();
     684           2 :         test_defaultonly ();
     685             : 
     686           2 :         printf ("\ntest_mountsplit RESULTS: %d test(s) done. %d error(s).\n", nbTest, nbError);
     687             : 
     688           2 :         return nbError;
     689             : }

Generated by: LCOV version 1.13