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

            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 dry_run_mode_1_test(void)
       7              : {
       8            2 :         INITTEST;
       9              : 
      10            2 :         create(char,result);
      11              : 
      12            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      13              : 
      14            2 :         ASSERT(SUCCESS == runit("--dry-run --database=database1.db tests/examples/diffs/diff1",result,COMPLETED,ALLOW_BOTH));
      15              : 
      16              :         #if 0
      17              :         echo(STDOUT,"%s\n",getcstring(result));
      18              :         #endif
      19              : 
      20            2 :         del(result);
      21              : 
      22              :         // Does file exists or not
      23            2 :         const char *db_filename = "database1.db";
      24            2 :         create(char,path);
      25            2 :         bool file_exists = false;
      26              : 
      27            2 :         ASSERT(SUCCESS == construct_path(db_filename,path));
      28              : 
      29            2 :         ASSERT(SUCCESS == check_file_exists(&file_exists,getcstring(path)));
      30              : 
      31            2 :         del(path);
      32              : 
      33              :         // Should not be exists
      34            2 :         ASSERT(file_exists == false);
      35              : 
      36            2 :         RETURN_STATUS;
      37              : }
      38              : 
      39              : /**
      40              :  * The db file should not be updated in the Dry Run mode
      41              :  */
      42            2 : static Return dry_run_mode_2_test(void)
      43              : {
      44            2 :         INITTEST;
      45              : 
      46              :         // Create memory for the result
      47            2 :         create(char,result);
      48              :         struct stat stat1;
      49              :         struct stat stat2;
      50            2 :         create(char,pattern);
      51            2 :         create(char,chunk);
      52              : 
      53            2 :         const char *command = "cd ${TMPDIR};"
      54              :                 "mv tests/examples/ tests/examples_backup/;"
      55              :                 "cp -a tests/examples_backup/ tests/examples/;";
      56              : 
      57              :         // Preparation for tests
      58            2 :         ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
      59              : 
      60            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      61              : 
      62            2 :         const char *arguments = "--database=database1.db tests/examples/diffs/diff1";
      63              : 
      64            2 :         ASSERT(SUCCESS == runit(arguments,NULL,COMPLETED,ALLOW_BOTH));
      65              : 
      66              :         #if 0
      67              :         printf("Path: %s\n",path);
      68              :         echo(STDOUT,"Path: %s\n",path);
      69              :         #endif
      70              : 
      71            2 :         create(char,path);
      72              : 
      73            2 :         const char *db_filename = "database1.db";
      74              : 
      75            2 :         ASSERT(SUCCESS == construct_path(db_filename,path));
      76              : 
      77            2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat1));
      78              : 
      79            2 :         command = "cd ${TMPDIR};"
      80              :                 "rm tests/examples/diffs/diff1/2/AAA/BBB/CZC/a.txt;" // Remove
      81              :                 "echo -n AFAKDSJ >> tests/examples/diffs/diff1/1/AAA/ZAW/D/e/f/b_file.txt;" // Modify
      82              :                 "echo -n WNEURHGO > tests/examples/diffs/diff1/2/AAA/BBB/CZC/b.txt;"; // New file
      83              : 
      84            2 :         ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
      85              : 
      86            2 :         arguments = "--dry-run --update --database=database1.db tests/examples/diffs/diff1";
      87              : 
      88            2 :         ASSERT(SUCCESS == runit(arguments,chunk,COMPLETED,ALLOW_BOTH));
      89            2 :         ASSERT(SUCCESS == copy(result,chunk));
      90              : 
      91              :         #if 0
      92              :         printf("%s\n",getcstring(result));
      93              :         echo(STDOUT,"%s\n",getcstring(result));
      94              :         #endif
      95              : 
      96            2 :         del(result);
      97            2 :         del(chunk);
      98              : 
      99            2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat2));
     100              : 
     101            2 :         ASSERT(SUCCESS == check_file_identity(&stat1,&stat2));
     102              : 
     103              :         // Compare against the sample. A message should be displayed indicating
     104              :         // that the --db-clean-ignored option must be specified for permanent
     105              :         // removal of ignored files from the database
     106            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     107              : 
     108            2 :         arguments = "--dry-run --ignore=\"^1/AAA/ZAW/.*\" --update --database=database1.db tests/examples/diffs/diff1";
     109              : 
     110            2 :         ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
     111              : 
     112              :         #if 0
     113              :         echo(STDOUT,"%s\n",getcstring(result));
     114              :         #endif
     115              : 
     116            2 :         const char *filename = "templates/0013_002_1.txt";
     117              : 
     118            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     119            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     120              : 
     121            2 :         del(pattern);
     122              : 
     123            2 :         del(result);
     124              : 
     125            2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat2));
     126              : 
     127            2 :         ASSERT(SUCCESS == check_file_identity(&stat1,&stat2));
     128              : 
     129              :         // Dry Run mode permanent deletion of all ignored file
     130              :         // references from the database
     131            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     132              : 
     133            2 :         arguments = "--db-clean-ignored --ignore=\"^1/AAA/ZAW/.*\" --update --dry-run --database=database1.db tests/examples/diffs/diff1";
     134              : 
     135            2 :         ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
     136              : 
     137              :         #if 0
     138              :         echo(STDOUT,"%s\n",getcstring(result));
     139              :         #endif
     140              : 
     141            2 :         filename = "templates/0013_002_2.txt";
     142              : 
     143            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     144            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     145              : 
     146            2 :         del(pattern);
     147              : 
     148            2 :         del(result);
     149              : 
     150            2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat2));
     151              : 
     152            2 :         ASSERT(SUCCESS == check_file_identity(&stat1,&stat2));
     153              : 
     154            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     155              : 
     156            2 :         ASSERT(SUCCESS == runit("--watch-timestamps --db-clean-ignored --ignore=\"^path2/AAA/ZAW/.*\" --update --dry-run --database=database1.db tests/examples/diffs/diff1",
     157              :                 result,
     158              :                 COMPLETED,ALLOW_BOTH));
     159              : 
     160              :         #if 0
     161              :         echo(STDOUT,"%s\n",getcstring(result));
     162              :         #endif
     163              : 
     164            2 :         filename = "templates/0013_002_3.txt";
     165              : 
     166            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     167            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     168              : 
     169            2 :         del(pattern);
     170              : 
     171            2 :         del(result);
     172              : 
     173            2 :         ASSERT(SUCCESS == get_file_stat(getcstring(path),&stat2));
     174              : 
     175            2 :         ASSERT(SUCCESS == check_file_identity(&stat1,&stat2));
     176              : 
     177            2 :         del(path);
     178              : 
     179              :         // Clean up test results
     180            2 :         ASSERT(SUCCESS == external_call("cd ${TMPDIR} && "
     181              :                 "rm database1.db && "
     182              :                 "rm -rf tests/examples/ && "
     183              :                 "mv tests/examples_backup/ tests/examples/",COMPLETED,ALLOW_BOTH));
     184              : 
     185            2 :         RETURN_STATUS;
     186              : }
     187              : 
     188              : /**
     189              :  * Everything that was previously executed in Dry Run mode
     190              :  * will now be tested in live mode without simulation, and
     191              :  * the results will be compared against each other
     192              :  */
     193            2 : static Return no_dry_run_mode_3_test(void)
     194              : {
     195            2 :         INITTEST;
     196              :         // Create memory for the result
     197            2 :         create(char,result);
     198            2 :         create(char,path);
     199            2 :         create(char,pattern);
     200            2 :         const char *db_file_name = "database1.db";
     201            2 :         const char *command = NULL;
     202            2 :         const char *arguments = NULL;
     203              : 
     204              :         // Preparation for tests
     205            2 :         ASSERT(SUCCESS == external_call("cd ${TMPDIR};"
     206              :                 "cp -a tests/examples/ tests/examples_backup/;",COMPLETED,ALLOW_BOTH));
     207              : 
     208            2 :         ASSERT(SUCCESS == construct_path(db_file_name,path));
     209              : 
     210            2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
     211              : 
     212            2 :         arguments = "--database=database1.db tests/examples/diffs/diff1";
     213              : 
     214            2 :         ASSERT(SUCCESS == runit(arguments,NULL,COMPLETED,ALLOW_BOTH));
     215              : 
     216              :         #if 0
     217              :         echo(STDOUT,"Path: %s\n",path);
     218              :         #endif
     219              : 
     220            2 :         command = "cd ${TMPDIR};"
     221              :                 "rm tests/examples/diffs/diff1/2/AAA/BBB/CZC/a.txt;" // Remove
     222              :                 "echo -n AFAKDSJ >> tests/examples/diffs/diff1/1/AAA/ZAW/D/e/f/b_file.txt;" // Modify
     223              :                 "echo -n WNEURHGO > tests/examples/diffs/diff1/2/AAA/BBB/CZC/b.txt;"; // New file
     224              : 
     225            2 :         ASSERT(SUCCESS == external_call(command,COMPLETED,ALLOW_BOTH));
     226              : 
     227              :         #if 0
     228              :         echo(STDOUT,"%s\n",getcstring(result));
     229              :         #endif
     230              : 
     231            2 :         del(result);
     232              : 
     233              :         // Compare against the sample. A message should be displayed indicating
     234              :         // that the --db-clean-ignored option must be specified for permanent
     235              :         // removal of ignored files from the database
     236            2 :         ASSERT(SUCCESS == external_call("cd ${TMPDIR};cp -a database1.db database1.db.backup;",COMPLETED,ALLOW_BOTH));
     237              : 
     238            2 :         arguments = "--ignore=\"^1/AAA/ZAW/.*\" --update --database=database1.db tests/examples/diffs/diff1";
     239              : 
     240            2 :         ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
     241              : 
     242              :         #if 0
     243              :         echo(STDOUT,"%s\n",getcstring(result));
     244              :         #endif
     245              : 
     246            2 :         const char *filename = "templates/0013_003_1.txt";
     247              : 
     248            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     249            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     250              : 
     251            2 :         del(pattern);
     252              : 
     253            2 :         del(result);
     254              : 
     255              :         // Real live mode permanent deletion of all ignored file
     256              :         // references from the database
     257            2 :         ASSERT(SUCCESS == external_call("cd ${TMPDIR};cp -a database1.db.backup database1.db;",COMPLETED,ALLOW_BOTH));
     258              : 
     259            2 :         arguments = "--db-clean-ignored --ignore=\"^1/AAA/ZAW/.*\" --update --database=database1.db tests/examples/diffs/diff1";
     260              : 
     261            2 :         ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
     262              : 
     263              :         #if 0
     264              :         echo(STDOUT,"%s\n",getcstring(result));
     265              :         #endif
     266              : 
     267            2 :         filename = "templates/0013_003_2.txt";
     268              : 
     269            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     270            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     271              : 
     272            2 :         del(pattern);
     273              : 
     274            2 :         del(result);
     275              : 
     276            2 :         ASSERT(SUCCESS == external_call("cd ${TMPDIR};mv database1.db.backup database1.db;",COMPLETED,ALLOW_BOTH));
     277              : 
     278            2 :         arguments = "--watch-timestamps --db-clean-ignored --ignore=\"^path2/AAA/ZAW/.*\" --update --database=database1.db tests/examples/diffs/diff1";
     279              : 
     280            2 :         ASSERT(SUCCESS == runit(arguments,result,COMPLETED,ALLOW_BOTH));
     281              : 
     282              :         #if 0
     283              :         echo(STDOUT,"%s\n",getcstring(result));
     284              :         #endif
     285              : 
     286            2 :         filename = "templates/0013_003_3.txt";
     287              : 
     288            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     289            2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
     290              : 
     291            2 :         del(pattern);
     292              : 
     293            2 :         del(result);
     294              : 
     295            2 :         del(path);
     296              : 
     297              :         // Clean up test results
     298            2 :         ASSERT(SUCCESS == external_call("cd ${TMPDIR} && "
     299              :                 "rm database1.db && "
     300              :                 "rm -rf tests/examples/ && "
     301              :                 "mv tests/examples_backup/ tests/examples/",COMPLETED,ALLOW_BOTH));
     302              : 
     303            2 :         RETURN_STATUS;
     304              : }
     305              : 
     306            2 : Return compare_dry_and_real_4_test(void)
     307              : {
     308            2 :         INITTEST;
     309              : 
     310            2 :         create(char,text1);
     311            2 :         create(char,text2);
     312            2 :         char *diff = NULL;
     313            2 :         create(char,pattern);
     314            2 :         const char *filename = NULL;
     315              : 
     316              :         /* 0013 002 1 */
     317            2 :         ASSERT(SUCCESS == get_file_content("templates/0013_002_1.txt",text1));
     318              : 
     319            2 :         ASSERT(SUCCESS == get_file_content("templates/0013_003_1.txt",text2));
     320              : 
     321            2 :         ASSERT(SUCCESS == compare_strings(&diff,getcstring(text1),getcstring(text2)));
     322              : 
     323            2 :         filename = "templates/0013_004_1.txt";
     324              : 
     325            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     326            2 :         create(char,diff_buffer);
     327            2 :         ASSERT(SUCCESS == copy_literal(diff_buffer,diff));
     328            2 :         ASSERT(SUCCESS == match_pattern(diff_buffer,pattern,filename));
     329              : 
     330            2 :         del(text1);
     331            2 :         del(text2);
     332            2 :         reset(&diff);
     333            2 :         del(pattern);
     334              : 
     335              :         /* 0013 002 2 */
     336            2 :         ASSERT(SUCCESS == get_file_content("templates/0013_002_2.txt",text1));
     337              : 
     338            2 :         ASSERT(SUCCESS == get_file_content("templates/0013_003_2.txt",text2));
     339              : 
     340            2 :         ASSERT(SUCCESS == compare_strings(&diff,getcstring(text1),getcstring(text2)));
     341              : 
     342            2 :         filename = "templates/0013_004_2.txt";
     343              : 
     344            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     345            2 :         del(diff_buffer);
     346            2 :         ASSERT(SUCCESS == copy_literal(diff_buffer,diff));
     347            2 :         ASSERT(SUCCESS == match_pattern(diff_buffer,pattern,filename));
     348              : 
     349            2 :         del(text1);
     350            2 :         del(text2);
     351            2 :         reset(&diff);
     352            2 :         del(pattern);
     353              : 
     354              :         /* 0013 002 3 */
     355            2 :         ASSERT(SUCCESS == get_file_content("templates/0013_002_3.txt",text1));
     356              : 
     357            2 :         ASSERT(SUCCESS == get_file_content("templates/0013_003_3.txt",text2));
     358              : 
     359            2 :         ASSERT(SUCCESS == compare_strings(&diff,getcstring(text1),getcstring(text2)));
     360              : 
     361              :         // _2 is not a mistake. 2 and 3 are equals
     362            2 :         filename = "templates/0013_004_2.txt";
     363              : 
     364            2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     365            2 :         del(diff_buffer);
     366            2 :         ASSERT(SUCCESS == copy_literal(diff_buffer,diff));
     367            2 :         ASSERT(SUCCESS == match_pattern(diff_buffer,pattern,filename));
     368              : 
     369            2 :         del(text1);
     370            2 :         del(text2);
     371            2 :         reset(&diff);
     372            2 :         del(pattern);
     373            2 :         del(diff_buffer);
     374              : 
     375            2 :         RETURN_STATUS;
     376              : }
     377              : 
     378              : /**
     379              :  *
     380              :  * Dry Run mode testing
     381              :  *
     382              :  */
     383            2 : Return test0013(void)
     384              : {
     385            2 :         INITTEST;
     386              : 
     387            2 :         TEST(dry_run_mode_1_test,"The DB file should not be created…");
     388              : #ifndef EVIL_EMPIRE_OS
     389            2 :         TEST(dry_run_mode_2_test,"The DB file should not be updated…");
     390              : #endif
     391            2 :         TEST(no_dry_run_mode_3_test,"Now run the same without simulation…");
     392            2 :         TEST(compare_dry_and_real_4_test,"Compare dry and real mode templates…");
     393              : 
     394            2 :         RETURN_STATUS;
     395              : }
        

Generated by: LCOV version 2.0-1