summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2011-06-25 22:44:46 -0400
committerMatthias Clasen <mclasen@redhat.com>2011-07-05 16:08:09 -0400
commitabe6c28bc207624ddbbadcd0eb8bca49b0f797e4 (patch)
treecedc02bc18dbb2d2c44180f279a3c4bcb4f41e9c
parent2358be732daeff41233ff5c6044269c10ac20126 (diff)
downloadgtk+-abe6c28bc207624ddbbadcd0eb8bca49b0f797e4.tar.gz
Add some texts for text selection signals
Test that we do emit ::text_caret_moved and ::text_selection_changed as expected.
-rw-r--r--tests/a11y/text.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/a11y/text.c b/tests/a11y/text.c
index 73041bcc44..d5cdcd27d8 100644
--- a/tests/a11y/text.c
+++ b/tests/a11y/text.c
@@ -575,6 +575,27 @@ select_region (GtkWidget *widget,
gtk_label_select_region (GTK_LABEL (widget), start, end);
}
+typedef struct {
+ gint count;
+ gint position;
+ gint bound;
+} SelectionData;
+
+static void
+caret_moved_cb (AtkText *text, gint position, SelectionData *data)
+{
+ data->count++;
+ data->position = position;
+}
+
+static void
+selection_changed_cb (AtkText *text, SelectionData *data)
+{
+ data->count++;
+
+ atk_text_get_selection (text, 0, &data->bound, &data->position);
+}
+
static void
test_selection (GtkWidget *widget)
{
@@ -583,18 +604,37 @@ test_selection (GtkWidget *widget)
gint n;
gchar *ret;
gint start, end;
+ SelectionData data1;
+ SelectionData data2;
if (GTK_IS_LABEL (widget))
gtk_label_set_selectable (GTK_LABEL (widget), TRUE);
atk_text = ATK_TEXT (gtk_widget_get_accessible (widget));
+
+ data1.count = 0;
+ data2.count = 0;
+ g_signal_connect (atk_text, "text_caret_moved",
+ G_CALLBACK (caret_moved_cb), &data1);
+ g_signal_connect (atk_text, "text_selection_changed",
+ G_CALLBACK (selection_changed_cb), &data2);
+
set_text (widget, text);
n = atk_text_get_n_selections (atk_text);
g_assert_cmpint (n, ==, 0);
+ g_assert_cmpint (data1.count, ==, 0);
+ g_assert_cmpint (data2.count, ==, 0);
+
select_region (widget, 4, 7);
+ g_assert_cmpint (data1.count, ==, 1);
+ g_assert_cmpint (data1.position, ==, 7);
+ g_assert_cmpint (data2.count, >=, 1);
+ g_assert_cmpint (data2.bound, ==, 4);
+ g_assert_cmpint (data2.position, ==, 7);
+
n = atk_text_get_n_selections (atk_text);
g_assert_cmpint (n, ==, 1);
@@ -607,6 +647,11 @@ test_selection (GtkWidget *widget)
atk_text_remove_selection (atk_text, 0);
n = atk_text_get_n_selections (atk_text);
g_assert_cmpint (n, ==, 0);
+
+ g_assert_cmpint (data1.count, ==, 1);
+ g_assert_cmpint (data2.count, >=, 2);
+ g_assert_cmpint (data2.position, ==, 7);
+ g_assert_cmpint (data2.bound, ==, 7);
}
static void