LCOV - code coverage report
Current view: top level - libs/rational/src - rational_provide.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 77.8 % 27 21
Test Date: 2026-03-01 04:31:48 Functions: 100.0 % 1 1
Branches: 71.4 % 14 10

             Branch data     Line data    Source code
       1                 :             : #include "rational.h"
       2                 :             : 
       3                 :             : /// Converts Return enum to a string
       4                 :         485 : const char *show_status(const Return status)
       5                 :             : {
       6                 :         485 :         const char *status_label = "UNKNOWN";
       7                 :             : 
       8                 :             :         /* Keep behavior explicit for the zero status value. */
       9         [ -  + ]:         485 :         if(status == OK)
      10                 :             :         {
      11                 :           0 :                 status_label = "OK";
      12                 :             :         } else {
      13                 :             :                 static char buffer[MAX_CHARACTERS];
      14                 :         485 :                 buffer[0] = '\0';
      15                 :             : 
      16                 :             :                 struct {
      17                 :             :                         Return flag;
      18                 :             :                         const char *name;
      19                 :         485 :                 } mapping[] = {
      20                 :             :                         {FAILURE,"FAILURE"},
      21                 :             :                         {YES,"YES"},
      22                 :             :                         {UNSUCCESS,"UNSUCCESS"},
      23                 :             :                         {SUCCESS,"SUCCESS"},
      24                 :             :                         {HALTED,"HALTED"},
      25                 :             :                         {WARNING,"WARNING"},
      26                 :             :                         {DONOTHING,"DONOTHING"},
      27                 :             :                         {INFO,"INFO"},
      28                 :             :                         {0,NULL}
      29                 :             :                 };
      30                 :             : 
      31                 :         485 :                 size_t used = 0U;
      32                 :         485 :                 bool first = true;
      33                 :         485 :                 unsigned int remaining = (unsigned int)status;
      34                 :             : 
      35         [ +  + ]:        4365 :                 for(size_t i = 0U; mapping[i].name != NULL; i++)
      36                 :             :                 {
      37                 :        3880 :                         const unsigned int flag = (unsigned int)mapping[i].flag;
      38                 :             : 
      39         [ +  + ]:        3880 :                         if((remaining & flag) == 0U)
      40                 :             :                         {
      41                 :        3361 :                                 continue;
      42                 :             :                         }
      43                 :             : 
      44         [ +  + ]:         519 :                         const int written = snprintf(
      45                 :             :                                 buffer + used,
      46                 :             :                                 MAX_CHARACTERS - used,
      47                 :             :                                 "%s%s",
      48                 :             :                                 first ? "" : "|",
      49                 :             :                                 mapping[i].name);
      50                 :             : 
      51         [ -  + ]:         519 :                         if(written < 0)
      52                 :             :                         {
      53                 :           0 :                                 break;
      54                 :             :                         }
      55                 :             : 
      56         [ -  + ]:         519 :                         if((size_t)written >= (MAX_CHARACTERS - used))
      57                 :             :                         {
      58                 :           0 :                                 buffer[MAX_CHARACTERS - 1U] = '\0';
      59                 :           0 :                                 status_label = buffer;
      60                 :           0 :                                 first = false;
      61                 :           0 :                                 break;
      62                 :             :                         }
      63                 :             : 
      64                 :         519 :                         used += (size_t)written;
      65                 :         519 :                         first = false;
      66                 :         519 :                         remaining &= ~flag;
      67                 :             :                 }
      68                 :             : 
      69         [ +  - ]:         485 :                 if(first == false)
      70                 :             :                 {
      71                 :         485 :                         status_label = buffer;
      72                 :             :                 }
      73                 :             :         }
      74                 :         485 :         return(status_label);
      75                 :             : }
        

Generated by: LCOV version 2.0-1