1 /* Copyright (c) 2008 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
22 #include <UnitTest++.h>
\r
23 #include <enchant.h>
\r
24 #include <enchant-provider.h>
\r
26 #include <gmodule.h>
\r
28 #include "unittest_enchant_providers.h"
\r
30 int Test(char* path);
\r
31 int TestProvider(char* filename);
\r
32 int TestProvidersInDirectory(char * dir_name);
\r
34 typedef EnchantProvider *(*EnchantProviderInitFunc) (void);
\r
35 typedef void (*EnchantPreConfigureFunc) (EnchantProvider * provider, const char * module_dir);
\r
37 // from enchant.c we need this so that providers can set errors.
\r
38 struct str_enchant_broker
\r
40 GSList *provider_list; /* list of all of the spelling backend providers */
\r
41 GHashTable *dict_map; /* map of language tag -> dictionary */
\r
42 GHashTable *provider_ordering; /* map of language tag -> provider order */
\r
47 // comes with a list of directories or providers
\r
48 int main(int argc, char* argv[])
\r
51 for(int i=1; i < argc; ++i)
\r
53 int resultT = Test(argv[i]);
\r
62 char* current_dir = g_get_current_dir();
\r
63 TestProvidersInDirectory(current_dir);
\r
64 g_free(current_dir);
\r
70 EnchantProvider* g_provider;
\r
71 EnchantProvider* GetProviderForTests()
\r
76 char* GetErrorMessage(EnchantProvider* provider)
\r
78 return provider->owner->error;
\r
81 //path is provider filename or directory containing providers
\r
82 int Test(char* path)
\r
85 if (g_file_test (path, (GFileTest)(G_FILE_TEST_IS_DIR)))
\r
87 return TestProvidersInDirectory(path);
\r
91 return TestProvider(path);
\r
95 int TestProvidersInDirectory(char * dir_name)
\r
98 G_CONST_RETURN char *dir_entry;
\r
99 size_t entry_len, g_module_suffix_len;
\r
104 dir = g_dir_open (dir_name, 0, NULL);
\r
108 g_module_suffix_len = strlen (G_MODULE_SUFFIX);
\r
110 while ((dir_entry = g_dir_read_name (dir)) != NULL)
\r
112 entry_len = strlen (dir_entry);
\r
113 if ((entry_len > g_module_suffix_len) &&
\r
114 !strcmp(dir_entry+(entry_len-g_module_suffix_len), G_MODULE_SUFFIX))
\r
116 filename = g_build_filename (dir_name, dir_entry, NULL);
\r
117 int resultT = Test(filename);
\r
130 int TestProvider(char* filename)
\r
132 assert(g_provider == NULL);
\r
135 EnchantProviderInitFunc init_func;
\r
136 EnchantPreConfigureFunc conf_func;
\r
138 GModule* module = g_module_open (filename, (GModuleFlags) 0);
\r
141 if (g_module_symbol(module, "init_enchant_provider", (gpointer *) (&init_func))
\r
144 g_provider = init_func ();
\r
147 /* optional entry point to allow modules to look for associated files
\r
150 g_module_symbol(module, "configure_enchant_provider", (gpointer *) (&conf_func))
\r
153 char* dir_name = g_path_get_dirname(filename);
\r
154 conf_func (g_provider, dir_name);
\r
160 g_warning ("Could not load provider: %s\n", g_module_error());
\r
165 EnchantBroker broker; // just so we have someplace to put errors
\r
168 g_provider->enchant_private_data = (void *) module;
\r
169 g_provider->owner = &broker;
\r
170 printf("\nRunning tests on %s\n", filename);
\r
171 result = UnitTest::RunAllTests();
\r
172 if(g_provider->dispose)
\r
173 g_provider->dispose(g_provider);
\r
179 g_module_close(module);
\r