LCOV - code coverage report
Current view: top level - tests/src - test0013.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 290 290
Test Date: 2026-03-01 04:31:48 Functions: 100.0 % 9 9
Branches: 48.5 % 582 282

             Branch data     Line data    Source code
       1                 :             : #include "sute.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  * The db file should not be created in the Dry Run mode
       5                 :             :  */
       6                 :           2 : static Return test0013_1(void)
       7                 :             : {
       8                 :           2 :         INITTEST;
       9                 :             : 
      10                 :           2 :         create(char,result);
      11                 :             : 
      12   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      13                 :             : 
      14                 :           2 :         const char *arguments = "--dry-run --database=database1.db tests/fixtures/diffs/diff1";
      15                 :             : 
      16   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
      17                 :             : 
      18                 :             :         #if 0
      19                 :             :         echo(STDOUT,"%s\n",getcstring(result));
      20                 :             :         #endif
      21                 :             : 
      22                 :           2 :         del(result);
      23                 :             : 
      24                 :             :         // Does file exists or not
      25                 :           2 :         const char *db_filename = "database1.db";
      26                 :           2 :         create(char,path);
      27                 :           2 :         bool file_exists = false;
      28                 :             : 
      29   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == construct_path(db_filename,path));
      30                 :             : 
      31   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == check_file_exists(&file_exists,getcstring(path)));
      32                 :             : 
      33                 :           2 :         del(path);
      34                 :             : 
      35                 :             :         // Should not be exists
      36   [ +  -  +  - ]:           2 :         ASSERT(file_exists == false);
      37                 :             : 
      38   [ +  -  -  +  :           2 :         RETURN_STATUS;
          -  -  -  +  +  
                      - ]
      39                 :             : }
      40                 :             : 
      41                 :             : /**
      42                 :             :  * In dry-run mode with checksums, files are hashed but DB is still not modified
      43                 :             :  */
      44                 :           2 : static Return test0013_2(void)
      45                 :             : {
      46                 :           2 :         INITTEST;
      47                 :             : 
      48                 :           2 :         create(char,result);
      49                 :           2 :         create(char,pattern);
      50                 :           2 :         create(char,path);
      51                 :           2 :         bool file_exists = false;
      52                 :             : 
      53                 :           2 :         const char *command = "cd ${TMPDIR}; rm -f dry_run_regular.db dry_run_with_checksums.db;";
      54   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
      55                 :             : 
      56   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      57                 :             : 
      58                 :           2 :         const char *arguments = "--dry-run --database=dry_run_regular.db tests/fixtures/diffs/diff1";
      59   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
      60                 :             : 
      61                 :           2 :         const char *filename = "templates/0013_001_1.txt";
      62   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      63   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      64                 :             : 
      65                 :           2 :         del(pattern);
      66                 :           2 :         del(result);
      67                 :             : 
      68                 :           2 :         arguments = "--dry-run=with-checksums --database=dry_run_with_checksums.db tests/fixtures/diffs/diff1";
      69   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
      70                 :             : 
      71                 :           2 :         filename = "templates/0013_001_2.txt";
      72   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      73   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      74                 :             : 
      75                 :           2 :         del(pattern);
      76                 :           2 :         del(result);
      77                 :           2 :         del(path);
      78                 :             : 
      79                 :             :         /* Dry-run should not create either DB file. */
      80   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == construct_path("dry_run_regular.db",path));
      81   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == check_file_exists(&file_exists,getcstring(path)));
      82   [ +  -  +  - ]:           2 :         ASSERT(file_exists == false);
      83                 :             : 
      84                 :           2 :         del(path);
      85   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == construct_path("dry_run_with_checksums.db",path));
      86   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == check_file_exists(&file_exists,getcstring(path)));
      87   [ +  -  +  - ]:           2 :         ASSERT(file_exists == false);
      88                 :             : 
      89                 :           2 :         del(path);
      90                 :             : 
      91   [ +  -  -  +  :           2 :         RETURN_STATUS;
          -  -  -  +  +  
                      - ]
      92                 :             : }
      93                 :             : 
      94                 :             : /**
      95                 :             :  * Invalid dry-run mode should fail with error in stderr
      96                 :             :  */
      97                 :           2 : static Return test0013_3(void)
      98                 :             : {
      99                 :           2 :         INITTEST;
     100                 :             : 
     101                 :           2 :         create(char,result);
     102                 :           2 :         create(char,pattern);
     103                 :             : 
     104   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     105                 :             : 
     106                 :           2 :         const char *arguments = "--dry-run=bad-mode --database=dry_run_invalid.db tests/fixtures/diffs/diff1";
     107                 :             : 
     108   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,NULL,result,FAILURE,STDERR_ALLOW));
     109                 :             : 
     110                 :           2 :         const char *filename = "templates/0013_001_3.txt";
     111                 :             : 
     112   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     113   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     114                 :             : 
     115                 :           2 :         del(pattern);
     116                 :           2 :         del(result);
     117                 :             : 
     118   [ +  -  -  +  :           2 :         RETURN_STATUS;
          -  -  -  +  +  
                      - ]
     119                 :             : }
     120                 :             : 
     121                 :             : /**
     122                 :             :  * The db file should not be updated in the Dry Run mode
     123                 :             :  */
     124                 :           2 : static Return test0013_4(void)
     125                 :             : {
     126                 :           2 :         INITTEST;
     127                 :             : 
     128                 :             :         // Create memory for the result
     129                 :           2 :         create(char,result);
     130                 :             :         struct stat stat1;
     131                 :             :         struct stat stat2;
     132                 :           2 :         create(char,pattern);
     133                 :           2 :         create(char,chunk);
     134                 :             : 
     135                 :           2 :         const char *command = "cd ${TMPDIR};"
     136                 :             :                 "mv tests/fixtures/diffs/diff1 tests/fixtures/diff1_backup;"
     137                 :             :                 "cp -a tests/fixtures/diff1_backup tests/fixtures/diffs/diff1;";
     138                 :             : 
     139                 :             :         // Preparation for tests
     140   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
     141                 :             : 
     142   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     143                 :             : 
     144                 :           2 :         const char *arguments = "--database=database1.db tests/fixtures/diffs/diff1";
     145                 :             : 
     146   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
     147                 :             : 
     148                 :             :         #if 0
     149                 :             :         printf("Path: %s\n",path);
     150                 :             :         echo(STDOUT,"Path: %s\n",path);
     151                 :             :         #endif
     152                 :             : 
     153                 :           2 :         create(char,path);
     154                 :             : 
     155                 :           2 :         const char *db_filename = "database1.db";
     156                 :             : 
     157   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == construct_path(db_filename,path));
     158                 :             : 
     159   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat1));
     160                 :             : 
     161                 :           2 :         command = "cd ${TMPDIR};"
     162                 :             :                 "rm tests/fixtures/diffs/diff1/2/AAA/BBB/CZC/a.txt;" // Remove
     163                 :             :                 "echo -n AFAKDSJ >> tests/fixtures/diffs/diff1/1/AAA/ZAW/D/e/f/b_file.txt;" // Modify
     164                 :             :                 "echo -n WNEURHGO > tests/fixtures/diffs/diff1/2/AAA/BBB/CZC/b.txt;"; // New file
     165                 :             : 
     166   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
     167                 :             : 
     168                 :           2 :         arguments = "--dry-run --update --database=database1.db"
     169                 :             :                 " tests/fixtures/diffs/diff1";
     170                 :             : 
     171   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,chunk,NULL,COMPLETED,ALLOW_BOTH));
     172   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == copy(result,chunk));
     173                 :             : 
     174                 :             :         #if 0
     175                 :             :         printf("%s\n",getcstring(result));
     176                 :             :         echo(STDOUT,"%s\n",getcstring(result));
     177                 :             :         #endif
     178                 :             : 
     179                 :           2 :         del(result);
     180                 :           2 :         del(chunk);
     181                 :             : 
     182   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat2));
     183                 :             : 
     184   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == check_file_identity(&stat1,&stat2));
     185                 :             : 
     186                 :             :         // Compare against the sample. A message should be displayed indicating
     187                 :             :         // that the --db-drop-ignored option must be specified for permanent
     188                 :             :         // removal of ignored files from the database
     189   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     190                 :             : 
     191                 :           2 :         arguments = "--dry-run --ignore=\"^1/AAA/ZAW/.*\" --update "
     192                 :             :                 "--database=database1.db tests/fixtures/diffs/diff1";
     193                 :             : 
     194   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
     195                 :             : 
     196                 :             :         #if 0
     197                 :             :         echo(STDOUT,"%s\n",getcstring(result));
     198                 :             :         #endif
     199                 :             : 
     200                 :           2 :         const char *filename = "templates/0013_002_1.txt";
     201                 :             : 
     202   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     203   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     204                 :             : 
     205                 :           2 :         del(pattern);
     206                 :             : 
     207                 :           2 :         del(result);
     208                 :             : 
     209   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat2));
     210                 :             : 
     211   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == check_file_identity(&stat1,&stat2));
     212                 :             : 
     213                 :             :         // Dry Run mode permanent deletion of all ignored file
     214                 :             :         // references from the database
     215   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     216                 :             : 
     217                 :           2 :         arguments = "--dry-run --db-drop-ignored --update"
     218                 :             :                 " --ignore=\"^1/AAA/ZAW/D/e/f/b_file\\..*\""
     219                 :             :                 " --database=database1.db tests/fixtures/diffs/diff1";
     220                 :             : 
     221   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
     222                 :             : 
     223                 :             :         #if 0
     224                 :             :         echo(STDOUT,"%s\n",getcstring(result));
     225                 :             :         #endif
     226                 :             : 
     227                 :           2 :         filename = "templates/0013_002_2.txt";
     228                 :             : 
     229   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     230                 :             : 
     231   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     232                 :             : 
     233                 :           2 :         del(pattern);
     234                 :             : 
     235                 :           2 :         del(result);
     236                 :             : 
     237   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat2));
     238                 :             : 
     239   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == check_file_identity(&stat1,&stat2));
     240                 :             : 
     241   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     242                 :             : 
     243                 :           2 :         arguments = "--dry-run --db-drop-ignored --update --watch-timestamps"
     244                 :             :                 " --ignore=\"^path2/AAA/ZAW/.*\""
     245                 :             :                 " --database=database1.db tests/fixtures/diffs/diff1";
     246                 :             : 
     247   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
     248                 :             : 
     249                 :             :         #if 0
     250                 :             :         echo(STDOUT,"%s\n",getcstring(result));
     251                 :             :         #endif
     252                 :             : 
     253                 :           2 :         filename = "templates/0013_002_3.txt";
     254                 :             : 
     255   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     256                 :             : 
     257   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     258                 :             : 
     259                 :           2 :         del(pattern);
     260                 :             : 
     261                 :           2 :         del(result);
     262                 :             : 
     263   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat2));
     264                 :             : 
     265   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == check_file_identity(&stat1,&stat2));
     266                 :             : 
     267                 :           2 :         del(path);
     268                 :             : 
     269                 :             :         // Clean up test results
     270                 :           2 :         command = "cd ${TMPDIR} && "
     271                 :             :                 "rm database1.db && "
     272                 :             :                 "rm -rf tests/fixtures/diffs/diff1 && "
     273                 :             :                 "mv tests/fixtures/diff1_backup tests/fixtures/diffs/diff1";
     274                 :             : 
     275   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
     276                 :             : 
     277   [ +  -  -  +  :           2 :         RETURN_STATUS;
          -  -  -  +  +  
                      - ]
     278                 :             : }
     279                 :             : 
     280                 :             : /**
     281                 :             :  * Everything that was previously executed in Dry Run mode
     282                 :             :  * will now be tested in live mode without simulation, and
     283                 :             :  * the results will be compared against each other
     284                 :             :  */
     285                 :           2 : static Return test0013_5(void)
     286                 :             : {
     287                 :           2 :         INITTEST;
     288                 :             :         // Create memory for the result
     289                 :           2 :         create(char,result);
     290                 :           2 :         create(char,path);
     291                 :           2 :         create(char,pattern);
     292                 :           2 :         const char *db_file_name = "database1.db";
     293                 :           2 :         const char *command = NULL;
     294                 :           2 :         const char *arguments = NULL;
     295                 :             : 
     296                 :             :         // Preparation for tests
     297                 :           2 :         command = "cd ${TMPDIR};"
     298                 :             :                 "mv tests/fixtures/diffs/diff1 tests/fixtures/diff1_backup;"
     299                 :             :                 "cp -a tests/fixtures/diff1_backup tests/fixtures/diffs/diff1;";
     300                 :             : 
     301   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
     302                 :             : 
     303   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == construct_path(db_file_name,path));
     304                 :             : 
     305   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     306                 :             : 
     307                 :           2 :         arguments = "--database=database1.db tests/fixtures/diffs/diff1";
     308                 :             : 
     309   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
     310                 :             : 
     311                 :             :         #if 0
     312                 :             :         echo(STDOUT,"Path: %s\n",path);
     313                 :             :         #endif
     314                 :             : 
     315                 :           2 :         command = "cd ${TMPDIR};"
     316                 :             :                 "rm tests/fixtures/diffs/diff1/2/AAA/BBB/CZC/a.txt;"
     317                 :             :                 "echo -n AFAKDSJ >> tests/fixtures/diffs/diff1/1/AAA/ZAW/D/e/f/b_file.txt;"
     318                 :             :                 "echo -n WNEURHGO > tests/fixtures/diffs/diff1/2/AAA/BBB/CZC/b.txt;"; // New file
     319                 :             : 
     320   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
     321                 :             : 
     322                 :             :         #if 0
     323                 :             :         echo(STDOUT,"%s\n",getcstring(result));
     324                 :             :         #endif
     325                 :             : 
     326                 :           2 :         del(result);
     327                 :             : 
     328                 :             :         // Compare against the sample. A message should be displayed indicating
     329                 :             :         // that the --db-drop-ignored option must be specified for permanent
     330                 :             :         // removal of ignored files from the database
     331                 :           2 :         command = "cd ${TMPDIR};"
     332                 :             :                 "cp -a database1.db database1.db.backup;";
     333                 :             : 
     334   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
     335                 :             : 
     336                 :           2 :         arguments = "--ignore=\"^1/AAA/ZAW/.*\" --update --database=database1.db "
     337                 :             :                 "tests/fixtures/diffs/diff1";
     338                 :             : 
     339   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
     340                 :             : 
     341                 :             :         #if 0
     342                 :             :         echo(STDOUT,"%s\n",getcstring(result));
     343                 :             :         #endif
     344                 :             : 
     345                 :           2 :         const char *filename = "templates/0013_003_1.txt";
     346                 :             : 
     347   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     348   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     349                 :             : 
     350                 :           2 :         del(pattern);
     351                 :             : 
     352                 :           2 :         del(result);
     353                 :             : 
     354                 :             :         // Real live mode permanent deletion of all ignored file
     355                 :             :         // references from the database
     356                 :           2 :         command = "cd ${TMPDIR};"
     357                 :             :                 "cp -a database1.db.backup database1.db;";
     358                 :             : 
     359   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
     360                 :             : 
     361                 :           2 :         arguments = "--db-drop-ignored --update"
     362                 :             :                 " --ignore=\"^1/AAA/ZAW/D/e/f/b_file\\..*\""
     363                 :             :                 " --database=database1.db tests/fixtures/diffs/diff1";
     364                 :             : 
     365   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
     366                 :             : 
     367                 :             :         #if 0
     368                 :             :         echo(STDOUT,"%s\n",getcstring(result));
     369                 :             :         #endif
     370                 :             : 
     371                 :           2 :         filename = "templates/0013_003_2.txt";
     372                 :             : 
     373   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     374   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     375                 :             : 
     376                 :           2 :         del(pattern);
     377                 :             : 
     378                 :           2 :         del(result);
     379                 :             : 
     380                 :           2 :         command = "cd ${TMPDIR};"
     381                 :             :                 "mv database1.db.backup database1.db;";
     382                 :             : 
     383   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
     384                 :             : 
     385                 :           2 :         arguments = "--watch-timestamps --db-drop-ignored "
     386                 :             :                 "--ignore=\"^path2/AAA/ZAW/.*\" --update "
     387                 :             :                 "--database=database1.db tests/fixtures/diffs/diff1";
     388                 :             : 
     389   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
     390                 :             : 
     391                 :             :         #if 0
     392                 :             :         echo(STDOUT,"%s\n",getcstring(result));
     393                 :             :         #endif
     394                 :             : 
     395                 :           2 :         filename = "templates/0013_003_3.txt";
     396                 :             : 
     397   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     398   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     399                 :             : 
     400                 :           2 :         del(pattern);
     401                 :             : 
     402                 :           2 :         del(result);
     403                 :             : 
     404                 :           2 :         del(path);
     405                 :             : 
     406                 :             :         // Clean up test results
     407                 :           2 :         command = "cd ${TMPDIR} && "
     408                 :             :                 "rm database1.db && "
     409                 :             :                 "rm -rf tests/fixtures/diffs/diff1 && "
     410                 :             :                 "mv tests/fixtures/diff1_backup tests/fixtures/diffs/diff1";
     411                 :             : 
     412   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
     413                 :             : 
     414   [ +  -  -  +  :           2 :         RETURN_STATUS;
          -  -  -  +  +  
                      - ]
     415                 :             : }
     416                 :             : 
     417                 :           2 : Return test0013_6(void)
     418                 :             : {
     419                 :           2 :         INITTEST;
     420                 :             : 
     421                 :           2 :         create(char,text1);
     422                 :           2 :         create(char,text2);
     423                 :           2 :         char *diff = NULL;
     424                 :           2 :         create(char,pattern);
     425                 :           2 :         const char *filename = NULL;
     426                 :             : 
     427                 :             :         /* 0013 002 1 */
     428   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content("templates/0013_002_1.txt",text1));
     429                 :             : 
     430   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content("templates/0013_003_1.txt",text2));
     431                 :             : 
     432   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == compare_strings(&diff,getcstring(text1),getcstring(text2)));
     433                 :             : 
     434                 :           2 :         filename = "templates/0013_004_1.txt";
     435                 :             : 
     436   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     437                 :           2 :         create(char,diff_buffer);
     438   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == copy_literal(diff_buffer,diff));
     439   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(diff_buffer,pattern,filename));
     440                 :             : 
     441                 :           2 :         del(text1);
     442                 :           2 :         del(text2);
     443                 :           2 :         reset(&diff);
     444                 :           2 :         del(pattern);
     445                 :             : 
     446                 :             :         /* 0013 002 2 */
     447   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content("templates/0013_002_2.txt",text1));
     448                 :             : 
     449   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content("templates/0013_003_2.txt",text2));
     450                 :             : 
     451   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == compare_strings(&diff,getcstring(text1),getcstring(text2)));
     452                 :             : 
     453                 :           2 :         filename = "templates/0013_004_2.txt";
     454                 :             : 
     455   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     456                 :           2 :         del(diff_buffer);
     457   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == copy_literal(diff_buffer,diff));
     458   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(diff_buffer,pattern,filename));
     459                 :             : 
     460                 :           2 :         del(text1);
     461                 :           2 :         del(text2);
     462                 :           2 :         reset(&diff);
     463                 :           2 :         del(pattern);
     464                 :             : 
     465                 :             :         /* 0013 002 3 */
     466   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content("templates/0013_002_3.txt",text1));
     467                 :             : 
     468   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content("templates/0013_003_3.txt",text2));
     469                 :             : 
     470   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == compare_strings(&diff,getcstring(text1),getcstring(text2)));
     471                 :             : 
     472                 :             :         // _2 is not a mistake. 2 and 3 are equals
     473                 :           2 :         filename = "templates/0013_004_2.txt";
     474                 :             : 
     475   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     476                 :           2 :         del(diff_buffer);
     477   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == copy_literal(diff_buffer,diff));
     478   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(diff_buffer,pattern,filename));
     479                 :             : 
     480                 :           2 :         del(text1);
     481                 :           2 :         del(text2);
     482                 :           2 :         reset(&diff);
     483                 :           2 :         del(pattern);
     484                 :           2 :         del(diff_buffer);
     485                 :             : 
     486   [ +  -  -  +  :           2 :         RETURN_STATUS;
          -  -  -  +  +  
                      - ]
     487                 :             : }
     488                 :             : 
     489                 :             : /**
     490                 :             :  * Verifies detection of unexpected database metadata drift in dry-run mode.
     491                 :             :  *
     492                 :             :  * The function performs two runs. First, it creates `database1.db` in normal
     493                 :             :  * mode. Then it enables the testing hook
     494                 :             :  * `PRECIZER_TEST_DB_FILE_TIMESTAMPS_WILL_BUMPED=true` and runs the application
     495                 :             :  * with `--dry-run --update`. In test-hook mode this forces a DB timestamp bump
     496                 :             :  * inside the process before `db_check_changes()` compares the saved and current
     497                 :             :  * file metadata.
     498                 :             :  *
     499                 :             :  * The expected outcome of the second run is `WARNING`
     500                 :             :  */
     501                 :           2 : static Return test0013_7(void)
     502                 :             : {
     503                 :           2 :         INITTEST;
     504                 :             : 
     505                 :           2 :         create(char,result);
     506                 :           2 :         create(char,pattern);
     507                 :             : 
     508                 :           2 :         const char *cleanup_command = "cd ${TMPDIR}; rm -f database1.db;";
     509                 :           2 :         const char *arguments = NULL;
     510                 :             : 
     511   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     512   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("PRECIZER_TEST_DB_FILE_TIMESTAMPS_WILL_BUMPED","false"));
     513                 :             : 
     514   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(cleanup_command,NULL,NULL,COMPLETED,ALLOW_BOTH));
     515                 :             : 
     516                 :             :         /* First run: create DB in normal mode. */
     517                 :           2 :         arguments = "--database=database1.db tests/fixtures/diffs/diff1";
     518   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
     519                 :             : 
     520   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("PRECIZER_TEST_DB_FILE_TIMESTAMPS_WILL_BUMPED","true"));
     521                 :           2 :         arguments = "--dry-run --update --database=database1.db tests/fixtures/diffs/diff1";
     522   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,WARNING,ALLOW_BOTH));
     523                 :             : 
     524                 :           2 :         const char *filename = "templates/0013_005.txt";
     525   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     526   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     527                 :             : 
     528   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("PRECIZER_TEST_DB_FILE_TIMESTAMPS_WILL_BUMPED","false"));
     529   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(cleanup_command,NULL,NULL,COMPLETED,ALLOW_BOTH));
     530                 :             : 
     531                 :           2 :         del(pattern);
     532                 :           2 :         del(result);
     533                 :             : 
     534   [ +  -  -  +  :           2 :         RETURN_STATUS;
          -  -  -  +  +  
                      - ]
     535                 :             : }
     536                 :             : 
     537                 :             : /**
     538                 :             :  * Verifies internal consistency check when DB should be modified but appears unchanged.
     539                 :             :  *
     540                 :             :  * The function first validates a real update path: it creates `database1.db`,
     541                 :             :  * modifies one sample file, runs `--update`, compares output with template,
     542                 :             :  * and verifies that DB file metadata has actually changed.
     543                 :             :  *
     544                 :             :  * After that, it restores the pre-update DB state, enables
     545                 :             :  * `PRECIZER_TEST_DB_FILE_STAT_WILL_BE_RESYNCED=true`, and runs `--update`
     546                 :             :  * again. The hook rewrites the saved baseline database stat to the current
     547                 :             :  * stat right before comparison in db_check_changes(). This simulates a faulty
     548                 :             :  * "no metadata drift" result after a real database update and must trigger
     549                 :             :  * WARNING.
     550                 :             :  */
     551                 :           2 : static Return test0013_8(void)
     552                 :             : {
     553                 :           2 :         INITTEST;
     554                 :             : 
     555                 :           2 :         create(char,result);
     556                 :           2 :         create(char,pattern);
     557                 :           2 :         create(char,path);
     558                 :             : 
     559                 :           2 :         struct stat stat_before_real_update = {0};
     560                 :           2 :         struct stat stat_after_real_update = {0};
     561                 :             : 
     562                 :           2 :         const char *prepare_command = "cd ${TMPDIR}; "
     563                 :             :                 "rm -f database1.db database1.db.backup; "
     564                 :             :                 "rm -rf tests/fixtures/diff1_backup; "
     565                 :             :                 "mv tests/fixtures/diffs/diff1 tests/fixtures/diff1_backup; "
     566                 :             :                 "cp -a tests/fixtures/diff1_backup tests/fixtures/diffs/diff1;";
     567                 :           2 :         const char *cleanup_command = "cd ${TMPDIR}; "
     568                 :             :                 "rm -f database1.db database1.db.backup; "
     569                 :             :                 "rm -rf tests/fixtures/diffs/diff1; "
     570                 :             :                 "mv tests/fixtures/diff1_backup tests/fixtures/diffs/diff1;";
     571                 :           2 :         const char *arguments = NULL;
     572                 :           2 :         const char *command = NULL;
     573                 :             : 
     574   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     575   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("PRECIZER_TEST_DB_FILE_TIMESTAMPS_WILL_BUMPED","false"));
     576   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("PRECIZER_TEST_DB_FILE_STAT_WILL_BE_RESYNCED","false"));
     577                 :             : 
     578   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(prepare_command,NULL,NULL,COMPLETED,ALLOW_BOTH));
     579                 :             : 
     580                 :             :         /* First run: create DB in normal mode. */
     581                 :           2 :         arguments = "--database=database1.db tests/fixtures/diffs/diff1";
     582   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
     583                 :             : 
     584                 :             :         /* Make at least one real filesystem change so --update modifies DB. */
     585                 :           2 :         command = "cd ${TMPDIR}; "
     586                 :             :                 "echo -n AFAKDSJ >> tests/fixtures/diffs/diff1/1/AAA/ZAW/D/e/f/b_file.txt;";
     587   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
     588                 :             : 
     589                 :             :         /* Control check: real --update must modify database metadata. */
     590   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == construct_path("database1.db",path));
     591   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat_before_real_update));
     592                 :             : 
     593                 :           2 :         command = "cd ${TMPDIR}; cp -a database1.db database1.db.backup;";
     594   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
     595                 :             : 
     596                 :           2 :         arguments = "--update --database=database1.db tests/fixtures/diffs/diff1";
     597   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
     598                 :             : 
     599                 :           2 :         const char *filename = "templates/0013_006_1.txt";
     600   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     601   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     602                 :             : 
     603   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat_after_real_update));
     604   [ +  -  +  - ]:           2 :         ASSERT(FAILURE == check_file_identity(&stat_before_real_update,&stat_after_real_update));
     605                 :             : 
     606                 :             :         /*
     607                 :             :          * Restore pre-update DB snapshot so the next run starts from the same state
     608                 :             :          * and tests only the simulation hook behavior.
     609                 :             :          */
     610                 :           2 :         command = "cd ${TMPDIR}; rm -f database1.db; mv database1.db.backup database1.db;";
     611   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
     612                 :             : 
     613                 :           2 :         del(result);
     614                 :           2 :         del(pattern);
     615                 :             : 
     616   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("PRECIZER_TEST_DB_FILE_STAT_WILL_BE_RESYNCED","true"));
     617                 :           2 :         arguments = "--update --database=database1.db tests/fixtures/diffs/diff1";
     618   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,WARNING,ALLOW_BOTH));
     619                 :             : 
     620                 :           2 :         filename = "templates/0013_006_2.txt";
     621   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     622   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     623                 :             : 
     624   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("PRECIZER_TEST_DB_FILE_STAT_WILL_BE_RESYNCED","false"));
     625   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(cleanup_command,NULL,NULL,COMPLETED,ALLOW_BOTH));
     626                 :             : 
     627                 :           2 :         del(path);
     628                 :           2 :         del(pattern);
     629                 :           2 :         del(result);
     630                 :             : 
     631   [ +  -  -  +  :           2 :         RETURN_STATUS;
          -  -  -  +  +  
                      - ]
     632                 :             : }
     633                 :             : 
     634                 :             : /**
     635                 :             :  *
     636                 :             :  * Dry Run mode testing
     637                 :             :  *
     638                 :             :  */
     639                 :           2 : Return test0013(void)
     640                 :             : {
     641                 :           2 :         INITTEST;
     642                 :             : 
     643         [ +  - ]:           2 :         TEST(test0013_1,"The DB file should not be created…");
     644         [ +  - ]:           2 :         TEST(test0013_2,"Dry run with checksums hashes files but keeps DB untouched…");
     645         [ +  - ]:           2 :         TEST(test0013_3,"Invalid dry-run mode should return failure and print stderr error…");
     646         [ +  - ]:           2 :         TEST(test0013_4,"The DB file should not be updated…");
     647         [ +  - ]:           2 :         TEST(test0013_5,"Now run the same without simulation…");
     648         [ +  - ]:           2 :         TEST(test0013_6,"Compare dry and real mode templates…");
     649         [ +  - ]:           2 :         TEST(test0013_7,"Dry-run DB metadata drift should trigger internal warning path…");
     650         [ +  - ]:           2 :         TEST(test0013_8,"Live update: force missing DB metadata drift and trigger warning…");
     651                 :             : 
     652   [ +  -  -  +  :           2 :         RETURN_STATUS;
          -  -  -  +  +  
                      - ]
     653                 :             : }
        

Generated by: LCOV version 2.0-1