LCOV - code coverage report
Current view: top level - tests/src - test0019.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 37 37
Test Date: 2026-03-01 04:31:48 Functions: 100.0 % 1 1
Branches: 48.6 % 70 34

             Branch data     Line data    Source code
       1                 :             : #include "sute.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  *
       5                 :             :  * Testing symlink operations
       6                 :             :  *
       7                 :             :  * Test Scenario:
       8                 :             :  * 1. Add symlinks, create database
       9                 :             :  * 2. Remove symlinks, update database
      10                 :             :  * 3. Add symlinks, update database
      11                 :             :  *
      12                 :             :  */
      13                 :           2 : Return test0019(void)
      14                 :             : {
      15                 :           2 :         INITTEST;
      16                 :             : 
      17                 :           2 :         create(char,pattern);
      18                 :             : 
      19                 :             :         // Create memory for the result
      20                 :           2 :         create(char,result);
      21                 :             : 
      22                 :           2 :         const char *command = "cd ${TMPDIR};"
      23                 :             :                 "mv tests/fixtures/diffs/diff1 tests/fixtures/diff1_backup;"
      24                 :             :                 "cp -a tests/fixtures/diff1_backup tests/fixtures/diffs/diff1;";
      25                 :             : 
      26                 :             :         // Preparation for the test
      27   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
      28                 :             : 
      29   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
      30                 :             : 
      31                 :           2 :         command = "cd ${TMPDIR} && "
      32                 :             :                 "ln -s ../../../../1/AAA/BCB/CCC/a.txt tests/fixtures/diffs/diff1/path1/AAA/BCB/CCC/symlink_to_the_file_a.txt && "
      33                 :             :                 "ln -s ../../../../AAA/ZAW/D/e/f tests/fixtures/diffs/diff1/path1/AAA/ZAW/A/b/symlink_to_dir_f && "
      34                 :             :                 "ln -s /to/nowhere tests/fixtures/diffs/diff1/path1/AAA/ZAW/A/b/broken_symlink";
      35                 :             : 
      36   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
      37                 :             : 
      38                 :           2 :         const char *arguments = "--database=database1.db tests/fixtures/diffs/diff1";
      39                 :             : 
      40                 :           2 :         const char *filename = "templates/0019_001.txt";
      41                 :             : 
      42   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
      43   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      44   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      45                 :             : 
      46                 :             :         // Clean to use it iteratively
      47                 :           2 :         del(pattern);
      48                 :           2 :         del(result);
      49                 :             : 
      50                 :           2 :         command = "cd ${TMPDIR} && "
      51                 :             :                 "rm tests/fixtures/diffs/diff1/path1/AAA/BCB/CCC/symlink_to_the_file_a.txt && "
      52                 :             :                 "rm tests/fixtures/diffs/diff1/path1/AAA/ZAW/A/b/symlink_to_dir_f && "
      53                 :             :                 "rm tests/fixtures/diffs/diff1/path1/AAA/ZAW/A/b/broken_symlink";
      54                 :             : 
      55   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
      56                 :             : 
      57                 :           2 :         arguments = "--update --database=database1.db tests/fixtures/diffs/diff1";
      58                 :             : 
      59                 :           2 :         filename = "templates/0019_002.txt";
      60                 :             : 
      61   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
      62   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      63   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      64                 :             : 
      65                 :             :         // Clean to use it iteratively
      66                 :           2 :         del(pattern);
      67                 :           2 :         del(result);
      68                 :             : 
      69                 :           2 :         command = "cd ${TMPDIR} && "
      70                 :             :                 "ln -s ../../../../1/AAA/BCB/CCC/a.txt tests/fixtures/diffs/diff1/path1/AAA/BCB/CCC/symlink_to_the_file_a.txt && "
      71                 :             :                 "ln -s ../../../../AAA/ZAW/D/e/f tests/fixtures/diffs/diff1/path1/AAA/ZAW/A/b/symlink_to_dir_f && "
      72                 :             :                 "ln -s /to/nowhere tests/fixtures/diffs/diff1/path1/AAA/ZAW/A/b/broken_symlink";
      73                 :             : 
      74   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
      75                 :             : 
      76                 :           2 :         arguments = "--update --database=database1.db tests/fixtures/diffs/diff1";
      77                 :             : 
      78                 :           2 :         filename = "templates/0019_003.txt";
      79                 :             : 
      80   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
      81   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
      82   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      83                 :             : 
      84                 :             :         // Clean to use it iteratively
      85                 :           2 :         del(pattern);
      86                 :           2 :         del(result);
      87                 :             : 
      88                 :             :         // Clean up test results
      89                 :           2 :         command = "cd ${TMPDIR} && "
      90                 :             :                 "rm database1.db && "
      91                 :             :                 "rm -rf tests/fixtures/diffs/diff1 && "
      92                 :             :                 "mv tests/fixtures/diff1_backup tests/fixtures/diffs/diff1";
      93                 :             : 
      94   [ +  -  +  - ]:           2 :         ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
      95                 :             : 
      96   [ +  -  -  +  :           2 :         RETURN_STATUS;
          -  -  -  +  +  
                      - ]
      97                 :             : }
        

Generated by: LCOV version 2.0-1