summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Albright <eric_albright@sil.org>2007-11-28 06:01:53 +0000
committerEric Albright <eric_albright@sil.org>2007-11-28 06:01:53 +0000
commitdb7b4940bf979b3c05a4fc92796fd00bf0e1ccd6 (patch)
tree4bf5d4efa994d0cb00eb81276ac85a999c768629
parente6af13f13647334dc8db6f7fb04cb33faba40174 (diff)
downloadenchant-db7b4940bf979b3c05a4fc92796fd00bf0e1ccd6.tar.gz
Add enchant_get_user_config_dir and change default location of providers, dictionaries, etc. on Windows ($APPDATA/enchant instead of $HOME/.enchant)
git-svn-id: svn+ssh://svn.abisource.com/svnroot/enchant/trunk@22343 bcba8976-2d24-0410-9c9c-aab3bd5fdfd6
-rw-r--r--msvc/unittest-enchant.vcproj4
-rw-r--r--src/enchant-provider.h3
-rw-r--r--src/enchant.c118
-rw-r--r--src/ispell/ispell_checker.cpp14
-rw-r--r--src/myspell/myspell_checker.cpp18
-rw-r--r--src/uspell/uspell_provider.cpp30
-rw-r--r--unittests/EnchantBrokerTestFixture.h20
-rw-r--r--unittests/EnchantTestFixture.h23
-rw-r--r--unittests/broker/enchant_broker_describe_tests.cpp7
-rw-r--r--unittests/broker/enchant_broker_set_ordering_tests.cpp470
-rw-r--r--unittests/provider/enchant_provider_get_config_home_dir_tests.cpp85
-rw-r--r--unittests/provider/enchant_provider_get_user_home_dir_tests.cpp3
12 files changed, 458 insertions, 337 deletions
diff --git a/msvc/unittest-enchant.vcproj b/msvc/unittest-enchant.vcproj
index d053e81..183f846 100644
--- a/msvc/unittest-enchant.vcproj
+++ b/msvc/unittest-enchant.vcproj
@@ -302,6 +302,10 @@
>
</File>
<File
+ RelativePath="..\unittests\provider\enchant_provider_get_config_home_dir_tests.cpp"
+ >
+ </File>
+ <File
RelativePath="..\unittests\provider\enchant_provider_get_prefix_dir_tests.cpp"
>
</File>
diff --git a/src/enchant-provider.h b/src/enchant-provider.h
index 339f963..8964563 100644
--- a/src/enchant-provider.h
+++ b/src/enchant-provider.h
@@ -58,6 +58,9 @@ ENCHANT_MODULE_EXPORT (char *)
enchant_get_user_home_dir (void);
ENCHANT_MODULE_EXPORT (char *)
+ enchant_get_user_config_dir (void);
+
+ENCHANT_MODULE_EXPORT (char *)
enchant_get_registry_value (const char * const prefix, const char * const key);
ENCHANT_MODULE_EXPORT(char *)
diff --git a/src/enchant.c b/src/enchant.c
index 64152d9..e57a036 100644
--- a/src/enchant.c
+++ b/src/enchant.c
@@ -46,6 +46,8 @@
#ifdef XP_TARGET_COCOA
#define ENCHANT_USER_PATH_EXTENSION "Library", "Application Support", "Enchant"
+#elif defined(_WIN32)
+#define ENCHANT_USER_PATH_EXTENSION "enchant"
#else
#define ENCHANT_USER_PATH_EXTENSION ".enchant"
#endif
@@ -56,6 +58,9 @@
ENCHANT_PLUGIN_DECLARE("Enchant")
+static char *
+enchant_get_registry_value_ex (int current_user, const char * const prefix, const char * const key);
+
/********************************************************************************/
/********************************************************************************/
@@ -96,24 +101,19 @@ static void
_enchant_ensure_private_datadir (void)
{
/* test if ~/.enchant exists */
- char * home_dir;
+ char * config_dir;
- home_dir = enchant_get_user_home_dir ();
- if (home_dir) {
- char * enchant_path;
-
- enchant_path = g_build_filename (home_dir, ENCHANT_USER_PATH_EXTENSION, NULL);
- if (enchant_path && !g_file_test (enchant_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
- {
- (void)g_remove (enchant_path);
- g_mkdir (enchant_path, 0700);
- }
-
- g_free (enchant_path);
- g_free (home_dir);
- }
+ config_dir = enchant_get_user_config_dir ();
+ if (config_dir && !g_file_test (config_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
+ {
+ (void)g_remove (config_dir);
+ g_mkdir_with_parents (config_dir, 0700);
+ }
+
+ g_free (config_dir);
}
+/* place to look for system level providers */
static char *
enchant_get_module_dir (void)
{
@@ -154,7 +154,7 @@ enchant_get_conf_dir (void)
char * ordering_dir = NULL, * prefix = NULL;;
/* Look for explicitly set registry values */
- ordering_dir = enchant_get_registry_value ("Config", "Data_Dir");
+ ordering_dir = enchant_get_registry_value_ex (0, "Config", "Data_Dir");
if (ordering_dir)
return ordering_dir;
@@ -174,6 +174,48 @@ enchant_get_conf_dir (void)
#endif
}
+/**
+ * enchant_get_user_config_dir
+ *
+ * Returns: the user's enchant directory, or %null. Returned value
+ * must be free'd.
+ *
+ * The enchant directory is the place where enchant finds user providers and
+ * dictionaries and settings related to enchant
+ *
+ * This API is private to the providers.
+ */
+ENCHANT_MODULE_EXPORT (char *)
+enchant_get_user_config_dir (void)
+{
+ char* user_config;
+
+ char* base_dir = NULL;
+
+ user_config = enchant_get_registry_value_ex (1, "Config", "Data_Dir");
+ if (user_config)
+ return user_config;
+
+#ifdef _WIN32
+ base_dir = g_strdup (g_get_user_config_dir());
+#endif
+
+ if (!base_dir)
+ base_dir = enchant_get_user_home_dir ();
+
+ if(base_dir)
+ {
+ user_config = g_build_filename (base_dir,
+ ENCHANT_USER_PATH_EXTENSION,
+ NULL);
+ g_free(base_dir);
+ return user_config;
+ }
+ else
+ return NULL;
+}
+
+
/*
* Returns: the value if it exists and is not an empty string ("") or %null otherwise. Must be free'd.
*/
@@ -431,27 +473,21 @@ static EnchantSession *
enchant_session_new (EnchantProvider *provider, const char * const lang)
{
EnchantSession * session;
- char * home_dir, * dic = NULL, *excl = NULL, * filename;
+ char * user_config_dir, * dic = NULL, *excl = NULL, * filename;
- home_dir = enchant_get_user_home_dir ();
- if (home_dir)
+ user_config_dir = enchant_get_user_config_dir ();
+ if (user_config_dir)
{
_enchant_ensure_private_datadir ();
filename = g_strdup_printf ("%s.dic", lang);
- dic = g_build_filename (home_dir,
- ENCHANT_USER_PATH_EXTENSION,
- filename,
- NULL);
+ dic = g_build_filename (user_config_dir, filename, NULL);
g_free (filename);
filename = g_strdup_printf ("%s.exc", lang);
- excl = g_build_filename (home_dir,
- ENCHANT_USER_PATH_EXTENSION,
- filename,
- NULL);
+ excl = g_build_filename (user_config_dir, filename, NULL);
g_free (filename);
- g_free (home_dir);
+ g_free (user_config_dir);
}
session = enchant_session_new_with_pwl (provider, dic, excl, lang, FALSE);
@@ -1275,19 +1311,17 @@ enchant_load_providers_in_dir (EnchantBroker * broker, const char *dir_name)
static void
enchant_load_providers (EnchantBroker * broker)
{
- gchar *user_dir, *home_dir, *system_dir;
+ gchar *user_dir, *system_dir;
/* load USER providers first. since the GSList is ordered,
this intentionally gives preference to USER providers */
- home_dir = enchant_get_user_home_dir ();
+ user_dir = enchant_get_user_config_dir ();
- if (home_dir)
+ if (user_dir)
{
- user_dir = g_build_filename (home_dir, ENCHANT_USER_PATH_EXTENSION, NULL);
enchant_load_providers_in_dir (broker, user_dir);
g_free (user_dir);
- g_free (home_dir);
}
system_dir = enchant_get_module_dir ();
@@ -1334,27 +1368,27 @@ enchant_load_ordering_from_file (EnchantBroker * broker, const char * file)
static void
enchant_load_provider_ordering (EnchantBroker * broker)
{
- char * ordering_file, * home_dir, * global_ordering;
+ char * ordering_file, * user_config_dir, * global_config_dir;
broker->provider_ordering = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
- global_ordering = enchant_get_conf_dir ();
- if (global_ordering)
+ global_config_dir = enchant_get_conf_dir ();
+ if (global_config_dir)
{
- ordering_file = g_build_filename (global_ordering, "enchant.ordering", NULL);
+ ordering_file = g_build_filename (global_config_dir, "enchant.ordering", NULL);
enchant_load_ordering_from_file (broker, ordering_file);
g_free (ordering_file);
- g_free (global_ordering);
+ g_free (global_config_dir);
}
- home_dir = enchant_get_user_home_dir ();
+ user_config_dir = enchant_get_user_config_dir ();
- if (home_dir)
+ if (user_config_dir)
{
- ordering_file = g_build_filename (home_dir, ENCHANT_USER_PATH_EXTENSION, "enchant.ordering", NULL);
+ ordering_file = g_build_filename (user_config_dir, "enchant.ordering", NULL);
enchant_load_ordering_from_file (broker, ordering_file);
g_free (ordering_file);
- g_free (home_dir);
+ g_free (user_config_dir);
}
}
diff --git a/src/ispell/ispell_checker.cpp b/src/ispell/ispell_checker.cpp
index fca6976..9bd6dd9 100644
--- a/src/ispell/ispell_checker.cpp
+++ b/src/ispell/ispell_checker.cpp
@@ -41,7 +41,7 @@
#include "enchant.h"
#ifndef ENCHANT_ISPELL_HOME_DIR
-#define ENCHANT_ISPELL_HOME_DIR ".enchant", "ispell"
+#define ENCHANT_ISPELL_HOME_DIR "ispell"
#endif
ENCHANT_PLUGIN_DECLARE("Ispell")
@@ -325,26 +325,26 @@ ispell_checker_get_prefix (void)
static void
s_buildHashNames (std::vector<std::string> & names, const char * dict)
{
- char * tmp, * private_dir, * home_dir, * ispell_prefix;
+ char * tmp, * private_dir, * config_dir, * ispell_prefix;
names.clear ();
/* until I work out how to link the modules against enchant in MacOSX - fjf
*/
#ifndef XP_TARGET_COCOA
- home_dir = enchant_get_user_home_dir ();
+ config_dir = enchant_get_user_config_dir ();
#else
- home_dir = g_strdup (g_getenv ("HOME"));
+ config_dir = g_strdup (g_getenv ("HOME"));
#endif
- if (home_dir) {
- private_dir = g_build_filename (home_dir, ENCHANT_ISPELL_HOME_DIR, NULL);
+ if (config_dir) {
+ private_dir = g_build_filename (config_dir, ENCHANT_ISPELL_HOME_DIR, NULL);
tmp = g_build_filename (private_dir, dict, NULL);
names.push_back (tmp);
g_free (tmp);
g_free (private_dir);
- g_free (home_dir);
+ g_free (config_dir);
}
ispell_prefix = ispell_checker_get_prefix ();
diff --git a/src/myspell/myspell_checker.cpp b/src/myspell/myspell_checker.cpp
index 379abcf..83f1420 100644
--- a/src/myspell/myspell_checker.cpp
+++ b/src/myspell/myspell_checker.cpp
@@ -184,15 +184,15 @@ MySpellChecker::suggestWord(const char* const utf8Word, size_t len, size_t *nsug
static void
s_buildHashNames (std::vector<std::string> & names, const char * dict)
{
- char * tmp, * private_dir, * home_dir, * myspell_prefix, * dict_dic;
+ char * tmp, * private_dir, * config_dir, * myspell_prefix, * dict_dic;
names.clear ();
dict_dic = g_strconcat(dict, ".dic", NULL);
- home_dir = enchant_get_user_home_dir ();
- if (home_dir) {
- private_dir = g_build_filename (home_dir, ".enchant",
+ config_dir = enchant_get_user_config_dir ();
+ if (config_dir) {
+ private_dir = g_build_filename (config_dir,
"myspell", NULL);
tmp = g_build_filename (private_dir, dict_dic, NULL);
@@ -200,7 +200,7 @@ s_buildHashNames (std::vector<std::string> & names, const char * dict)
g_free (tmp);
g_free (private_dir);
- g_free (home_dir);
+ g_free (config_dir);
}
myspell_prefix = myspell_checker_get_prefix ();
@@ -314,15 +314,15 @@ myspell_provider_list_dicts (EnchantProvider * me,
char ** dictionary_list = NULL;
std::vector<std::string> dicts;
- char * home_dir = enchant_get_user_home_dir ();
- if (home_dir) {
- char * private_dir = g_build_filename (home_dir, ".enchant",
+ char * config_dir = enchant_get_user_config_dir ();
+ if (config_dir) {
+ char * private_dir = g_build_filename (config_dir,
"myspell", NULL);
myspell_provider_enum_dicts (private_dir, dicts);
g_free (private_dir);
- g_free (home_dir);
+ g_free (config_dir);
}
char * myspell_prefix = myspell_checker_get_prefix ();
diff --git a/src/uspell/uspell_provider.cpp b/src/uspell/uspell_provider.cpp
index d185243..fd80e66 100644
--- a/src/uspell/uspell_provider.cpp
+++ b/src/uspell/uspell_provider.cpp
@@ -220,14 +220,14 @@ s_buildHashNames (std::vector<std::string> & names, const char * tag)
if (mapIndex < n_mappings) {
- char * tmp, * private_dir, * home_dir, * uspell_prefix;
+ char * tmp, * private_dir, * config_dir, * uspell_prefix;
char * dict = mapping[mapIndex].language_tag;
- home_dir = enchant_get_user_home_dir ();
+ config_dir = enchant_get_user_config_dir ();
- if (home_dir) {
- private_dir = g_build_filename (home_dir, ".enchant",
+ if (config_dir) {
+ private_dir = g_build_filename (config_dir,
"uspell", NULL);
tmp = g_build_filename (private_dir, dict, NULL);
@@ -235,7 +235,7 @@ s_buildHashNames (std::vector<std::string> & names, const char * tag)
g_free (tmp);
g_free (private_dir);
- g_free (home_dir);
+ g_free (config_dir);
}
uspell_prefix = uspell_checker_get_prefix ();
@@ -281,7 +281,7 @@ uspell_request_dict (const char * base, const char * mapping, const int flags)
static uSpell *
uspell_request_manager (const char * private_dir, size_t mapIndex)
{
- char * uspell_prefix, * home_dir;
+ char * uspell_prefix, * config_dir;
uSpell * manager = NULL;
@@ -302,13 +302,13 @@ uspell_request_manager (const char * private_dir, size_t mapIndex)
if (!manager) return NULL;
// look for a supplementary private dictionary
- home_dir = enchant_get_user_home_dir ();
- if (home_dir) {
+ config_dir = enchant_get_user_config_dir ();
+ if (config_dir) {
gchar * auxFileName, * transPart;
transPart = g_strconcat (mapping[mapIndex].language_tag, ".dic", NULL);
- auxFileName = g_build_filename (home_dir, ".enchant", transPart, NULL);
+ auxFileName = g_build_filename (config_dir, transPart, NULL);
g_free (transPart);
- g_free (home_dir);
+ g_free (config_dir);
(void) manager->assimilateFile (auxFileName);
g_free (auxFileName);
@@ -323,14 +323,14 @@ uspell_provider_request_dict (EnchantProvider * me, const char *const tag)
uSpell *manager = NULL;
int mapIndex;
- char * private_dir = NULL, * home_dir;
+ char * private_dir = NULL, * config_dir;
- home_dir = enchant_get_user_home_dir ();
+ config_dir = enchant_get_user_config_dir ();
- if (home_dir) {
- private_dir = g_build_filename (home_dir, ".enchant",
+ if (config_dir) {
+ private_dir = g_build_filename (config_dir,
"uspell", NULL);
- g_free (home_dir);
+ g_free (config_dir);
}
for (mapIndex = 0; mapIndex < n_mappings; mapIndex++) {
diff --git a/unittests/EnchantBrokerTestFixture.h b/unittests/EnchantBrokerTestFixture.h
index ebe0326..066dc03 100644
--- a/unittests/EnchantBrokerTestFixture.h
+++ b/unittests/EnchantBrokerTestFixture.h
@@ -161,7 +161,7 @@ struct EnchantBrokerTestFixture : EnchantTestFixture
CopyProvider("libenchant", "libenchant"); //not a provider
}
- SetRegistryHomeDir(GetDirectoryOfThisModule());
+ SetUserRegistryConfigDir(GetEnchantPersonalDir());
InitializeBroker();
}
@@ -234,16 +234,6 @@ struct EnchantBrokerTestFixture : EnchantTestFixture
return AddToPath(AddToPath(GetDirectoryOfThisModule(), "share"), "enchant");
}
- static std::string AddToPath(const std::string & path, const std::string & fileOrDirName)
- {
- std::string result;
- gchar* filename = g_build_filename(path.c_str(), fileOrDirName.c_str(), NULL);
- result = std::string(filename);
- g_free(filename);
-
- return result;
- }
-
EnchantProvider* GetMockProvider(){
return mock_provider;
}
@@ -274,7 +264,10 @@ struct EnchantBrokerTestFixture : EnchantTestFixture
}
static void CreateFile(const std::string& filepath)
{
- g_creat(filepath.c_str(), _S_IREAD | _S_IWRITE);
+ int fh = g_creat(filepath.c_str(), _S_IREAD | _S_IWRITE);
+ if(fh != -1) {
+ close(fh);
+ }
}
static void DeleteFile(const std::string& filepath)
{
@@ -351,7 +344,6 @@ struct EnchantBrokerTestFixture : EnchantTestFixture
userMockProvider2Configuration(me, dir_name);
}
}
-
};
struct DictionaryDescription
@@ -392,4 +384,4 @@ struct DictionaryDescription
#pragma warning(pop)
#endif
-#endif \ No newline at end of file
+#endif
diff --git a/unittests/EnchantTestFixture.h b/unittests/EnchantTestFixture.h
index e01a634..22391be 100644
--- a/unittests/EnchantTestFixture.h
+++ b/unittests/EnchantTestFixture.h
@@ -287,6 +287,29 @@ struct EnchantTestFixture
}
}
+
+ static std::string AddToPath(const std::string & path, const std::string & fileOrDirName)
+ {
+ std::string result;
+ gchar* filename = g_build_filename(path.c_str(), fileOrDirName.c_str(), NULL);
+ result = std::string(filename);
+ g_free(filename);
+
+ return result;
+ }
+
+ static std::string GetEnchantHomeDirFromBase(const std::string& basePath)
+ {
+#ifdef XP_TARGET_COCOA
+ return AddToPath(AddToPath(AddToPath(basePath,"Library"),
+ "Application Support"),
+ "Enchant");
+#elif defined(_WIN32)
+ return AddToPath(basePath,"enchant");
+#else
+ return AddToPath(basePath,".enchant");
+#endif
+ }
};
#endif \ No newline at end of file
diff --git a/unittests/broker/enchant_broker_describe_tests.cpp b/unittests/broker/enchant_broker_describe_tests.cpp
index c6958b0..e9492df 100644
--- a/unittests/broker/enchant_broker_describe_tests.cpp
+++ b/unittests/broker/enchant_broker_describe_tests.cpp
@@ -74,6 +74,7 @@ struct EnchantBrokerNoProvidersTestFixture : EnchantTestFixture
#ifdef _WIN32
SetRegistryHomeDir("someplace_that_does_not_exist");
SetUserRegistryModuleDir("someplace_that_does_not_exist");
+ SetUserRegistryConfigDir("someplace_that_does_not_exist");
#endif
_broker = enchant_broker_init ();
}
@@ -207,9 +208,11 @@ struct EnchantBrokerDescribe_ProviderHasInvalidUtf8Describe_TestFixture : Enchan
/*
* Providers are discovered by probing first in the .enchant directory
* in the user's home directory.
+ * [on windows in the enchant directory in the user's Application Data
+ * directory]
*
- * The user's home directory on windows can be overridden using the registry
- * setting HKEY_CURRENT_USER\Software\Enchant\Config\Home_Dir
+ * The user's provider directory on windows can be overridden using the registry
+ * setting HKEY_CURRENT_USER\Software\Enchant\Config\Data_Dir
*
* Then from the module directory (that libenchant is in).
*
diff --git a/unittests/broker/enchant_broker_set_ordering_tests.cpp b/unittests/broker/enchant_broker_set_ordering_tests.cpp
index d961928..6721391 100644
--- a/unittests/broker/enchant_broker_set_ordering_tests.cpp
+++ b/unittests/broker/enchant_broker_set_ordering_tests.cpp
@@ -29,13 +29,13 @@ static bool mock2ProviderRequestDictionaryCalled;
static EnchantDict * RequestDictionary1 (EnchantProvider *me, const char *tag)
{
- mock1ProviderRequestDictionaryCalled = true;
- return MockEnGbAndQaaProviderRequestDictionary(me, tag);
+ mock1ProviderRequestDictionaryCalled = true;
+ return MockEnGbAndQaaProviderRequestDictionary(me, tag);
}
static EnchantDict * RequestDictionary2 (EnchantProvider *me, const char *tag)
{
- mock2ProviderRequestDictionaryCalled = true;
- return MockEnGbAndQaaProviderRequestDictionary(me, tag);
+ mock2ProviderRequestDictionaryCalled = true;
+ return MockEnGbAndQaaProviderRequestDictionary(me, tag);
}
static char *
MockProvider1Identify (EnchantProvider *)
@@ -50,89 +50,89 @@ MockProvider2Identify (EnchantProvider *)
}
static void Request_Dictionary_ProviderConfiguration1 (EnchantProvider * me, const char *)
{
- me->request_dict = RequestDictionary1;
- me->dispose_dict = MockProviderDisposeDictionary;
- me->identify = MockProvider1Identify;
+ me->request_dict = RequestDictionary1;
+ me->dispose_dict = MockProviderDisposeDictionary;
+ me->identify = MockProvider1Identify;
}
static void Request_Dictionary_ProviderConfiguration2 (EnchantProvider * me, const char *)
{
- me->request_dict = RequestDictionary2;
- me->dispose_dict = MockProviderDisposeDictionary;
- me->identify = MockProvider2Identify;
+ me->request_dict = RequestDictionary2;
+ me->dispose_dict = MockProviderDisposeDictionary;
+ me->identify = MockProvider2Identify;
}
enum ProviderOrder {
- Mock1ThenMock2=1,
- Mock2ThenMock1=2,
- ErrorBothCalled=3,
- ErrorNeitherCalled=4
+ Mock1ThenMock2=1,
+ Mock2ThenMock1=2,
+ ErrorBothCalled=3,
+ ErrorNeitherCalled=4
};
struct EnchantBrokerSetOrdering_TestFixture : EnchantBrokerTestFixture
{
- //Setup
- EnchantBrokerSetOrdering_TestFixture():
- EnchantBrokerTestFixture(Request_Dictionary_ProviderConfiguration1,Request_Dictionary_ProviderConfiguration2)
-
- {
- mock1ProviderRequestDictionaryCalled = false;
- mock2ProviderRequestDictionaryCalled = false;
- }
-
- ProviderOrder GetProviderOrder(const std::string & languageTag)
- {
- ProviderOrder result = ErrorBothCalled;
-
- EnchantDict* dict = enchant_broker_request_dict(_broker, languageTag.c_str());
-
- if(mock2ProviderRequestDictionaryCalled && !mock1ProviderRequestDictionaryCalled)
- {
- result = Mock2ThenMock1;
- }
- else if(mock1ProviderRequestDictionaryCalled && !mock2ProviderRequestDictionaryCalled)
- {
- result = Mock1ThenMock2;
- }
- else if(!mock2ProviderRequestDictionaryCalled && !mock1ProviderRequestDictionaryCalled)
- {
- result = ErrorNeitherCalled;
- }
-
- FreeDictionary(dict);
-
- mock1ProviderRequestDictionaryCalled = false;
- mock2ProviderRequestDictionaryCalled = false;
-
- return result;
- }
+ //Setup
+ EnchantBrokerSetOrdering_TestFixture():
+ EnchantBrokerTestFixture(Request_Dictionary_ProviderConfiguration1,Request_Dictionary_ProviderConfiguration2)
+
+ {
+ mock1ProviderRequestDictionaryCalled = false;
+ mock2ProviderRequestDictionaryCalled = false;
+ }
+
+ ProviderOrder GetProviderOrder(const std::string & languageTag)
+ {
+ ProviderOrder result = ErrorBothCalled;
+
+ EnchantDict* dict = enchant_broker_request_dict(_broker, languageTag.c_str());
+
+ if(mock2ProviderRequestDictionaryCalled && !mock1ProviderRequestDictionaryCalled)
+ {
+ result = Mock2ThenMock1;
+ }
+ else if(mock1ProviderRequestDictionaryCalled && !mock2ProviderRequestDictionaryCalled)
+ {
+ result = Mock1ThenMock2;
+ }
+ else if(!mock2ProviderRequestDictionaryCalled && !mock1ProviderRequestDictionaryCalled)
+ {
+ result = ErrorNeitherCalled;
+ }
+
+ FreeDictionary(dict);
+
+ mock1ProviderRequestDictionaryCalled = false;
+ mock2ProviderRequestDictionaryCalled = false;
+
+ return result;
+ }
};
struct EnchantBrokerFileSetOrdering_TestFixture: EnchantBrokerSetOrdering_TestFixture
{
- std::string _tempPath;
-
- EnchantBrokerFileSetOrdering_TestFixture()
- {
- if(_broker){ // this is now freed so that individual tests can set up the file state they
- // need before calling _broker = enchant_broker_init ();
- enchant_broker_free (_broker);
- _broker = NULL;
- }
- _tempPath = GetTemporaryFilename("");
- }
-
- ~EnchantBrokerFileSetOrdering_TestFixture()
- {
- DeleteDirAndFiles(_tempPath);
- }
-
- static void WriteStringToOrderingFile(const std::string& path, const std::string& contents)
- {
- CreateDirectory(path);
- std::ofstream file(AddToPath(path, "enchant.ordering").c_str());
- file << contents;
- }
+ std::string _tempPath;
+
+ EnchantBrokerFileSetOrdering_TestFixture()
+ {
+ if(_broker){ // this is now freed so that individual tests can set up the file state they
+ // need before calling _broker = enchant_broker_init ();
+ enchant_broker_free (_broker);
+ _broker = NULL;
+ }
+ _tempPath = GetTemporaryFilename("");
+ }
+
+ ~EnchantBrokerFileSetOrdering_TestFixture()
+ {
+ DeleteDirAndFiles(_tempPath);
+ }
+
+ static void WriteStringToOrderingFile(const std::string& path, const std::string& contents)
+ {
+ CreateDirectory(path);
+ std::ofstream file(AddToPath(path, "enchant.ordering").c_str());
+ file << contents;
+ }
};
@@ -154,41 +154,41 @@ struct EnchantBrokerFileSetOrdering_TestFixture: EnchantBrokerSetOrdering_TestFi
/////////////////////////////////////////////////////////////////////////////
// Test Normal Operation
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_AsteriskForLanguage_SetsDefaultOrdering)
+ EnchantBrokerSetOrdering_AsteriskForLanguage_SetsDefaultOrdering)
{
- enchant_broker_set_ordering(_broker, "*", "mock2,mock1");
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
+ enchant_broker_set_ordering(_broker, "*", "mock2,mock1");
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
- enchant_broker_set_ordering(_broker, "*", "mock1,mock2");
- CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("qaa"));
+ enchant_broker_set_ordering(_broker, "*", "mock1,mock2");
+ CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("qaa"));
}
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_NoSpaces)
+ EnchantBrokerSetOrdering_NoSpaces)
{
- enchant_broker_set_ordering(_broker, "qaa", "mock2,mock1");
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
+ enchant_broker_set_ordering(_broker, "qaa", "mock2,mock1");
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
}
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_WhitespaceAroundProvider)
+ EnchantBrokerSetOrdering_WhitespaceAroundProvider)
{
- enchant_broker_set_ordering(_broker, "qaa", "\n\f\t\r mock2\n \f\t\r,mock1");
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
+ enchant_broker_set_ordering(_broker, "qaa", "\n\f\t\r mock2\n \f\t\r,mock1");
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
}
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_WhitespaceAroundProviderAfterComma)
+ EnchantBrokerSetOrdering_WhitespaceAroundProviderAfterComma)
{
- enchant_broker_set_ordering(_broker, "qaa", "aspell,\n\f\t \rmock2\n\f \r\t,mock1");
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
+ enchant_broker_set_ordering(_broker, "qaa", "aspell,\n\f\t \rmock2\n\f \r\t,mock1");
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
}
/* Vertical tab is not considered to be whitespace in glib!
- See bug# 59388 http://bugzilla.gnome.org/show_bug.cgi?id=59388
+ See bug# 59388 http://bugzilla.gnome.org/show_bug.cgi?id=59388
*/
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_VerticalTabSurroundingProvider_NotRemoved)
+ EnchantBrokerSetOrdering_VerticalTabSurroundingProvider_NotRemoved)
{
enchant_broker_set_ordering(_broker, "qaa", "\vmock2,mock1");
CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("qaa"));
@@ -205,35 +205,35 @@ TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
}
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_SpecificLanguage_SetsOrderingForSpecific)
+ EnchantBrokerSetOrdering_SpecificLanguage_SetsOrderingForSpecific)
{
- enchant_broker_set_ordering(_broker, "qaa", "mock2,mock1");
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
+ enchant_broker_set_ordering(_broker, "qaa", "mock2,mock1");
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
- enchant_broker_set_ordering(_broker, "qaa", "mock1,mock2");
- CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("qaa"));
+ enchant_broker_set_ordering(_broker, "qaa", "mock1,mock2");
+ CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("qaa"));
}
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_UnknownProvider_Ignored)
+ EnchantBrokerSetOrdering_UnknownProvider_Ignored)
{
- enchant_broker_set_ordering(_broker, "qaa", "unknown,mock2,mock1");
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
+ enchant_broker_set_ordering(_broker, "qaa", "unknown,mock2,mock1");
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
}
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_WhitespaceSurroundingLanguageTag_Removed)
+ EnchantBrokerSetOrdering_WhitespaceSurroundingLanguageTag_Removed)
{
- enchant_broker_set_ordering(_broker, "\n\r qaa \t\f", "mock2,mock1");
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
+ enchant_broker_set_ordering(_broker, "\n\r qaa \t\f", "mock2,mock1");
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
}
/* Vertical tab is not considered to be whitespace in glib!
- See bug# 59388 http://bugzilla.gnome.org/show_bug.cgi?id=59388
+ See bug# 59388 http://bugzilla.gnome.org/show_bug.cgi?id=59388
*/
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_VerticalTabPreceedingLanguageTag_NotRemoved)
+ EnchantBrokerSetOrdering_VerticalTabPreceedingLanguageTag_NotRemoved)
{
enchant_broker_set_ordering(_broker, "*", "mock1,mock2");
enchant_broker_set_ordering(_broker, "\vqaa", "mock2,mock1");
@@ -241,10 +241,10 @@ TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
}
/* Vertical tab is not considered to be whitespace in glib!
- See bug# 59388 http://bugzilla.gnome.org/show_bug.cgi?id=59388
+ See bug# 59388 http://bugzilla.gnome.org/show_bug.cgi?id=59388
*/
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_VerticalTabFollowingLanguageTag_NotRemoved)
+ EnchantBrokerSetOrdering_VerticalTabFollowingLanguageTag_NotRemoved)
{
enchant_broker_set_ordering(_broker, "*", "mock1,mock2");
enchant_broker_set_ordering(_broker, "qaa\v", "mock2,mock1");
@@ -252,42 +252,42 @@ TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
}
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_AtSignInLanguageTag_RemovesToTail)
+ EnchantBrokerSetOrdering_AtSignInLanguageTag_RemovesToTail)
{
- enchant_broker_set_ordering(_broker, "en_GB@euro", "mock2,mock1");
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
+ enchant_broker_set_ordering(_broker, "en_GB@euro", "mock2,mock1");
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerDictExists_PeriodInLanguageTag_RemovesToTail)
+ EnchantBrokerDictExists_PeriodInLanguageTag_RemovesToTail)
{
- enchant_broker_set_ordering(_broker, "en_GB.UTF-8", "unknown,mock2,mock1");
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
+ enchant_broker_set_ordering(_broker, "en_GB.UTF-8", "unknown,mock2,mock1");
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_HyphensInLanguageTag_SubstitutedWithUnderscore)
+ EnchantBrokerSetOrdering_HyphensInLanguageTag_SubstitutedWithUnderscore)
{
- enchant_broker_set_ordering(_broker, "en-GB", "mock2,mock1");
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
+ enchant_broker_set_ordering(_broker, "en-GB", "mock2,mock1");
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_DifferentCaseInLanguageTag_SubstitutedWithCorrectCase)
+ EnchantBrokerSetOrdering_DifferentCaseInLanguageTag_SubstitutedWithCorrectCase)
{
- enchant_broker_set_ordering(_broker, "EN-gb", "mock2,mock1");
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
+ enchant_broker_set_ordering(_broker, "EN-gb", "mock2,mock1");
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_DifferentCaseInLanguageTagNoRegion_SubstitutedWithCorrectCase)
+ EnchantBrokerSetOrdering_DifferentCaseInLanguageTagNoRegion_SubstitutedWithCorrectCase)
{
- enchant_broker_set_ordering(_broker, "QAA", "mock2,mock1");
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
+ enchant_broker_set_ordering(_broker, "QAA", "mock2,mock1");
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
}
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_HasPreviousError_ErrorCleared)
+ EnchantBrokerSetOrdering_HasPreviousError_ErrorCleared)
{
SetErrorOnMockProvider("something bad happened");
@@ -299,47 +299,47 @@ TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
/////////////////////////////////////////////////////////////////////////////
// Test Error Conditions
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_NullBroker_DoNothing)
+ EnchantBrokerSetOrdering_NullBroker_DoNothing)
{
- enchant_broker_set_ordering(_broker, "qaa", "mock2,mock1");
- enchant_broker_set_ordering(NULL, "qaa", "mock1,mock2");
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
+ enchant_broker_set_ordering(_broker, "qaa", "mock2,mock1");
+ enchant_broker_set_ordering(NULL, "qaa", "mock1,mock2");
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
}
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_NullLanguageTag_DoNothing)
+ EnchantBrokerSetOrdering_NullLanguageTag_DoNothing)
{
- enchant_broker_set_ordering(_broker, "*", "mock2,mock1");
- enchant_broker_set_ordering(_broker, NULL, "mock1,mock2");
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
+ enchant_broker_set_ordering(_broker, "*", "mock2,mock1");
+ enchant_broker_set_ordering(_broker, NULL, "mock1,mock2");
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
}
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_EmptyAfterNormalization_DoNothing)
+ EnchantBrokerSetOrdering_EmptyAfterNormalization_DoNothing)
{
- testResults_;
- enchant_broker_set_ordering(_broker, " @ ", "mock1,mock2");
+ testResults_;
+ enchant_broker_set_ordering(_broker, " @ ", "mock1,mock2");
}
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_EmptyLanguageTag_DoNothing)
+ EnchantBrokerSetOrdering_EmptyLanguageTag_DoNothing)
{
- testResults_;
- enchant_broker_set_ordering(_broker, "", "aspell,myspell,ispell");
+ testResults_;
+ enchant_broker_set_ordering(_broker, "", "aspell,myspell,ispell");
}
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_NullOrdering_DoNothing)
+ EnchantBrokerSetOrdering_NullOrdering_DoNothing)
{
- testResults_;
- enchant_broker_set_ordering(_broker, "en_GB", NULL);
+ testResults_;
+ enchant_broker_set_ordering(_broker, "en_GB", NULL);
}
TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
- EnchantBrokerSetOrdering_EmptyOrdering_DoNothing)
+ EnchantBrokerSetOrdering_EmptyOrdering_DoNothing)
{
- testResults_;
- enchant_broker_set_ordering(_broker, "en_GB", "");
+ testResults_;
+ enchant_broker_set_ordering(_broker, "en_GB", "");
}
@@ -370,163 +370,143 @@ TEST_FIXTURE(EnchantBrokerSetOrdering_TestFixture,
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrderingMock1ThenMock2_DefaultConfigDirectory)
{
- WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:mock1,mock2");
- InitializeBroker();
+ WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:mock1,mock2");
+ InitializeBroker();
- CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
+ CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrderingMock2ThenMock1_DefaultConfigDirectory)
{
- WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:mock2,mock1");
- InitializeBroker();
+ WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:mock2,mock1");
+ InitializeBroker();
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrderingMock1ThenMock2_UserOverriddenConfigDirectory)
{
- WriteStringToOrderingFile(_tempPath, "en_GB:mock1,mock2");
- SetUserRegistryConfigDir(_tempPath);
- InitializeBroker();
+ WriteStringToOrderingFile(_tempPath, "en_GB:mock1,mock2");
+ SetUserRegistryConfigDir(_tempPath);
+ InitializeBroker();
- CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
+ CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrderingMock2ThenMock1_UserOverriddenConfigDirectory)
{
- WriteStringToOrderingFile(_tempPath, "en_GB:mock2,mock1");
- SetUserRegistryConfigDir(_tempPath);
- InitializeBroker();
+ WriteStringToOrderingFile(_tempPath, "en_GB:mock2,mock1");
+ SetUserRegistryConfigDir(_tempPath);
+ InitializeBroker();
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrderingMock1ThenMock2_MachineOverriddenConfigDirectory)
{
- WriteStringToOrderingFile(_tempPath, "en_GB:mock1,mock2");
- SetMachineRegistryConfigDir(_tempPath);
- InitializeBroker();
-
- CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
+ WriteStringToOrderingFile(_tempPath, "en_GB:mock1,mock2");
+ SetMachineRegistryConfigDir(_tempPath);
+ InitializeBroker();
+
+ CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrderingMock2ThenMock1_MachineOverriddenConfigDirectory)
{
- WriteStringToOrderingFile(_tempPath, "en_GB:mock2,mock1");
- SetMachineRegistryConfigDir(_tempPath);
- InitializeBroker();
-
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
-}
-
-TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
- EnchantBrokerFileOrderingMock1ThenMock2_HomeDirectory)
-{
- WriteStringToOrderingFile(AddToPath(_tempPath,".enchant"), "en_GB:mock1,mock2");
- SetRegistryHomeDir(_tempPath);
- InitializeBroker();
-
- CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
-}
-
-TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
- EnchantBrokerFileOrderingMock2ThenMock1_HomeDirectory)
-{
- WriteStringToOrderingFile(AddToPath(_tempPath,".enchant"), "en_GB:mock2,mock1");
- SetRegistryHomeDir(_tempPath);
- InitializeBroker();
-
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
+ WriteStringToOrderingFile(_tempPath, "en_GB:mock2,mock1");
+ SetMachineRegistryConfigDir(_tempPath);
+ InitializeBroker();
+
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
}
// if config registry "" global from share/enchant
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrdering_OverriddenConfigDirectoryIsBlank_UsesSettingsFromDefaultConfigDirectory_Mock1Then2)
{
- WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:mock1,mock2");
- SetUserRegistryConfigDir("");
- InitializeBroker();
-
- CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
+ WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:mock1,mock2");
+ SetMachineRegistryConfigDir("");
+ InitializeBroker();
+
+ CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrdering_OverriddenConfigDirectoryIsBlank_UsesSettingsFromDefaultConfigDirectory_Mock2Then1)
{
- WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:mock2,mock1");
- SetUserRegistryConfigDir("");
- InitializeBroker();
-
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
+ WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:mock2,mock1");
+ SetMachineRegistryConfigDir("");
+ InitializeBroker();
+
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrdering_ExtraSpacesAndTabs_Mock1Then2)
{
- WriteStringToOrderingFile(GetEnchantConfigDir(),"\t en_GB\f \t:\r\t mock1\t , \tmock2\t ");
- InitializeBroker();
-
- CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
+ WriteStringToOrderingFile(GetEnchantConfigDir(),"\t en_GB\f \t:\r\t mock1\t , \tmock2\t ");
+ InitializeBroker();
+
+ CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrdering_ExtraSpaces_Mock2Then1)
{
- WriteStringToOrderingFile(GetEnchantConfigDir()," \ten_GB\t \f:\r \tmock2 \t,\t mock1 \t");
- InitializeBroker();
-
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
+ WriteStringToOrderingFile(GetEnchantConfigDir()," \ten_GB\t \f:\r \tmock2 \t,\t mock1 \t");
+ InitializeBroker();
+
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrdering_ExtraNewLines_Mock1Then2)
{
- WriteStringToOrderingFile(GetEnchantConfigDir(),"\nen_GB:mock1,mock2\n\nqaa:mock2,mock1\n*:mock2\n");
- InitializeBroker();
-
- CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
+ WriteStringToOrderingFile(GetEnchantConfigDir(),"\nen_GB:mock1,mock2\n\nqaa:mock2,mock1\n*:mock2\n");
+ InitializeBroker();
+
+ CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrdering_ExtraNewLines_Mock2Then1)
{
- WriteStringToOrderingFile(GetEnchantConfigDir(),"\nen_GB:mock2,mock1\n\nqaa:mock2,mock1\n*:mock2\n");
- InitializeBroker();
-
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
+ WriteStringToOrderingFile(GetEnchantConfigDir(),"\nen_GB:mock2,mock1\n\nqaa:mock2,mock1\n*:mock2\n");
+ InitializeBroker();
+
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrdering_HomeAndGlobal_HomeMergedWithGlobal_HomeTakesPrecedence_Mock1Then2)
{
- WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:mock2,mock1\nqaa:mock1,mock2");
- WriteStringToOrderingFile(AddToPath(_tempPath,".enchant"), "en_GB:mock1,mock2");
- SetRegistryHomeDir(_tempPath);
+ WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:mock2,mock1\nqaa:mock1,mock2");
+ WriteStringToOrderingFile(_tempPath, "en_GB:mock1,mock2");
+ SetUserRegistryConfigDir(_tempPath);
- InitializeBroker();
-
- CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
- CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("qaa"));
+ InitializeBroker();
+
+ CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
+ CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("qaa"));
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrdering_HomeAndGlobal_HomeMergedWithGlobal_HomeTakesPrecedence_Mock2Then1)
{
- WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:mock1,mock2\nqaa:mock2,mock1");
- WriteStringToOrderingFile(AddToPath(_tempPath,".enchant"), "en_GB:mock2,mock1");
- SetRegistryHomeDir(_tempPath);
+ WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:mock1,mock2\nqaa:mock2,mock1");
+ WriteStringToOrderingFile(_tempPath, "en_GB:mock2,mock1");
+ SetUserRegistryConfigDir(_tempPath);
- InitializeBroker();
-
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
+ InitializeBroker();
+
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("qaa"));
}
/////////////////////////////////////////////////////////////////////////////
@@ -534,64 +514,64 @@ TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrdering_EmptyFile)
{
- WriteStringToOrderingFile(GetEnchantConfigDir(),"");
+ WriteStringToOrderingFile(GetEnchantConfigDir(),"");
- InitializeBroker();
+ InitializeBroker();
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrdering_NoLanguageTag)
{
- WriteStringToOrderingFile(GetEnchantConfigDir(),":mock1,mock2");
+ WriteStringToOrderingFile(GetEnchantConfigDir(),":mock1,mock2");
- InitializeBroker();
+ InitializeBroker();
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrdering_NoColon)
{
- WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB mock1,mock2");
+ WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB mock1,mock2");
- InitializeBroker();
+ InitializeBroker();
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrdering_NoProviders_DoesNotOverridePreviousOrdering_Mock1Then2)
{
- WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:");
- WriteStringToOrderingFile(AddToPath(_tempPath,".enchant"), "en_GB:mock1,mock2");
- SetRegistryHomeDir(_tempPath);
+ WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:");
+ WriteStringToOrderingFile(_tempPath, "en_GB:mock1,mock2");
+ SetUserRegistryConfigDir(_tempPath);
- InitializeBroker();
+ InitializeBroker();
- CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
+ CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrdering_NoProviders_DoesNotOverridePreviousOrdering_Mock2Then1)
{
- WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:");
- WriteStringToOrderingFile(AddToPath(_tempPath,".enchant"), "en_GB:mock2,mock1");
- SetRegistryHomeDir(_tempPath);
+ WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:");
+ WriteStringToOrderingFile(_tempPath, "en_GB:mock2,mock1");
+ SetUserRegistryConfigDir(_tempPath);
- InitializeBroker();
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
+ InitializeBroker();
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrdering_ListedTwice_LastTakesPrecedence_Mock1ThenMock2)
{
- WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:mock2,mock1\nen_GB:mock1,mock2");
- InitializeBroker();
+ WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:mock2,mock1\nen_GB:mock1,mock2");
+ InitializeBroker();
- CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
+ CHECK_EQUAL(Mock1ThenMock2, GetProviderOrder("en_GB"));
}
TEST_FIXTURE(EnchantBrokerFileSetOrdering_TestFixture,
EnchantBrokerFileOrdering_ListedTwice_LastTakesPrecedence_Mock2ThenMock1)
{
- WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:mock1,mock2\nen_GB:mock2,mock1");
- InitializeBroker();
+ WriteStringToOrderingFile(GetEnchantConfigDir(),"en_GB:mock1,mock2\nen_GB:mock2,mock1");
+ InitializeBroker();
- CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
+ CHECK_EQUAL(Mock2ThenMock1, GetProviderOrder("en_GB"));
}
diff --git a/unittests/provider/enchant_provider_get_config_home_dir_tests.cpp b/unittests/provider/enchant_provider_get_config_home_dir_tests.cpp
new file mode 100644
index 0000000..391eb56
--- /dev/null
+++ b/unittests/provider/enchant_provider_get_config_home_dir_tests.cpp
@@ -0,0 +1,85 @@
+/* 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 "../EnchantTestFixture.h"
+#include <UnitTest++.h>
+#include <enchant-provider.h>
+
+/**
+ * enchant_get_user_config_dir
+ *
+ * Returns: the user's enchant directory, or %null. Returned value
+ * must be free'd.
+ *
+ * The enchant directory is the place where enchant finds user providers and
+ * dictionaries and settings related to enchant
+ *
+ * This API is private to the providers.
+ */
+
+/*
+ * The user's config directory on windows can be overridden using the registry
+ * setting HKEY_CURRENT_USER\Software\Enchant\Config\Data_Dir
+ */
+#ifdef _WIN32
+TEST_FIXTURE(EnchantTestFixture,
+ GetUserConfigDir_FromRegistry)
+{
+ std::string configDir("here I am");
+ SetUserRegistryConfigDir(configDir);
+
+ char * enchantUserConfigDir = enchant_get_user_config_dir();
+
+ CHECK(enchantUserConfigDir);
+ CHECK_EQUAL(configDir, enchantUserConfigDir);
+
+ g_free(enchantUserConfigDir);
+}
+
+TEST_FIXTURE(EnchantTestFixture,
+ GetUserConfigDir_BlankFromRegistry_RegistryEntryIgnored)
+{
+ std::string configDir("");
+ SetUserRegistryConfigDir(configDir);
+
+ char * enchantUserConfigDir = enchant_get_user_config_dir();
+
+ CHECK(enchantUserConfigDir);
+
+ CHECK_EQUAL(GetEnchantHomeDirFromBase(g_get_user_config_dir()), enchantUserConfigDir);
+
+ g_free(enchantUserConfigDir);
+}
+#endif
+
+TEST_FIXTURE(EnchantTestFixture,
+ GetUserConfigDir)
+{
+ char * enchantUserConfigDir = enchant_get_user_config_dir();
+
+ CHECK(enchantUserConfigDir);
+#ifdef _WIN32
+ CHECK_EQUAL(GetEnchantHomeDirFromBase(g_get_user_config_dir()), enchantUserConfigDir);
+#else
+ CHECK_EQUAL(GetEnchantHomeDirFromBase(g_get_home_dir()), enchantUserConfigDir);
+#endif
+ g_free(enchantUserConfigDir);
+} \ No newline at end of file
diff --git a/unittests/provider/enchant_provider_get_user_home_dir_tests.cpp b/unittests/provider/enchant_provider_get_user_home_dir_tests.cpp
index 9cc0b56..6cab018 100644
--- a/unittests/provider/enchant_provider_get_user_home_dir_tests.cpp
+++ b/unittests/provider/enchant_provider_get_user_home_dir_tests.cpp
@@ -51,7 +51,6 @@ TEST_FIXTURE(EnchantTestFixture,
g_free(enchantUserHomeDir);
}
-#ifdef _WIN32
TEST_FIXTURE(EnchantTestFixture,
GetUserHomeDir_BlankFromRegistry_RegistryEntryIgnored)
{
@@ -67,8 +66,6 @@ TEST_FIXTURE(EnchantTestFixture,
}
#endif
-#endif
-
TEST_FIXTURE(EnchantTestFixture,
GetUserHomeDir)
{