LCOV - code coverage report
Current view: top level - tests/src - test0012.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 59 59
Test Date: 2026-01-12 05:34:38 Functions: 100.0 % 6 6

            Line data    Source code
       1              : #include "sute.h"
       2              : 
       3              : // Test helper function to verify array contents
       4            1 : static Return verify_array_contents(
       5              :         char       **array,
       6              :         const char **expected,
       7              :         size_t     expected_size)
       8              : {
       9              : 
      10            1 :         INITTEST;
      11              : 
      12            1 :         ASSERT(array != NULL);
      13              : 
      14            4 :         for(size_t i = 0; i < expected_size; i++)
      15              :         {
      16            3 :                 ASSERT(array[i] != NULL);
      17            3 :                 ASSERT(strcmp(array[i],expected[i]) == 0);
      18              :         }
      19            1 :         ASSERT(array[expected_size] == NULL);  // Verify NULL termination
      20              : 
      21            1 :         return(status);
      22              : }
      23              : 
      24            1 : static Return test_add_string_to_empty_array(void)
      25              : {
      26            1 :         INITTEST;
      27              : 
      28            1 :         char **array = NULL;
      29            1 :         const char *test_string = "Hello World";
      30              : 
      31            1 :         ASSERT(SUCCESS == add_string_to_array(&array,test_string));
      32            1 :         ASSERT(array != NULL);
      33            1 :         ASSERT(array[0] != NULL);
      34            1 :         ASSERT(strcmp(array[0],test_string) == 0);
      35            1 :         ASSERT(array[1] == NULL);
      36              : 
      37            1 :         free_str_array(array);
      38              : 
      39            1 :         RETURN_STATUS;
      40              : }
      41              : 
      42            1 : static Return test_add_multiple_strings(void)
      43              : {
      44            1 :         INITTEST;
      45              : 
      46            1 :         char **array = NULL;
      47            1 :         const char *strings[] = {
      48              :                 "First","Second","Third"
      49              :         };
      50            1 :         const size_t num_strings = sizeof(strings) / sizeof(strings[0]);
      51              : 
      52            4 :         for(size_t i = 0; i < num_strings; i++)
      53              :         {
      54            3 :                 ASSERT(SUCCESS == add_string_to_array(&array,strings[i]));
      55              :         }
      56              : 
      57            1 :         ASSERT(SUCCESS == verify_array_contents(array,strings,num_strings));
      58              : 
      59            1 :         free_str_array(array);
      60              : 
      61            1 :         RETURN_STATUS;
      62              : }
      63              : 
      64            1 : static Return test_add_empty_string(void)
      65              : {
      66            1 :         INITTEST;
      67              : 
      68            1 :         char **array = NULL;
      69            1 :         const char *empty_string = "";
      70              : 
      71            1 :         ASSERT(SUCCESS == add_string_to_array(&array,empty_string));
      72            1 :         ASSERT(array != NULL);
      73            1 :         ASSERT(array[0] != NULL);
      74            1 :         ASSERT(strcmp(array[0],empty_string) == 0);
      75            1 :         ASSERT(array[1] == NULL);
      76              : 
      77            1 :         free_str_array(array);
      78              : 
      79            1 :         RETURN_STATUS;
      80              : }
      81              : 
      82            1 : static Return test_add_long_string(void)
      83              : {
      84            1 :         INITTEST;
      85              : 
      86            1 :         char **array = NULL;
      87              :         char long_string[1024];
      88            1 :         memset(long_string,'A',sizeof(long_string) - 1);
      89            1 :         long_string[sizeof(long_string) - 1] = '\0';
      90              : 
      91            1 :         ASSERT(SUCCESS == add_string_to_array(&array,long_string));
      92            1 :         ASSERT(array != NULL);
      93            1 :         ASSERT(array[0] != NULL);
      94            1 :         ASSERT(strcmp(array[0],long_string) == 0);
      95            1 :         ASSERT(array[1] == NULL);
      96              : 
      97            1 :         free_str_array(array);
      98              : 
      99            1 :         RETURN_STATUS;
     100              : }
     101              : 
     102              : /**
     103              :  *
     104              :  * Unit Testing of precizer. add_string_to_array() function test set
     105              :  *
     106              :  */
     107            1 : Return test0012(void)
     108              : {
     109            1 :         INITTEST;
     110              : 
     111            1 :         TEST(test_add_string_to_empty_array,"Adding string to empty array…");
     112            1 :         TEST(test_add_multiple_strings,"Testing adding multiple strings…");
     113            1 :         TEST(test_add_empty_string,"Testing adding empty string…");
     114            1 :         TEST(test_add_long_string,"Testing adding long string…");
     115              : 
     116            1 :         RETURN_STATUS;
     117              : }
        

Generated by: LCOV version 2.0-1