test/harness/testcaseio.c
changeset 10 f28ad4577863
parent 8 cf332d440466
child 11 4a80c6053a66
     1.1 --- a/test/harness/testcaseio.c	Fri Jan 27 23:59:51 2012 +0000
     1.2 +++ b/test/harness/testcaseio.c	Mon Jan 30 09:11:07 2012 +0000
     1.3 @@ -4,6 +4,7 @@
     1.4  #include <glib.h>
     1.5  #include <bl/bl.h>
     1.6  #include "testcaseparser.h"
     1.7 +#include "testcaseinput.h"
     1.8  #include "testcaseio.h"
     1.9  
    1.10  /*
    1.11 @@ -15,7 +16,8 @@
    1.12  {
    1.13      Testcase *testcase;
    1.14      TestcaseParser *parser;
    1.15 -    char *s;
    1.16 +    TestcaseInput *input=NULL;
    1.17 +    char *s,*arg;
    1.18      const char *tag,*text;
    1.19      gboolean found_tag=FALSE;
    1.20      parser=testcase_parser_new_from_file(filename);
    1.21 @@ -34,12 +36,44 @@
    1.22  	*s='\0';
    1.23      while(testcase_parser_get_next_tag(parser,&tag,&text))
    1.24      {
    1.25 -	if (!testcase->input && !strcmp(tag,"INPUT"))
    1.26 -	    testcase->input=g_strdup(text);
    1.27 +	if (!input && !strcmp(tag,"INPUT"))
    1.28 +	    input=testcase_input_new("TEST-XXXXXX",text);
    1.29 +	else if (g_str_has_prefix(tag,"INPUT(") && tag[strlen(tag)-1]==')')
    1.30 +	{
    1.31 +	    arg=g_strndup(tag+6,strlen(tag)-7);
    1.32 +	    s=g_path_get_dirname(arg);
    1.33 +	    if (strcmp(s,"."))
    1.34 +	    {
    1.35 +		/*
    1.36 +		 * Otherwise it would be possible to overwrite an arbitary
    1.37 +		 * file on somebody's computer by getting them to run a
    1.38 +		 * testcase!
    1.39 +		 */
    1.40 +		fprintf(stderr,
    1.41 +		  "%s: Input files may not have a directory component\n",arg);
    1.42 +		g_free(s);
    1.43 +		g_free(arg);
    1.44 +		testcase_free(testcase);
    1.45 +		testcase_parser_free(parser);
    1.46 +		return NULL;
    1.47 +	    }
    1.48 +	    g_free(s);
    1.49 +	    testcase->inputs=g_slist_prepend(testcase->inputs,
    1.50 +	      testcase_input_new(arg,text));
    1.51 +	    if (!strstr(arg,"XXXXXX"))
    1.52 +		testcase->flags|=TESTCASE_TMP_DIR;
    1.53 +	    g_free(arg);
    1.54 +	}
    1.55  	else if (!testcase->expected && !strcmp(tag,"EXPECTED"))
    1.56  	    testcase->expected=g_strdup(text);
    1.57  	else if (!testcase->encoding && !strcmp(tag,"ENCODING"))
    1.58  	    testcase->encoding=g_strchomp(g_strdup(text));
    1.59 +	else if (!testcase->encoding && !strcmp(tag,"OPTIONS"))
    1.60 +	{
    1.61 +	    testcase->options=g_strsplit(text,"\n",0);
    1.62 +	    g_free(testcase->options[g_strv_length(testcase->options)-1]);
    1.63 +	    testcase->options[g_strv_length(testcase->options)-1]=NULL;
    1.64 +	}
    1.65  	else
    1.66  	{
    1.67  	    fprintf(stderr,"%s: Not a valid testcase (%s)\n",filename,tag);
    1.68 @@ -61,6 +95,9 @@
    1.69  	testcase_parser_free(parser);
    1.70  	return NULL;
    1.71      }
    1.72 +    if (!input)
    1.73 +	input=testcase_input_new("TEST-XXXXXX",NULL);
    1.74 +    testcase->inputs=g_slist_prepend(testcase->inputs,input);
    1.75      testcase_parser_free(parser);
    1.76      return testcase;
    1.77  }