[gtk/misc-multiselection] Add tests for select_callback
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/misc-multiselection] Add tests for select_callback
- Date: Sat, 6 Jun 2020 15:23:47 +0000 (UTC)
commit 27ce68b74a0858447c8b86f63c4994f4666d9fef
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jun 6 11:20:47 2020 -0400
Add tests for select_callback
testsuite/gtk/multiselection.c | 73 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 73 insertions(+)
---
diff --git a/testsuite/gtk/multiselection.c b/testsuite/gtk/multiselection.c
index 2fd60aa1f5..f56387a878 100644
--- a/testsuite/gtk/multiselection.c
+++ b/testsuite/gtk/multiselection.c
@@ -438,6 +438,78 @@ test_readd (void)
g_object_unref (selection);
}
+typedef struct {
+ guint start;
+ guint n;
+ gboolean in;
+} SelectionData;
+
+static void
+select_some (guint position,
+ guint *start,
+ guint *n,
+ gboolean *selected,
+ gpointer data)
+{
+ SelectionData *sdata = data;
+ guint i;
+
+ for (i = 0; sdata[i].n != 0; i++)
+ {
+ if (sdata[i].start <= position &&
+ position < sdata[i].start + sdata[i].n)
+ break;
+ }
+
+ *start = sdata[i].start;
+ *n = sdata[i].n;
+ *selected = sdata[i].in;
+}
+
+static void
+test_callback (void)
+{
+ GtkSelectionModel *selection;
+ gboolean ret;
+ GListStore *store;
+ SelectionData data[] = {
+ { 0, 2, FALSE },
+ { 2, 3, TRUE },
+ { 5, 2, FALSE },
+ { 6, 3, TRUE },
+ { 9, 1, FALSE },
+ { 0, 0, FALSE }
+ };
+
+ SelectionData more_data[] = {
+ { 0, 3, FALSE },
+ { 3, 1, TRUE },
+ { 4, 3, FALSE },
+ { 7, 1, TRUE },
+ { 0, 0, FALSE }
+ };
+
+ store = new_store (1, 10, 1);
+
+ selection = new_model (store);
+ assert_model (selection, "1 2 3 4 5 6 7 8 9 10");
+ assert_selection (selection, "");
+ assert_selection_changes (selection, "");
+
+ ret = gtk_selection_model_select_callback (selection, select_some, data);
+ g_assert_true (ret);
+ assert_selection (selection, "3 4 5 7 8 9");
+ assert_selection_changes (selection, "2:7");
+
+ ret = gtk_selection_model_unselect_callback (selection, select_some, more_data);
+ g_assert_true (ret);
+ assert_selection (selection, "3 5 7 9");
+ assert_selection_changes (selection, "3:5");
+
+ g_object_unref (store);
+ g_object_unref (selection);
+}
+
int
main (int argc, char *argv[])
{
@@ -456,6 +528,7 @@ main (int argc, char *argv[])
g_test_add_func ("/multiselection/selection", test_selection);
g_test_add_func ("/multiselection/select-range", test_select_range);
g_test_add_func ("/multiselection/readd", test_readd);
+ g_test_add_func ("/multiselection/callback", test_callback);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]