[gtk+] Improve text a11y test
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Improve text a11y test
- Date: Fri, 16 Oct 2015 02:36:26 +0000 (UTC)
commit af8c2d2f7ba5b1881b4c75c8d7aaff05d3655a64
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Oct 15 22:35:38 2015 -0400
Improve text a11y test
Test appending text as well as replacing the entire text.
Insert non-ASCII text to verify offsets are correct.
testsuite/a11y/text.c | 78 +++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 66 insertions(+), 12 deletions(-)
---
diff --git a/testsuite/a11y/text.c b/testsuite/a11y/text.c
index 93c5853..04db8f1 100644
--- a/testsuite/a11y/text.c
+++ b/testsuite/a11y/text.c
@@ -36,6 +36,39 @@ set_text (GtkWidget *widget,
}
static void
+append_text (GtkWidget *widget,
+ const gchar *text)
+{
+ if (GTK_IS_LABEL (widget))
+ {
+ gchar *tmp;
+
+ tmp = g_strconcat (gtk_label_get_text (GTK_LABEL (widget)), text, NULL);
+ gtk_label_set_text (GTK_LABEL (widget), tmp);
+ g_free (tmp);
+ }
+ else if (GTK_IS_ENTRY (widget))
+ {
+ gchar *tmp;
+
+ tmp = g_strconcat (gtk_entry_get_text (GTK_ENTRY (widget)), text, NULL);
+ gtk_entry_set_text (GTK_ENTRY (widget), tmp);
+ g_free (tmp);
+ }
+ else if (GTK_IS_TEXT_VIEW (widget))
+ {
+ GtkTextBuffer *buffer;
+ GtkTextIter end;
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
+ gtk_text_buffer_get_end_iter (buffer, &end);
+ gtk_text_buffer_insert (buffer, &end, text, -1);
+ }
+ else
+ g_assert_not_reached ();
+}
+
+static void
test_basic (GtkWidget *widget)
{
AtkText *atk_text;
@@ -95,10 +128,14 @@ static void
test_text_changed (GtkWidget *widget)
{
AtkText *atk_text;
- const gchar *text = "Text goes here";
- const gchar *text2 = "Text again";
+ const gchar *text = "Täxt goes here";
+ const gchar *text2 = "Täxt again";
SignalData delete_data;
SignalData insert_data;
+ gboolean cant_append = FALSE;
+
+ if (GTK_IS_LABEL (widget) || GTK_IS_ENTRY (widget))
+ cant_append = TRUE;
atk_text = ATK_TEXT (gtk_widget_get_accessible (widget));
@@ -118,23 +155,40 @@ test_text_changed (GtkWidget *widget)
g_assert_cmpint (insert_data.position, ==, 0);
g_assert_cmpint (insert_data.length, ==, g_utf8_strlen (text, -1));
- set_text (widget, text2);
+ delete_data.count = 0;
+ insert_data.count = 0;
- g_assert_cmpint (delete_data.count, ==, 1);
- g_assert_cmpint (delete_data.position, ==, 0);
- g_assert_cmpint (delete_data.length, ==, g_utf8_strlen (text, -1));
+ append_text (widget, text2);
- g_assert_cmpint (insert_data.count, ==, 2);
- g_assert_cmpint (insert_data.position, ==, 0);
- g_assert_cmpint (insert_data.length, ==, g_utf8_strlen (text2, -1));
+ if (cant_append)
+ {
+ g_assert_cmpint (delete_data.count, ==, 1);
+ g_assert_cmpint (delete_data.position, ==, 0);
+ g_assert_cmpint (delete_data.length, ==, g_utf8_strlen (text, -1));
+
+ g_assert_cmpint (insert_data.count, ==, 1);
+ g_assert_cmpint (insert_data.position, ==, 0);
+ g_assert_cmpint (insert_data.length, ==, g_utf8_strlen (text, -1) + g_utf8_strlen (text2, -1));
+ }
+ else
+ {
+ g_assert_cmpint (delete_data.count, ==, 0);
+
+ g_assert_cmpint (insert_data.count, ==, 1);
+ g_assert_cmpint (insert_data.position, ==, g_utf8_strlen (text, -1));
+ g_assert_cmpint (insert_data.length, ==, g_utf8_strlen (text2, -1));
+ }
+
+ delete_data.count = 0;
+ insert_data.count = 0;
set_text (widget, "");
- g_assert_cmpint (delete_data.count, ==, 2);
+ g_assert_cmpint (delete_data.count, ==, 1);
g_assert_cmpint (delete_data.position, ==, 0);
- g_assert_cmpint (delete_data.length, ==, g_utf8_strlen (text2, -1));
+ g_assert_cmpint (delete_data.length, ==, g_utf8_strlen (text, -1) + g_utf8_strlen (text2, -1));
- g_assert_cmpint (insert_data.count, ==, 2);
+ g_assert_cmpint (insert_data.count, ==, 0);
g_signal_handlers_disconnect_by_func (atk_text, G_CALLBACK (text_deleted), &delete_data);
g_signal_handlers_disconnect_by_func (atk_text, G_CALLBACK (text_inserted), &insert_data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]