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
22 #include <UnitTest++.h>
\r
23 #include <enchant.h>
\r
24 #include "../EnchantBrokerTestFixture.h"
\r
26 static bool requestDictionaryCalled;
\r
27 static EnchantDict * RequestDictionary (EnchantProvider *me, const char *tag)
\r
29 requestDictionaryCalled = true;
\r
30 return MockEnGbAndQaaProviderRequestDictionary(me, tag);
\r
33 static void Request_Dictionary_ProviderConfiguration (EnchantProvider * me, const char *)
\r
35 me->request_dict = RequestDictionary;
\r
36 me->dispose_dict = MockProviderDisposeDictionary;
\r
39 struct EnchantBrokerRequestDictionary_TestFixture : EnchantBrokerTestFixture
\r
42 EnchantBrokerRequestDictionary_TestFixture():
\r
43 EnchantBrokerTestFixture(Request_Dictionary_ProviderConfiguration)
\r
46 requestDictionaryCalled = false;
\r
50 ~EnchantBrokerRequestDictionary_TestFixture()
\r
52 FreeDictionary(_dict);
\r
59 * enchant_broker_request_dict
\r
60 * @broker: A non-null #EnchantBroker
\r
61 * @tag: The non-null language tag you wish to request a dictionary for ("en_US", "de_DE", ...)
\r
63 * Returns: An #EnchantDict, or %null if no suitable dictionary could be found.
\r
68 /////////////////////////////////////////////////////////////////////////////
\r
69 // Test Normal Operation
\r
71 TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
\r
72 EnchantBrokerRequestDictionary_ProviderHas_CallsProvider)
\r
74 _dict = enchant_broker_request_dict(_broker, "en_GB");
\r
76 CHECK(requestDictionaryCalled);
\r
79 TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
\r
80 EnchantBrokerRequestDictionary_CalledTwice_CallsProviderOnceReturnsSame)
\r
82 _dict = enchant_broker_request_dict(_broker, "en_GB");
\r
83 requestDictionaryCalled = false;
\r
84 EnchantDict* dict = enchant_broker_request_dict(_broker, "en_GB");
\r
85 CHECK(!requestDictionaryCalled);
\r
87 CHECK_EQUAL(_dict, dict);
\r
90 TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
\r
91 EnchantBrokerRequestDictionary_ProviderDoesNotHave_CallsProvider)
\r
93 _dict = enchant_broker_request_dict(_broker, "en");
\r
94 CHECK_EQUAL((void*)NULL, (void*)_dict);
\r
95 CHECK(requestDictionaryCalled);
\r
98 TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
\r
99 EnchantBrokerRequestDictionary_ProviderHasBase_CallsProvider)
\r
101 _dict = enchant_broker_request_dict(_broker, "qaa_CA");
\r
103 CHECK(requestDictionaryCalled);
\r
107 TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
\r
108 EnchantBrokerRequestDictionary_WhitespaceSurroundingLanguageTag_Removed)
\r
110 _dict = enchant_broker_request_dict(_broker, "\n\r en_GB \t\f");
\r
114 /* Vertical tab is not considered to be whitespace in glib!
\r
115 See bug# 59388 http://bugzilla.gnome.org/show_bug.cgi?id=59388
\r
117 TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
\r
118 EnchantBrokerRequestDictionary_VerticalTabBeforeLanguageTag_NotRemoved)
\r
120 _dict = enchant_broker_request_dict(_broker, "\ven_GB");
\r
121 CHECK_EQUAL((void*)NULL, (void*)_dict);
\r
124 TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
\r
125 EnchantBrokerRequestDictionary_VerticalTabAfterLanguageTag_NotRemoved)
\r
127 _dict = enchant_broker_request_dict(_broker, "en_GB\v");
\r
128 CHECK_EQUAL((void*)NULL, (void*)_dict);
\r
132 TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
\r
133 EnchantBrokerRequestDictionary_AtSignInLanguageTag_RemovesToTail)
\r
135 _dict = enchant_broker_request_dict(_broker, "en_GB@euro");
\r
139 TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
\r
140 EnchantBrokerRequestDictionary_PeriodInLanguageTag_RemovesToTail)
\r
142 _dict = enchant_broker_request_dict(_broker, "en_GB.UTF-8");
\r
146 TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
\r
147 EnchantBrokerRequestDictionary_HyphensInLanguageTag_SubstitutedWithUnderscore)
\r
149 _dict = enchant_broker_request_dict(_broker, "en-GB");
\r
153 TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
\r
154 EnchantBrokerRequestDictionary_DifferentCase_Finds)
\r
156 _dict = enchant_broker_request_dict(_broker, "En_gb");
\r
160 TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
\r
161 EnchantBrokerRequestDictionary_DifferentCase_NoRegion_Finds)
\r
163 _dict = enchant_broker_request_dict(_broker, "QAA");
\r
167 TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
\r
168 EnchantBrokerRequestDictionary_HasPreviousError_ErrorCleared)
\r
170 SetErrorOnMockProvider("something bad happened");
\r
172 _dict = enchant_broker_request_dict(_broker, "en-GB");
\r
174 CHECK_EQUAL((void*)NULL, (void*)enchant_broker_get_error(_broker));
\r
177 // ordering of providers for request is tested by enchant_broker_set_ordering tests
\r
179 /////////////////////////////////////////////////////////////////////////////
\r
180 // Test Error Conditions
\r
181 TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
\r
182 EnchantBrokerRequestDictionary_NullBroker_NULL)
\r
184 _dict = enchant_broker_request_dict(NULL, "en_GB");
\r
186 CHECK_EQUAL((void*)NULL, (void*)_dict);
\r
187 CHECK(!requestDictionaryCalled);
\r
190 TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
\r
191 EnchantBrokerRequestDictionary_NullLanguageTag_NULL)
\r
193 _dict = enchant_broker_request_dict(_broker, NULL);
\r
195 CHECK_EQUAL((void*)NULL, (void*)_dict);
\r
196 CHECK(!requestDictionaryCalled);
\r
199 TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
\r
200 EnchantBrokerRequestDictionary_EmptyLanguageTag_NULL)
\r
202 _dict = enchant_broker_request_dict(_broker, "");
\r
204 CHECK_EQUAL((void*)NULL, _dict);
\r
205 CHECK(!requestDictionaryCalled);
\r
209 TEST_FIXTURE(EnchantBrokerRequestDictionary_TestFixture,
\r
210 EnchantBrokerRequestDictionary_InvalidTag_NULL_ErrorSet)
\r
212 _dict = enchant_broker_request_dict(_broker, "en~US");
\r
213 CHECK_EQUAL((void*)NULL, _dict);
\r
214 CHECK(NULL != enchant_broker_get_error(_broker));
\r
217 TEST_FIXTURE(EnchantBrokerTestFixture,
\r
218 EnchantBrokerRequestDictionary_ProviderLacksListDictionaries_CallbackNeverCalled)
\r
220 requestDictionaryCalled = false;
\r
221 EnchantDict* dict = enchant_broker_request_dict(_broker, "en_GB");
\r
223 CHECK_EQUAL((void*)NULL, dict);
\r
224 CHECK(!requestDictionaryCalled);
\r