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 "../EnchantDictionaryTestFixture.h"
\r
26 static bool addToPersonalCalled;
\r
27 static std::string wordToAdd;
\r
30 MockDictionaryAddToPersonal (EnchantDict * dict, const char *const word, size_t len)
\r
33 addToPersonalCalled = true;
\r
34 wordToAdd = std::string(word, len);
\r
37 static EnchantDict* MockProviderRequestAddToPersonalMockDictionary(EnchantProvider * me, const char *tag)
\r
40 EnchantDict* dict = MockProviderRequestEmptyMockDictionary(me, tag);
\r
41 dict->add_to_personal = MockDictionaryAddToPersonal;
\r
45 static void DictionaryAddToPersonal_ProviderConfiguration (EnchantProvider * me, const char *)
\r
47 me->request_dict = MockProviderRequestAddToPersonalMockDictionary;
\r
48 me->dispose_dict = MockProviderDisposeDictionary;
\r
51 struct EnchantDictionaryAdd_TestFixture : EnchantDictionaryTestFixture
\r
54 EnchantDictionaryAdd_TestFixture():
\r
55 EnchantDictionaryTestFixture(DictionaryAddToPersonal_ProviderConfiguration)
\r
57 addToPersonalCalled = false;
\r
61 struct EnchantDictionaryAddToPersonalNotImplemented_TestFixture : EnchantDictionaryTestFixture
\r
64 EnchantDictionaryAddToPersonalNotImplemented_TestFixture():
\r
65 EnchantDictionaryTestFixture(EmptyDictionary_ProviderConfiguration)
\r
67 addToPersonalCalled = false;
\r
73 * @dict: A non-null #EnchantDict
\r
74 * @word: The non-null word you wish to add to your personal dictionary, in UTF-8 encoding
\r
75 * @len: The byte length of @word, or -1 for strlen (@word)
\r
77 * Remarks: if the word exists in the exclude dictionary, it will be removed from the
\r
78 * exclude dictionary
\r
81 /////////////////////////////////////////////////////////////////////////////
\r
82 // Test Normal Operation
\r
83 TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
\r
84 EnchantDictionaryAdd_WordExistsInDictionary)
\r
86 enchant_dict_add(_dict, "hello", -1);
\r
87 CHECK(IsWordInDictionary("hello"));
\r
90 TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
\r
91 EnchantDictionaryAdd_WordExistsInSession)
\r
93 enchant_dict_add(_dict, "hello", -1);
\r
94 CHECK(IsWordInSession("hello"));
\r
97 TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
\r
98 EnchantDictionaryAdd_WordAddedToEnchantPwlFile)
\r
100 CHECK(!PersonalWordListFileHasContents());
\r
101 enchant_dict_add(_dict, "hello", -1);
\r
102 CHECK(PersonalWordListFileHasContents());
\r
105 TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
\r
106 EnchantDictionaryAdd_PassedOnToProvider_LenComputed)
\r
108 enchant_dict_add(_dict, "hello", -1);
\r
109 CHECK(addToPersonalCalled);
\r
110 CHECK_EQUAL(std::string("hello"), wordToAdd);
\r
113 TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
\r
114 EnchantDictionaryAdd_PassedOnToProvider_LenSpecified)
\r
116 enchant_dict_add(_dict, "hellodisregard me", 5);
\r
117 CHECK(addToPersonalCalled);
\r
118 CHECK_EQUAL(std::string("hello"), wordToAdd);
\r
122 TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
\r
123 EnchantDictionaryAdd_WordExistsInSession_StillCallsProvider)
\r
125 enchant_dict_add_to_session(_dict, "session", -1);
\r
126 CHECK(!addToPersonalCalled);
\r
128 enchant_dict_add(_dict, "session", -1);
\r
129 CHECK(addToPersonalCalled);
\r
130 CHECK_EQUAL(std::string("session"), wordToAdd);
\r
133 TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
\r
134 EnchantDictionaryAdd_WordExistsInPersonal_StillCallsProvider)
\r
136 enchant_dict_add(_dict, "personal", -1);
\r
137 addToPersonalCalled=false;
\r
138 wordToAdd = std::string();
\r
140 enchant_dict_add(_dict, "personal", -1);
\r
141 CHECK(addToPersonalCalled);
\r
142 CHECK_EQUAL(std::string("personal"), wordToAdd);
\r
145 TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
\r
146 EnchantDictionaryAdd_WordExistsInExclude_RemovedFromExcludeAddedToPersonal)
\r
148 enchant_dict_remove(_dict, "personal", -1);
\r
149 CHECK(ExcludeFileHasContents());
\r
150 enchant_dict_add(_dict, "personal", -1);
\r
151 CHECK(!ExcludeFileHasContents());
\r
152 CHECK(PersonalWordListFileHasContents());
\r
155 TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
\r
156 EnchantDictionaryAdd_InBrokerPwl)
\r
158 enchant_dict_add(_pwl, "personal", -1);
\r
159 CHECK(!addToPersonalCalled);
\r
160 CHECK(!PersonalWordListFileHasContents());
\r
163 TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
\r
164 EnchantDictionaryAdd_IsPermanent)
\r
166 enchant_dict_add(_dict, "hello", -1);
\r
167 CHECK(IsWordInDictionary("hello"));
\r
169 ReloadTestDictionary();
\r
171 CHECK(IsWordInDictionary("hello"));
\r
175 TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
\r
176 EnchantDictionaryAdd_HasPreviousError_ErrorCleared)
\r
178 SetErrorOnMockDictionary("something bad happened");
\r
180 enchant_dict_add(_dict, "hello", -1);
\r
181 CHECK_EQUAL((void*)NULL, (void*)enchant_dict_get_error(_dict));
\r
184 /////////////////////////////////////////////////////////////////////////////
\r
185 // Test Error Conditions
\r
186 TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
\r
187 EnchantDictionaryAdd_NullDictionary_NotAdded)
\r
189 enchant_dict_add(NULL, "hello", -1);
\r
190 CHECK(!addToPersonalCalled);
\r
193 TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
\r
194 EnchantDictionaryAdd_NullWord_NotAdded)
\r
196 enchant_dict_add(_dict, NULL, -1);
\r
197 CHECK(!addToPersonalCalled);
\r
200 TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
\r
201 EnchantDictionaryAdd_EmptyWord_NotAdded)
\r
203 enchant_dict_add(_dict, "", -1);
\r
204 CHECK(!addToPersonalCalled);
\r
207 TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
\r
208 EnchantDictionaryAdd_WordSize0_NotAdded)
\r
210 enchant_dict_add(_dict, "hello", 0);
\r
211 CHECK(!addToPersonalCalled);
\r
214 TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
\r
215 EnchantDictionaryAdd_InvalidUtf8Word_NotAdded)
\r
217 enchant_dict_add(_dict, "\xa5\xf1\x08", -1);
\r
218 CHECK(!addToPersonalCalled);
\r
221 TEST_FIXTURE(EnchantDictionaryAddToPersonalNotImplemented_TestFixture,
\r
222 EnchantDictionaryAddToPersonalNotImplemented_WordAddedToEnchantPwlFile)
\r
224 CHECK(!PersonalWordListFileHasContents());
\r
225 enchant_dict_add(_dict, "hello", -1);
\r
226 CHECK(PersonalWordListFileHasContents());
\r
229 TEST_FIXTURE(EnchantDictionaryAddToPersonalNotImplemented_TestFixture,
\r
230 EnchantDictionaryAddToPersonalNotImplemented_NotPassedOnToProvider)
\r
232 enchant_dict_add(_dict, "hello", -1);
\r
233 CHECK(!addToPersonalCalled);
\r