summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2012-10-16 06:00:40 -0400
committerMatthias Clasen <mclasen@redhat.com>2012-10-16 06:02:03 -0400
commit4e09e180e4a47ab03193cad71273130817fb8d83 (patch)
tree6f2e9a67e30b8344023f70248a834e9452e82f96
parentf9dae1d526f84bb9af4dcc415c9ff7ae8dbc3540 (diff)
downloadgtk+-4e09e180e4a47ab03193cad71273130817fb8d83.tar.gz
Fix css parser tests
Parsing a shorthand background property was running into unexpected errors when trying position values where there were none. To fix this, introduce a try_parse variant of the position parse function that silently returns NULL.
-rw-r--r--gtk/gtkcsspositionvalue.c25
-rw-r--r--gtk/gtkcsspositionvalueprivate.h3
-rw-r--r--gtk/gtkcssshorthandpropertyimpl.c2
3 files changed, 23 insertions, 7 deletions
diff --git a/gtk/gtkcsspositionvalue.c b/gtk/gtkcsspositionvalue.c
index 09c845d2fc..8f09db72f2 100644
--- a/gtk/gtkcsspositionvalue.c
+++ b/gtk/gtkcsspositionvalue.c
@@ -173,8 +173,8 @@ _gtk_css_position_value_new (GtkCssValue *x,
return result;
}
-GtkCssValue *
-_gtk_css_position_value_parse (GtkCssParser *parser)
+static GtkCssValue *
+position_value_parse (GtkCssParser *parser, gboolean try)
{
static const struct {
const char *name;
@@ -225,7 +225,8 @@ _gtk_css_position_value_parse (GtkCssParser *parser)
}
else
{
- _gtk_css_parser_error (parser, "Unrecognized position value");
+ if (!try)
+ _gtk_css_parser_error (parser, "Unrecognized position value");
return NULL;
}
}
@@ -245,7 +246,8 @@ _gtk_css_position_value_parse (GtkCssParser *parser)
{
if (missing != &y)
{
- _gtk_css_parser_error (parser, "Invalid combination of values");
+ if (!try)
+ _gtk_css_parser_error (parser, "Invalid combination of values");
_gtk_css_value_unref (y);
return NULL;
}
@@ -269,7 +271,8 @@ _gtk_css_position_value_parse (GtkCssParser *parser)
if ((names[first].horizontal && !names[second].vertical) ||
(!names[first].horizontal && !names[second].horizontal))
{
- _gtk_css_parser_error (parser, "Invalid combination of values");
+ if (!try)
+ _gtk_css_parser_error (parser, "Invalid combination of values");
_gtk_css_value_unref (x);
_gtk_css_value_unref (y);
return NULL;
@@ -279,6 +282,18 @@ _gtk_css_position_value_parse (GtkCssParser *parser)
return _gtk_css_position_value_new (x, y);
}
+GtkCssValue *
+_gtk_css_position_value_parse (GtkCssParser *parser)
+{
+ return position_value_parse (parser, FALSE);
+}
+
+GtkCssValue *
+_gtk_css_position_value_try_parse (GtkCssParser *parser)
+{
+ return position_value_parse (parser, TRUE);
+}
+
double
_gtk_css_position_value_get_x (const GtkCssValue *position,
double one_hundred_percent)
diff --git a/gtk/gtkcsspositionvalueprivate.h b/gtk/gtkcsspositionvalueprivate.h
index ee3b1521cd..d1d113bb13 100644
--- a/gtk/gtkcsspositionvalueprivate.h
+++ b/gtk/gtkcsspositionvalueprivate.h
@@ -26,8 +26,9 @@
G_BEGIN_DECLS
GtkCssValue * _gtk_css_position_value_new (GtkCssValue *x,
- GtkCssValue *y);
+ GtkCssValue *y);
GtkCssValue * _gtk_css_position_value_parse (GtkCssParser *parser);
+GtkCssValue * _gtk_css_position_value_try_parse (GtkCssParser *parser);
double _gtk_css_position_value_get_x (const GtkCssValue *position,
double one_hundred_percent);
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index 7dd3e3d1f2..0e9524d2ea 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -484,7 +484,7 @@ parse_one_background (GtkCssShorthandProperty *shorthand,
values[0] = _gtk_css_image_value_new (image);
}
else if (values[1] == NULL &&
- (value = _gtk_css_position_value_parse (parser)))
+ (value = _gtk_css_position_value_try_parse (parser)))
{
values[1] = value;
value = NULL;