From 87c33fa21ac11f9aa3c359d675349fcca2cfa6c5 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 5 Jul 2011 23:34:13 +0200 Subject: [PATCH] tests: Update text test for textview 1) Allow inserting text to move the cursor to after the inserted text 2) Implement selecting text for GtkTextView. Also assert if it's an unsupported widget type. 3) Select an inside part of the widget, not the end. --- tests/a11y/text.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/a11y/text.c b/tests/a11y/text.c index 641157d8a2..80b8b77fcb 100644 --- a/tests/a11y/text.c +++ b/tests/a11y/text.c @@ -577,6 +577,18 @@ select_region (GtkWidget *widget, gtk_editable_select_region (GTK_EDITABLE (widget), start, end); else if (GTK_IS_LABEL (widget)) gtk_label_select_region (GTK_LABEL (widget), start, end); + else if (GTK_IS_TEXT_VIEW (widget)) + { + GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget)); + GtkTextIter start_iter, end_iter; + + gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, end); + gtk_text_buffer_get_iter_at_offset (buffer, &end_iter, start); + + gtk_text_buffer_select_range (buffer, &start_iter, &end_iter); + } + else + g_assert_not_reached (); } typedef struct { @@ -604,7 +616,7 @@ static void test_selection (GtkWidget *widget) { AtkText *atk_text; - const gchar *text = "Bla bla"; + const gchar *text = "Bla bla bla"; gint n; gchar *ret; gint start, end; @@ -628,12 +640,17 @@ test_selection (GtkWidget *widget) n = atk_text_get_n_selections (atk_text); g_assert_cmpint (n, ==, 0); - g_assert_cmpint (data1.count, ==, 0); + if (data1.count == 1) + /* insertion before cursor */ + g_assert_cmpint (data1.position, ==, 11); + else + /* insertion after cursor */ + 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.count, >=, 1); g_assert_cmpint (data1.position, ==, 7); g_assert_cmpint (data2.count, >=, 1); g_assert_cmpint (data2.bound, ==, 4); @@ -652,7 +669,7 @@ test_selection (GtkWidget *widget) n = atk_text_get_n_selections (atk_text); g_assert_cmpint (n, ==, 0); - g_assert_cmpint (data1.count, ==, 1); + g_assert_cmpint (data1.count, >=, 1); g_assert_cmpint (data2.count, >=, 2); g_assert_cmpint (data2.position, ==, 7); g_assert_cmpint (data2.bound, ==, 7);