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

             Branch data     Line data    Source code
       1                 :             : #include "test_libmem_all.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  * @brief Capture string truncate rejection for descriptors whose reserve does not cover the payload
       5                 :             :  *
       6                 :             :  * @return Return describing success or failure
       7                 :             :  */
       8                 :           1 : static Return capture_libmem_inconsistent_string_truncate_reserve(void)
       9                 :             : {
      10                 :           1 :         INITTEST;
      11                 :             : 
      12                 :           1 :         char materialized_same_length[] = "alpha";
      13                 :           1 :         char materialized_growth_noop[] = "omega";
      14                 :           1 :         memory invalid_same_length = m_init(char,MEMORY_STRING);
      15                 :           1 :         memory invalid_growth_noop = m_init(char,MEMORY_STRING);
      16                 :             : 
      17                 :           1 :         invalid_same_length.data = materialized_same_length;
      18                 :           1 :         invalid_same_length.length = sizeof(materialized_same_length);
      19                 :           1 :         invalid_same_length.actually_allocated_bytes = sizeof(materialized_same_length) - 1u;
      20                 :           1 :         invalid_same_length.string_length = sizeof(materialized_same_length) - 1u;
      21                 :           1 :         invalid_same_length.is_string = true;
      22                 :             : 
      23                 :           1 :         invalid_growth_noop.data = materialized_growth_noop;
      24                 :           1 :         invalid_growth_noop.length = sizeof(materialized_growth_noop);
      25                 :           1 :         invalid_growth_noop.actually_allocated_bytes = sizeof(materialized_growth_noop) - 1u;
      26                 :           1 :         invalid_growth_noop.string_length = sizeof(materialized_growth_noop) - 1u;
      27                 :           1 :         invalid_growth_noop.is_string = true;
      28                 :             : 
      29                 :           1 :         ASSERT(FAILURE == m_string_truncate(&invalid_same_length,invalid_same_length.string_length));
      30                 :           1 :         ASSERT(invalid_same_length.data == materialized_same_length);
      31                 :           1 :         ASSERT(invalid_same_length.length == sizeof(materialized_same_length));
      32                 :           1 :         ASSERT(invalid_same_length.actually_allocated_bytes == sizeof(materialized_same_length) - 1u);
      33                 :           1 :         ASSERT(invalid_same_length.string_length == sizeof(materialized_same_length) - 1u);
      34                 :           1 :         ASSERT(invalid_same_length.is_string == true);
      35                 :             : 
      36                 :           1 :         ASSERT(FAILURE == m_string_truncate(&invalid_growth_noop,invalid_growth_noop.string_length + 1u));
      37                 :           1 :         ASSERT(invalid_growth_noop.data == materialized_growth_noop);
      38                 :           1 :         ASSERT(invalid_growth_noop.length == sizeof(materialized_growth_noop));
      39                 :           1 :         ASSERT(invalid_growth_noop.actually_allocated_bytes == sizeof(materialized_growth_noop) - 1u);
      40                 :           1 :         ASSERT(invalid_growth_noop.string_length == sizeof(materialized_growth_noop) - 1u);
      41                 :           1 :         ASSERT(invalid_growth_noop.is_string == true);
      42                 :             : 
      43                 :           1 :         deliver(status);
      44                 :             : }
      45                 :             : 
      46                 :             : /**
      47                 :             :  * @brief Check string truncate rejection for descriptors whose reserve does not cover the payload
      48                 :             :  *
      49                 :             :  * @return Return describing success or failure
      50                 :             :  */
      51                 :           1 : Return test_libmem_0042(void)
      52                 :             : {
      53                 :           1 :         INITTEST;
      54                 :             : 
      55                 :             :         static const char expected_stderr_pattern_libmem_0042[] =
      56                 :             :                 "\\A.*Descriptor reserve is smaller than logical payload during string truncate.*\\Z";
      57                 :             : 
      58                 :           1 :         ASSERT(SUCCESS == match_function_output(NULL,expected_stderr_pattern_libmem_0042,capture_libmem_inconsistent_string_truncate_reserve));
      59                 :             : 
      60                 :           1 :         RETURN_STATUS;
      61                 :             : }
        

Generated by: LCOV version 2.0-1