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

             Branch data     Line data    Source code
       1                 :             : #include "test_libtestitall_all.h"
       2                 :             : 
       3                 :             : /* Store the expected value in this library suite instead of an application template file */
       4                 :             : static const char expected_capability_demonstration_output[] =
       5                 :             :         "The gentle melody floated through\n"
       6                 :             :         "the afternoon air as children played in the garden,\n"
       7                 :             :         "their laughter mixing with birdsong.\n"
       8                 :             :         "Butterflies danced among colorful flowers while a\n"
       9                 :             :         "tabby cat watched lazily from its sunny spot on the\n"
      10                 :             :         "wooden fence, tail swaying gently in the warm summer breeze.\n";
      11                 :             : 
      12                 :             : /**
      13                 :             :  * @brief Print demonstration output for function_capture()
      14                 :             :  */
      15                 :           1 : static void print_capability_demonstration_output(void)
      16                 :             : {
      17                 :             :         // Produce output independently from the expected string stored by this test
      18                 :           1 :         printf(
      19                 :             :                 "The %se melody floated through\n"
      20                 :             :                 "the afternoon air as children played in the garden,\n"
      21                 :             :                 "their laughter mixing with birdsong.\n"
      22                 :             :                 "Butterflies danced among colorful flowers while a\n"
      23                 :             :                 "tabby cat watched lazily from its sunny spot on the\n"
      24                 :             :                 "wooden fence, tail swaying %sy in the warm summer breeze.\n",
      25                 :             :                 "gentl",
      26                 :             :                 "gentl");
      27                 :           1 : }
      28                 :             : 
      29                 :             : /**
      30                 :             :  * @brief Produce no output while exercising empty capture results
      31                 :             :  */
      32                 :           1 : static void print_no_capture_output(void)
      33                 :             : {
      34                 :             :         /* Intentionally empty: verifies capture behavior when the callback prints nothing */
      35                 :           1 : }
      36                 :             : 
      37                 :             : /**
      38                 :             :  * @brief Check stdout capture against an expected string kept in the library test
      39                 :             :  * @details The test is self-contained and does not depend on application template files
      40                 :             :  *
      41                 :             :  * @return Return status code
      42                 :             :  */
      43                 :           1 : Return test_libtestitall_0004(void)
      44                 :             : {
      45                 :           1 :         INITTEST;
      46                 :             : 
      47                 :           1 :         m_create(char,captured_stdout,MEMORY_STRING);
      48                 :           1 :         m_create(char,captured_stderr,MEMORY_STRING);
      49                 :             : 
      50                 :             :         // Capture output before comparing it with the inline expectation
      51                 :           1 :         ASSERT(SUCCESS == function_capture(
      52                 :             :                 print_capability_demonstration_output,
      53                 :             :                 captured_stdout,
      54                 :             :                 captured_stderr));
      55                 :             : 
      56                 :           1 :         ASSERT(captured_stdout->length > 0U);
      57                 :           1 :         ASSERT(captured_stderr->length == 0U);
      58                 :           1 :         ASSERT(m_text(captured_stdout) != NULL);
      59                 :             : 
      60                 :           1 :         IF(m_text(captured_stdout) != NULL)
      61                 :             :         {
      62                 :             :                 /* Compare the materialized capture only after its text view is confirmed available */
      63                 :           1 :                 ASSERT(0 == strcmp(m_text(captured_stdout),expected_capability_demonstration_output));
      64                 :             :         }
      65                 :             : 
      66                 :           1 :         ASSERT(SUCCESS == m_copy_literal(captured_stdout,"previous stdout"));
      67                 :           1 :         ASSERT(SUCCESS == m_copy_literal(captured_stderr,"previous stderr"));
      68                 :             : 
      69                 :           1 :         ASSERT(SUCCESS == function_capture(
      70                 :             :                 print_no_capture_output,
      71                 :             :                 captured_stdout,
      72                 :             :                 captured_stderr));
      73                 :             : 
      74                 :           1 :         ASSERT(captured_stdout->length == 0U);
      75                 :           1 :         ASSERT(captured_stderr->length == 0U);
      76                 :           1 :         ASSERT(captured_stdout->string_length == 0U);
      77                 :           1 :         ASSERT(captured_stderr->string_length == 0U);
      78                 :           1 :         ASSERT(0 == strcmp(m_text(captured_stdout),""));
      79                 :           1 :         ASSERT(0 == strcmp(m_text(captured_stderr),""));
      80                 :             : 
      81                 :           1 :         call(m_del(captured_stderr));
      82                 :           1 :         call(m_del(captured_stdout));
      83                 :             : 
      84                 :           1 :         RETURN_STATUS;
      85                 :             : }
        

Generated by: LCOV version 2.0-1