summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-08-28 22:11:59 -0400
committerMatthias Clasen <mclasen@redhat.com>2021-08-29 16:27:08 -0400
commit674d86a1c82e93e2ff31f502224e0f21f9eb59b8 (patch)
tree344125ba8b26390827bff44e28f1363c0b88c2eb
parent76eca4dce1d308780b5b6712896eebebdd77e79f (diff)
downloadpango-674d86a1c82e93e2ff31f502224e0f21f9eb59b8.tar.gz
tests: Use introspection for attributes
Now that we have introspection helpers for attributes, we can use them ourselves to make this code less brittle.
-rw-r--r--tests/test-common.c101
1 files changed, 37 insertions, 64 deletions
diff --git a/tests/test-common.c b/tests/test-common.c
index 0e3719e7..b59ca4a0 100644
--- a/tests/test-common.c
+++ b/tests/test-common.c
@@ -106,6 +106,15 @@ print_attribute (PangoAttribute *attr, GString *string)
{
GEnumClass *class;
GEnumValue *value;
+ PangoAttrString *str;
+ PangoAttrLanguage *lang;
+ PangoAttrInt *integer;
+ PangoAttrFloat *flt;
+ PangoAttrFontDesc *font;
+ PangoAttrColor *color;
+ PangoAttrShape *shape;
+ PangoAttrSize *size;
+ PangoAttrFontFeatures *features;
g_string_append_printf (string, "[%d,%d]", attr->start_index, attr->end_index);
@@ -114,75 +123,39 @@ print_attribute (PangoAttribute *attr, GString *string)
g_string_append_printf (string, "%s=", value->value_nick);
g_type_class_unref (class);
- switch (attr->klass->type)
+ if ((str = pango_attribute_as_string (attr)) != NULL)
+ g_string_append (string, str->value);
+ else if ((lang = pango_attribute_as_language (attr)) != NULL)
+ g_string_append (string, pango_language_to_string (lang->value));
+ else if ((integer = pango_attribute_as_int (attr)) != NULL)
+ g_string_append_printf (string, "%d", integer->value);
+ else if ((flt = pango_attribute_as_float (attr)) != NULL)
{
- case PANGO_ATTR_LANGUAGE:
- g_string_append (string, pango_language_to_string (((PangoAttrLanguage *)attr)->value));
- break;
- case PANGO_ATTR_FAMILY:
- case PANGO_ATTR_FONT_FEATURES:
- g_string_append (string, ((PangoAttrString *)attr)->value);
- break;
- case PANGO_ATTR_STYLE:
- case PANGO_ATTR_WEIGHT:
- case PANGO_ATTR_VARIANT:
- case PANGO_ATTR_STRETCH:
- case PANGO_ATTR_SIZE:
- case PANGO_ATTR_ABSOLUTE_SIZE:
- case PANGO_ATTR_UNDERLINE:
- case PANGO_ATTR_OVERLINE:
- case PANGO_ATTR_STRIKETHROUGH:
- case PANGO_ATTR_RISE:
- case PANGO_ATTR_FALLBACK:
- case PANGO_ATTR_LETTER_SPACING:
- case PANGO_ATTR_GRAVITY:
- case PANGO_ATTR_GRAVITY_HINT:
- case PANGO_ATTR_FOREGROUND_ALPHA:
- case PANGO_ATTR_BACKGROUND_ALPHA:
- case PANGO_ATTR_ALLOW_BREAKS:
- case PANGO_ATTR_INSERT_HYPHENS:
- case PANGO_ATTR_SHOW:
- case PANGO_ATTR_TEXT_TRANSFORM:
- case PANGO_ATTR_ABSOLUTE_LINE_HEIGHT:
- case PANGO_ATTR_WORD:
- case PANGO_ATTR_SENTENCE:
- g_string_append_printf (string, "%d", ((PangoAttrInt *)attr)->value);
- break;
- case PANGO_ATTR_FONT_DESC:
- {
- char *text = pango_font_description_to_string (((PangoAttrFontDesc *)attr)->desc);
- g_string_append (string, text);
- g_free (text);
- }
- break;
- case PANGO_ATTR_FOREGROUND:
- case PANGO_ATTR_BACKGROUND:
- case PANGO_ATTR_UNDERLINE_COLOR:
- case PANGO_ATTR_OVERLINE_COLOR:
- case PANGO_ATTR_STRIKETHROUGH_COLOR:
- {
- char *text = pango_color_to_string (&((PangoAttrColor *)attr)->color);
- g_string_append (string, text);
- g_free (text);
- }
- break;
- case PANGO_ATTR_SHAPE:
- g_string_append_printf (string, "shape");
- break;
- case PANGO_ATTR_SCALE:
- case PANGO_ATTR_LINE_HEIGHT:
- {
char val[20];
- g_ascii_formatd (val, 20, "%f", ((PangoAttrFloat *)attr)->value);
+ g_ascii_formatd (val, 20, "%f", flt->value);
g_string_append (string, val);
- }
- break;
- case PANGO_ATTR_INVALID:
- default:
- g_assert_not_reached ();
- break;
+ }
+ else if ((font = pango_attribute_as_font_desc (attr)) != NULL)
+ {
+ char *text = pango_font_description_to_string (font->desc);
+ g_string_append (string, text);
+ g_free (text);
+ }
+ else if ((color = pango_attribute_as_color (attr)) != NULL)
+ {
+ char *text = pango_color_to_string (&color->color);
+ g_string_append (string, text);
+ g_free (text);
}
+ else if ((shape = pango_attribute_as_shape (attr)) != NULL)
+ g_string_append_printf (string, "shape");
+ else if ((size = pango_attribute_as_size (attr)) != NULL)
+ g_string_append_printf (string, "%d", size->size);
+ else if ((features = pango_attribute_as_font_features (attr)) != NULL)
+ g_string_append_printf (string, "%s", features->features);
+ else
+ g_assert_not_reached ();
}
void