[gtk/wip/matthiasc/sortlistmodel: 7/7] Add a simple sorting testcase
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/sortlistmodel: 7/7] Add a simple sorting testcase
- Date: Sat, 11 Jul 2020 14:51:36 +0000 (UTC)
commit 1af22716b7727d6aa99e9f4861052e4502dba784
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jul 11 10:45:47 2020 -0400
Add a simple sorting testcase
Testcase for gathering profiler data.
This just sorts a million items, and then quits.
tests/meson.build | 1 +
tests/sorting.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+)
---
diff --git a/tests/meson.build b/tests/meson.build
index 4618df6b97..3afe241dfa 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -11,6 +11,7 @@ gtk_tests = [
['scrolling-performance', ['frame-stats.c', 'variable.c']],
['blur-performance', ['../gsk/gskcairoblur.c']],
['simple'],
+ ['sorting'],
['video-timer', ['variable.c']],
['testaccel'],
['testadjustsize'],
diff --git a/tests/sorting.c b/tests/sorting.c
new file mode 100644
index 0000000000..507c9ca81b
--- /dev/null
+++ b/tests/sorting.c
@@ -0,0 +1,78 @@
+#include <gtk/gtk.h>
+
+static GListModel *
+get_model (guint size)
+{
+ GtkStringList *model;
+ guint i;
+
+ model = gtk_string_list_new (NULL);
+
+ for (i = 0; i < size; i++)
+ {
+ char *string = g_strdup_printf ("%d", g_random_int_range (0, 1000000));
+ gtk_string_list_append (model, string);
+ g_free (string);
+ }
+
+ return G_LIST_MODEL (model);
+}
+
+static int
+sort_func (gconstpointer a, gconstpointer b, gpointer data)
+{
+ return strcmp (gtk_string_object_get_string (GTK_STRING_OBJECT ((gpointer)a)),
+ gtk_string_object_get_string (GTK_STRING_OBJECT ((gpointer)b)));
+}
+
+static void
+sorting_changed (GtkSor3ListModel *model)
+{
+ gboolean sorting;
+
+ g_object_get (model, "sorting", &sorting, NULL);
+
+ if (!sorting)
+ exit (0);
+}
+
+static gboolean
+start_sort (gpointer data)
+{
+ GListModel *model = data;
+ GListModel *sort;
+ GtkSorter *sorter;
+
+ sorter = GTK_SORTER (gtk_custom_sorter_new (sort_func, NULL, NULL));
+
+ if (g_getenv ("TIMSORT"))
+ {
+ sort = G_LIST_MODEL (gtk_tim2_sort_model_new (model, NULL));
+ gtk_tim2_sort_model_set_sorter (GTK_TIM2_SORT_MODEL (sort), sorter);
+ }
+ else
+ {
+ sort = G_LIST_MODEL (gtk_sor3_list_model_new (model, NULL));
+ gtk_sor3_list_model_set_sorter (GTK_SOR3_LIST_MODEL (sort), sorter);
+ }
+
+ g_signal_connect (sort, "notify::sorting", G_CALLBACK (sorting_changed), NULL);
+
+ return G_SOURCE_REMOVE;
+}
+
+int main (int argc, char *argv[])
+{
+ GListModel *model;
+
+ gtk_init ();
+
+ model = get_model (1000000);
+
+ g_idle_add (start_sort, model);
+
+ while (1)
+ g_main_context_iteration (NULL, TRUE);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]