int weechat_aspell_speller_dict_supported (const char *lang) { #ifdef USE_ENCHANT return enchant_broker_dict_exists (broker, lang); #else struct AspellConfig *config; AspellDictInfoList *list; AspellDictInfoEnumeration *elements; const AspellDictInfo *dict; int rc; rc = 0; config = new_aspell_config (); list = get_aspell_dict_info_list (config); elements = aspell_dict_info_list_elements (list); while ((dict = aspell_dict_info_enumeration_next (elements)) != NULL) { if (strcmp (dict->name, lang) == 0) { rc = 1; break; } } delete_aspell_dict_info_enumeration (elements); delete_aspell_config (config); return rc; #endif /* USE_ENCHANT */ }
TEST_FIXTURE(EnchantBrokerDictExists_ProviderImplementsAll_TestFixture, EnchantBrokerDictExists_CalledWhenDictionaryIsInUse_DoesNotCallAnyMethods_GetsCachedResult) { EnchantDict* dict = enchant_broker_request_dict(_broker, "en-GB"); enchant_broker_dict_exists(_broker, "en-GB"); CHECK_EQUAL(0,listDictionariesCalled); CHECK_EQUAL(0,dictionaryExistsCalled); enchant_broker_free_dict(_broker, dict); }
TEST_FIXTURE(EnchantBrokerTestFixture, EnchantBrokerDictExists_ProviderImplementsNoMethods_0) { CHECK_EQUAL(0, enchant_broker_dict_exists(_broker, "en_GB")); }
gboolean suggestions_init() { gchar dict_tag[DICT_TAG_MAX_LENGTH] = ""; if(g_module_supported() && (mod_enchant = g_module_open(ENCHANT_FILE, G_MODULE_BIND_LAZY))) { g_module_symbol(mod_enchant, G_STRINGIFY(enchant_broker_init), (gpointer *) &enchant_broker_init); g_module_symbol(mod_enchant, G_STRINGIFY(enchant_broker_free), (gpointer *) &enchant_broker_free); g_module_symbol(mod_enchant, G_STRINGIFY(enchant_broker_list_dicts), (gpointer *) &enchant_broker_list_dicts); g_module_symbol(mod_enchant, G_STRINGIFY(enchant_broker_dict_exists), (gpointer *) &enchant_broker_dict_exists); g_module_symbol(mod_enchant, G_STRINGIFY(enchant_broker_request_dict), (gpointer *) &enchant_broker_request_dict); g_module_symbol(mod_enchant, G_STRINGIFY(enchant_broker_free_dict), (gpointer *) &enchant_broker_free_dict); g_module_symbol(mod_enchant, G_STRINGIFY(enchant_dict_check), (gpointer *) &enchant_dict_check); g_module_symbol(mod_enchant, G_STRINGIFY(enchant_dict_suggest), (gpointer *) &enchant_dict_suggest); g_module_symbol(mod_enchant, G_STRINGIFY(enchant_dict_free_string_list), (gpointer *) &enchant_dict_free_string_list); // in older version of Enchant, enchant_dict_free_string_list might be absent, they will have the // now deprecated function enchant_dict_free_suggestions if(NULL == enchant_dict_free_string_list) g_module_symbol(mod_enchant, G_STRINGIFY(enchant_dict_free_string_list), (gpointer *) &enchant_dict_free_string_list); // check if we have obtained the essential function pointers if(NULL != enchant_broker_init && NULL != enchant_broker_free && NULL != enchant_broker_dict_exists && NULL != enchant_broker_request_dict && NULL != enchant_broker_free_dict && NULL != enchant_dict_check && NULL != enchant_dict_suggest && NULL != enchant_dict_free_string_list) { enchant_broker = enchant_broker_init(); if(enchant_broker) { /* if the sys. lang is suitable, copy that else copy the default lang tag */ if(try_sys_lang(dict_tag, DICT_TAG_MAX_LENGTH)) { if(enchant_broker_dict_exists(enchant_broker, dict_tag)) { enchant_dict = enchant_broker_request_dict(enchant_broker, dict_tag); return TRUE; } G_MESSAGE("Suggestions: Couldn't get '%s' dict. Looking for alternatives...\n", dict_lang_tag); } g_strlcpy(dict_tag, dict_lang_tag, DICT_TAG_MAX_LENGTH); /* if the req. dict. doesn't exist and if list dict func. exists then try to enumerate the dictionaries and see if a compatible one can be found */ if(!enchant_broker_dict_exists(enchant_broker, dict_tag) && enchant_broker_list_dicts) { G_MESSAGE("Suggestions: Couldn't get '%s' dict. Looking for alternatives...\n", dict_lang_tag); dict_tag[0] = '\0'; enchant_broker_list_dicts(enchant_broker, find_dictionary, dict_tag); } if(dict_tag[0] != '\0') { enchant_dict = enchant_broker_request_dict(enchant_broker, dict_tag); G_MESSAGE("Suggestions module successfully loaded"); return TRUE; } } } } if(enchant_broker) { enchant_broker_free(enchant_broker); enchant_broker = NULL; } if(mod_enchant) { g_module_close(mod_enchant); mod_enchant = NULL; } G_MESSAGE("Failed to load suggestions module"); return FALSE; }