1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/* Copyright (c) 2007 Eric Scott Albright
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <glib.h>
#include <string.h>
#include <string>
#include <stdio.h>
#include "mock_provider.h"
static void
mock_provider_dispose(EnchantProvider *me)
{
g_free(me);
}
static void
mock_provider_dispose_dict(EnchantProvider *me, EnchantDict *dict)
{
}
static const char *
mock_provider_identify (EnchantProvider *)
{
return "mock";
}
static const char *
mock_provider_describe (EnchantProvider *)
{
return "Mock Provider";
}
static char **
mock_provider_list_dicts (EnchantProvider *me, size_t *out_n_dicts)
{
*out_n_dicts = 0;
return NULL;
}
static ConfigureHook _hook;
extern "C" {
void
set_configure(ConfigureHook hook){
_hook = hook;
}
EnchantProvider *
init_enchant_provider(void)
{
#ifndef ENCHANT_TEST_NULL_IDENTIFY
bool hasIdentify = true;
#else
bool hasIdentify = false;
#endif
#ifndef ENCHANT_TEST_NULL_DESCRIBE
bool hasDescribe = true;
#else
bool hasDescribe = false;
#endif
#ifdef ENCHANT_TEST_NULL_PROVIDER
return NULL;
#endif
EnchantProvider *provider;
provider = g_new0(EnchantProvider, 1);
provider->dispose = mock_provider_dispose; //although this is technically optional, it will result in a memory leak
provider->request_dict = NULL;
provider->dispose_dict = mock_provider_dispose_dict;
provider->identify = hasIdentify ? mock_provider_identify : NULL; // this is required or module won't load
provider->describe = hasDescribe ? mock_provider_describe : NULL; // this is required or module won't load
provider->list_dicts = mock_provider_list_dicts;
provider->dictionary_exists = NULL;
return provider;
}
void
configure_enchant_provider(EnchantProvider * me, const char *dir_name)
{
if(_hook){
_hook(me, dir_name);
}
}
}
|