test/harness/warningsparser.c
changeset 101 f44c530f80da
parent 17 2c88fd553e5d
     1.1 --- a/test/harness/warningsparser.c	Mon Feb 06 23:55:27 2012 +0000
     1.2 +++ b/test/harness/warningsparser.c	Sat Oct 26 18:47:33 2013 +0100
     1.3 @@ -15,11 +15,12 @@
     1.4      enum {
     1.5  	WARNINGS_INIT,
     1.6  	WARNINGS_IN_EXPECTED,
     1.7 +	WARNINGS_IN_SUMMARY,
     1.8  	WARNINGS_IN_WARNING,
     1.9  	WARNINGS_IN_AT,
    1.10  	WARNINGS_IN_TEXT,
    1.11  	WARNINGS_DONE,
    1.12 -    } state;
    1.13 +    } state,parent_state;
    1.14  } WarningsBaton;
    1.15  
    1.16  static void warnings_parser_start_element(GMarkupParseContext *context,
    1.17 @@ -30,6 +31,7 @@
    1.18      guint64 tmp;
    1.19      char *endp;
    1.20      WarningsBaton *baton=user_data;
    1.21 +    baton->parent_state=baton->state;
    1.22      switch(baton->state)
    1.23      {
    1.24  	case WARNINGS_INIT:
    1.25 @@ -45,20 +47,36 @@
    1.26  		baton->state=WARNINGS_IN_EXPECTED;
    1.27  	    break;
    1.28  	case WARNINGS_IN_EXPECTED:
    1.29 -	    baton->warning=g_new0(TestcaseWarning,1);
    1.30 -	    if (!strcmp(element_name,"error"))
    1.31 -		baton->warning->is_real=TRUE;
    1.32 -	    else if (!strcmp(element_name,"false-positive"))
    1.33 -		baton->warning->xfail=TRUE;
    1.34 -	    else if (!strcmp(element_name,"false-negative"))
    1.35 -		baton->warning->is_real=baton->warning->xfail=TRUE;
    1.36 +	    if (!strcmp(element_name,"summary"))
    1.37 +	    {
    1.38 +		if (baton->testcase->summary.texts)
    1.39 +		{
    1.40 +		    g_set_error(error,G_MARKUP_ERROR,
    1.41 +		      G_MARKUP_ERROR_INVALID_CONTENT,"Multiple summary "
    1.42 +		      "elements are not valid");
    1.43 +		}
    1.44 +		else
    1.45 +		    baton->state=WARNINGS_IN_SUMMARY;
    1.46 +	    }
    1.47  	    else
    1.48  	    {
    1.49 -		g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_UNKNOWN_ELEMENT,
    1.50 -		  "Unknown element in 'expected': '%s'",element_name);
    1.51 -		g_free(baton->warning);
    1.52 -		baton->warning=NULL;
    1.53 -		return;
    1.54 +		baton->warning=g_new0(TestcaseWarning,1);
    1.55 +		if (!strcmp(element_name,"error"))
    1.56 +		    baton->warning->is_real=TRUE;
    1.57 +		else if (!strcmp(element_name,"false-positive"))
    1.58 +		    baton->warning->xfail=TRUE;
    1.59 +		else if (!strcmp(element_name,"false-negative"))
    1.60 +		    baton->warning->is_real=baton->warning->xfail=TRUE;
    1.61 +		else
    1.62 +		{
    1.63 +		    g_set_error(error,G_MARKUP_ERROR,
    1.64 +		      G_MARKUP_ERROR_UNKNOWN_ELEMENT,
    1.65 +		      "Unknown element in 'expected': '%s'",element_name);
    1.66 +		    g_free(baton->warning);
    1.67 +		    baton->warning=NULL;
    1.68 +		    return;
    1.69 +		}
    1.70 +		baton->state=WARNINGS_IN_WARNING;
    1.71  	    }
    1.72  	    if (attribute_names[0])
    1.73  	    {
    1.74 @@ -66,12 +84,28 @@
    1.75  		  G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
    1.76  		  "Unknown attribute on element '%s': '%s'",element_name,
    1.77  		  attribute_names[0]);
    1.78 -		g_free(baton->warning);
    1.79 -		baton->warning=NULL;
    1.80 +		if (baton->state==WARNINGS_IN_WARNING)
    1.81 +		{
    1.82 +		    g_free(baton->warning);
    1.83 +		    baton->warning=NULL;
    1.84 +		}
    1.85 +		baton->state=WARNINGS_IN_EXPECTED;
    1.86  		return;
    1.87  	    }
    1.88 -	    else
    1.89 -		baton->state=WARNINGS_IN_WARNING;
    1.90 +	    break;
    1.91 +	case WARNINGS_IN_SUMMARY:
    1.92 +	    if (!strcmp(element_name,"text"))
    1.93 +	    {
    1.94 +		if (attribute_names[0])
    1.95 +		{
    1.96 +		    g_set_error(error,G_MARKUP_ERROR,
    1.97 +		      G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
    1.98 +		      "Unknown attribute on element 'text': '%s'",
    1.99 +		      attribute_names[0]);
   1.100 +		    return;
   1.101 +		}
   1.102 +		baton->state=WARNINGS_IN_TEXT;
   1.103 +	    }
   1.104  	    break;
   1.105  	case WARNINGS_IN_WARNING:
   1.106  	    if (!strcmp(element_name,"at"))
   1.107 @@ -162,6 +196,15 @@
   1.108  	      g_slist_reverse(baton->testcase->warnings);
   1.109  	    baton->state=WARNINGS_DONE;
   1.110  	    break;
   1.111 +	case WARNINGS_IN_SUMMARY:
   1.112 +	    if (!baton->testcase->summary.texts)
   1.113 +		g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT,
   1.114 +		  "Summary element must contain at least one text element");
   1.115 +	    else
   1.116 +		baton->testcase->summary.texts=
   1.117 +		  g_slist_reverse(baton->testcase->summary.texts);
   1.118 +	    baton->state=WARNINGS_IN_EXPECTED;
   1.119 +	    break;
   1.120  	case WARNINGS_IN_WARNING:
   1.121  	    baton->warning->locations=
   1.122  	      g_slist_reverse(baton->warning->locations);
   1.123 @@ -177,7 +220,7 @@
   1.124  	    baton->state=WARNINGS_IN_WARNING;
   1.125  	    break;
   1.126  	case WARNINGS_IN_TEXT:
   1.127 -	    baton->state=WARNINGS_IN_WARNING;
   1.128 +	    baton->state=baton->parent_state;
   1.129  	    break;
   1.130  	default:
   1.131  	    g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_UNKNOWN_ELEMENT,
   1.132 @@ -198,6 +241,11 @@
   1.133  		g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT,
   1.134  		  "The 'expected' tag does not take any content");
   1.135  	    break;
   1.136 +	case WARNINGS_IN_SUMMARY:
   1.137 +	    if (strspn(text," \t\n")!=text_len)
   1.138 +		g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT,
   1.139 +		  "The summary tags do not take any content");
   1.140 +	    break;
   1.141  	case WARNINGS_IN_WARNING:
   1.142  	    if (strspn(text," \t\n")!=text_len)
   1.143  		g_set_error(error,G_MARKUP_ERROR,G_MARKUP_ERROR_INVALID_CONTENT,
   1.144 @@ -211,7 +259,10 @@
   1.145  	case WARNINGS_IN_TEXT:
   1.146  	    s=g_strdup(text+strspn(text," \t\n"));
   1.147  	    g_strchomp(s);
   1.148 -	    if (baton->warning->text)
   1.149 +	    if (baton->parent_state==WARNINGS_IN_SUMMARY)
   1.150 +		baton->testcase->summary.texts=
   1.151 +		  g_slist_prepend(baton->testcase->summary.texts,s);
   1.152 +	    else if (baton->warning->text)
   1.153  	    {
   1.154  		t=g_strconcat(baton->warning->text,s,NULL);
   1.155  		g_free(baton->warning->text);
   1.156 @@ -237,6 +288,7 @@
   1.157      parser.text=warnings_parser_text;
   1.158      baton=g_new0(WarningsBaton,1);
   1.159      baton->testcase=testcase;
   1.160 +    baton->parent_state=WARNINGS_INIT;
   1.161      baton->state=WARNINGS_INIT;
   1.162      return g_markup_parse_context_new(&parser,
   1.163        G_MARKUP_TREAT_CDATA_AS_TEXT|G_MARKUP_PREFIX_ERROR_POSITION,