"Fossies" - the Fresh Open Source Software Archive

Member "mariadb-connector-c-3.0.8-src/examples/test_output.c" (18 Dec 2018, 1401 Bytes) of package /linux/misc/mariadb-connector-c-3.0.8-src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include <stdio.h>
    2 #include <stdlib.h>
    3 #include <string.h>
    4 #ifdef _WIN32
    5 #define popen _popen
    6 #define pclose _pclose
    7 #endif
    8 int main(int argc, char *argv[])
    9 {
   10   char cmd_output[1024];
   11   char cmd_exp[1024];
   12   FILE *fp_exec, *fp_out, *fp_exp;
   13 
   14   if (argc < 3)
   15   {
   16     printf("Syntax: test_output test output expected");
   17     exit(-1);
   18   }
   19   if (!(fp_exec= popen(argv[1], "r")))
   20   {
   21     printf("Failed to run %s\n", argv[1]);
   22     exit(-1);
   23   }
   24 
   25   if (!(fp_out= fopen(argv[2], "w")))
   26   {
   27     printf("Failed to open %s for write\n", argv[2]);
   28     exit(-1);
   29   }
   30 
   31   while (NULL != fgets(cmd_output, sizeof(cmd_output-1), fp_exec))
   32   {
   33     fputs(cmd_output, fp_out);
   34   }
   35   pclose(fp_exec);
   36   fflush(fp_out);
   37   fclose(fp_out);
   38 
   39   if (argc == 3)
   40     return 0;
   41 
   42   if (!(fp_exp= fopen(argv[3], "r")))
   43   {
   44     /* if no exp file exists, we just return
   45        without an error = skip check */
   46     return(0);
   47   }
   48   if (!(fp_out= fopen(argv[2], "r")))
   49   {
   50     printf("Failed to open %s for read\n", argv[2]);
   51     exit(-1);
   52   }
   53 
   54   while (fgets(cmd_exp, sizeof(cmd_exp)-1, fp_exp))
   55   {
   56     if (!fgets(cmd_output, sizeof(cmd_output)-1, fp_out))
   57     {
   58       printf("Can't read from output file\n");
   59       goto error;
   60     }
   61     if (strcmp(cmd_output, cmd_exp))
   62     {
   63       printf("output and expected output are different\n");
   64       goto error;
   65     }
   66   }
   67   return 0;
   68 error:
   69   fclose(fp_exp);
   70   fclose(fp_out);
   71   return 1;
   72 }