LCOV - code coverage report
Current view: top level - tests/src - test0022.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 21 21
Test Date: 2026-03-01 04:31:48 Functions: 100.0 % 2 2
Branches: 50.0 % 36 18

             Branch data     Line data    Source code
       1                 :             : #include "sute.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  * @brief Helper function to test remove_trailing_slash and compare with expected output.
       5                 :             :  *
       6                 :             :  * This function copies the input string, applies remove_trailing_slash(), and
       7                 :             :  * compares the result with the expected output.
       8                 :             :  *
       9                 :             :  * @param input The original path to be processed.
      10                 :             :  * @param expected The expected output after removing trailing slashes.
      11                 :             :  */
      12                 :          17 : static Return test_remove_trailing_slash(
      13                 :             :         const char *input,
      14                 :             :         const char *expected)
      15                 :             : {
      16                 :          17 :         INITTEST;
      17                 :             : 
      18                 :          17 :         create(char,temp_buffer);
      19                 :          17 :         size_t len = strlen(input) + 1; // +1 for null terminator
      20                 :             : 
      21   [ +  -  +  - ]:          17 :         ASSERT(SUCCESS == resize(temp_buffer,len));
      22                 :             : 
      23         [ +  - ]:          17 :         if(SUCCESS == status)
      24                 :             :         {
      25                 :          17 :                 char *buffer_data = data(char,temp_buffer);
      26                 :             : 
      27   [ +  -  +  - ]:          17 :                 ASSERT(buffer_data != NULL);
      28                 :             : 
      29         [ +  - ]:          17 :                 if(SUCCESS == status)
      30                 :             :                 {
      31                 :          17 :                         memcpy(buffer_data,input,len);
      32                 :             : 
      33                 :          17 :                         remove_trailing_slash(buffer_data);
      34                 :             : 
      35                 :          17 :                         const char *buffer_view = cdata(char,temp_buffer);
      36                 :             : 
      37   [ +  -  +  - ]:          17 :                         ASSERT(buffer_view != NULL);
      38                 :             : 
      39   [ +  -  +  - ]:          17 :                         ASSERT(COMPLETED == strcmp(buffer_view,expected));
      40                 :             :                 }
      41                 :             :         }
      42                 :             : 
      43                 :          17 :         del(temp_buffer);
      44                 :             : 
      45                 :          17 :         return(status);
      46                 :             : }
      47                 :             : 
      48                 :             : /**
      49                 :             :  * @brief Runs a series of test cases for remove_trailing_slash().
      50                 :             :  *
      51                 :             :  * Unit Testing of precizer. This function tests various scenarios including:
      52                 :             :  * - Removing trailing slashes from paths
      53                 :             :  * - Ensuring single '/' paths remain unchanged
      54                 :             :  * - Handling edge cases with multiple slashes
      55                 :             :  */
      56                 :           1 : Return test0022(void)
      57                 :             : {
      58                 :           1 :         INITTEST;
      59                 :             : 
      60                 :             :         static const struct {
      61                 :             :                 const char *input;
      62                 :             :                 const char *expected;
      63                 :             :         } test_cases[] = {
      64                 :             :                 // Basic cases
      65                 :             :                 {"path/","path"},
      66                 :             :                 {"folder////","folder"},
      67                 :             :                 {"/home/user////","/home/user"},
      68                 :             :                 {"/var/log//","/var/log"},
      69                 :             :                 {"/usr/local/bin/","/usr/local/bin"},
      70                 :             :                 {"///home///","///home"},
      71                 :             : 
      72                 :             :                 // Root path cases
      73                 :             :                 {"/","/"},
      74                 :             :                 {"////","/"},
      75                 :             : 
      76                 :             :                 // No trailing slashes
      77                 :             :                 {"path","path"},
      78                 :             :                 {"/usr/local/bin","/usr/local/bin"},
      79                 :             :                 {"no/slash/here","no/slash/here"},
      80                 :             : 
      81                 :             :                 // Empty string
      82                 :             :                 {"",""},
      83                 :             : 
      84                 :             :                 // Edge cases
      85                 :             :                 {"//double//slash//","//double//slash"},
      86                 :             :                 {"////multiple///leading/slashes////","////multiple///leading/slashes"},
      87                 :             : 
      88                 :             :                 // Single character paths
      89                 :             :                 {"a/","a"},
      90                 :             :                 {"b////","b"},
      91                 :             :                 {"c","c"},
      92                 :             :                 {NULL,NULL} // Sentinel value
      93                 :             :         };
      94                 :             : 
      95         [ +  + ]:          18 :         for(size_t i = 0; test_cases[i].input != NULL; i++)
      96                 :             :         {
      97   [ +  -  +  - ]:          17 :                 ASSERT(SUCCESS == test_remove_trailing_slash(test_cases[i].input,test_cases[i].expected));
      98                 :             :         }
      99                 :             : 
     100   [ +  -  -  +  :           1 :         RETURN_STATUS;
          -  -  -  +  +  
                      - ]
     101                 :             : }
        

Generated by: LCOV version 2.0-1