1 /* Copyright (c) 2007 Eric Scott Albright
\r
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
4 * of this software and associated documentation files (the "Software"), to deal
\r
5 * in the Software without restriction, including without limitation the rights
\r
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
7 * copies of the Software, and to permit persons to whom the Software is
\r
8 * furnished to do so, subject to the following conditions:
\r
10 * The above copyright notice and this permission notice shall be included in
\r
11 * all copies or substantial portions of the Software.
\r
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
23 #include "mock_provider.h"
\r
25 ENCHANT_PLUGIN_DECLARE("mock")
\r
28 mock_provider_dispose(EnchantProvider *me)
\r
34 mock_provider_identify (EnchantProvider *)
\r
40 mock_provider_describe (EnchantProvider *)
\r
42 return "Mock Provider";
\r
45 static ConfigureHook _hook;
\r
50 ENCHANT_MODULE_EXPORT(void)
\r
51 set_configure(ConfigureHook hook){
\r
56 ENCHANT_MODULE_EXPORT(EnchantProvider *)
\r
57 init_enchant_provider(void)
\r
59 bool hasIdentify = true;
\r
60 bool hasDescribe = true;
\r
62 std::wstring null_provider(L"null_provider.dll");
\r
63 std::wstring null_identify(L"null_identify.dll");
\r
64 std::wstring null_describe(L"null_describe.dll");
\r
65 WCHAR szFilename[MAX_PATH];
\r
66 DWORD cFilename = GetModuleFileName((HMODULE)s_hModule, (LPWSTR) &szFilename, sizeof(szFilename));
\r
67 if(cFilename > null_provider.size()){
\r
68 if(std::wstring(&szFilename[cFilename-null_provider.size()]) == null_provider){
\r
72 if(cFilename > null_identify.size()){
\r
73 if(std::wstring(&szFilename[cFilename-null_identify.size()]) == null_identify){
\r
74 hasIdentify = false;
\r
77 if(cFilename > null_describe.size()){
\r
78 if(std::wstring(&szFilename[cFilename-null_describe.size()]) == null_describe){
\r
79 hasDescribe = false;
\r
85 EnchantProvider *provider;
\r
87 provider = g_new0(EnchantProvider, 1);
\r
88 provider->dispose = mock_provider_dispose; //although this is technically optional, it will result in a memory leak
\r
89 provider->request_dict = NULL;
\r
90 provider->dispose_dict = NULL;
\r
91 provider->identify = hasIdentify ? mock_provider_identify : NULL; // this is required or module won't load
\r
92 provider->describe = hasDescribe ? mock_provider_describe : NULL; // this is required or module won't load
\r
93 provider->list_dicts = NULL;
\r
94 provider->dictionary_exists = NULL;
\r
95 provider->free_string_list = NULL;
\r
100 ENCHANT_MODULE_EXPORT(void)
\r
101 configure_enchant_provider(EnchantProvider * me, const char *dir_name)
\r
104 _hook(me, dir_name);
\r