LCOV - code coverage report
Current view: top level - libs/testitall/src - match_file_template.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 85.7 % 14 12
Test Date: 2026-01-12 05:34:38 Functions: 100.0 % 1 1

            Line data    Source code
       1              : #include "testitall.h"
       2              : 
       3              : /**
       4              :  * @brief Executes command and matches its output against a template from file
       5              :  *
       6              :  * @param command Command to execute
       7              :  * @param filename File containing the template pattern
       8              :  * @param template Template placeholder to replace
       9              :  * @param replacement String to replace template placeholder with
      10              :  * @param expected_return_code Expected return code from command execution
      11              :  *
      12              :  * @return SUCCESS if command output matches modified template
      13              :  *         FAILURE if any step fails (file read, placeholder replacement, command execution, pattern match)
      14              :  *
      15              :  * @note Function combines multiple operations:
      16              :  *       1. Reads template from file
      17              :  *       2. Replaces placeholder in template
      18              :  *       3. Executes command
      19              :  *       4. Matches command output against modified template
      20              :  */
      21            1 : Return match_file_template(
      22              :         const char *command,
      23              :         const char *filename,
      24              :         const char *template,
      25              :         const char *replacement,
      26              :         const int  expected_return_code)
      27              : {
      28            1 :         if(!command || !filename || !template || !replacement)
      29              :         {
      30            0 :                 echo(STDERR,"NULL pointer passed to match_file_template\n");
      31            0 :                 return FAILURE;
      32              :         }
      33              : 
      34              :         /// The status that will be passed to return() before exiting.
      35              :         /// By default, the function worked without errors.
      36            1 :         Return status = SUCCESS;
      37              : 
      38              :         // Will store template content from file
      39            1 :         create(char,pattern);
      40              : 
      41              :         // Create memory for command output
      42            1 :         create(char,result);
      43              : 
      44              :         // Read template pattern from file
      45            1 :         status = get_file_content(filename,pattern);
      46              : 
      47              :         // Replace template placeholder with actual value
      48            1 :         ASSERT(SUCCESS == replace_placeholder(pattern,template,replacement));
      49              : 
      50              :         // Execute command and capture output
      51            1 :         ASSERT(SUCCESS == execute_command(command,result,expected_return_code,ALLOW_BOTH));
      52              : 
      53              :         // Compare command output against modified template
      54            1 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      55              : 
      56              :         #if 0
      57              :         write_to_temp_file(result_text ? result_text : "");
      58              :         #endif
      59              : 
      60              :         // Final cleanup
      61            1 :         call(del(result));
      62            1 :         call(del(pattern));
      63              : 
      64            1 :         return(status);
      65              : }
        

Generated by: LCOV version 2.0-1