22 #ifndef __ENCHANTBROKERTESTFIXTURE
23 #define __ENCHANTBROKERTESTFIXTURE
25 #include "EnchantTestFixture.h"
26 #include "mock_provider.h"
35 MockEnGbAndQaaProviderDictionaryExists (EnchantProvider *,
36 const char *
const tag)
38 return (strcmp(tag,
"en_GB")==0 || strcmp(tag,
"qaa") ==0);
43 MockEnGbAndQaaProviderRequestDictionary(EnchantProvider * me,
const char *tag)
45 EnchantDict *dict = NULL;
47 if(MockEnGbAndQaaProviderDictionaryExists(me, tag)){
48 dict = enchant_broker_new_dict (me->owner);
54 MockProviderDisposeDictionary (EnchantProvider *, EnchantDict * dict)
59 MockProviderIdentify (EnchantProvider *)
65 MockProviderDescribe (EnchantProvider *)
67 return "Mock Provider";
71 MockEnGbAndQaaProviderListDictionaries (EnchantProvider *,
75 char** out_list = g_new0 (
char *, *out_n_dicts + 1);
76 out_list[0] = g_strdup (
"en_GB");
77 out_list[1] = g_strdup (
"qaa");
83 MockEnGbProviderListDictionaries (EnchantProvider *,
87 char** out_list = g_new0 (
char *, *out_n_dicts + 1);
88 out_list[0] = g_strdup (
"en_GB");
93 typedef void (*SET_CONFIGURE)(ConfigureHook);
97 EnchantBroker* _broker;
98 GModule *hModule, *hModule2;
102 ConfigureHook user2Configuration=NULL,
103 bool includeNullProviders =
false)
105 userMockProviderConfiguration = userConfiguration;
106 userMockProvider2Configuration = user2Configuration;
108 CopyProvider(
"enchant_mock_provider",
"enchant_mock_provider");
109 hModule = g_module_open(LIBDIR_SUBDIR
"/enchant-" ENCHANT_MAJOR_VERSION
"/enchant_mock_provider", (GModuleFlags) 0);
112 assert(g_module_symbol(hModule,
"set_configure", (gpointer *)&sc));
113 (sc)(ConfigureMockProvider);
117 if(user2Configuration != NULL){
118 CopyProvider(
"enchant_mock_provider2",
"enchant_mock_provider2");
119 hModule2 = g_module_open(LIBDIR_SUBDIR
"/enchant-" ENCHANT_MAJOR_VERSION
"/enchant_mock_provider2", (GModuleFlags) 0);
122 assert(g_module_symbol(hModule2,
"set_configure", (gpointer *)&sc));
123 (sc)(ConfigureMockProvider2);
127 if(includeNullProviders){
128 CopyProvider(
"enchant_null_provider",
"null_provider");
129 CopyProvider(
"enchant_null_identify",
"null_identify");
130 CopyProvider(
"enchant_null_describe",
"null_describe");
131 CopyProvider(
"enchant-" ENCHANT_MAJOR_VERSION,
"enchant-" ENCHANT_MAJOR_VERSION);
140 g_module_close(hModule);
143 g_module_close(hModule2);
147 enchant_broker_free (_broker);
149 while(!pwlFilenames.empty())
151 DeleteFile(pwlFilenames.top());
156 void InitializeBroker()
158 _broker = enchant_broker_init ();
161 void CopyProvider(
const std::string& sourceProviderName,
const std::string& destinationProviderName)
165 #if defined(__MSYS__)
167 #elif defined(__CYGWIN__)
173 std::string sourceName = prefix + sourceProviderName +
"." + G_MODULE_SUFFIX;
174 std::string destinationName = destinationProviderName +
"." + G_MODULE_SUFFIX;
176 std::string destinationDir = AddToPath(LIBDIR_SUBDIR,
"enchant-" ENCHANT_MAJOR_VERSION);
178 CreateDirectory(destinationDir);
180 std::string destinationPath = AddToPath(destinationDir, destinationName);
184 if(g_file_get_contents(sourceName.c_str(), &contents, &length, NULL)){
185 g_file_set_contents(destinationPath.c_str(), contents, length, NULL);
191 EnchantProvider* GetMockProvider(){
192 return mock_provider;
195 void SetErrorOnMockProvider(
const std::string& error)
197 EnchantProvider* provider = GetMockProvider();
200 enchant_provider_set_error(provider, error.c_str());
204 EnchantDict* RequestDictionary(
const std::string& tag){
205 return enchant_broker_request_dict(_broker, tag.c_str());
208 EnchantDict* RequestPersonalDictionary()
210 std::string pwlFileName = GetTemporaryFilename(
"epwl");
211 CreateFile(pwlFileName);
212 pwlFilenames.push(pwlFileName);
213 return enchant_broker_request_pwl_dict(_broker, pwlFileName.c_str());
216 std::string GetLastPersonalDictionaryFileName()
218 return pwlFilenames.top();
222 void FreeDictionary(EnchantDict* dictionary){
223 if(dictionary != NULL){
224 enchant_broker_free_dict(_broker, dictionary);
229 std::stack<std::string> pwlFilenames;
230 static EnchantProvider * mock_provider;
231 static ConfigureHook userMockProviderConfiguration;
232 static ConfigureHook userMockProvider2Configuration;
233 static void ConfigureMockProvider (EnchantProvider * me,
const char * dir_name)
236 if(userMockProviderConfiguration){
237 userMockProviderConfiguration(me, dir_name);
241 static void ConfigureMockProvider2 (EnchantProvider * me,
const char * dir_name)
244 if(userMockProvider2Configuration){
245 userMockProvider2Configuration(me, dir_name);
252 std::string LanguageTag;
254 std::string Description;
259 const char *
const provider_name,
260 const char *
const provider_desc,
261 const char *
const provider_file):
262 LanguageTag(language_tag),
264 Description(provider_desc),
265 DllFile(provider_file)
269 LanguageTag(d.LanguageTag),
271 Description(d.Description),
275 bool DataIsComplete()
277 return (LanguageTag.length() &&
279 Description.length() &&
Definition: EnchantBrokerTestFixture.h:251
Definition: EnchantBrokerTestFixture.h:96
Definition: EnchantTestFixture.h:44