Changeset 97cdbaf5 for tester.c


Ignore:
Timestamp:
Mar 11, 2012, 10:57:35 PM (9 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.9
Children:
a03a409
Parents:
1f39ded
git-author:
David Benjamin <davidben@mit.edu> (01/23/12 00:38:29)
git-committer:
David Benjamin <davidben@mit.edu> (03/11/12 22:57:35)
Message:
Rewrite call_filter to use g_spawn_async_with_pipes

This simplifies the error-handling code. Also fixes a bug where file
descriptors get double-closed in call_filter. Also adds a unit test. The
separate prog argument is removed to avoid having to deal with
G_SPAWN_FILE_AND_ARGV_ZERO, and since we don't really use it anyway.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tester.c

    ra74a044 r97cdbaf5  
    33#include "owl.h"
    44#undef WINDOW
     5#include "filterproc.h"
    56
    67#include <stdio.h>
     
    2324int owl_smartfilter_regtest(void);
    2425int owl_history_regtest(void);
     26int call_filter_regtest(void);
    2527
    2628extern void owl_perl_xs_init(pTHX);
     
    113115  numfailures += owl_smartfilter_regtest();
    114116  numfailures += owl_history_regtest();
     117  numfailures += call_filter_regtest();
    115118  if (numfailures) {
    116119      fprintf(stderr, "# *** WARNING: %d failures total\n", numfailures);
     
    981984  return numfailed;
    982985}
     986
     987int call_filter_regtest(void)
     988{
     989  int numfailed = 0;
     990  int ret;
     991  char *out = NULL;
     992  int status;
     993
     994  printf("# BEGIN testing call_filter\n");
     995
     996  const char *cat_argv[] = { "cat", NULL };
     997  ret = call_filter(cat_argv, "Mangos!", &out, &status);
     998  FAIL_UNLESS("call_filter cat", (ret == 0 &&
     999                                  status == 0 &&
     1000                                  strcmp(out, "Mangos!") == 0));
     1001  g_free(out); out = NULL;
     1002
     1003  ret = call_filter(cat_argv, "", &out, &status);
     1004  FAIL_UNLESS("call_filter cat", (ret == 0 &&
     1005                                  status == 0 &&
     1006                                  strcmp(out, "") == 0));
     1007  g_free(out); out = NULL;
     1008
     1009  ret = call_filter(cat_argv, NULL, &out, &status);
     1010  FAIL_UNLESS("call_filter cat", (ret == 0 &&
     1011                                  status == 0 &&
     1012                                  strcmp(out, "") == 0));
     1013  g_free(out); out = NULL;
     1014
     1015  printf("# END testing call_filter (%d failures)\n", numfailed);
     1016  return numfailed;
     1017}
Note: See TracChangeset for help on using the changeset viewer.