LCOV - code coverage report
Current view: top level - tests/src - test0027.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 31 31
Test Date: 2026-10-20 14:27:43 Functions: 100.0 % 2 2
Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : #include "sute.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  * @brief Detect changes to files protected by repeated --lock-checksum rules
       5                 :             :  *
       6                 :             :  * CLI and configuration updates start from the same saved database and
       7                 :             :  * modified files, then check the same full output and warning status.
       8                 :             :  * Files outside the protected paths continue to update normally
       9                 :             :  */
      10                 :           2 : static Return test0027_1(void)
      11                 :             : {
      12                 :           2 :         INITTEST;
      13                 :             : 
      14                 :             :         // Preparation for tests
      15                 :           2 :         ASSERT(SUCCESS == prepare_mutable_fixture("tests/fixtures/diffs/diff1"));
      16                 :           2 :         ASSERT(SUCCESS == prepare_mutable_fixture("tests/fixtures/diffs/diff2"));
      17                 :             : 
      18                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      19                 :             : 
      20                 :           2 :         const struct argument_test_case initial_cases[] = {
      21                 :             :                 {"--database=lock.db --lock-checksum=\"^diff1/1/.*\" "
      22                 :             :                  "--lock-checksum=\"^diff2/path1/.*\" tests/fixtures/diffs",COMPLETED,"templates/0027_001_1.txt",STDERR_MUST_BE_EMPTY},
      23                 :             :                 {"--update --check-level=QUICK --database=lock.db --lock-checksum=\"^diff1/1/.*\" "
      24                 :             :                  "--lock-checksum=\"^diff2/path1/.*\" tests/fixtures/diffs",COMPLETED,"templates/0027_001_2.txt",STDERR_MUST_BE_EMPTY},
      25                 :             :                 {0}
      26                 :             :         };
      27                 :             : 
      28                 :           2 :         ASSERT(SUCCESS == run_and_match_templates(initial_cases,NULL,NULL));
      29                 :             : 
      30                 :           2 :         ASSERT(SUCCESS == add_string_to("corrupted","tests/fixtures/diffs/diff1/1/AAA/ZAW/A/b/c/a_file.txt"));
      31                 :           2 :         ASSERT(SUCCESS == add_string_to("corrupted","tests/fixtures/diffs/diff2/path1/AAA/BCB/CCC/b.txt"));
      32                 :           2 :         ASSERT(SUCCESS == add_string_to("changed","tests/fixtures/diffs/diff2/3/AAA/BBB/CCC/a.txt"));
      33                 :             : 
      34                 :           2 :         ASSERT(SUCCESS == copy_path("lock.db","lock1.db"));
      35                 :             : 
      36                 :             :         // Bump file mtime by a nanosecond delta without changing file content
      37                 :           2 :         ASSERT(SUCCESS == touch_file_mtime_with_reference_delta_ns(NULL,"tests/fixtures/diffs/diff2/2/AAA/BBB/CZC/a.txt",999));
      38                 :             : 
      39                 :           2 :         const struct argument_test_case update_cases[] = {
      40                 :             :                 {"--progress --update --check-level=QUICK --database=lock.db "
      41                 :             :                  "--lock-checksum=\"^diff1/1/.*\" "
      42                 :             :                  "--lock-checksum=\"^diff2/path1/.*\" tests/fixtures/diffs",WARNING,"templates/0027_001_3.txt",STDERR_MUST_BE_EMPTY},
      43                 :             :                 {0}
      44                 :             :         };
      45                 :             : 
      46                 :           2 :         ASSERT(SUCCESS == run_and_match_templates(update_cases,NULL,NULL));
      47                 :             : 
      48                 :             :         /* Restore the database for the configuration run without repeating file changes.
      49                 :             :            Keep lock1.db unchanged for the subsequent run without testing diagnostics */
      50                 :           2 :         ASSERT(SUCCESS == copy_path("lock1.db","lock.db"));
      51                 :           2 :         ASSERT(SUCCESS == copy_path("tests/templates/0027_001_3.conf","0027_001_3.conf"));
      52                 :           2 :         const struct argument_test_case file_cases[] = {
      53                 :             :                 {"--config=0027_001_3.conf",WARNING,"templates/0027_001_3.txt",STDERR_MUST_BE_EMPTY},
      54                 :             :                 {0}
      55                 :             :         };
      56                 :           2 :         ASSERT(SUCCESS == run_and_match_templates(file_cases,NULL,NULL));
      57                 :           2 :         call(delete_path_if_present("0027_001_3.conf"));
      58                 :             : 
      59                 :           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","false"));
      60                 :             : 
      61                 :           2 :         const struct argument_test_case non_testing_cases[] = {
      62                 :             :                 {"--progress --update --check-level=QUICK --database=lock1.db "
      63                 :             :                  "--lock-checksum=\"^diff1/1/.*\" "
      64                 :             :                  "--lock-checksum=\"^diff2/path1/.*\" tests/fixtures/diffs",WARNING,"templates/0027_001_4.txt",STDERR_MUST_BE_EMPTY},
      65                 :             :                 {0}
      66                 :             :         };
      67                 :             : 
      68                 :           2 :         ASSERT(SUCCESS == run_and_match_templates(non_testing_cases,NULL,NULL));
      69                 :             : 
      70                 :             :         // Clean up test results
      71                 :           2 :         ASSERT(SUCCESS == delete_path("lock.db"));
      72                 :           2 :         ASSERT(SUCCESS == delete_path("lock1.db"));
      73                 :           2 :         ASSERT(SUCCESS == restore_mutable_fixture("tests/fixtures/diffs/diff1"));
      74                 :           2 :         ASSERT(SUCCESS == restore_mutable_fixture("tests/fixtures/diffs/diff2"));
      75                 :             : 
      76                 :           2 :         RETURN_STATUS;
      77                 :             : }
      78                 :             : 
      79                 :           2 : Return test0027(void)
      80                 :             : {
      81                 :           2 :         INITTEST;
      82                 :             : 
      83                 :           2 :         TEST(test0027_1,"Attempt to modify files protected by the --lock-checksum");
      84                 :             : 
      85                 :           2 :         RETURN_STATUS;
      86                 :             : }
        

Generated by: LCOV version 2.0-1