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

             Branch data     Line data    Source code
       1                 :             : #include "sute.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  *
       5                 :             :  * Attempt to modify files protected by the --lock-checksum
       6                 :             :  *
       7                 :             :  */
       8                 :           2 : static Return test0027_1(void)
       9                 :             : {
      10                 :           2 :         INITTEST;
      11                 :             : 
      12                 :           2 :         create(char,result);
      13                 :           2 :         create(char,pattern);
      14                 :             : 
      15                 :             :         // Preparation for tests
      16                 :           2 :         ASSERT(SUCCESS == move_path("tests/fixtures/diffs/diff1","tests/fixtures/diff1_backup"));
      17                 :           2 :         ASSERT(SUCCESS == move_path("tests/fixtures/diffs/diff2","tests/fixtures/diff2_backup"));
      18                 :           2 :         ASSERT(SUCCESS == copy_path("tests/fixtures/diff1_backup","tests/fixtures/diffs/diff1"));
      19                 :           2 :         ASSERT(SUCCESS == copy_path("tests/fixtures/diff2_backup","tests/fixtures/diffs/diff2"));
      20                 :             : 
      21                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      22                 :             : 
      23                 :           2 :         const char *arguments = "--database=lock.db --lock-checksum=\"^diff1/1/.*\" "
      24                 :             :                 "--lock-checksum=\"^diff2/path1/.*\" tests/fixtures/diffs";
      25                 :             : 
      26                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
      27                 :             : 
      28                 :           2 :         const char *filename = "templates/0027_001_1.txt";
      29                 :             : 
      30                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      31                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      32                 :             : 
      33                 :           2 :         arguments = "--update --database=lock.db --lock-checksum=\"^diff1/1/.*\" "
      34                 :             :                 "--lock-checksum=\"^diff2/path1/.*\" tests/fixtures/diffs";
      35                 :             : 
      36                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
      37                 :             : 
      38                 :           2 :         filename = "templates/0027_001_2.txt";
      39                 :             : 
      40                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      41                 :             : 
      42                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      43                 :             : 
      44                 :           2 :         filename = "templates/0027_001_3.txt";
      45                 :             : 
      46                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      47                 :             : 
      48                 :           2 :         ASSERT(SUCCESS == add_string_to("corrupted","tests/fixtures/diffs/diff1/1/AAA/ZAW/A/b/c/a_file.txt"));
      49                 :           2 :         ASSERT(SUCCESS == add_string_to("corrupted","tests/fixtures/diffs/diff2/path1/AAA/BCB/CCC/b.txt"));
      50                 :           2 :         ASSERT(SUCCESS == add_string_to("changed","tests/fixtures/diffs/diff2/3/AAA/BBB/CCC/a.txt"));
      51                 :             : 
      52                 :           2 :         ASSERT(SUCCESS == copy_path("lock.db","lock1.db"));
      53                 :             : 
      54                 :             :         // Bump file mtime by a nanosecond delta without changing file content
      55                 :           2 :         ASSERT(SUCCESS == touch_file_mtime_with_reference_delta_ns(NULL,"tests/fixtures/diffs/diff2/2/AAA/BBB/CZC/a.txt",999));
      56                 :             : 
      57                 :           2 :         arguments = "--progress --update --database=lock.db "
      58                 :             :                 "--lock-checksum=\"^diff1/1/.*\" "
      59                 :             :                 "--lock-checksum=\"^diff2/path1/.*\" tests/fixtures/diffs";
      60                 :             : 
      61                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,WARNING,ALLOW_BOTH));
      62                 :             : 
      63                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      64                 :             : 
      65                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
      66                 :             : 
      67                 :           2 :         arguments = "--progress --update --database=lock1.db "
      68                 :             :                 "--lock-checksum=\"^diff1/1/.*\" "
      69                 :             :                 "--lock-checksum=\"^diff2/path1/.*\" tests/fixtures/diffs";
      70                 :             : 
      71                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,WARNING,ALLOW_BOTH));
      72                 :             : 
      73                 :           2 :         filename = "templates/0027_001_4.txt";
      74                 :             : 
      75                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      76                 :             : 
      77                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      78                 :             : 
      79                 :             :         // Clean up test results
      80                 :           2 :         ASSERT(SUCCESS == delete_path("lock.db"));
      81                 :           2 :         ASSERT(SUCCESS == delete_path("lock1.db"));
      82                 :           2 :         ASSERT(SUCCESS == delete_path("tests/fixtures/diffs/diff1"));
      83                 :           2 :         ASSERT(SUCCESS == delete_path("tests/fixtures/diffs/diff2"));
      84                 :             : 
      85                 :           2 :         ASSERT(SUCCESS == move_path("tests/fixtures/diff1_backup","tests/fixtures/diffs/diff1"));
      86                 :           2 :         ASSERT(SUCCESS == move_path("tests/fixtures/diff2_backup","tests/fixtures/diffs/diff2"));
      87                 :             : 
      88                 :           2 :         del(result);
      89                 :           2 :         del(pattern);
      90                 :             : 
      91                 :           2 :         RETURN_STATUS;
      92                 :             : }
      93                 :             : 
      94                 :           2 : Return test0027(void)
      95                 :             : {
      96                 :           2 :         INITTEST;
      97                 :             : 
      98                 :           2 :         TEST(test0027_1,"Attempt to modify files protected by the --lock-checksum…");
      99                 :             : 
     100                 :           2 :         RETURN_STATUS;
     101                 :             : }
        

Generated by: LCOV version 2.0-1