LCOV - code coverage report
Current view: top level - tests/src - test0008.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 140 140
Test Date: 2026-03-01 04:31:48 Functions: 100.0 % 7 7
Branches: 45.7 % 94 43

             Branch data     Line data    Source code
       1                 :             : #include "sute.h"
       2                 :             : #include <errno.h>
       3                 :             : 
       4                 :           1 : static void report_test(void)
       5                 :             : {
       6                 :           1 :         errno = ENOMEM;
       7                 :             :         // Report an error with formatted message
       8                 :           1 :         report("Memory reallocation failed with bytes %d",10);
       9                 :           1 :         errno = EOVERFLOW;
      10                 :             :         // Report an error with multiple arguments
      11                 :           1 :         report("Buffer overflow at position %d with value %s",42,"overflow");
      12                 :           1 : }
      13                 :             : 
      14                 :           1 : static void slog_test(void)
      15                 :             : {
      16                 :           1 :         printf("All available combinations:\n");
      17                 :           1 :         printf("%s\n",rational_convert(REGULAR));
      18                 :           1 :         printf("%s\n",rational_convert(VERBOSE));
      19                 :           1 :         printf("%s\n",rational_convert(TESTING));
      20                 :           1 :         printf("%s\n",rational_convert(SILENT));
      21                 :           1 :         printf("%s\n",rational_convert(REGULAR|VERBOSE));
      22                 :           1 :         printf("%s\n",rational_convert(REGULAR|TESTING));
      23                 :           1 :         printf("%s\n",rational_convert(VERBOSE|TESTING));
      24                 :           1 :         printf("%s\n",rational_convert(REGULAR|VERBOSE|TESTING));
      25                 :           1 :         printf("%s\n",rational_convert(ERROR));
      26                 :           1 :         printf("%s\n",rational_convert(UNDECOR));
      27                 :           1 :         printf("%s\n",rational_convert(EVERY|UNDECOR));
      28                 :           1 :         printf("%s\n",rational_convert(ERROR|UNDECOR));
      29                 :             : 
      30                 :             :         /* Test REGULAR mode combinations */
      31                 :           1 :         rational_logger_mode = REGULAR;
      32                 :           1 :         printf("Mode: %s\n",rational_reconvert(rational_logger_mode));
      33                 :           1 :         printf("1.  Must print:"); slog(REGULAR,"true"); printf("\n");
      34                 :           1 :         printf("2. Won't print:"); slog(VERBOSE,"but printed!"); printf("\n");
      35                 :           1 :         printf("3. Won't print:"); slog(TESTING,"but printed!"); printf("\n");
      36                 :           1 :         printf("4.  Must print:");   slog(ERROR,"true"); printf("\n");
      37                 :             : 
      38                 :             :         /* Test VERBOSE mode combinations */
      39                 :           1 :         rational_logger_mode = VERBOSE;
      40                 :           1 :         printf("Mode: %s\n",rational_reconvert(rational_logger_mode));
      41                 :           1 :         printf("5. Won't print:"); slog(REGULAR,"but printed!"); printf("\n");
      42                 :           1 :         printf("6.  Must print:"); slog(VERBOSE,"true"); printf("\n");
      43                 :           1 :         printf("7. Won't print:"); slog(TESTING,"but printed!"); printf("\n");
      44                 :           1 :         printf("8.  Must print:");   slog(ERROR,"true"); printf("\n");
      45                 :             : 
      46                 :             :         /* Test TESTING mode combinations */
      47                 :           1 :         rational_logger_mode = TESTING;
      48                 :           1 :         printf("Mode: %s\n",rational_reconvert(rational_logger_mode));
      49                 :           1 :         printf("9.  Won't print:"); slog(REGULAR,"but printed!"); printf("\n");
      50                 :           1 :         printf("10. Won't print:"); slog(VERBOSE,"but printed!"); printf("\n");
      51                 :           1 :         printf("11.  Must print:"); slog(TESTING,"true"); printf("\n");
      52                 :           1 :         printf("12.  Must print:");   slog(ERROR,"true"); printf("\n");
      53                 :             : 
      54                 :             :         /* Test SILENT mode combinations */
      55                 :           1 :         rational_logger_mode = SILENT;
      56                 :           1 :         printf("Mode: %s\n",rational_reconvert(rational_logger_mode));
      57                 :           1 :         printf("13. Won't print:"); slog(REGULAR,"but printed!"); printf("\n");
      58                 :           1 :         printf("14. Won't print:"); slog(VERBOSE,"but printed!"); printf("\n");
      59                 :           1 :         printf("15. Won't print:"); slog(TESTING,"but printed!"); printf("\n");
      60                 :           1 :         printf("16. Won't print:");   slog(ERROR,"but printed!"); printf("\n");
      61                 :             : 
      62                 :             :         /* Test REGULAR|VERBOSE combinations */
      63                 :           1 :         rational_logger_mode = REGULAR|VERBOSE;
      64                 :           1 :         printf("Mode: %s\n",rational_reconvert(rational_logger_mode));
      65                 :           1 :         printf("17.  Must print:"); slog(REGULAR,"true"); printf("\n");
      66                 :           1 :         printf("18.  Must print:"); slog(VERBOSE,"true"); printf("\n");
      67                 :           1 :         printf("19. Won't print:"); slog(TESTING,"but printed!"); printf("\n");
      68                 :           1 :         printf("20.  Must print:");   slog(ERROR,"true"); printf("\n");
      69                 :             : 
      70                 :             :         /* Test REGULAR|TESTING combinations */
      71                 :           1 :         rational_logger_mode = REGULAR|TESTING;
      72                 :           1 :         printf("Mode: %s\n",rational_reconvert(rational_logger_mode));
      73                 :           1 :         printf("21.  Must print:"); slog(REGULAR,"true"); printf("\n");
      74                 :           1 :         printf("22. Won't print:"); slog(VERBOSE,"but printed!"); printf("\n");
      75                 :           1 :         printf("23.  Must print:"); slog(TESTING,"true"); printf("\n");
      76                 :           1 :         printf("24.  Must print:"); slog(ERROR,"true"); printf("\n");
      77                 :             : 
      78                 :             :         /* Test VERBOSE|TESTING combinations */
      79                 :           1 :         rational_logger_mode = VERBOSE|TESTING;
      80                 :           1 :         printf("Mode: %s\n",rational_reconvert(rational_logger_mode));
      81                 :           1 :         printf("25. Won't print:"); slog(REGULAR,"but printed!"); printf("\n");
      82                 :           1 :         printf("26.  Must print:"); slog(VERBOSE,"true"); printf("\n");
      83                 :           1 :         printf("27.  Must print:"); slog(TESTING,"true"); printf("\n");
      84                 :           1 :         printf("28.  Must print:");   slog(ERROR,"true"); printf("\n");
      85                 :             : 
      86                 :             :         /* Test REGULAR|VERBOSE|TESTING combinations */
      87                 :           1 :         rational_logger_mode = REGULAR|VERBOSE|TESTING;
      88                 :           1 :         printf("Mode: %s\n",rational_reconvert(rational_logger_mode));
      89                 :           1 :         printf("29. Must print:"); slog(REGULAR,"true"); printf("\n");
      90                 :           1 :         printf("30. Must print:"); slog(VERBOSE,"true"); printf("\n");
      91                 :           1 :         printf("31. Must print:"); slog(TESTING,"true"); printf("\n");
      92                 :           1 :         printf("32. Must print:");   slog(ERROR,"true"); printf("\n");
      93                 :             : 
      94                 :             :         /* Test ERROR mode combinations */
      95                 :           1 :         rational_logger_mode = ERROR;
      96                 :           1 :         printf("Mode: %s\n",rational_reconvert(rational_logger_mode));
      97                 :           1 :         printf("33. Won't print:"); slog(REGULAR,"but printed!"); printf("\n");
      98                 :           1 :         printf("34. Won't print:"); slog(VERBOSE,"but printed!"); printf("\n");
      99                 :           1 :         printf("35. Won't print:"); slog(TESTING,"but printed!"); printf("\n");
     100                 :           1 :         printf("36.  Must print:");   slog(ERROR,"true"); printf("\n");
     101                 :             : 
     102                 :             :         /*
     103                 :             :          * Test UNDECOR flag: suppress logger prefixes (TESTING:, time/file/line/func, ERROR:)
     104                 :             :          * The output between the '|' markers should contain only the message payload
     105                 :             :          */
     106                 :           1 :         rational_logger_mode = EVERY|ERROR;
     107                 :           1 :         printf("Mode: %s\n",rational_reconvert(rational_logger_mode));
     108                 :           1 :         printf("37. Must print no prefixes:|"); slog(EVERY|UNDECOR,"true"); printf("|\n");
     109                 :           1 :         printf("38. Must print no ERROR prefix:|"); slog(ERROR|UNDECOR,"true"); printf("|\n");
     110                 :             : 
     111                 :           1 :         rational_logger_mode = VERBOSE;
     112                 :           1 :         printf("Mode: %s\n",rational_reconvert(rational_logger_mode));
     113                 :           1 :         printf("39. Must print no time/file/line/func:|"); slog(VERBOSE|UNDECOR,"true"); printf("|\n");
     114                 :             : 
     115                 :           1 :         rational_logger_mode = TESTING;
     116                 :           1 :         printf("Mode: %s\n",rational_reconvert(rational_logger_mode));
     117                 :           1 :         printf("40. Must print no TESTING prefix:|"); slog(TESTING|UNDECOR,"true"); printf("|\n");
     118                 :             : 
     119                 :           1 :         rational_logger_mode = REGULAR;
     120                 :           1 :         printf("Mode: %s\n",rational_reconvert(rational_logger_mode));
     121                 :           1 :         printf("41. Must not print (VERBOSE not enabled):|"); slog(VERBOSE|UNDECOR,"but printed!"); printf("|\n");
     122                 :           1 : }
     123                 :             : 
     124                 :           1 : static void serp_case(void)
     125                 :             : {
     126                 :           1 :         errno = ENOENT;
     127                 :           1 :         serp("Failed to open file");
     128                 :           1 : }
     129                 :             : 
     130                 :           1 : static Return test0008_1(void)
     131                 :             : {
     132                 :           1 :         INITTEST;
     133                 :           1 :         create(char,captured_stdout);
     134                 :           1 :         create(char,captured_stderr);
     135                 :           1 :         create(char,pattern);
     136                 :           1 :         const char *filename = "templates/0008_001.txt";
     137                 :             : 
     138   [ +  -  +  - ]:           1 :         ASSERT(SUCCESS == function_capture(report_test,captured_stdout,captured_stderr));
     139                 :             : 
     140                 :             :         #if 0
     141                 :             :         printf("captured_stderr:%s",getcstring(captured_stderr));
     142                 :             :         printf("captured_stdout:%s\n",getcstring(captured_stdout));
     143                 :             :         #endif
     144                 :             : 
     145   [ +  -  +  - ]:           1 :         ASSERT(captured_stdout->length == 0);
     146                 :             : 
     147   [ +  -  +  - ]:           1 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     148                 :             : 
     149   [ +  -  +  - ]:           1 :         ASSERT(SUCCESS == match_pattern(captured_stderr,pattern,filename));
     150                 :             : 
     151                 :           1 :         del(pattern);
     152                 :             : 
     153                 :           1 :         del(captured_stdout);
     154                 :           1 :         del(captured_stderr);
     155                 :             : 
     156   [ +  -  -  +  :           1 :         RETURN_STATUS;
          -  -  -  +  +  
                      - ]
     157                 :             : }
     158                 :             : 
     159                 :           1 : static Return test0008_2(void)
     160                 :             : {
     161                 :           1 :         INITTEST;
     162                 :             : 
     163                 :           1 :         create(char,captured_stdout);
     164                 :           1 :         create(char,captured_stderr);
     165                 :           1 :         create(char,pattern);
     166                 :           1 :         const char *filename = "templates/0008_002.txt";
     167                 :             : 
     168   [ +  -  +  - ]:           1 :         ASSERT(SUCCESS == function_capture(slog_test,captured_stdout,captured_stderr));
     169                 :             : 
     170                 :             :         #if 0
     171                 :             :         printf("captured_stderr:%s",getcstring(captured_stderr));
     172                 :             :         printf("captured_stdout:%s",getcstring(captured_stdout));
     173                 :             :         #endif
     174                 :             : 
     175   [ +  -  +  - ]:           1 :         ASSERT(captured_stderr->length == 0);
     176                 :             : 
     177   [ +  -  +  - ]:           1 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     178                 :             : 
     179   [ +  -  +  - ]:           1 :         ASSERT(SUCCESS == match_pattern(captured_stdout,pattern,filename));
     180                 :             : 
     181                 :           1 :         del(pattern);
     182                 :             : 
     183                 :           1 :         del(captured_stdout);
     184                 :           1 :         del(captured_stderr);
     185                 :             : 
     186   [ +  -  -  +  :           1 :         RETURN_STATUS;
          -  -  -  +  +  
                      - ]
     187                 :             : }
     188                 :             : 
     189                 :           1 : static Return test0008_3(void)
     190                 :             : {
     191                 :           1 :         INITTEST;
     192                 :             : 
     193                 :           1 :         create(char,captured_stdout);
     194                 :           1 :         create(char,captured_stderr);
     195                 :           1 :         create(char,pattern);
     196                 :           1 :         const char *filename = "templates/0008_003.txt";
     197                 :             : 
     198   [ +  -  +  - ]:           1 :         ASSERT(SUCCESS == function_capture(serp_case,captured_stdout,captured_stderr));
     199                 :             : 
     200   [ +  -  +  - ]:           1 :         ASSERT(captured_stdout->length == 0);
     201                 :             : 
     202   [ +  -  +  - ]:           1 :         ASSERT(SUCCESS == get_file_content(filename,pattern));
     203                 :             : 
     204   [ +  -  +  - ]:           1 :         ASSERT(SUCCESS == match_pattern(captured_stderr,pattern,filename));
     205                 :             : 
     206                 :           1 :         del(pattern);
     207                 :             : 
     208                 :           1 :         del(captured_stdout);
     209                 :           1 :         del(captured_stderr);
     210                 :             : 
     211   [ +  -  -  +  :           1 :         RETURN_STATUS;
          -  -  -  +  +  
                      - ]
     212                 :             : }
     213                 :             : 
     214                 :             : /**
     215                 :             :  * @brief librational report and logger tests
     216                 :             :  *
     217                 :             :  * @return SUCCESS when all subtests pass
     218                 :             :  */
     219                 :           1 : Return test0008(void)
     220                 :             : {
     221                 :           1 :         INITTEST;
     222                 :             : 
     223         [ +  - ]:           1 :         TEST(test0008_1,"librational test report messaging…");
     224         [ +  - ]:           1 :         TEST(test0008_2,"librational test slog messaging…");
     225         [ +  - ]:           1 :         TEST(test0008_3,"librational test serp messaging…");
     226                 :             : 
     227   [ +  -  -  +  :           1 :         RETURN_STATUS;
          -  -  -  +  +  
                      - ]
     228                 :             : }
        

Generated by: LCOV version 2.0-1