LCOV - code coverage report
Current view: top level - tests/src - test0020.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 117 117
Test Date: 2026-03-31 13:51:38 Functions: 100.0 % 8 8
Branches: - 0 0

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

Generated by: LCOV version 2.0-1