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

             Branch data     Line data    Source code
       1                 :             : #include "test_libmem_all.h"
       2                 :             : 
       3                 :             : /**
       4                 :             :  * @brief Truncate a string through direct buffer access and let the helper add the terminator
       5                 :             :  *
       6                 :             :  * The descriptor is created as a string, modified via the writable pointer
       7                 :             :  * returned from m_data(...), and then finalized with a shorter length derived
       8                 :             :  * from the descriptor's own cached string_length. The terminator is materialized
       9                 :             :  * by m_finalize_string through WRITE_TERMINATOR_ALWAYS
      10                 :             :  *
      11                 :             :  * @return Return describing success or failure
      12                 :             :  */
      13                 :           1 : Return test_libmem_0049(void)
      14                 :             : {
      15                 :           1 :         INITTEST;
      16                 :             : 
      17                 :             :         static const char drafting_text[] = "drafting";
      18                 :           1 :         m_create(char,title,MEMORY_STRING);
      19                 :             : 
      20                 :           1 :         ASSERT(SUCCESS == m_copy_fixed_string(title,sizeof(drafting_text),drafting_text));
      21                 :           1 :         ASSERT(title->string_length == 8);
      22                 :           1 :         ASSERT(title->is_string == true);
      23                 :             : 
      24                 :           1 :         char *title_view = m_data(char,title);
      25                 :           1 :         ASSERT(title_view != NULL);
      26                 :             : 
      27                 :           1 :         size_t title_length = 0U;
      28                 :           1 :         ASSERT(SUCCESS == m_string_length(title,&title_length));
      29                 :             : 
      30                 :           1 :         const size_t truncated_length = title_length - 3U;
      31                 :             : 
      32                 :           1 :         IF(title_view != NULL)
      33                 :             :         {
      34                 :           1 :                 memcpy(title_view,"hello",truncated_length);
      35                 :             :         }
      36                 :             : 
      37                 :           1 :         ASSERT(SUCCESS == m_finalize_string(title,truncated_length,WRITE_TERMINATOR_ALWAYS));
      38                 :           1 :         ASSERT(title->string_length == 5);
      39                 :           1 :         ASSERT(title->is_string == true);
      40                 :           1 :         ASSERT(0 == strcmp(m_text(title),"hello"));
      41                 :           1 :         call(m_del(title));
      42                 :             : 
      43                 :           1 :         RETURN_STATUS;
      44                 :             : }
        

Generated by: LCOV version 2.0-1