[gtk+] tests: Update text test for textview



commit 87c33fa21ac11f9aa3c359d675349fcca2cfa6c5
Author: Benjamin Otte <otte redhat com>
Date:   Tue Jul 5 23:34:13 2011 +0200

    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 files changed, 21 insertions(+), 4 deletions(-)
---
diff --git a/tests/a11y/text.c b/tests/a11y/text.c
index 641157d..80b8b77 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);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]