LCOV - code coverage report
Current view: top level - tests/src - test0027.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 44 44
Test Date: 2026-07-12 01:01:34 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 :         m_create(char,result,MEMORY_STRING);
      13                 :           2 :         m_create(char,pattern,MEMORY_STRING);
      14                 :             : 
      15                 :             :         // Preparation for tests
      16                 :           2 :         ASSERT(SUCCESS == prepare_mutable_fixture("tests/fixtures/diffs/diff1"));
      17                 :           2 :         ASSERT(SUCCESS == prepare_mutable_fixture("tests/fixtures/diffs/diff2"));
      18                 :             : 
      19                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      20                 :             : 
      21                 :           2 :         const char *arguments = "--database=lock.db --lock-checksum=\"^diff1/1/.*\" "
      22                 :             :                 "--lock-checksum=\"^diff2/path1/.*\" tests/fixtures/diffs";
      23                 :             : 
      24                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
      25                 :             : 
      26                 :           2 :         const char *filename = "templates/0027_001_1.txt";
      27                 :             : 
      28                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      29                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      30                 :             : 
      31                 :           2 :         arguments = "--update --database=lock.db --lock-checksum=\"^diff1/1/.*\" "
      32                 :             :                 "--lock-checksum=\"^diff2/path1/.*\" tests/fixtures/diffs";
      33                 :             : 
      34                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
      35                 :             : 
      36                 :           2 :         filename = "templates/0027_001_2.txt";
      37                 :             : 
      38                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      39                 :             : 
      40                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      41                 :             : 
      42                 :           2 :         filename = "templates/0027_001_3.txt";
      43                 :             : 
      44                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      45                 :             : 
      46                 :           2 :         ASSERT(SUCCESS == add_string_to("corrupted","tests/fixtures/diffs/diff1/1/AAA/ZAW/A/b/c/a_file.txt"));
      47                 :           2 :         ASSERT(SUCCESS == add_string_to("corrupted","tests/fixtures/diffs/diff2/path1/AAA/BCB/CCC/b.txt"));
      48                 :           2 :         ASSERT(SUCCESS == add_string_to("changed","tests/fixtures/diffs/diff2/3/AAA/BBB/CCC/a.txt"));
      49                 :             : 
      50                 :           2 :         ASSERT(SUCCESS == copy_path("lock.db","lock1.db"));
      51                 :             : 
      52                 :             :         // Bump file mtime by a nanosecond delta without changing file content
      53                 :           2 :         ASSERT(SUCCESS == touch_file_mtime_with_reference_delta_ns(NULL,"tests/fixtures/diffs/diff2/2/AAA/BBB/CZC/a.txt",999));
      54                 :             : 
      55                 :           2 :         arguments = "--progress --update --database=lock.db "
      56                 :             :                 "--lock-checksum=\"^diff1/1/.*\" "
      57                 :             :                 "--lock-checksum=\"^diff2/path1/.*\" tests/fixtures/diffs";
      58                 :             : 
      59                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,WARNING,ALLOW_BOTH));
      60                 :             : 
      61                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      62                 :             : 
      63                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
      64                 :             : 
      65                 :           2 :         arguments = "--progress --update --database=lock1.db "
      66                 :             :                 "--lock-checksum=\"^diff1/1/.*\" "
      67                 :             :                 "--lock-checksum=\"^diff2/path1/.*\" tests/fixtures/diffs";
      68                 :             : 
      69                 :           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,WARNING,ALLOW_BOTH));
      70                 :             : 
      71                 :           2 :         filename = "templates/0027_001_4.txt";
      72                 :             : 
      73                 :           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      74                 :             : 
      75                 :           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      76                 :             : 
      77                 :             :         // Clean up test results
      78                 :           2 :         ASSERT(SUCCESS == delete_path("lock.db"));
      79                 :           2 :         ASSERT(SUCCESS == delete_path("lock1.db"));
      80                 :           2 :         ASSERT(SUCCESS == restore_mutable_fixture("tests/fixtures/diffs/diff1"));
      81                 :           2 :         ASSERT(SUCCESS == restore_mutable_fixture("tests/fixtures/diffs/diff2"));
      82                 :             : 
      83                 :           2 :         m_del(result);
      84                 :           2 :         m_del(pattern);
      85                 :             : 
      86                 :           2 :         RETURN_STATUS;
      87                 :             : }
      88                 :             : 
      89                 :           2 : Return test0027(void)
      90                 :             : {
      91                 :           2 :         INITTEST;
      92                 :             : 
      93                 :           2 :         TEST(test0027_1,"Attempt to modify files protected by the --lock-checksum");
      94                 :             : 
      95                 :           2 :         RETURN_STATUS;
      96                 :             : }
        

Generated by: LCOV version 2.0-1