From 81c809e27a76f2cd1d8b46e4bedceb52d0b0489a Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 24 Jun 2011 20:57:22 -0400 Subject: [PATCH] Add some more basic tests --- tests/a11y/text.c | 64 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/tests/a11y/text.c b/tests/a11y/text.c index 083438b8fc..b66da911f1 100644 --- a/tests/a11y/text.c +++ b/tests/a11y/text.c @@ -21,6 +21,55 @@ */ #include +#include + +static void +set_text (GtkWidget *widget, + const gchar *text) +{ + if (GTK_IS_LABEL (widget)) + gtk_label_set_text (GTK_LABEL (widget), text); + else if (GTK_IS_ENTRY (widget)) + gtk_entry_set_text (GTK_ENTRY (widget), text); + else if (GTK_IS_TEXT_VIEW (widget)) + gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget)), text, -1); + else + g_assert_not_reached (); +} + +static void +test_basic (GtkWidget *widget) +{ + AtkText *atk_text; + const gchar *text = "Text goes here"; + gchar *ret; + gint count; + gunichar c; + + atk_text = ATK_TEXT (gtk_widget_get_accessible (widget)); + + set_text (widget, text); + ret = atk_text_get_text (atk_text, 5, 9); + g_assert_cmpstr (ret, ==, "goes"); + g_free (ret); + + ret = atk_text_get_text (atk_text, 0, 14); + g_assert_cmpstr (ret, ==, text); + g_free (ret); + + ret = atk_text_get_text (atk_text, 0, -1); + g_assert_cmpstr (ret, ==, text); + g_free (ret); + + count = atk_text_get_character_count (atk_text); + g_assert_cmpint (count, ==, g_utf8_strlen (text, -1)); + + c = atk_text_get_character_at_offset (atk_text, 0); + g_assert_cmpint (c, ==, 'T'); + + c = atk_text_get_character_at_offset (atk_text, 13); + g_assert_cmpint (c, ==, 'e'); +} typedef struct { gint count; @@ -44,20 +93,6 @@ text_inserted (AtkText *atk_text, gint position, gint length, SignalData *data) data->length = length; } -static void -set_text (GtkWidget *widget, - const gchar *text) -{ - if (GTK_IS_LABEL (widget)) - gtk_label_set_text (GTK_LABEL (widget), text); - else if (GTK_IS_ENTRY (widget)) - gtk_entry_set_text (GTK_ENTRY (widget), text); - else if (GTK_IS_TEXT_VIEW (widget)) - gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget)), text, -1); - else - g_assert_not_reached (); -} - static void test_text_changed (GtkWidget *widget) { @@ -546,6 +581,7 @@ static void add_text_tests (GtkWidget *widget) { g_object_ref_sink (widget); + add_text_test ("/text/basic", (GTestFixtureFunc) test_basic, widget); add_text_test ("/text/words", (GTestFixtureFunc) test_words, widget); add_text_test ("/text/changed", (GTestFixtureFunc) test_text_changed, widget); g_object_unref (widget);