[pango/matthiasc/for-main: 23/25] tests: Add more attribute tests
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/matthiasc/for-main: 23/25] tests: Add more attribute tests
- Date: Sun, 22 Aug 2021 04:36:52 +0000 (UTC)
commit d61aa45efa0516794c6459db1213ca221c3a5497
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Aug 21 21:35:41 2021 -0400
tests: Add more attribute tests
Handle all attribute types when testing copying,
and add tests for the binding helpers.
tests/test-common.c | 3 ++
tests/testattributes.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 110 insertions(+)
---
diff --git a/tests/test-common.c b/tests/test-common.c
index 3df4015c..011b2eef 100644
--- a/tests/test-common.c
+++ b/tests/test-common.c
@@ -143,6 +143,7 @@ print_attribute (PangoAttribute *attr, GString *string)
case PANGO_ATTR_INSERT_HYPHENS:
case PANGO_ATTR_SHOW:
case PANGO_ATTR_TEXT_TRANSFORM:
+ case PANGO_ATTR_ABSOLUTE_LINE_HEIGHT:
g_string_append_printf (string, "%d", ((PangoAttrInt *)attr)->value);
break;
case PANGO_ATTR_FONT_DESC:
@@ -167,6 +168,7 @@ print_attribute (PangoAttribute *attr, GString *string)
g_string_append_printf (string, "shape");
break;
case PANGO_ATTR_SCALE:
+ case PANGO_ATTR_LINE_HEIGHT:
{
char val[20];
@@ -174,6 +176,7 @@ print_attribute (PangoAttribute *attr, GString *string)
g_string_append (string, val);
}
break;
+ case PANGO_ATTR_INVALID:
default:
g_assert_not_reached ();
break;
diff --git a/tests/testattributes.c b/tests/testattributes.c
index bd1a4028..662a6142 100644
--- a/tests/testattributes.c
+++ b/tests/testattributes.c
@@ -66,10 +66,15 @@ test_attributes_basic (void)
test_copy (pango_attr_shape_new (&rect, &rect));
test_copy (pango_attr_gravity_new (PANGO_GRAVITY_SOUTH));
test_copy (pango_attr_gravity_hint_new (PANGO_GRAVITY_HINT_STRONG));
+ test_copy (pango_attr_font_features_new ("csc=1"));
+ test_copy (pango_attr_foreground_alpha_new (8000));
+ test_copy (pango_attr_background_alpha_new (8000));
test_copy (pango_attr_allow_breaks_new (FALSE));
test_copy (pango_attr_show_new (PANGO_SHOW_SPACES));
test_copy (pango_attr_insert_hyphens_new (FALSE));
test_copy (pango_attr_text_transform_new (PANGO_TEXT_TRANSFORM_UPPERCASE));
+ test_copy (pango_attr_line_height_new (1.5));
+ test_copy (pango_attr_line_height_new_absolute (3000));
}
static void
@@ -111,6 +116,107 @@ test_attributes_register (void)
g_type_class_unref (class);
}
+#define g_assert_as(x, y) \
+ if (x == NULL) \
+ { \
+ GString *s = g_string_new (""); \
+ print_attribute (y, s); \
+ g_print ("failed to convert: %s\n", s->str); \
+ g_string_free (s, TRUE); \
+ }
+
+static void
+test_binding (PangoAttribute *attr)
+{
+ enum {
+ INVALID, INT, LANGUAGE, STRING, SIZE, FONT_DESC, COLOR, SHAPE, FLOAT, FONT_FEATURES,
+ } attr_base[] = {
+ INVALID, LANGUAGE, STRING, INT, INT, INT, INT, SIZE, FONT_DESC, COLOR,
+ COLOR, INT, INT, INT, SHAPE, FLOAT, INT, INT, COLOR, COLOR, SIZE,
+ INT, INT, FONT_FEATURES, INT, INT, INT, INT, INT, INT, COLOR, FLOAT,
+ INT, INT, INT, INT
+ };
+
+ switch (attr_base[attr->klass->type])
+ {
+ case INT:
+ g_assert_as (pango_attribute_as_int (attr), attr);
+ break;
+ case LANGUAGE:
+ g_assert_as (pango_attribute_as_language (attr), attr);
+ break;
+ case STRING:
+ g_assert_as (pango_attribute_as_string (attr), attr);
+ break;
+ case SIZE:
+ g_assert_as (pango_attribute_as_size (attr), attr);
+ break;
+ case FONT_DESC:
+ g_assert_as (pango_attribute_as_font_desc (attr), attr);
+ break;
+ case COLOR:
+ g_assert_as (pango_attribute_as_color (attr), attr);
+ break;
+ case SHAPE:
+ g_assert_as (pango_attribute_as_shape (attr), attr);
+ break;
+ case FLOAT:
+ g_assert_as (pango_attribute_as_float (attr), attr);
+ break;
+ case FONT_FEATURES:
+ g_assert_as (pango_attribute_as_font_features (attr), attr);
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ pango_attribute_destroy (attr);
+}
+
+static void
+test_binding_helpers (void)
+{
+ PangoFontDescription *desc;
+ PangoRectangle rect = { 0, 0, 10, 10 };
+
+ test_binding (pango_attr_language_new (pango_language_from_string ("ja-JP")));
+ test_binding (pango_attr_family_new ("Times"));
+ test_binding (pango_attr_foreground_new (100, 200, 300));
+ test_binding (pango_attr_background_new (100, 200, 300));
+ test_binding (pango_attr_size_new (1024));
+ test_binding (pango_attr_size_new_absolute (1024));
+ test_binding (pango_attr_style_new (PANGO_STYLE_ITALIC));
+ test_binding (pango_attr_weight_new (PANGO_WEIGHT_ULTRALIGHT));
+ test_binding (pango_attr_variant_new (PANGO_VARIANT_SMALL_CAPS));
+ test_binding (pango_attr_stretch_new (PANGO_STRETCH_SEMI_EXPANDED));
+ desc = pango_font_description_from_string ("Computer Modern 12");
+ test_binding (pango_attr_font_desc_new (desc));
+ pango_font_description_free (desc);
+ test_binding (pango_attr_underline_new (PANGO_UNDERLINE_LOW));
+ test_binding (pango_attr_underline_new (PANGO_UNDERLINE_ERROR_LINE));
+ test_binding (pango_attr_underline_color_new (100, 200, 300));
+ test_binding (pango_attr_overline_new (PANGO_OVERLINE_SINGLE));
+ test_binding (pango_attr_overline_color_new (100, 200, 300));
+ test_binding (pango_attr_strikethrough_new (TRUE));
+ test_binding (pango_attr_strikethrough_color_new (100, 200, 300));
+ test_binding (pango_attr_rise_new (256));
+ test_binding (pango_attr_scale_new (2.56));
+ test_binding (pango_attr_fallback_new (FALSE));
+ test_binding (pango_attr_letter_spacing_new (1024));
+ test_binding (pango_attr_shape_new (&rect, &rect));
+ test_binding (pango_attr_gravity_new (PANGO_GRAVITY_SOUTH));
+ test_binding (pango_attr_gravity_hint_new (PANGO_GRAVITY_HINT_STRONG));
+ test_binding (pango_attr_font_features_new ("csc=1"));
+ test_binding (pango_attr_foreground_alpha_new (8000));
+ test_binding (pango_attr_background_alpha_new (8000));
+ test_binding (pango_attr_allow_breaks_new (FALSE));
+ test_binding (pango_attr_show_new (PANGO_SHOW_SPACES));
+ test_binding (pango_attr_insert_hyphens_new (FALSE));
+ test_binding (pango_attr_text_transform_new (PANGO_TEXT_TRANSFORM_UPPERCASE));
+ test_binding (pango_attr_line_height_new (1.5));
+ test_binding (pango_attr_line_height_new_absolute (3000));
+}
+
static void
assert_attributes (GSList *attrs,
const char *expected)
@@ -1211,6 +1317,7 @@ main (int argc, char *argv[])
g_test_add_func ("/attributes/basic", test_attributes_basic);
g_test_add_func ("/attributes/equal", test_attributes_equal);
g_test_add_func ("/attributes/register", test_attributes_register);
+ g_test_add_func ("/attributes/binding-helpers", test_binding_helpers);
g_test_add_func ("/attributes/list/basic", test_list);
g_test_add_func ("/attributes/list/change", test_list_change);
g_test_add_func ("/attributes/list/change2", test_list_change2);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]