[pango/matthiasc/for-main] Maintain order in pango_attr_list_change
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/matthiasc/for-main] Maintain order in pango_attr_list_change
- Date: Sat, 19 Mar 2022 03:28:26 +0000 (UTC)
commit b36001e880dc13ba4d782a4f2a4a58467284229d
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Mar 18 23:25:14 2022 -0400
Maintain order in pango_attr_list_change
When PangoAttrList was changed to use an array,
we lost the code that maintained non-decreasing
order in pango_attr_list_change. Bring it back,
and add a test for this.
pango/pango-attributes.c | 3 +++
tests/testattributes.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+)
---
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index 60d14706..4d7111fa 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -2184,6 +2184,9 @@ pango_attr_list_change (PangoAttrList *list,
if (tmp_attr2->start_index >= tmp_attr->start_index)
break;
+
+ g_ptr_array_index (list->attributes, k - 1) = tmp_attr2;
+ g_ptr_array_index (list->attributes, k) = tmp_attr;
}
}
}
diff --git a/tests/testattributes.c b/tests/testattributes.c
index d396269f..4a6b69b4 100644
--- a/tests/testattributes.c
+++ b/tests/testattributes.c
@@ -237,12 +237,32 @@ assert_attributes (GSList *attrs,
pango_attr_list_unref (list2);
}
+static void
+assert_attr_list_order (PangoAttrList *list)
+{
+ GSList *attrs, *l;
+ guint start = 0;
+
+ attrs = pango_attr_list_get_attributes (list);
+
+ for (l = attrs; l; l = l->next)
+ {
+ PangoAttribute *attr = l->data;
+ g_assert (start <= attr->start_index);
+ start = attr->start_index;
+ }
+
+ g_slist_free_full (attrs, (GDestroyNotify) pango_attribute_destroy);
+}
+
static void
assert_attr_list (PangoAttrList *list,
const char *expected)
{
PangoAttrList *list2;
+ assert_attr_list_order (list);
+
list2 = pango_attr_list_from_string (expected);
if (!pango_attr_list_equal (list, list2))
{
@@ -1355,6 +1375,29 @@ test_gnumeric_splice (void)
pango_attr_list_unref (list2);
}
+static void
+test_change_order (void)
+{
+ PangoAttrList *list;
+ PangoAttribute *attr;
+
+ list = pango_attr_list_from_string ("1 -1 font-features \"tnum=1\"\n"
+ "0 20 font-desc \"sans-serif\"\n"
+ "0 9 size 102400\n");
+
+ attr = pango_attr_font_features_new ("tnum=2");
+ attr->end_index = 9;
+
+ pango_attr_list_change (list, attr);
+
+ assert_attr_list (list, "0 9 font-features \"tnum=2\"\n"
+ "0 20 font-desc \"sans-serif\"\n"
+ "0 9 size 102400\n"
+ "9 4294967295 font-features \"tnum=1\"\n");
+
+ pango_attr_list_unref (list);
+}
+
int
main (int argc, char *argv[])
{
@@ -1395,6 +1438,7 @@ main (int argc, char *argv[])
g_test_add_func ("/attributes/iter/get_attrs", test_iter_get_attrs);
g_test_add_func ("/attributes/iter/epsilon_zero", test_iter_epsilon_zero);
g_test_add_func ("/attributes/gnumeric-splice", test_gnumeric_splice);
+ g_test_add_func ("/attributes/list/change_order", test_change_order);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]