|
Packit |
aa0600 |
/*
|
|
Packit |
aa0600 |
* This file is part of gspell, a spell-checking library.
|
|
Packit |
aa0600 |
*
|
|
Packit |
aa0600 |
* Copyright 2016 - Sébastien Wilmet <swilmet@gnome.org>
|
|
Packit |
aa0600 |
*
|
|
Packit |
aa0600 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
aa0600 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
aa0600 |
* License as published by the Free Software Foundation; either
|
|
Packit |
aa0600 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
aa0600 |
*
|
|
Packit |
aa0600 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
aa0600 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
aa0600 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
aa0600 |
* Lesser General Public License for more details.
|
|
Packit |
aa0600 |
*
|
|
Packit |
aa0600 |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit |
aa0600 |
* along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
aa0600 |
*/
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
#include <gspell/gspell.h>
|
|
Packit |
aa0600 |
#include "gspell/gspell-entry-utils.h"
|
|
Packit |
aa0600 |
#include "gspell/gspell-entry-private.h"
|
|
Packit |
aa0600 |
#include "gspell/gspell-checker-private.h"
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
/* Returns: (transfer full) */
|
|
Packit |
aa0600 |
static GtkEntry *
|
|
Packit |
aa0600 |
create_entry (void)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
GtkEntry *gtk_entry;
|
|
Packit |
aa0600 |
GtkEntryBuffer *gtk_buffer;
|
|
Packit |
aa0600 |
const GspellLanguage *lang;
|
|
Packit |
aa0600 |
GspellChecker *checker;
|
|
Packit |
aa0600 |
GspellEntryBuffer *gspell_buffer;
|
|
Packit |
aa0600 |
GspellEntry *gspell_entry;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_entry = GTK_ENTRY (gtk_entry_new ());
|
|
Packit |
aa0600 |
g_object_ref_sink (gtk_entry);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
lang = gspell_language_lookup ("en_US");
|
|
Packit |
aa0600 |
g_assert (lang != NULL);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
checker = gspell_checker_new (lang);
|
|
Packit |
aa0600 |
gtk_buffer = gtk_entry_get_buffer (gtk_entry);
|
|
Packit |
aa0600 |
gspell_buffer = gspell_entry_buffer_get_from_gtk_entry_buffer (gtk_buffer);
|
|
Packit |
aa0600 |
gspell_entry_buffer_set_spell_checker (gspell_buffer, checker);
|
|
Packit |
aa0600 |
g_object_unref (checker);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gspell_entry = gspell_entry_get_from_gtk_entry (gtk_entry);
|
|
Packit |
aa0600 |
gspell_entry_set_inline_spell_checking (gspell_entry, TRUE);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
return gtk_entry;
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static GSList *
|
|
Packit |
aa0600 |
add_word (GSList *list,
|
|
Packit |
aa0600 |
const gchar *word_str,
|
|
Packit |
aa0600 |
gint byte_start,
|
|
Packit |
aa0600 |
gint byte_end)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
GspellEntryWord *word;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
word = _gspell_entry_word_new ();
|
|
Packit |
aa0600 |
word->word_str = g_strdup (word_str);
|
|
Packit |
aa0600 |
word->byte_start = byte_start;
|
|
Packit |
aa0600 |
word->byte_end = byte_end;
|
|
Packit |
aa0600 |
word->char_start = -1;
|
|
Packit |
aa0600 |
word->char_end = -1;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
return g_slist_append (list, word);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static GSList *
|
|
Packit |
aa0600 |
add_word_full (GSList *list,
|
|
Packit |
aa0600 |
const gchar *word_str,
|
|
Packit |
aa0600 |
gint byte_start,
|
|
Packit |
aa0600 |
gint byte_end,
|
|
Packit |
aa0600 |
gint char_start,
|
|
Packit |
aa0600 |
gint char_end)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
GspellEntryWord *word;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
word = _gspell_entry_word_new ();
|
|
Packit |
aa0600 |
word->word_str = g_strdup (word_str);
|
|
Packit |
aa0600 |
word->byte_start = byte_start;
|
|
Packit |
aa0600 |
word->byte_end = byte_end;
|
|
Packit |
aa0600 |
word->char_start = char_start;
|
|
Packit |
aa0600 |
word->char_end = char_end;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
return g_slist_append (list, word);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static void
|
|
Packit |
aa0600 |
free_word_list (GSList *list)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
g_slist_free_full (list, _gspell_entry_word_free);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static void
|
|
Packit |
aa0600 |
check_entry_word_equal (GspellEntryWord *word1,
|
|
Packit |
aa0600 |
GspellEntryWord *word2)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
g_assert (word1 != NULL);
|
|
Packit |
aa0600 |
g_assert (word2 != NULL);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
g_assert_cmpstr (word1->word_str, ==, word2->word_str);
|
|
Packit |
aa0600 |
g_assert_cmpint (word1->byte_start, ==, word2->byte_start);
|
|
Packit |
aa0600 |
g_assert_cmpint (word1->byte_end, ==, word2->byte_end);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
if (word1->char_start != -1 &&
|
|
Packit |
aa0600 |
word2->char_start != -1)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
g_assert_cmpint (word1->char_start, ==, word2->char_start);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
if (word1->char_end != -1 &&
|
|
Packit |
aa0600 |
word2->char_end != -1)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
g_assert_cmpint (word1->char_end, ==, word2->char_end);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static void
|
|
Packit |
aa0600 |
check_entry_word_list_equal (const GSList *list1,
|
|
Packit |
aa0600 |
const GSList *list2)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
const GSList *l1;
|
|
Packit |
aa0600 |
const GSList *l2;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
for (l1 = list1, l2 = list2;
|
|
Packit |
aa0600 |
l1 != NULL && l2 != NULL;
|
|
Packit |
aa0600 |
l1 = l1->next, l2 = l2->next)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
GspellEntryWord *word1 = l1->data;
|
|
Packit |
aa0600 |
GspellEntryWord *word2 = l2->data;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
check_entry_word_equal (word1, word2);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
g_assert (l1 == NULL);
|
|
Packit |
aa0600 |
g_assert (l2 == NULL);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static void
|
|
Packit |
aa0600 |
test_get_words (void)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
GtkEntry *entry;
|
|
Packit |
aa0600 |
GSList *expected_list;
|
|
Packit |
aa0600 |
GSList *received_list;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
entry = GTK_ENTRY (gtk_entry_new ());
|
|
Packit |
aa0600 |
g_object_ref_sink (entry);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
expected_list = NULL;
|
|
Packit |
aa0600 |
received_list = _gspell_entry_utils_get_words (entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
/* Only one word */
|
|
Packit |
aa0600 |
gtk_entry_set_text (entry, "Finntroll");
|
|
Packit |
aa0600 |
expected_list = add_word_full (NULL, "Finntroll", 0, 9, 0, 9);
|
|
Packit |
aa0600 |
received_list = _gspell_entry_utils_get_words (entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
free_word_list (expected_list);
|
|
Packit |
aa0600 |
free_word_list (received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
/* Only one word, not at the start and end */
|
|
Packit |
aa0600 |
gtk_entry_set_text (entry, " Finntroll ");
|
|
Packit |
aa0600 |
expected_list = add_word_full (NULL, "Finntroll", 1, 10, 1, 10);
|
|
Packit |
aa0600 |
received_list = _gspell_entry_utils_get_words (entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
free_word_list (expected_list);
|
|
Packit |
aa0600 |
free_word_list (received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
/* Several words */
|
|
Packit |
aa0600 |
gtk_entry_set_text (entry, "Finntroll - Svart Djup");
|
|
Packit |
aa0600 |
expected_list = add_word_full (NULL, "Finntroll", 0, 9, 0, 9);
|
|
Packit |
aa0600 |
expected_list = add_word_full (expected_list, "Svart", 12, 17, 12, 17);
|
|
Packit |
aa0600 |
expected_list = add_word_full (expected_list, "Djup", 18, 22, 18, 22);
|
|
Packit |
aa0600 |
received_list = _gspell_entry_utils_get_words (entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
free_word_list (expected_list);
|
|
Packit |
aa0600 |
free_word_list (received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
/* Multi-byte UTF-8 words */
|
|
Packit |
aa0600 |
// å takes two bytes.
|
|
Packit |
aa0600 |
// ö takes two bytes.
|
|
Packit |
aa0600 |
gtk_entry_set_text (entry, "Asfågelns Död");
|
|
Packit |
aa0600 |
expected_list = add_word_full (NULL, "Asfågelns", 0, 10, 0, 9);
|
|
Packit |
aa0600 |
expected_list = add_word_full (expected_list, "Död", 11, 15, 10, 13);
|
|
Packit |
aa0600 |
received_list = _gspell_entry_utils_get_words (entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
free_word_list (expected_list);
|
|
Packit |
aa0600 |
free_word_list (received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
/* One apostrophe */
|
|
Packit |
aa0600 |
gtk_entry_set_text (entry, "doesn't");
|
|
Packit |
aa0600 |
expected_list = add_word_full (NULL, "doesn't", 0, 7, 0, 7);
|
|
Packit |
aa0600 |
received_list = _gspell_entry_utils_get_words (entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
free_word_list (expected_list);
|
|
Packit |
aa0600 |
free_word_list (received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
/* Several apostrophes */
|
|
Packit |
aa0600 |
gtk_entry_set_text (entry, "rock'n'roll");
|
|
Packit |
aa0600 |
expected_list = add_word_full (NULL, "rock'n'roll", 0, 11, 0, 11);
|
|
Packit |
aa0600 |
received_list = _gspell_entry_utils_get_words (entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
free_word_list (expected_list);
|
|
Packit |
aa0600 |
free_word_list (received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
/* Apostrophe at end of word. Not yet supported. */
|
|
Packit |
aa0600 |
gtk_entry_set_text (entry, "doin'");
|
|
Packit |
aa0600 |
expected_list = add_word_full (NULL, "doin", 0, 4, 0, 4);
|
|
Packit |
aa0600 |
received_list = _gspell_entry_utils_get_words (entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
free_word_list (expected_list);
|
|
Packit |
aa0600 |
free_word_list (received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
/* Apostrophe at beginning of word. Not yet supported. */
|
|
Packit |
aa0600 |
gtk_entry_set_text (entry, "'til");
|
|
Packit |
aa0600 |
expected_list = add_word_full (NULL, "til", 1, 4, 1, 4);
|
|
Packit |
aa0600 |
received_list = _gspell_entry_utils_get_words (entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
free_word_list (expected_list);
|
|
Packit |
aa0600 |
free_word_list (received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
/* Dash */
|
|
Packit |
aa0600 |
gtk_entry_set_text (entry, "spell-checking");
|
|
Packit |
aa0600 |
expected_list = add_word_full (NULL, "spell-checking", 0, 14, 0, 14);
|
|
Packit |
aa0600 |
received_list = _gspell_entry_utils_get_words (entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
free_word_list (expected_list);
|
|
Packit |
aa0600 |
free_word_list (received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
g_object_unref (entry);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static void
|
|
Packit |
aa0600 |
test_init (void)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
GtkEntry *gtk_entry;
|
|
Packit |
aa0600 |
GtkEntryBuffer *gtk_buffer;
|
|
Packit |
aa0600 |
const GspellLanguage *lang;
|
|
Packit |
aa0600 |
GspellChecker *checker;
|
|
Packit |
aa0600 |
GspellEntryBuffer *gspell_buffer;
|
|
Packit |
aa0600 |
GspellEntry *gspell_entry;
|
|
Packit |
aa0600 |
GSList *expected_list;
|
|
Packit |
aa0600 |
const GSList *received_list;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_entry = GTK_ENTRY (gtk_entry_new ());
|
|
Packit |
aa0600 |
g_object_ref_sink (gtk_entry);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
/* Set initial text before initializing GspellEntry. */
|
|
Packit |
aa0600 |
gtk_entry_set_text (gtk_entry, "auienrst");
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
lang = gspell_language_lookup ("en_US");
|
|
Packit |
aa0600 |
g_assert (lang != NULL);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
checker = gspell_checker_new (lang);
|
|
Packit |
aa0600 |
gtk_buffer = gtk_entry_get_buffer (gtk_entry);
|
|
Packit |
aa0600 |
gspell_buffer = gspell_entry_buffer_get_from_gtk_entry_buffer (gtk_buffer);
|
|
Packit |
aa0600 |
gspell_entry_buffer_set_spell_checker (gspell_buffer, checker);
|
|
Packit |
aa0600 |
g_object_unref (checker);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
/* Test just after creating the GspellEntry.
|
|
Packit |
aa0600 |
* The inline-spell-checking property is FALSE by default, so there are
|
|
Packit |
aa0600 |
* no misspelled words.
|
|
Packit |
aa0600 |
*/
|
|
Packit |
aa0600 |
gspell_entry = gspell_entry_get_from_gtk_entry (gtk_entry);
|
|
Packit |
aa0600 |
expected_list = NULL;
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gspell_entry_set_inline_spell_checking (gspell_entry, TRUE);
|
|
Packit |
aa0600 |
expected_list = add_word (NULL, "auienrst", 0, 8);
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
free_word_list (expected_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
g_object_unref (gtk_entry);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static void
|
|
Packit |
aa0600 |
test_inline_spell_checking_property (void)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
GtkEntry *gtk_entry;
|
|
Packit |
aa0600 |
GspellEntry *gspell_entry;
|
|
Packit |
aa0600 |
GSList *expected_list;
|
|
Packit |
aa0600 |
const GSList *received_list;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_entry = create_entry ();
|
|
Packit |
aa0600 |
gspell_entry = gspell_entry_get_from_gtk_entry (gtk_entry);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
expected_list = NULL;
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gspell_entry_set_inline_spell_checking (gspell_entry, FALSE);
|
|
Packit |
aa0600 |
expected_list = NULL;
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_entry_set_text (gtk_entry, "auienrst");
|
|
Packit |
aa0600 |
expected_list = NULL;
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gspell_entry_set_inline_spell_checking (gspell_entry, TRUE);
|
|
Packit |
aa0600 |
expected_list = add_word (NULL, "auienrst", 0, 8);
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
free_word_list (expected_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_entry_set_text (gtk_entry, "Hello Död");
|
|
Packit |
aa0600 |
expected_list = add_word (NULL, "Död", 6, 10);
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
free_word_list (expected_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gspell_entry_set_inline_spell_checking (gspell_entry, FALSE);
|
|
Packit |
aa0600 |
expected_list = NULL;
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
g_object_unref (gtk_entry);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static void
|
|
Packit |
aa0600 |
test_buffer_change (void)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
GtkEntry *gtk_entry;
|
|
Packit |
aa0600 |
GtkEntryBuffer *other_buffer;
|
|
Packit |
aa0600 |
GspellEntry *gspell_entry;
|
|
Packit |
aa0600 |
GSList *expected_list;
|
|
Packit |
aa0600 |
const GSList *received_list;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_entry = create_entry ();
|
|
Packit |
aa0600 |
gspell_entry = gspell_entry_get_from_gtk_entry (gtk_entry);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_entry_set_text (gtk_entry, "auienrst");
|
|
Packit |
aa0600 |
expected_list = add_word (NULL, "auienrst", 0, 8);
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
free_word_list (expected_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
other_buffer = gtk_entry_buffer_new (NULL, -1);
|
|
Packit |
aa0600 |
gtk_entry_set_buffer (gtk_entry, other_buffer);
|
|
Packit |
aa0600 |
g_object_unref (other_buffer);
|
|
Packit |
aa0600 |
expected_list = NULL;
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
g_object_unref (gtk_entry);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static void
|
|
Packit |
aa0600 |
test_spell_checker_change (void)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
GtkEntry *gtk_entry;
|
|
Packit |
aa0600 |
GspellEntry *gspell_entry;
|
|
Packit |
aa0600 |
gint i;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_entry = GTK_ENTRY (gtk_entry_new ());
|
|
Packit |
aa0600 |
g_object_ref_sink (gtk_entry);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gspell_entry = gspell_entry_get_from_gtk_entry (gtk_entry);
|
|
Packit |
aa0600 |
gspell_entry_set_inline_spell_checking (gspell_entry, TRUE);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
for (i = 0; i < 2; i++)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
GtkEntryBuffer *gtk_buffer;
|
|
Packit |
aa0600 |
GspellEntryBuffer *gspell_buffer;
|
|
Packit |
aa0600 |
GSList *expected_list;
|
|
Packit |
aa0600 |
const GSList *received_list;
|
|
Packit |
aa0600 |
const GspellLanguage *lang;
|
|
Packit |
aa0600 |
GspellChecker *checker;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_buffer = gtk_entry_get_buffer (gtk_entry);
|
|
Packit |
aa0600 |
gspell_buffer = gspell_entry_buffer_get_from_gtk_entry_buffer (gtk_buffer);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
/* Not yet a spell checker */
|
|
Packit |
aa0600 |
gtk_entry_set_text (gtk_entry, "auienrst");
|
|
Packit |
aa0600 |
expected_list = NULL;
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
/* Set a spell checker */
|
|
Packit |
aa0600 |
lang = gspell_language_lookup ("en_US");
|
|
Packit |
aa0600 |
g_assert (lang != NULL);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
checker = gspell_checker_new (lang);
|
|
Packit |
aa0600 |
gspell_entry_buffer_set_spell_checker (gspell_buffer, checker);
|
|
Packit |
aa0600 |
g_object_unref (checker);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
expected_list = add_word (NULL, "auienrst", 0, 8);
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
free_word_list (expected_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
/* Set NULL spell checker */
|
|
Packit |
aa0600 |
gspell_entry_buffer_set_spell_checker (gspell_buffer, NULL);
|
|
Packit |
aa0600 |
expected_list = NULL;
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
/* Change buffer for next iteration, to see if the signal
|
|
Packit |
aa0600 |
* connection for spell-checker changes still works.
|
|
Packit |
aa0600 |
*/
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
GtkEntryBuffer *new_gtk_buffer;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
new_gtk_buffer = gtk_entry_buffer_new (NULL, -1);
|
|
Packit |
aa0600 |
gtk_entry_set_buffer (gtk_entry, new_gtk_buffer);
|
|
Packit |
aa0600 |
g_object_unref (new_gtk_buffer);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
g_object_unref (gtk_entry);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static void
|
|
Packit |
aa0600 |
test_language_change (void)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
GtkEntry *gtk_entry;
|
|
Packit |
aa0600 |
GspellEntry *gspell_entry;
|
|
Packit |
aa0600 |
GtkEntryBuffer *gtk_buffer;
|
|
Packit |
aa0600 |
GspellEntryBuffer *gspell_buffer;
|
|
Packit |
aa0600 |
const GspellLanguage *lang;
|
|
Packit |
aa0600 |
GspellChecker *checker;
|
|
Packit |
aa0600 |
GSList *expected_list;
|
|
Packit |
aa0600 |
const GSList *received_list;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_entry = GTK_ENTRY (gtk_entry_new ());
|
|
Packit |
aa0600 |
g_object_ref_sink (gtk_entry);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gspell_entry = gspell_entry_get_from_gtk_entry (gtk_entry);
|
|
Packit |
aa0600 |
gspell_entry_set_inline_spell_checking (gspell_entry, TRUE);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_buffer = gtk_entry_get_buffer (gtk_entry);
|
|
Packit |
aa0600 |
gspell_buffer = gspell_entry_buffer_get_from_gtk_entry_buffer (gtk_buffer);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
lang = gspell_language_lookup ("en_US");
|
|
Packit |
aa0600 |
g_assert (lang != NULL);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
checker = gspell_checker_new (lang);
|
|
Packit |
aa0600 |
gspell_entry_buffer_set_spell_checker (gspell_buffer, checker);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_entry_set_text (gtk_entry, "auienrst");
|
|
Packit |
aa0600 |
expected_list = add_word (NULL, "auienrst", 0, 8);
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
free_word_list (expected_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
_gspell_checker_force_set_language (checker, NULL);
|
|
Packit |
aa0600 |
expected_list = NULL;
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
g_object_unref (gtk_entry);
|
|
Packit |
aa0600 |
g_object_unref (checker);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static void
|
|
Packit |
aa0600 |
test_password_mode (void)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
GtkEntry *gtk_entry;
|
|
Packit |
aa0600 |
GspellEntry *gspell_entry;
|
|
Packit |
aa0600 |
GSList *expected_list;
|
|
Packit |
aa0600 |
const GSList *received_list;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_entry = create_entry ();
|
|
Packit |
aa0600 |
gspell_entry = gspell_entry_get_from_gtk_entry (gtk_entry);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
g_assert (gtk_entry_get_visibility (gtk_entry));
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_entry_set_text (gtk_entry, "auienrst");
|
|
Packit |
aa0600 |
expected_list = add_word (NULL, "auienrst", 0, 8);
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
free_word_list (expected_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_entry_set_visibility (gtk_entry, FALSE);
|
|
Packit |
aa0600 |
expected_list = NULL;
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_entry_set_visibility (gtk_entry, TRUE);
|
|
Packit |
aa0600 |
expected_list = add_word (NULL, "auienrst", 0, 8);
|
|
Packit |
aa0600 |
received_list = _gspell_entry_get_misspelled_words (gspell_entry);
|
|
Packit |
aa0600 |
check_entry_word_list_equal (expected_list, received_list);
|
|
Packit |
aa0600 |
free_word_list (expected_list);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
g_object_unref (gtk_entry);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gint
|
|
Packit |
aa0600 |
main (gint argc,
|
|
Packit |
aa0600 |
gchar **argv)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
gtk_test_init (&argc, &argv);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
g_test_add_func ("/entry-utils/get-words", test_get_words);
|
|
Packit |
aa0600 |
g_test_add_func ("/entry/init", test_init);
|
|
Packit |
aa0600 |
g_test_add_func ("/entry/inline-spell-checking-property", test_inline_spell_checking_property);
|
|
Packit |
aa0600 |
g_test_add_func ("/entry/buffer-change", test_buffer_change);
|
|
Packit |
aa0600 |
g_test_add_func ("/entry/spell-checker-change", test_spell_checker_change);
|
|
Packit |
aa0600 |
g_test_add_func ("/entry/language-change", test_language_change);
|
|
Packit |
aa0600 |
g_test_add_func ("/entry/password-mode", test_password_mode);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
return g_test_run ();
|
|
Packit |
aa0600 |
}
|