LCOV - code coverage report
Current view: top level - tests/src - test0027.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 39 39
Test Date: 2026-03-01 04:31:48 Functions: 100.0 % 2 2
Branches: 47.8 % 90 43

             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                 :           2 :         const char *command = "cd ${TMPDIR};"
      16                 :             :                 "mv tests/fixtures/diffs/diff1 tests/fixtures/diff1_backup;"
      17                 :             :                 "mv tests/fixtures/diffs/diff2 tests/fixtures/diff2_backup;"
      18                 :             :                 "cp -a tests/fixtures/diff1_backup tests/fixtures/diffs/diff1;"
      19                 :             :                 "cp -a tests/fixtures/diff2_backup tests/fixtures/diffs/diff2;";
      20                 :             : 
      21                 :             :         // Preparation for tests
      22   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
      23                 :             : 
      24   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      25                 :             : 
      26                 :           2 :         const char *arguments = "--database=lock.db --lock-checksum=\"^diff1/1/.*\" "
      27                 :             :                 "--lock-checksum=\"^diff2/path1/.*\" tests/fixtures/diffs";
      28                 :             : 
      29   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
      30                 :             : 
      31                 :           2 :         const char *filename = "templates/0027_001_1.txt";
      32                 :             : 
      33   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      34   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      35                 :             : 
      36                 :           2 :         arguments = "--update --database=lock.db --lock-checksum=\"^diff1/1/.*\" "
      37                 :             :                 "--lock-checksum=\"^diff2/path1/.*\" tests/fixtures/diffs";
      38                 :             : 
      39   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
      40                 :             : 
      41                 :           2 :         filename = "templates/0027_001_2.txt";
      42                 :             : 
      43   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      44                 :             : 
      45   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      46                 :             : 
      47                 :           2 :         filename = "templates/0027_001_3.txt";
      48                 :             : 
      49   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      50                 :             : 
      51                 :           2 :         command = "cd ${TMPDIR};"
      52                 :             :                 "echo 'corrupted' >> tests/fixtures/diffs/diff1/1/AAA/ZAW/A/b/c/a_file.txt;"
      53                 :             :                 "echo 'corrupted' >> tests/fixtures/diffs/diff2/path1/AAA/BCB/CCC/b.txt;"
      54                 :             :                 "echo 'changed' >> tests/fixtures/diffs/diff2/3/AAA/BBB/CCC/a.txt;"
      55                 :             :                 "touch tests/fixtures/diffs/diff2/2/AAA/BBB/CZC/a.txt;"
      56                 :             :                 "cp lock.db lock1.db";
      57                 :             : 
      58   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
      59                 :             : 
      60                 :           2 :         arguments = "--progress --update --database=lock.db "
      61                 :             :                 "--lock-checksum=\"^diff1/1/.*\" "
      62                 :             :                 "--lock-checksum=\"^diff2/path1/.*\" tests/fixtures/diffs";
      63                 :             : 
      64   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,WARNING,ALLOW_BOTH));
      65                 :             : 
      66   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      67                 :             : 
      68   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
      69                 :             : 
      70                 :           2 :         arguments = "--progress --update --database=lock1.db "
      71                 :             :                 "--lock-checksum=\"^diff1/1/.*\" "
      72                 :             :                 "--lock-checksum=\"^diff2/path1/.*\" tests/fixtures/diffs";
      73                 :             : 
      74   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,WARNING,ALLOW_BOTH));
      75                 :             : 
      76                 :           2 :         filename = "templates/0027_001_4.txt";
      77                 :             : 
      78   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      79                 :             : 
      80   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      81                 :             : 
      82                 :             :         // Clean up test results
      83                 :           2 :         command = "cd ${TMPDIR} && "
      84                 :             :                 "rm lock.db lock1.db && "
      85                 :             :                 "rm -rf tests/fixtures/diffs/diff1 tests/fixtures/diffs/diff2 && "
      86                 :             :                 "mv tests/fixtures/diff1_backup tests/fixtures/diffs/diff1 && "
      87                 :             :                 "mv tests/fixtures/diff2_backup tests/fixtures/diffs/diff2";
      88                 :             : 
      89   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
      90                 :             : 
      91                 :           2 :         del(result);
      92                 :           2 :         del(pattern);
      93                 :             : 
      94   [ +  -  -  +  :           2 :         RETURN_STATUS;
          -  -  -  +  +  
                      - ]
      95                 :             : }
      96                 :             : 
      97                 :           2 : Return test0027(void)
      98                 :             : {
      99                 :           2 :         INITTEST;
     100                 :             : 
     101         [ +  - ]:           2 :         TEST(test0027_1,"Attempt to modify files protected by the --lock-checksum…");
     102                 :             : 
     103   [ +  -  -  +  :           2 :         RETURN_STATUS;
          -  -  -  +  +  
                      - ]
     104                 :             : }
        

Generated by: LCOV version 2.0-1