LCOV - code coverage report
Current view: top level - tests/src - test0020.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 105 105
Test Date: 2026-01-12 05:34:38 Functions: 100.0 % 8 8

            Line data    Source code
       1              : #include "sute.h"
       2              : 
       3              : /**
       4              :  *
       5              :  * Testing database creation attempt in missing directory
       6              :  *
       7              :  */
       8            2 : Return test0020_1(void)
       9              : {
      10            2 :         INITTEST;
      11              : 
      12            2 :         create(char,result);
      13              : 
      14            2 :         create(char,pattern);
      15              : 
      16            2 :         const char *filename = "templates/0020_001.txt";
      17              : 
      18            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      19              : 
      20            2 :         ASSERT(SUCCESS == runit("--update --database=nonexistent_directory/database1.db tests/examples/diffs/diff1",result,FAILURE,ALLOW_BOTH));
      21              : 
      22            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      23              : 
      24              :         // Match the result against the pattern
      25            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      26              : 
      27              :         // Clean to use it iteratively
      28            2 :         del(pattern);
      29            2 :         del(result);
      30              : 
      31            2 :         RETURN_STATUS;
      32              : }
      33              : 
      34              : /**
      35              :  *
      36              :  * Testing attempt to open DB with --update when database is missing
      37              :  *
      38              :  */
      39            2 : Return test0020_2(void)
      40              : {
      41            2 :         INITTEST;
      42              : 
      43            2 :         create(char,result);
      44              : 
      45            2 :         create(char,pattern);
      46              : 
      47            2 :         const char *filename = "templates/0020_002.txt";
      48              : 
      49            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      50              : 
      51            2 :         ASSERT(SUCCESS == runit("--update --database=nonexistent_database1.db tests/examples/diffs/diff1",result,FAILURE,ALLOW_BOTH));
      52              : 
      53            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      54              : 
      55              :         // Match the result against the pattern
      56            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      57              : 
      58              :         // Clean to use it iteratively
      59            2 :         del(pattern);
      60            2 :         del(result);
      61              : 
      62            2 :         RETURN_STATUS;
      63              : }
      64              : 
      65              : /**
      66              :  *
      67              :  * Testing DB creation in write protected directory
      68              :  *
      69              :  */
      70            2 : Return test0020_3(void)
      71              : {
      72            2 :         INITTEST;
      73              : 
      74            2 :         create(char,result);
      75              : 
      76            2 :         create(char,pattern);
      77              : 
      78            2 :         const char *command = "cd ${TMPDIR} && "
      79              :                 "mkdir write_protected_directory && "
      80              :                 "chmod a-rwx write_protected_directory";
      81              : 
      82            2 :         ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
      83              : 
      84            2 :         const char *filename = "templates/0020_003.txt";
      85              : 
      86            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      87              : 
      88            2 :         ASSERT(SUCCESS == runit("--database=write_protected_directory/database1.db tests/examples/diffs/diff1",result,FAILURE,ALLOW_BOTH));
      89              : 
      90            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      91              : 
      92              :         // Match the result against the pattern
      93            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      94              : 
      95              :         // Clean to use it iteratively
      96            2 :         del(pattern);
      97            2 :         del(result);
      98              : 
      99            2 :         ASSERT(SUCCESS == external_call("cd ${TMPDIR} && chmod a+rwx write_protected_directory && rm -rf write_protected_directory",COMPLETED,ALLOW_BOTH));
     100              : 
     101            2 :         RETURN_STATUS;
     102              : }
     103              : 
     104              : /**
     105              :  *
     106              :  * Testing attempt to open DB with write protected database file
     107              :  *
     108              :  */
     109            2 : Return test0020_4(void)
     110              : {
     111            2 :         INITTEST;
     112              : 
     113            2 :         create(char,result);
     114              : 
     115            2 :         create(char,pattern);
     116              : 
     117            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     118              : 
     119            2 :         ASSERT(SUCCESS == runit("--database=write_protected_database1.db tests/examples/diffs/diff1",NULL,COMPLETED,ALLOW_BOTH));
     120            2 :         ASSERT(SUCCESS == runit("--database=database2.db tests/examples/diffs/diff2",NULL,COMPLETED,ALLOW_BOTH));
     121              : 
     122            2 :         const char *command = "cd ${TMPDIR} && "
     123              :                 "chmod a-rwx write_protected_database1.db";
     124              : 
     125            2 :         ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
     126              : 
     127            2 :         const char *filename = "templates/0020_004.txt";
     128              : 
     129            2 :         ASSERT(SUCCESS == runit("--compare write_protected_database1.db database2.db",result,FAILURE,ALLOW_BOTH));
     130              : 
     131            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     132              : 
     133              :         // Match the result against the pattern
     134            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     135              : 
     136              :         // Clean to use it iteratively
     137            2 :         del(pattern);
     138            2 :         del(result);
     139              : 
     140            2 :         ASSERT(SUCCESS == external_call("cd ${TMPDIR} && rm database2.db",COMPLETED,ALLOW_BOTH));
     141              : 
     142            2 :         RETURN_STATUS;
     143              : }
     144              : 
     145              : /**
     146              :  *
     147              :  * Testing attempt to update DB with --update when database file is write protected
     148              :  *
     149              :  */
     150            2 : Return test0020_5(void)
     151              : {
     152            2 :         INITTEST;
     153              : 
     154            2 :         create(char,result);
     155              : 
     156            2 :         create(char,pattern);
     157              : 
     158            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     159              : 
     160            2 :         const char *filename = "templates/0020_005.txt";
     161              : 
     162            2 :         ASSERT(SUCCESS == runit("--update --database=write_protected_database1.db tests/examples/diffs/diff1",result,FAILURE,ALLOW_BOTH));
     163              : 
     164            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     165              : 
     166              :         // Match the result against the pattern
     167            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     168              : 
     169              :         // Clean to use it iteratively
     170            2 :         del(pattern);
     171            2 :         del(result);
     172              : 
     173            2 :         ASSERT(SUCCESS == external_call("cd ${TMPDIR} && rm -f write_protected_database1.db",COMPLETED,ALLOW_BOTH));
     174              : 
     175            2 :         RETURN_STATUS;
     176              : }
     177              : 
     178              : /**
     179              :  *
     180              :  * Attempt to change the primary path in the database
     181              :  *
     182              :  */
     183            2 : Return test0020_6(void)
     184              : {
     185            2 :         INITTEST;
     186              : 
     187            2 :         create(char,result);
     188              : 
     189            2 :         create(char,pattern);
     190              : 
     191            2 :         const char *filename = "templates/0020_006.txt";
     192              : 
     193            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     194              : 
     195            2 :         ASSERT(SUCCESS == runit("--database=database1.db tests/examples/diffs/diff1",result,COMPLETED,ALLOW_BOTH));
     196            2 :         ASSERT(SUCCESS == runit("--update --database=database1.db tests/examples/diffs/diff2",result,WARNING,ALLOW_BOTH));
     197              : 
     198            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     199              : 
     200              :         // Match the result against the pattern
     201            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     202              : 
     203              :         // Clean to use it iteratively
     204            2 :         del(pattern);
     205            2 :         del(result);
     206              : 
     207            2 :         RETURN_STATUS;
     208              : }
     209              : 
     210              : /**
     211              :  *
     212              :  * Replace the primary path in the database
     213              :  *
     214              :  */
     215            2 : Return test0020_7(void)
     216              : {
     217            2 :         INITTEST;
     218              : 
     219            2 :         create(char,result);
     220              : 
     221            2 :         create(char,pattern);
     222              : 
     223            2 :         const char *filename = "templates/0020_007.txt";
     224              : 
     225            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     226              : 
     227            2 :         ASSERT(SUCCESS == runit("--update --force --database=database1.db tests/examples/diffs/diff2",result,COMPLETED,ALLOW_BOTH));
     228              : 
     229            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     230              : 
     231              :         // Match the result against the pattern
     232            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     233              : 
     234              :         // Clean to use it iteratively
     235            2 :         del(pattern);
     236            2 :         del(result);
     237              : 
     238            2 :         ASSERT(SUCCESS == external_call("cd ${TMPDIR} && rm -f database1.db",COMPLETED,ALLOW_BOTH));
     239              : 
     240            2 :         RETURN_STATUS;
     241              : }
     242              : 
     243            2 : Return test0020(void)
     244              : {
     245            2 :         INITTEST;
     246              : 
     247            2 :         TEST(test0020_1,"DB creation in missing directory…")
     248            2 :         TEST(test0020_2,"Attempt to open DB with --update when database is missing…")
     249            2 :         TEST(test0020_3,"DB creation in write protected directory…")
     250            2 :         TEST(test0020_4,"Attempt to open DB with write protected database file…")
     251            2 :         TEST(test0020_5,"Attempt to update DB with --update when database file is write protected…")
     252            2 :         TEST(test0020_6,"Attempt to change the primary path in the database…")
     253            2 :         TEST(test0020_7,"Replace the primary path in the database…")
     254              : 
     255            2 :         RETURN_STATUS;
     256              : }
        

Generated by: LCOV version 2.0-1