[gtk+] Fix css parser tests



commit 4e09e180e4a47ab03193cad71273130817fb8d83
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Oct 16 06:00:40 2012 -0400

    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.

 gtk/gtkcsspositionvalue.c         |   25 ++++++++++++++++++++-----
 gtk/gtkcsspositionvalueprivate.h  |    3 ++-
 gtk/gtkcssshorthandpropertyimpl.c |    2 +-
 3 files changed, 23 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkcsspositionvalue.c b/gtk/gtkcsspositionvalue.c
index 09c845d..8f09db7 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 ee3b152..d1d113b 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 7dd3e3d..0e9524d 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;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]