LCOV - code coverage report
Current view: top level - tests/ctest - test_cmerge.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 109 112 97.3 %
Date: 2019-09-12 12:28:41 Functions: 5 5 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 <kdbmerge.h>
      10             : #include <tests.h>
      11             : 
      12             : #define default_result_size 30 // Enough space for possible strange results
      13             : #define OUR_ROOT "user/our"
      14             : #define THEIR_ROOT "user/their"
      15             : #define BASE_ROOT "user/base"
      16             : #define RESULT_ROOT "user/result"
      17             : #define OUR_KEY1 "user/our/key1"
      18             : #define THEIR_KEY1 "user/their/key1"
      19             : #define BASE_KEY1 "user/base/key1"
      20             : #define RESULT_KEY1 "user/result/key1"
      21             : #define ORIGINAL_VALUE "1"
      22             : #define CHANGED_VALUE "2"
      23             : #define MORE_CHANGED_VALUE "3"
      24             : #define COMMENT "comment"
      25             : #define SOME_COMMENT "some_comment"
      26             : #define OTHER_COMMENT "other_comment"
      27             : #define OTHER_COMMENT_LENGTH 13
      28             : // This is arbitrarily chosen.
      29             : // In test cases were no conflict should occur the strategy is irrelevant.
      30             : #define MERGE_STRATEGY_IRRELEVANT 1
      31             : 
      32             : /**
      33             :  * When there is a single key in each key set and all key names are equal
      34             :  *
      35             :  * The parameters are the values for the single key in each set
      36             :  *
      37             :  * If a parameter is null then no key is set (!= key with empty value)
      38             :  *
      39             :  * If expected_result = NULL then the merge result must be NULL, this is for error cases
      40             :  * If expected_result = "EMPTY" then the merge result must not contain the key (it is completely
      41             :  * empty as only one key could be in it)
      42             :  */
      43         108 : static void simple_test (char * our_value, char * their_value, char * base_value, int strategy, char * expected_result)
      44             : {
      45         108 :         printf ("Executing %s with our=%s their=%s base=%s, strategy=%d, expected_result=%s\n", __func__, our_value, their_value,
      46             :                 base_value, strategy, expected_result);
      47         108 :         Key * our_root = keyNew ("user/our", KEY_END);
      48         108 :         Key * their_root = keyNew ("user/their", KEY_END);
      49         108 :         Key * base_root = keyNew ("user/base", KEY_END);
      50         108 :         Key * result_root = keyNew ("user/result", KEY_END);
      51         108 :         Key * informationKey = keyNew (0, KEY_END);
      52         108 :         KeySet * our = ksNew (0, KS_END);
      53         108 :         KeySet * their = ksNew (0, KS_END);
      54         108 :         KeySet * base = ksNew (0, KS_END);
      55         108 :         if (strcmp (our_value, "EMPTY") != 0)
      56             :         {
      57          78 :                 ksAppendKey (our, keyNew ("user/our/key", KEY_VALUE, our_value, KEY_END));
      58             :         }
      59         108 :         if (strcmp (their_value, "EMPTY") != 0)
      60             :         {
      61          78 :                 ksAppendKey (their, keyNew ("user/their/key", KEY_VALUE, their_value, KEY_END));
      62             :         }
      63         108 :         if (strcmp (base_value, "EMPTY") != 0)
      64             :         {
      65          78 :                 ksAppendKey (base, keyNew ("user/base/key", KEY_VALUE, base_value, KEY_END));
      66             :         }
      67         108 :         KeySet * result = elektraMerge (our, our_root, their, their_root, base, base_root, result_root, strategy, informationKey);
      68             : 
      69         108 :         if (expected_result == NULL)
      70             :         {
      71             :                 char msg[200];
      72          16 :                 snprintf (msg, 200,
      73             :                           "Executing %s with our=%s their=%s base=%s and strategy %i. Expected the merge result to be NULL but it was "
      74             :                           "existant.",
      75             :                           __func__, our_value, their_value, base_value, strategy);
      76          16 :                 succeed_if (result == NULL, msg);
      77             :         }
      78             :         else
      79             :         {
      80          92 :                 Key * resultKey = ksLookupByName (result, "user/result/key", 0);
      81          92 :                 if (resultKey == NULL)
      82             :                 {
      83             :                         char msg[200];
      84          26 :                         snprintf (msg, 200,
      85             :                                   "Executing %s with our=%s their=%s base=%s and strategy %i. Expected result to be %s and not an empty "
      86             :                                   "key set.\n",
      87             :                                   __func__, our_value, their_value, base_value, strategy, expected_result);
      88          26 :                         succeed_if (strcmp (expected_result, "EMPTY") == 0, msg);
      89          26 :                         succeed_if_same_string (expected_result, "EMPTY");
      90             :                 }
      91             :                 else
      92             :                 {
      93          66 :                         char * resultValue = elektraMalloc (default_result_size);
      94          66 :                         keyGetString (resultKey, resultValue, default_result_size);
      95             :                         char msg[200];
      96          66 :                         snprintf (msg, 200,
      97             :                                   "Executing %s with our=%s their=%s base=%s and strategy %i. Expected result was %s but in reality it was "
      98             :                                   "%s.\n",
      99             :                                   __func__, our_value, their_value, base_value, strategy, expected_result, resultValue);
     100          66 :                         succeed_if (strcmp (resultValue, expected_result) == 0, msg);
     101          66 :                         elektraFree (resultValue);
     102             :                 }
     103          92 :                 keyDel (resultKey); // Necessary?
     104             :         }
     105             : 
     106         108 :         ksDel (our);
     107         108 :         ksDel (their);
     108         108 :         ksDel (base);
     109         108 :         ksDel (result);
     110         108 :         keyDel (our_root);
     111         108 :         keyDel (their_root);
     112         108 :         keyDel (base_root);
     113         108 :         keyDel (result_root);
     114         108 :         keyDel (informationKey);
     115         108 : }
     116             : 
     117             : /**
     118             :  * Use this when the result of the merge is the same for all strategies
     119             :  */
     120          20 : static void all_strategies_same_result (char * our_value, char * their_value, char * base_value, char * expected_result)
     121             : {
     122          20 :         simple_test (our_value, their_value, base_value, MERGE_STRATEGY_ABORT, expected_result);
     123          20 :         simple_test (our_value, their_value, base_value, MERGE_STRATEGY_OUR, expected_result);
     124          20 :         simple_test (our_value, their_value, base_value, MERGE_STRATEGY_THEIR, expected_result);
     125          20 : }
     126             : 
     127             : /**
     128             :  * Use this when the merge conflicts or overlaps
     129             :  * According to https://www.gnu.org/software/diffutils/manual/html_node/diff3-Merging.html
     130             :  */
     131          16 : static void all_strategies_conflict (char * our_value, char * their_value, char * base_value)
     132             : {
     133          16 :         printf ("In %s with our=%s and their=%s and base=%s\n", __func__, our_value, their_value, base_value);
     134          16 :         simple_test (our_value, their_value, base_value, MERGE_STRATEGY_ABORT, NULL);
     135          16 :         simple_test (our_value, their_value, base_value, MERGE_STRATEGY_OUR, our_value);
     136          16 :         simple_test (our_value, their_value, base_value, MERGE_STRATEGY_THEIR, their_value);
     137          16 : }
     138             : 
     139           4 : static void test_order (char * our_order, char * their_order, char * base_order, int strategy, char * expected_result)
     140             : {
     141           4 :         printf ("Executing %s with our=%s their=%s base=%s, strategy=%d, expected_result=%s\n", __func__, our_order, their_order,
     142             :                 base_order, strategy, expected_result);
     143           4 :         Key * our_root = keyNew ("user/our", KEY_END);
     144           4 :         Key * their_root = keyNew ("user/their", KEY_END);
     145           4 :         Key * base_root = keyNew ("user/base", KEY_END);
     146           4 :         Key * result_root = keyNew ("user/result", KEY_END);
     147           4 :         Key * informationKey = keyNew (0, KEY_END);
     148           4 :         KeySet * our = ksNew (1, keyNew ("user/our/key", KEY_VALUE, "1", KEY_META, "order", our_order, KEY_END), KS_END);
     149           4 :         KeySet * their = ksNew (1, keyNew ("user/their/key", KEY_VALUE, "1", KEY_META, "order", their_order, KEY_END), KS_END);
     150           4 :         KeySet * base = ksNew (1, keyNew ("user/base/key", KEY_VALUE, "1", KEY_META, "order", base_order, KEY_END), KS_END);
     151             : 
     152           4 :         KeySet * result = elektraMerge (our, our_root, their, their_root, base, base_root, result_root, strategy, informationKey);
     153             : 
     154           4 :         if (expected_result == NULL)
     155             :         {
     156           0 :                 yield_error ("expected_result parameter must not be null");
     157             :         }
     158             :         else
     159             :         {
     160           4 :                 const Key * resultKey = ksLookupByName (result, "user/result/key", 0);
     161           4 :                 if (resultKey == NULL)
     162             :                 {
     163           0 :                         yield_error ("Lookup must succeed");
     164             :                 }
     165           4 :                 const Key * metaKey = keyGetMeta (resultKey, "order");
     166           4 :                 if (metaKey == NULL)
     167             :                 {
     168           0 :                         yield_error ("Meta key must exist");
     169             :                 }
     170           4 :                 char * resultValue = elektraMalloc (default_result_size);
     171           4 :                 keyGetString (metaKey, resultValue, default_result_size);
     172             :                 char msg[200];
     173           4 :                 snprintf (msg, 200,
     174             :                           "Executing %s with our=%s their=%s base=%s and strategy %i. Expected result was %s but in reality it was "
     175             :                           "%s.\n",
     176             :                           __func__, our_order, their_order, base_order, strategy, expected_result, resultValue);
     177           4 :                 succeed_if (strcmp (resultValue, expected_result) == 0, msg);
     178           4 :                 elektraFree (resultValue);
     179             :         }
     180             : 
     181           4 :         ksDel (our);
     182           4 :         ksDel (their);
     183           4 :         ksDel (base);
     184           4 :         ksDel (result);
     185           4 :         keyDel (our_root);
     186           4 :         keyDel (their_root);
     187           4 :         keyDel (base_root);
     188           4 :         keyDel (result_root);
     189           4 :         keyDel (informationKey);
     190           4 : }
     191             : 
     192             : /**
     193             :  * Changing a comment in a own configuration file leaves this comment be if an upgrade happens and
     194             :  * the comment changes
     195             :  * Similar to ucf https://packages.debian.org/sid/ucf
     196             :  * Base                 Ours                  Theirs                Result
     197             :  * key1=1               key1=1                key1=1                key1=1
     198             :  * comment=some_comment comment=other_comment comment=some_comment comment=other_comment
     199             :  *
     200             :  */
     201             : // static void test_15 (void)
     202             : // {
     203             : //      printf ("In test function %s\n", __func__);
     204             : //      Key * a = keyNew (OUR_ROOT, KEY_END);
     205             : //      Key * b = keyNew (THEIR_ROOT, KEY_END);
     206             : //      Key * c = keyNew (BASE_ROOT, KEY_END);
     207             : //      Key * d = keyNew (RESULT_ROOT, KEY_END);
     208             : //      KeySet * our = ksNew (1, keyNew (OUR_KEY1, KEY_VALUE, ORIGINAL_VALUE, KEY_META, COMMENT, OTHER_COMMENT, KEY_END), KS_END);
     209             : //      KeySet * their = ksNew (1, keyNew (THEIR_KEY1, KEY_VALUE, ORIGINAL_VALUE, KEY_META, COMMENT, SOME_COMMENT, KEY_END), KS_END);
     210             : //      KeySet * base = ksNew (1, keyNew (BASE_KEY1, KEY_VALUE, ORIGINAL_VALUE, KEY_META, COMMENT, SOME_COMMENT, KEY_END), KS_END);
     211             : //      KeySet * result = kdbMerge (our, a, their, b, base, c, d, MERGE_STRATEGY_IRRELEVANT);
     212             : 
     213             : //      Key * resultKey = ksLookupByName (result, RESULT_KEY1, 0);
     214             : //      if (resultKey == NULL)
     215             : //      {
     216             : //              yield_error ("Should not be NULL");
     217             : //      }
     218             : //      else
     219             : //      {
     220             : //              char * resultValue = elektraMalloc (default_result_size);
     221             : //              const Key * metakey = keyGetMeta (resultKey, COMMENT);
     222             : //              if (metakey == 0) yield_error ("Meta key must not be null");
     223             : //              succeed_if_same_string (keyValue (metakey), OTHER_COMMENT);
     224             : //              elektraFree (resultValue);
     225             : //      }
     226             : 
     227             : //      ksDel (our);
     228             : //      ksDel (their);
     229             : //      ksDel (base);
     230             : //      ksDel (result);
     231             : //      keyDel (a);
     232             : //      keyDel (b);
     233             : //      keyDel (c);
     234             : //      keyDel (d);
     235             : // }
     236             : 
     237             : ///**
     238             : // * When local changes have been done and the comment gets updated then really do this update
     239             : // * Base                 Ours                 Theirs                Result
     240             : // * key1=1               key1=1               key1=1                key1=1
     241             : // * comment=some_comment comment=some_comment comment=other_comment comment=other_comment
     242             : // *
     243             : // */
     244             : // static void test_16 (void)
     245             : //{
     246             : //      printf ("In test function %s\n", __func__);
     247             : //      KeySet * our = ksNew (1, keyNew (OUR_KEY1, KEY_VALUE, ORIGINAL_VALUE, KEY_META, COMMENT, SOME_COMMENT, KEY_END), KS_END);
     248             : //      KeySet * their = ksNew (1, keyNew (THEIR_KEY1, KEY_VALUE, ORIGINAL_VALUE, KEY_META, COMMENT, OTHER_COMMENT, KEY_END), KS_END);
     249             : //      KeySet * base = ksNew (1, keyNew (BASE_KEY1, KEY_VALUE, ORIGINAL_VALUE, KEY_META, COMMENT, SOME_COMMENT, KEY_END), KS_END);
     250             : //      KeySet * result = kdbMerge (our, keyNew (OUR_ROOT, KEY_END), their, keyNew (THEIR_ROOT, KEY_END), base, keyNew (BASE_ROOT, KEY_END),
     251             : //                                  keyNew (RESULT_ROOT, KEY_END), MERGE_STRATEGY_IRRELEVANT);
     252             : //
     253             : //      Key * resultKey = ksLookupByName (result, RESULT_KEY1, 0);
     254             : //      if (resultKey == NULL)
     255             : //      {
     256             : //              yield_error ("Should not be NULL");
     257             : //      }
     258             : //      else
     259             : //      {
     260             : //              char * resultValue = elektraMalloc (default_result_size);
     261             : //              const Key * metakey = keyGetMeta (resultKey, COMMENT);
     262             : //              if (metakey == 0) yield_error ("Meta key must not be null");
     263             : //              succeed_if_same_string (keyValue (metakey), OTHER_COMMENT);
     264             : //              elektraFree (resultValue);
     265             : //      }
     266             : //
     267             : //      ksDel (our);
     268             : //      ksDel (their);
     269             : //      ksDel (base);
     270             : //}
     271             : //
     272             : ///**
     273             : // * When local changes have been done and the comment gets updated then really do this update
     274             : // * Base                 Ours                 Theirs                Result
     275             : // * key1=1               key1=1               key1=1                key1=1
     276             : // * comment=some_comment comment=other_comment comment=some_comment comment=other_comment
     277             : // *
     278             : // */
     279             : // static void test_16a (void)
     280             : //{
     281             : //      printf ("In test function %s\n", __func__);
     282             : //      KeySet * our = ksNew (1, keyNew (OUR_KEY1, KEY_VALUE, ORIGINAL_VALUE, KEY_META, COMMENT, OTHER_COMMENT, KEY_END), KS_END);
     283             : //      KeySet * their = ksNew (1, keyNew (THEIR_KEY1, KEY_VALUE, ORIGINAL_VALUE, KEY_META, COMMENT, SOME_COMMENT, KEY_END), KS_END);
     284             : //      KeySet * base = ksNew (1, keyNew (BASE_KEY1, KEY_VALUE, ORIGINAL_VALUE, KEY_META, COMMENT, SOME_COMMENT, KEY_END), KS_END);
     285             : //      KeySet * result = kdbMerge (our, keyNew (OUR_ROOT, KEY_END), their, keyNew (THEIR_ROOT, KEY_END), base, keyNew (BASE_ROOT, KEY_END),
     286             : //                                  keyNew (RESULT_ROOT, KEY_END), MERGE_STRATEGY_IRRELEVANT);
     287             : //
     288             : //      Key * resultKey = ksLookupByName (result, RESULT_KEY1, 0);
     289             : //      if (resultKey == NULL)
     290             : //      {
     291             : //              yield_error ("Should not be NULL");
     292             : //      }
     293             : //      else
     294             : //      {
     295             : //              char * resultValue = elektraMalloc (default_result_size);
     296             : //              const Key * metakey = keyGetMeta (resultKey, COMMENT);
     297             : //              if (metakey == 0) yield_error ("Meta key must not be null");
     298             : //              succeed_if_same_string (keyValue (metakey), OTHER_COMMENT);
     299             : //              elektraFree (resultValue);
     300             : //      }
     301             : //
     302             : //      ksDel (our);
     303             : //      ksDel (their);
     304             : //      ksDel (base);
     305             : //}
     306             : //
     307             : ///**
     308             : // * Base                 Ours                 Theirs                Result
     309             : // * key1=1               key1=1               key1=1                key1=1
     310             : // * comment=other_comment comment=some_comment comment=some_comment comment=other_comment
     311             : // *
     312             : // */
     313             : // static void test_16b (void)
     314             : //{
     315             : //      printf ("In test function %s\n", __func__);
     316             : //      KeySet * our = ksNew (1, keyNew (OUR_KEY1, KEY_VALUE, ORIGINAL_VALUE, KEY_META, COMMENT, SOME_COMMENT, KEY_END), KS_END);
     317             : //      KeySet * their = ksNew (1, keyNew (THEIR_KEY1, KEY_VALUE, ORIGINAL_VALUE, KEY_META, COMMENT, SOME_COMMENT, KEY_END), KS_END);
     318             : //      KeySet * base = ksNew (1, keyNew (BASE_KEY1, KEY_VALUE, ORIGINAL_VALUE, KEY_META, COMMENT, OTHER_COMMENT, KEY_END), KS_END);
     319             : //      KeySet * result = kdbMerge (our, keyNew (OUR_ROOT, KEY_END), their, keyNew (THEIR_ROOT, KEY_END), base, keyNew (BASE_ROOT, KEY_END),
     320             : //                                  keyNew (RESULT_ROOT, KEY_END), MERGE_STRATEGY_IRRELEVANT);
     321             : //
     322             : //      Key * resultKey = ksLookupByName (result, RESULT_KEY1, 0);
     323             : //      if (resultKey == NULL)
     324             : //      {
     325             : //              yield_error ("Should not be NULL");
     326             : //      }
     327             : //      else
     328             : //      {
     329             : //              char * resultValue = elektraMalloc (default_result_size);
     330             : //              const Key * metakey = keyGetMeta (resultKey, COMMENT);
     331             : //              if (metakey == 0) yield_error ("Meta key must not be null");
     332             : //              succeed_if_same_string (keyValue (metakey), OTHER_COMMENT);
     333             : //              elektraFree (resultValue);
     334             : //      }
     335             : //
     336             : //      ksDel (our);
     337             : //      ksDel (their);
     338             : //      ksDel (base);
     339             : //}
     340             : //
     341             : ///**
     342             : // * Base                 Ours                 Theirs                Result
     343             : // * key1=1               key1=1               key1=1                key1=1
     344             : // * comment=other_comment comment=some_comment comment=some_comment comment=other_comment
     345             : // *
     346             : // */
     347             : // static void test_16c (void)
     348             : //{
     349             : //      printf ("In test function %s\n", __func__);
     350             : //      KeySet * our = ksNew (1, keyNew (OUR_KEY1, KEY_VALUE, ORIGINAL_VALUE, KEY_META, COMMENT, SOME_COMMENT, KEY_END), KS_END);
     351             : //      KeySet * their = ksNew (1, keyNew (THEIR_KEY1, KEY_VALUE, ORIGINAL_VALUE, KEY_META, COMMENT, SOME_COMMENT, KEY_END), KS_END);
     352             : //      KeySet * base = ksNew (1, keyNew (BASE_KEY1, KEY_VALUE, ORIGINAL_VALUE, KEY_META, COMMENT, OTHER_COMMENT, KEY_END), KS_END);
     353             : //      KeySet * result = kdbMerge (our, keyNew (OUR_ROOT, KEY_END), their, keyNew (THEIR_ROOT, KEY_END), base, keyNew (BASE_ROOT, KEY_END),
     354             : //                                  keyNew (RESULT_ROOT, KEY_END), MERGE_STRATEGY_IRRELEVANT);
     355             : //
     356             : //      Key * resultKey = ksLookupByName (result, RESULT_KEY1, 0);
     357             : //      if (resultKey == NULL)
     358             : //      {
     359             : //              yield_error ("Should not be NULL");
     360             : //      }
     361             : //      else
     362             : //      {
     363             : //              char * resultValue = elektraMalloc (default_result_size);
     364             : //              const Key * metakey = keyGetMeta (resultKey, COMMENT);
     365             : //              if (metakey == 0) yield_error ("Meta key must not be null");
     366             : //              succeed_if_same_string (keyValue (metakey), OTHER_COMMENT);
     367             : //              elektraFree (resultValue);
     368             : //      }
     369             : //
     370             : //      ksDel (our);
     371             : //      ksDel (their);
     372             : //      ksDel (base);
     373             : //}
     374             : //
     375             : ///**
     376             : // * This is the example from the file build/doc/html/doc_tutorials_merge_md.html
     377             : // *
     378             : // * Key 4 is deleted in our and changed in their key set. Strategy abort.
     379             : // */
     380             : // static void test_17 (void)
     381             : //{
     382             : //      printf ("In test function %s\n", __func__);
     383             : //      KeySet * their = ksNew (
     384             : //              5, keyNew ("user/their/key1", KEY_VALUE, "1", KEY_END), keyNew ("user/their/key2", KEY_VALUE, "pie", KEY_END),
     385             : //              keyNew ("user/their/key4", KEY_VALUE, "banana", KEY_END), keyNew ("user/their/key5", KEY_VALUE, "5", KEY_END), KS_END);
     386             : //
     387             : //      KeySet * our =
     388             : //              ksNew (4, keyNew ("user/our/key1", KEY_VALUE, "apple", KEY_END), keyNew ("user/our/key2", KEY_VALUE, "2", KEY_END),
     389             : //                     keyNew ("user/our/key3", KEY_VALUE, "3", KEY_END), keyNew ("user/our/key5", KEY_VALUE, "fish", KEY_END), KS_END);
     390             : //
     391             : //      KeySet * base = ksNew (5, keyNew ("user/base/key1", KEY_VALUE, "1", KEY_END), keyNew ("user/base/key2", KEY_VALUE, "2", KEY_END),
     392             : //                             keyNew ("user/base/key3", KEY_VALUE, "3", KEY_END), keyNew ("user/base/key4", KEY_VALUE, "4", KEY_END),
     393             : //                             keyNew ("user/base/key5", KEY_VALUE, "5", KEY_END), KS_END);
     394             : //      KeySet * result = kdbMerge (our, keyNew (OUR_ROOT, KEY_END), their, keyNew (THEIR_ROOT, KEY_END), base, keyNew (BASE_ROOT, KEY_END),
     395             : //                                  keyNew (RESULT_ROOT, KEY_END), MERGE_STRATEGY_ABORT);
     396             : //
     397             : //      succeed_if (result == NULL, "There should be a conflict and that should lead to NULL as keyset!");
     398             : //
     399             : //      ksDel (our);
     400             : //      ksDel (their);
     401             : //      ksDel (base);
     402             : //}
     403             : //
     404             : ///**
     405             : // * This is the example from the file build/doc/html/doc_tutorials_merge_md.html
     406             : // *
     407             : // * Key 4 is deleted in our and changed in their key set. Strategy our.
     408             : // */
     409             : // static void test_17a (void)
     410             : //{
     411             : //      printf ("In test function %s\n", __func__);
     412             : //      KeySet * their = ksNew (
     413             : //              5, keyNew ("user/their/key1", KEY_VALUE, "1", KEY_END), keyNew ("user/their/key2", KEY_VALUE, "pie", KEY_END),
     414             : //              keyNew ("user/their/key4", KEY_VALUE, "banana", KEY_END), keyNew ("user/their/key5", KEY_VALUE, "5", KEY_END), KS_END);
     415             : //
     416             : //      KeySet * our =
     417             : //              ksNew (4, keyNew ("user/our/key1", KEY_VALUE, "apple", KEY_END), keyNew ("user/our/key2", KEY_VALUE, "2", KEY_END),
     418             : //                     keyNew ("user/our/key3", KEY_VALUE, "3", KEY_END), keyNew ("user/our/key5", KEY_VALUE, "fish", KEY_END), KS_END);
     419             : //
     420             : //      KeySet * base = ksNew (5, keyNew ("user/base/key1", KEY_VALUE, "1", KEY_END), keyNew ("user/base/key2", KEY_VALUE, "2", KEY_END),
     421             : //                             keyNew ("user/base/key3", KEY_VALUE, "3", KEY_END), keyNew ("user/base/key4", KEY_VALUE, "4", KEY_END),
     422             : //                             keyNew ("user/base/key5", KEY_VALUE, "5", KEY_END), KS_END);
     423             : //      KeySet * result = kdbMerge (our, keyNew (OUR_ROOT, KEY_END), their, keyNew (THEIR_ROOT, KEY_END), base, keyNew (BASE_ROOT, KEY_END),
     424             : //                                  keyNew (RESULT_ROOT, KEY_END), MERGE_STRATEGY_OUR);
     425             : //
     426             : //      if (result == NULL)
     427             : //      {
     428             : //              yield_error ("Not the whole key set should be null. Only key 4 must not be found!\n");
     429             : //      }
     430             : //      Key * resultKey = ksLookupByName (result, "user/result/key4", 0);
     431             : //      succeed_if (resultKey == NULL, "key 4 must not be found!");
     432             : //
     433             : //      ksDel (our);
     434             : //      ksDel (their);
     435             : //      ksDel (base);
     436             : //}
     437             : ///**
     438             : // * This is the example from the file build/doc/html/doc_tutorials_merge_md.html
     439             : // * At the moment there is only the preserve strategy
     440             : // *
     441             : // * Key 4 is deleted in our and changed in their key set. Strategy their.
     442             : // */
     443             : // static void test_17b (void)
     444             : //{
     445             : //      printf ("In test function %s\n", __func__);
     446             : //      KeySet * their = ksNew (
     447             : //              5, keyNew ("user/their/key1", KEY_VALUE, "1", KEY_END), keyNew ("user/their/key2", KEY_VALUE, "pie", KEY_END),
     448             : //              keyNew ("user/their/key4", KEY_VALUE, "banana", KEY_END), keyNew ("user/their/key5", KEY_VALUE, "5", KEY_END), KS_END);
     449             : //
     450             : //      KeySet * our =
     451             : //              ksNew (4, keyNew ("user/our/key1", KEY_VALUE, "apple", KEY_END), keyNew ("user/our/key2", KEY_VALUE, "2", KEY_END),
     452             : //                     keyNew ("user/our/key3", KEY_VALUE, "3", KEY_END), keyNew ("user/our/key5", KEY_VALUE, "fish", KEY_END), KS_END);
     453             : //
     454             : //      KeySet * base = ksNew (5, keyNew ("user/base/key1", KEY_VALUE, "1", KEY_END), keyNew ("user/base/key2", KEY_VALUE, "2", KEY_END),
     455             : //                             keyNew ("user/base/key3", KEY_VALUE, "3", KEY_END), keyNew ("user/base/key4", KEY_VALUE, "4", KEY_END),
     456             : //                             keyNew ("user/base/key5", KEY_VALUE, "5", KEY_END), KS_END);
     457             : //      KeySet * result = kdbMerge (our, keyNew (OUR_ROOT, KEY_END), their, keyNew (THEIR_ROOT, KEY_END), base, keyNew (BASE_ROOT, KEY_END),
     458             : //                                  keyNew (RESULT_ROOT, KEY_END), MERGE_STRATEGY_THEIR);
     459             : //
     460             : //      Key * resultKey = ksLookupByName (result, "user/result/key4", 0);
     461             : //      if (resultKey == NULL)
     462             : //      {
     463             : //              yield_error ("Should not be NULL");
     464             : //      }
     465             : //      else
     466             : //      {
     467             : //              char * resultValue = elektraMalloc (default_result_size);
     468             : //              keyGetString (resultKey, resultValue, default_result_size);
     469             : //              succeed_if_same_string ("banana", resultValue);
     470             : //              elektraFree (resultValue);
     471             : //      }
     472             : //
     473             : //      ksDel (our);
     474             : //      ksDel (their);
     475             : //      ksDel (base);
     476             : //}
     477             : ///**
     478             : // * Adding two values to an array independently
     479             : // * base              our              their            result
     480             : // * [First Element]   [First Element]  [First Element]  [First Element]
     481             : // * [Second Element]  [Second Element] [Second Element] [Second Element]
     482             : // *                   [Third Element]                   [Third Element]
     483             : // *                                    [Fourth Element] [Fourth Element]
     484             : // */
     485             : // static void test_18 (void)
     486             : //{
     487             : //      printf ("In test function %s\n", __func__);
     488             : //      KeySet * base = ksNew (2, keyNew ("user/base/key1/#1", KEY_VALUE, "First Element", KEY_END),
     489             : //                             keyNew ("user/base/key1/#2", KEY_VALUE, "Second Element", KEY_END), KS_END);
     490             : //
     491             : //      KeySet * our = ksNew (3, keyNew ("user/our/key1/#1", KEY_VALUE, "First Element", KEY_END),
     492             : //                            keyNew ("user/our/key1/#2", KEY_VALUE, "Second Element", KEY_END),
     493             : //                            keyNew ("user/our/key1/#3", KEY_VALUE, "Third Element", KEY_END), KS_END);
     494             : //
     495             : //      KeySet * their = ksNew (3, keyNew ("user/their/key1/#1", KEY_VALUE, "First Element", KEY_END),
     496             : //                              keyNew ("user/their/key1/#2", KEY_VALUE, "Second Element", KEY_END),
     497             : //                              keyNew ("user/their/key1/#4", KEY_VALUE, "Fourth Element", KEY_END), KS_END);
     498             : //      KeySet * result = kdbMerge (our, keyNew (OUR_ROOT, KEY_END), their, keyNew (THEIR_ROOT, KEY_END), base, keyNew (BASE_ROOT, KEY_END),
     499             : //                                  keyNew (RESULT_ROOT, KEY_END), MERGE_STRATEGY_IRRELEVANT);
     500             : //
     501             : //      Key * resultKey = ksLookupByName (result, "user/result/key1/#3", 0);
     502             : //      char * resultValue = elektraMalloc (default_result_size);
     503             : //      if (keyGetString (resultKey, resultValue, default_result_size) <= 0)
     504             : //      {
     505             : //              yield_error ("Getting value has not worked")
     506             : //      }
     507             : //      else
     508             : //      {
     509             : //              succeed_if_same_string (resultValue, "Third Element");
     510             : //      }
     511             : //      elektraFree (resultValue);
     512             : //
     513             : //      Key * resultKey2 = ksLookupByName (result, "user/result/key1/#4", 0);
     514             : //      char * resultValue2 = elektraMalloc (default_result_size);
     515             : //      if (keyGetString (resultKey2, resultValue2, default_result_size) <= 1)
     516             : //      {
     517             : //              yield_error ("Getting second value has not worked")
     518             : //      }
     519             : //      else
     520             : //      {
     521             : //              succeed_if_same_string (resultValue2, "Fourth Element");
     522             : //      }
     523             : //      elektraFree (resultValue2);
     524             : //
     525             : //      ksDel (our);
     526             : //      ksDel (their);
     527             : //      ksDel (base);
     528             : //}
     529             : 
     530           2 : int main (int argc, char ** argv)
     531             : {
     532           2 :         printf ("CMERGE       TESTS\n");
     533           2 :         printf ("==================\n\n");
     534             : 
     535           2 :         init (argc, argv);
     536           2 :         all_strategies_same_result ("EMPTY", "EMPTY", "EMPTY", "EMPTY");
     537           2 :         all_strategies_conflict ("EMPTY", "EMPTY", "1");
     538           2 :         all_strategies_same_result ("EMPTY", "1", "EMPTY", "1");
     539           2 :         all_strategies_same_result ("EMPTY", "1", "1", "EMPTY");
     540           2 :         all_strategies_same_result ("1", "EMPTY", "EMPTY", "1");
     541           2 :         all_strategies_same_result ("1", "EMPTY", "1", "EMPTY");
     542           2 :         all_strategies_conflict ("1", "1", "EMPTY");
     543           2 :         all_strategies_same_result ("1", "1", "1", "1");
     544           2 :         all_strategies_conflict ("1", "1", "2");
     545           2 :         all_strategies_same_result ("1", "2", "1", "2");
     546           2 :         all_strategies_same_result ("1", "2", "2", "1");
     547           2 :         all_strategies_same_result ("2", "1", "1", "2");
     548           2 :         all_strategies_same_result ("2", "1", "2", "1");
     549           2 :         all_strategies_conflict ("2", "2", "1");
     550           2 :         all_strategies_conflict ("1", "2", "3");
     551           2 :         all_strategies_conflict ("1", "2", "EMPTY");
     552           2 :         all_strategies_conflict ("1", "EMPTY", "3");
     553           2 :         all_strategies_conflict ("EMPTY", "2", "3");
     554           2 :         test_order ("1", "1", "1", 1, "1");
     555           2 :         test_order ("2", "1", "1", 1, "2");
     556             : 
     557             : 
     558             :         // test_15 ();
     559             :         //      test_16 ();
     560             :         //      test_17 ();
     561             :         //      test_17a ();
     562             :         //      test_17b ();
     563             :         //      test_18 ();
     564             : 
     565             : 
     566           2 :         printf ("\ntest_merge RESULTS: %d test(s) done. %d error(s).\n", nbTest, nbError);
     567             : 
     568           2 :         return nbError;
     569             : }

Generated by: LCOV version 1.13