LCOV - code coverage report
Current view: top level - libs/testitall/src - match_app_output.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 Runs the tested application and matches its stdout against a template file.
       5              :  *
       6              :  * @param arguments Command-line arguments passed to the application (without the binary name).
       7              :  * @param filename Path to the file that stores the output template/pattern.
       8              :  * @param template Placeholder in the template that should be replaced before matching.
       9              :  * @param replacement Value that substitutes the placeholder (e.g., dynamic DB names).
      10              :  * @param expected_return_code Exit code that the application is expected to return.
      11              :  *
      12              :  * @return SUCCESS when the template is loaded, the placeholder is replaced, the
      13              :  *         application exits with the expected code, and its stdout matches the pattern.
      14              :  *         FAILURE if any of these stages fails.
      15              :  *
      16              :  * @note Combines several steps:
      17              :  *       1. Reads the template from disk.
      18              :  *       2. Performs placeholder substitution.
      19              :  *       3. Invokes the application via runit() and captures stdout.
      20              :  *       4. Matches the captured output against the prepared pattern with match_pattern().
      21              :  */
      22           24 : Return match_app_output(
      23              :         const char *arguments,
      24              :         const char *filename,
      25              :         const char *template,
      26              :         const char *replacement,
      27              :         const int  expected_return_code)
      28              : {
      29           24 :         if(!arguments || !filename || !template || !replacement)
      30              :         {
      31            0 :                 echo(STDERR,"NULL pointer passed to match_file_template\n");
      32            0 :                 return FAILURE;
      33              :         }
      34              : 
      35              :         /// The status that will be passed to return() before exiting.
      36              :         /// By default, the function worked without errors.
      37           24 :         Return status = SUCCESS;
      38              : 
      39              :         // Will store template content from file
      40           24 :         create(char,pattern);
      41              : 
      42              :         // Create memory for the output
      43           24 :         create(char,result);
      44              : 
      45              :         // Read template pattern from file
      46           24 :         status = get_file_content(filename,pattern);
      47              : 
      48              :         // Replace template placeholder with actual value
      49           24 :         ASSERT(SUCCESS == replace_placeholder(pattern,template,replacement));
      50              : 
      51              :         // Execute the application and capture output
      52           24 :         ASSERT(SUCCESS == runit(arguments,result,expected_return_code,ALLOW_BOTH));
      53              : 
      54              :         // Compare application output against modified template
      55           24 :         ASSERT(SUCCESS == match_pattern(result,pattern,filename));
      56              : 
      57              :         #if 0
      58              :         write_to_temp_file(result_text ? result_text : "");
      59              :         #endif
      60              : 
      61              :         // Final cleanup
      62           24 :         call(del(result));
      63           24 :         call(del(pattern));
      64              : 
      65           24 :         return(status);
      66              : }
        

Generated by: LCOV version 2.0-1