22 #ifndef __ENCHANTBROKERTESTFIXTURE
23 #define __ENCHANTBROKERTESTFIXTURE
25 #include "EnchantTestFixture.h"
26 #include "mock_provider.h"
42 const char *
const tag)
44 return (strcmp(tag,
"en_GB")==0 || strcmp(tag,
"qaa") ==0);
49 MockEnGbAndQaaProviderRequestDictionary(
EnchantProvider * me,
const char *tag)
53 if(MockEnGbAndQaaProviderDictionaryExists(me, tag)){
74 return "Mock Provider";
82 char** out_list = g_new0 (
char *, *out_n_dicts + 1);
83 out_list[0] = g_strdup (
"en_GB");
84 out_list[1] = g_strdup (
"qaa");
94 char** out_list = g_new0 (
char *, *out_n_dicts + 1);
95 out_list[0] = g_strdup (
"en_GB");
100 typedef void (*SET_CONFIGURE)(ConfigureHook);
105 GModule *hModule, *hModule2;
109 ConfigureHook user2Configuration=NULL,
110 bool includeNullProviders =
false)
112 userMockProviderConfiguration = userConfiguration;
113 userMockProvider2Configuration = user2Configuration;
115 CopyProvider(
"enchant_mock_provider",
"enchant_mock_provider");
116 hModule = g_module_open(LIBDIR_SUBDIR
"/enchant-" ENCHANT_MAJOR_VERSION
"/enchant_mock_provider", (GModuleFlags) 0);
119 assert(g_module_symbol(hModule,
"set_configure", (gpointer *)&sc));
120 (sc)(ConfigureMockProvider);
124 if(user2Configuration != NULL){
125 CopyProvider(
"enchant_mock_provider2",
"enchant_mock_provider2");
126 hModule2 = g_module_open(LIBDIR_SUBDIR
"/enchant-" ENCHANT_MAJOR_VERSION
"/enchant_mock_provider2", (GModuleFlags) 0);
129 assert(g_module_symbol(hModule2,
"set_configure", (gpointer *)&sc));
130 (sc)(ConfigureMockProvider2);
134 if(includeNullProviders){
135 CopyProvider(
"enchant_null_provider",
"null_provider");
136 CopyProvider(
"enchant_null_identify",
"null_identify");
137 CopyProvider(
"enchant_null_describe",
"null_describe");
138 CopyProvider(
"enchant-" ENCHANT_MAJOR_VERSION,
"enchant-" ENCHANT_MAJOR_VERSION);
147 g_module_close(hModule);
150 g_module_close(hModule2);
154 enchant_broker_free (_broker);
156 while(!pwlFilenames.empty())
158 DeleteFile(pwlFilenames.top());
163 void InitializeBroker()
165 _broker = enchant_broker_init ();
168 void CopyProvider(
const std::string& sourceProviderName,
const std::string& destinationProviderName)
172 #if defined(__MSYS__)
174 #elif defined(__CYGWIN__)
180 std::string sourceName = prefix + sourceProviderName +
"." + G_MODULE_SUFFIX;
181 std::string destinationName = destinationProviderName +
"." + G_MODULE_SUFFIX;
183 std::string destinationDir = AddToPath(LIBDIR_SUBDIR,
"enchant-" ENCHANT_MAJOR_VERSION);
185 CreateDirectory(destinationDir);
187 std::string destinationPath = AddToPath(destinationDir, destinationName);
191 if(g_file_get_contents(sourceName.c_str(), &contents, &length, NULL)){
192 g_file_set_contents(destinationPath.c_str(), contents, length, NULL);
199 return mock_provider;
202 void SetErrorOnMockProvider(
const std::string& error)
207 enchant_provider_set_error(provider, error.c_str());
211 EnchantDict* RequestDictionary(
const std::string& tag){
212 return enchant_broker_request_dict(_broker, tag.c_str());
217 std::string pwlFileName = GetTemporaryFilename(
"epwl");
218 CreateFile(pwlFileName);
219 pwlFilenames.push(pwlFileName);
220 return enchant_broker_request_pwl_dict(_broker, pwlFileName.c_str());
223 std::string GetLastPersonalDictionaryFileName()
225 return pwlFilenames.top();
230 if(dictionary != NULL){
231 enchant_broker_free_dict(_broker, dictionary);
236 std::stack<std::string> pwlFilenames;
238 static ConfigureHook userMockProviderConfiguration;
239 static ConfigureHook userMockProvider2Configuration;
240 static void ConfigureMockProvider (
EnchantProvider * me,
const char * dir_name)
243 if(userMockProviderConfiguration){
244 userMockProviderConfiguration(me, dir_name);
248 static void ConfigureMockProvider2 (
EnchantProvider * me,
const char * dir_name)
251 if(userMockProvider2Configuration){
252 userMockProvider2Configuration(me, dir_name);
259 std::string LanguageTag;
261 std::string Description;
266 const char *
const provider_name,
267 const char *
const provider_desc,
268 const char *
const provider_file):
269 LanguageTag(language_tag),
271 Description(provider_desc),
272 DllFile(provider_file)
276 LanguageTag(d.LanguageTag),
278 Description(d.Description),
282 bool DataIsComplete()
284 return (LanguageTag.length() &&
286 Description.length() &&
Definition: EnchantBrokerTestFixture.h:258
Definition: EnchantBrokerTestFixture.h:103
Definition: EnchantTestFixture.h:44
Definition: enchant-provider.h:125
Definition: enchant-provider.h:150