4f476837.diff 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. diff --git a/gtk/gtktreelistmodel.c b/gtk/gtktreelistmodel.c
  2. index dd3b3009ccc6003d5899cb0d64b0d902a8cf1ca2..1e55323c0a4e548bcde5389e72928eee1438c0c9 100644
  3. --- a/gtk/gtktreelistmodel.c
  4. +++ b/gtk/gtktreelistmodel.c
  5. @@ -357,7 +357,7 @@ gtk_tree_list_model_items_changed_cb (GListModel *model,
  6. }
  7. tree_added = added;
  8. - for (i = 0; i < added; i++)
  9. + for (i = added; i-- > 0;)
  10. {
  11. child = gtk_rb_tree_insert_before (node->children, child);
  12. child->parent = node;
  13. diff --git a/testsuite/gtk/treelistmodel.c b/testsuite/gtk/treelistmodel.c
  14. index 941ac3d306b91fdd2df298ccebbfdb16d4ebe605..98493a3ba5638561ff4668ce022f2cbbadb38e25 100644
  15. --- a/testsuite/gtk/treelistmodel.c
  16. +++ b/testsuite/gtk/treelistmodel.c
  17. @@ -261,6 +261,51 @@ test_remove_some (void)
  18. g_object_unref (tree);
  19. }
  20. +static void
  21. +splice (GListStore *store,
  22. + guint pos,
  23. + guint removed,
  24. + guint *numbers,
  25. + guint added)
  26. +{
  27. + GObject **objects = g_newa (GObject *, added);
  28. + guint i;
  29. +
  30. + for (i = 0; i < added; i++)
  31. + {
  32. + /* 0 cannot be differentiated from NULL, so don't use it */
  33. + g_assert_cmpint (numbers[i], !=, 0);
  34. + objects[i] = g_object_new (G_TYPE_OBJECT, NULL);
  35. + g_object_set_qdata (objects[i], number_quark, GUINT_TO_POINTER (numbers[i]));
  36. + }
  37. +
  38. + g_list_store_splice (store, pos, removed, (gpointer *) objects, added);
  39. +
  40. + for (i = 0; i < added; i++)
  41. + g_object_unref (objects[i]);
  42. +}
  43. +
  44. +static void
  45. +test_splice (void)
  46. +{
  47. + GtkTreeListModel *tree = new_model (100, TRUE);
  48. + gpointer item;
  49. +
  50. + assert_model (tree, "100 100 100 99 98 97 96 95 94 93 92 91 90 90 89 88 87 86 85 84 83 82 81 80 80 79 78 77 76 75 74 73 72 71 70 70 69 68 67 66 65 64 63 62 61 60 60 59 58 57 56 55 54 53 52 51 50 50 49 48 47 46 45 44 43 42 41 40 40 39 38 37 36 35 34 33 32 31 30 30 29 28 27 26 25 24 23 22 21 20 20 19 18 17 16 15 14 13 12 11 10 10 9 8 7 6 5 4 3 2 1");
  51. + assert_changes (tree, "");
  52. +
  53. + item = g_list_model_get_item (G_LIST_MODEL (tree), 1);
  54. + g_assert_true (G_IS_LIST_MODEL (item));
  55. + splice (item, 0, 5, (guint[5]) { 300, 301, 302, 303, 304 }, 5);
  56. + /* expected */
  57. + assert_model (tree, "100 100 300 301 302 303 304 95 94 93 92 91 90 90 89 88 87 86 85 84 83 82 81 80 80 79 78 77 76 75 74 73 72 71 70 70 69 68 67 66 65 64 63 62 61 60 60 59 58 57 56 55 54 53 52 51 50 50 49 48 47 46 45 44 43 42 41 40 40 39 38 37 36 35 34 33 32 31 30 30 29 28 27 26 25 24 23 22 21 20 20 19 18 17 16 15 14 13 12 11 10 10 9 8 7 6 5 4 3 2 1");
  58. + /* real outcome */
  59. + // assert_model (tree, "100 100 304 303 302 301 300 95 94 93 92 91 90 90 89 88 87 86 85 84 83 82 81 80 80 79 78 77 76 75 74 73 72 71 70 70 69 68 67 66 65 64 63 62 61 60 60 59 58 57 56 55 54 53 52 51 50 50 49 48 47 46 45 44 43 42 41 40 40 39 38 37 36 35 34 33 32 31 30 30 29 28 27 26 25 24 23 22 21 20 20 19 18 17 16 15 14 13 12 11 10 10 9 8 7 6 5 4 3 2 1");
  60. + assert_changes (tree, "2-5+5");
  61. +
  62. + g_object_unref (tree);
  63. +}
  64. +
  65. /* Test for https://gitlab.gnome.org/GNOME/gtk/-/issues/4595 */
  66. typedef struct _DemoNode DemoNode;
  67. @@ -391,6 +436,7 @@ main (int argc, char *argv[])
  68. g_test_add_func ("/treelistmodel/expand", test_expand);
  69. g_test_add_func ("/treelistmodel/remove_some", test_remove_some);
  70. + g_test_add_func ("/treelistmodel/remove_splice", test_splice);
  71. g_test_add_func ("/treelistmodel/collapse-change", test_collapse_change);
  72. return g_test_run ();