[gspell/wip/entry: 7/7] test-entry: better unit test for spell checker changes



commit b67bcf8faa241d630b87e247f55e47d197899adf
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Oct 30 18:40:30 2016 +0100

    test-entry: better unit test for spell checker changes

 testsuite/test-entry.c |   85 +++++++++++++++++++++++++++++------------------
 1 files changed, 52 insertions(+), 33 deletions(-)
---
diff --git a/testsuite/test-entry.c b/testsuite/test-entry.c
index 403b5ae..db7a4b0 100644
--- a/testsuite/test-entry.c
+++ b/testsuite/test-entry.c
@@ -237,42 +237,61 @@ test_spell_checker_change (void)
 {
        GtkEntry *gtk_entry;
        GspellEntry *gspell_entry;
-       GtkEntryBuffer *gtk_buffer;
-       GspellEntryBuffer *gspell_buffer;
-       GSList *expected_list;
-       const GSList *received_list;
-       const GspellLanguage *lang;
-       GspellChecker *other_checker;
-
-       gtk_entry = create_entry ();
-       gspell_entry = gspell_entry_get_from_gtk_entry (gtk_entry);
-       gtk_buffer = gtk_entry_get_buffer (gtk_entry);
-       gspell_buffer = gspell_entry_buffer_get_from_gtk_entry_buffer (gtk_buffer);
-
-       gtk_entry_set_text (gtk_entry, "auienrst");
-       expected_list = add_word (NULL, "auienrst", 0, 8);
-       received_list = _gspell_entry_get_misspelled_words (gspell_entry);
-       check_entry_word_list_equal (expected_list, received_list);
-       free_word_list (expected_list);
+       gint i;
 
-       /* Set NULL spell checker */
-       gspell_entry_buffer_set_spell_checker (gspell_buffer, NULL);
-       expected_list = NULL;
-       received_list = _gspell_entry_get_misspelled_words (gspell_entry);
-       check_entry_word_list_equal (expected_list, received_list);
-
-       /* Set another spell checker */
-       lang = gspell_language_lookup ("en_US");
-       g_assert (lang != NULL);
+       gtk_entry = GTK_ENTRY (gtk_entry_new ());
+       g_object_ref_sink (gtk_entry);
 
-       other_checker = gspell_checker_new (lang);
-       gspell_entry_buffer_set_spell_checker (gspell_buffer, other_checker);
-       g_object_unref (other_checker);
+       gspell_entry = gspell_entry_get_from_gtk_entry (gtk_entry);
 
-       expected_list = add_word (NULL, "auienrst", 0, 8);
-       received_list = _gspell_entry_get_misspelled_words (gspell_entry);
-       check_entry_word_list_equal (expected_list, received_list);
-       free_word_list (expected_list);
+       for (i = 0; i < 2; i++)
+       {
+               GtkEntryBuffer *gtk_buffer;
+               GspellEntryBuffer *gspell_buffer;
+               GSList *expected_list;
+               const GSList *received_list;
+               const GspellLanguage *lang;
+               GspellChecker *checker;
+
+               gtk_buffer = gtk_entry_get_buffer (gtk_entry);
+               gspell_buffer = gspell_entry_buffer_get_from_gtk_entry_buffer (gtk_buffer);
+
+               /* Not yet a spell checker */
+               gtk_entry_set_text (gtk_entry, "auienrst");
+               expected_list = NULL;
+               received_list = _gspell_entry_get_misspelled_words (gspell_entry);
+               check_entry_word_list_equal (expected_list, received_list);
+
+               /* Set a spell checker */
+               lang = gspell_language_lookup ("en_US");
+               g_assert (lang != NULL);
+
+               checker = gspell_checker_new (lang);
+               gspell_entry_buffer_set_spell_checker (gspell_buffer, checker);
+               g_object_unref (checker);
+
+               expected_list = add_word (NULL, "auienrst", 0, 8);
+               received_list = _gspell_entry_get_misspelled_words (gspell_entry);
+               check_entry_word_list_equal (expected_list, received_list);
+               free_word_list (expected_list);
+
+               /* Set NULL spell checker */
+               gspell_entry_buffer_set_spell_checker (gspell_buffer, NULL);
+               expected_list = NULL;
+               received_list = _gspell_entry_get_misspelled_words (gspell_entry);
+               check_entry_word_list_equal (expected_list, received_list);
+
+               /* Change buffer for next iteration, to see if the signal
+                * connection for spell-checker changes still works.
+                */
+               {
+                       GtkEntryBuffer *new_gtk_buffer;
+
+                       new_gtk_buffer = gtk_entry_buffer_new (NULL, -1);
+                       gtk_entry_set_buffer (gtk_entry, new_gtk_buffer);
+                       g_object_unref (new_gtk_buffer);
+               }
+       }
 
        g_object_unref (gtk_entry);
 }


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