LCOV - code coverage report
Current view: top level - libs/mem/tests/src - test_libmem_0069.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 81 81
Test Date: 2026-07-12 01:01:34 Functions: 100.0 % 3 3
Branches: 100.0 % 12 12

             Branch data     Line data    Source code
       1                 :             : #include "test_libmem_all.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  * @brief Capture inline string descriptors stored inside one root descriptor
       5                 :             :  *
       6                 :             :  * @return Return describing success or failure
       7                 :             :  */
       8                 :           1 : static Return capture_inline_string_descriptor_table(void)
       9                 :             : {
      10                 :           1 :         INITTEST;
      11                 :             : 
      12                 :           1 :         m_create(int,numbers);
      13                 :           1 :         m_create(memory,table);
      14                 :             : 
      15                 :           1 :         ASSERT(SUCCESS == m_resize(numbers,3));
      16                 :             : 
      17                 :           1 :         int *number_view = m_data(int,numbers);
      18                 :           1 :         ASSERT(number_view != NULL);
      19                 :             : 
      20                 :           1 :         IF(number_view != NULL)
      21                 :             :         {
      22                 :           1 :                 number_view[0] = 1;
      23                 :           1 :                 number_view[1] = 2;
      24                 :           1 :                 number_view[2] = 3;
      25                 :             :         }
      26                 :             : 
      27                 :           1 :         int *second_number = m_item(int,numbers,1);
      28                 :           1 :         ASSERT(second_number != NULL);
      29                 :             : 
      30                 :           1 :         IF(second_number != NULL)
      31                 :             :         {
      32                 :           1 :                 ASSERT(*second_number == 2);
      33                 :             :         }
      34                 :             : 
      35                 :           1 :         const int *third_number = m_item_ro(int,numbers,2);
      36                 :           1 :         ASSERT(third_number != NULL);
      37                 :             : 
      38                 :           1 :         IF(third_number != NULL)
      39                 :             :         {
      40                 :           1 :                 ASSERT(*third_number == 3);
      41                 :             :         }
      42                 :             : 
      43                 :           1 :         size_t number_count = 0;
      44                 :           1 :         int number_sum = 0;
      45                 :             : 
      46   [ +  +  +  + ]:           5 :         mem_core_array_foreach(numbers,int,number)
      47                 :             :         {
      48                 :           3 :                 *number += 1;
      49                 :           3 :                 number_sum += *number;
      50                 :           3 :                 ++number_count;
      51                 :             :         }
      52                 :             : 
      53                 :           1 :         ASSERT(number_count == 3U);
      54                 :           1 :         ASSERT(number_sum == 9);
      55                 :             : 
      56                 :           1 :         IF(number_view != NULL)
      57                 :             :         {
      58                 :           1 :                 ASSERT(number_view[0] == 2);
      59                 :           1 :                 ASSERT(number_view[1] == 3);
      60                 :           1 :                 ASSERT(number_view[2] == 4);
      61                 :             :         }
      62                 :             : 
      63                 :             :         static const char epsilon_bounded_source[] =
      64                 :             :         {'e','p','s','i','l','o','n','\0','x'};
      65                 :             : 
      66                 :           1 :         ASSERT(SUCCESS == m_string_array_append(table,char,"delta"));
      67                 :           1 :         ASSERT(SUCCESS == m_string_array_append(table,char,sizeof(epsilon_bounded_source),epsilon_bounded_source));
      68                 :           1 :         ASSERT(SUCCESS == m_string_array_append(table,char,"zeta"));
      69                 :           1 :         ASSERT(table->is_string == false);
      70                 :           1 :         ASSERT(table->single_element_size == sizeof(memory));
      71                 :           1 :         ASSERT(table->length == 3);
      72                 :             : 
      73                 :           1 :         const memory *epsilon_descriptor = m_item_ro(memory,table,1);
      74                 :           1 :         ASSERT(epsilon_descriptor != NULL);
      75                 :             : 
      76                 :           1 :         IF(epsilon_descriptor != NULL)
      77                 :             :         {
      78                 :           1 :                 ASSERT(strcmp(m_text(epsilon_descriptor),"epsilon") == 0);
      79                 :             :         }
      80                 :             : 
      81                 :           1 :         size_t descriptor_count = 0;
      82                 :             : 
      83   [ +  +  +  + ]:           5 :         m_string_array_foreach(table,descriptor)
      84                 :             :         {
      85                 :           3 :                 ASSERT(descriptor->is_string == true);
      86                 :           3 :                 ASSERT(descriptor->single_element_size == sizeof(char));
      87                 :           3 :                 ASSERT(SUCCESS == m_concat_literal(descriptor,"!"));
      88                 :           3 :                 ++descriptor_count;
      89                 :             :         }
      90                 :             : 
      91                 :           1 :         ASSERT(descriptor_count == table->length);
      92                 :             : 
      93   [ +  +  +  + ]:           5 :         m_string_array_foreach(table,descriptor)
      94                 :             :         {
      95                 :           3 :                 ASSERT(descriptor->is_string == true);
      96                 :           3 :                 ASSERT(descriptor->single_element_size == sizeof(char));
      97                 :           3 :                 printf("%s\n",m_text(descriptor));
      98                 :             :         }
      99                 :             : 
     100                 :           1 :         call(m_del(numbers));
     101                 :           1 :         ASSERT(SUCCESS == m_array_del(table));
     102                 :           1 :         ASSERT(table->data == NULL);
     103                 :           1 :         ASSERT(table->length == 0);
     104                 :           1 :         ASSERT(table->string_length == 0);
     105                 :           1 :         ASSERT(table->is_string == false);
     106                 :           1 :         ASSERT(table->single_element_size == sizeof(memory));
     107                 :             : 
     108                 :           1 :         deliver(status);
     109                 :             : }
     110                 :             : 
     111                 :             : /**
     112                 :             :  * @brief Capture negative item-access cases for descriptor-backed arrays
     113                 :             :  *
     114                 :             :  * @return Return describing success or failure
     115                 :             :  */
     116                 :           1 : static Return capture_array_item_negative_cases(void)
     117                 :             : {
     118                 :           1 :         INITTEST;
     119                 :             : 
     120                 :           1 :         m_create(int,numbers);
     121                 :           1 :         m_create(int,empty);
     122                 :             : 
     123                 :           1 :         ASSERT(SUCCESS == m_resize(numbers,2));
     124                 :             : 
     125                 :           1 :         ASSERT(NULL == m_item_ro(int,NULL,0));
     126                 :           1 :         ASSERT(NULL == m_item(int,NULL,0));
     127                 :           1 :         ASSERT(NULL == m_item_ro(int,empty,0));
     128                 :           1 :         ASSERT(NULL == m_item(int,empty,0));
     129                 :           1 :         ASSERT(NULL == m_item_ro(int,numbers,2));
     130                 :           1 :         ASSERT(NULL == m_item(int,numbers,2));
     131                 :           1 :         ASSERT(NULL == m_item_ro(unsigned long long,numbers,0));
     132                 :           1 :         ASSERT(NULL == m_item(unsigned long long,numbers,0));
     133                 :             : 
     134                 :           1 :         call(m_del(numbers));
     135                 :           1 :         call(m_del(empty));
     136                 :             : 
     137                 :           1 :         deliver(status);
     138                 :             : }
     139                 :             : 
     140                 :             : /**
     141                 :             :  * @brief Check inline string descriptors in one root descriptor
     142                 :             :  *
     143                 :             :  * @return Return describing success or failure
     144                 :             :  */
     145                 :           1 : Return test_libmem_0069(void)
     146                 :             : {
     147                 :           1 :         INITTEST;
     148                 :             : 
     149                 :             :         static const char expected_stdout_pattern[] =
     150                 :             :                 "\\A"
     151                 :             :                 "delta!\n"
     152                 :             :                 "epsilon!\n"
     153                 :             :                 "zeta!\n"
     154                 :             :                 "\\Z";
     155                 :             : 
     156                 :             :         static const char expected_negative_stderr_pattern[] =
     157                 :             :                 "\\A.*Descriptor is NULL"
     158                 :             :                 ".*Item index 0 is out of range for descriptor length 0"
     159                 :             :                 ".*Item index 2 is out of range for descriptor length 2"
     160                 :             :                 ".*Expected.*\\Z";
     161                 :             : 
     162                 :           1 :         ASSERT(SUCCESS == match_function_output(expected_stdout_pattern,NULL,capture_inline_string_descriptor_table));
     163                 :             : 
     164                 :           1 :         ASSERT(SUCCESS == match_function_output(NULL,expected_negative_stderr_pattern,capture_array_item_negative_cases));
     165                 :             : 
     166                 :           1 :         RETURN_STATUS;
     167                 :             : }
        

Generated by: LCOV version 2.0-1