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 addToSessionCalled;
\r
27 static std::string wordToAdd;
\r
30 MockDictionaryAddToSession (EnchantDict * dict, const char *const word, size_t len)
\r
33 addToSessionCalled = true;
\r
34 wordToAdd = std::string(word, len);
\r
37 static EnchantDict* MockProviderRequestAddToSessionMockDictionary(EnchantProvider * me, const char *tag)
\r
40 EnchantDict* dict = MockProviderRequestEmptyMockDictionary(me, tag);
\r
41 dict->add_to_session = MockDictionaryAddToSession;
\r
45 static void DictionaryAddToSession_ProviderConfiguration (EnchantProvider * me, const char *)
\r
47 me->request_dict = MockProviderRequestAddToSessionMockDictionary;
\r
48 me->dispose_dict = MockProviderDisposeDictionary;
\r
51 struct EnchantDictionaryAddToSession_TestFixture : EnchantDictionaryTestFixture
\r
54 EnchantDictionaryAddToSession_TestFixture():
\r
55 EnchantDictionaryTestFixture(DictionaryAddToSession_ProviderConfiguration)
\r
57 addToSessionCalled = false;
\r
61 struct EnchantDictionaryAddToSessionNotImplemented_TestFixture : EnchantDictionaryTestFixture
\r
64 EnchantDictionaryAddToSessionNotImplemented_TestFixture():
\r
65 EnchantDictionaryTestFixture(EmptyDictionary_ProviderConfiguration)
\r
67 addToSessionCalled = false;
\r
71 * enchant_dict_add_to_session
\r
72 * @dict: A non-null #EnchantDict
\r
73 * @word: The non-null word you wish to add to this spell-checking session, in UTF-8 encoding
\r
74 * @len: The byte length of @word, or -1 for strlen (@word)
\r
78 /////////////////////////////////////////////////////////////////////////////
\r
79 // Test Normal Operation
\r
80 TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
\r
81 EnchantDictionaryAddToSession_WordNotAddedToEnchantPwlFile)
\r
83 enchant_dict_add_to_session(_dict, "hello", -1);
\r
84 CHECK(!PersonalWordListFileHasContents());
\r
87 TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
\r
88 EnchantDictionaryAddToSession_PassedOnToProvider_LenComputed)
\r
90 enchant_dict_add_to_session(_dict, "hello", -1);
\r
91 CHECK(addToSessionCalled);
\r
92 CHECK_EQUAL(std::string("hello"), wordToAdd);
\r
95 TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
\r
96 EnchantDictionaryAddToSession_PassedOnToProvider_LenSpecified)
\r
98 enchant_dict_add_to_session(_dict, "hellodisregard me", 5);
\r
99 CHECK(addToSessionCalled);
\r
100 CHECK_EQUAL(std::string("hello"), wordToAdd);
\r
103 TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
\r
104 EnchantDictionaryAddToSession_WordExistsInSession_StillCallsProvider)
\r
106 enchant_dict_add_to_session(_dict, "session", -1);
\r
107 addToSessionCalled=false;
\r
108 wordToAdd = std::string();
\r
110 enchant_dict_add_to_session(_dict, "session", -1);
\r
111 CHECK(addToSessionCalled);
\r
112 CHECK_EQUAL(std::string("session"), wordToAdd);
\r
115 TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
\r
116 EnchantDictionaryAddToSession_WordExistsInPersonal_StillCallsProvider)
\r
118 enchant_dict_add(_dict, "personal", -1);
\r
119 CHECK(!addToSessionCalled);
\r
121 enchant_dict_add_to_session(_dict, "personal", -1);
\r
122 CHECK(addToSessionCalled);
\r
123 CHECK_EQUAL(std::string("personal"), wordToAdd);
\r
126 TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
\r
127 EnchantDictionaryAddToSession_WordExistsInExclude_AddedToSessionNotRemovedFromExcludeFile)
\r
129 enchant_dict_remove(_dict, "personal", -1);
\r
131 enchant_dict_add_to_session(_dict, "personal", -1);
\r
132 CHECK(IsWordInDictionary("personal"));
\r
133 CHECK(ExcludeFileHasContents());
\r
137 TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
\r
138 EnchantDictionaryAddToSession_WordAddedToSession)
\r
140 enchant_dict_add_to_session(_dict, "hello", -1);
\r
141 CHECK(IsWordInSession("hello"));
\r
144 TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
\r
145 EnchantDictionaryAddToSession_InBrokerSession)
\r
147 enchant_dict_add_to_session(_pwl, "personal", -1);
\r
148 CHECK(!addToSessionCalled);
\r
149 CHECK(!PersonalWordListFileHasContents());
\r
152 TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
\r
153 EnchantDictionaryAddToSession_IsNotPermanent)
\r
155 enchant_dict_add_to_session(_dict, "hello", -1);
\r
156 CHECK(IsWordInSession("hello"));
\r
158 ReloadTestDictionary();
\r
160 CHECK(!IsWordInSession("hello"));
\r
163 TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
\r
164 EnchantDictionaryAddToSession_HasPreviousError_ErrorCleared)
\r
166 SetErrorOnMockDictionary("something bad happened");
\r
168 enchant_dict_add_to_session(_dict, "hello", -1);
\r
169 CHECK_EQUAL((void*)NULL, (void*)enchant_dict_get_error(_dict));
\r
172 /////////////////////////////////////////////////////////////////////////////
\r
173 // Test Error Conditions
\r
174 TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
\r
175 EnchantDictionaryAddToSession_NullDictionary_NotAdded)
\r
177 enchant_dict_add_to_session(NULL, "hello", -1);
\r
178 CHECK(!addToSessionCalled);
\r
181 TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
\r
182 EnchantDictionaryAddToSession_NullWord_NotAdded)
\r
184 enchant_dict_add_to_session(_dict, NULL, -1);
\r
185 CHECK(!addToSessionCalled);
\r
188 TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
\r
189 EnchantDictionaryAddToSession_EmptyWord_NotAdded)
\r
191 enchant_dict_add_to_session(_dict, "", -1);
\r
192 CHECK(!addToSessionCalled);
\r
195 TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
\r
196 EnchantDictionaryAddToSession_WordSize0_NotAdded)
\r
198 enchant_dict_add_to_session(_dict, "hello", 0);
\r
199 CHECK(!addToSessionCalled);
\r
202 TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
\r
203 EnchantDictionaryAddToSession_InvalidUtf8Word_NotAdded)
\r
205 enchant_dict_add_to_session(_dict, "\xa5\xf1\x08", -1);
\r
206 CHECK(!addToSessionCalled);
\r
209 TEST_FIXTURE(EnchantDictionaryAddToSessionNotImplemented_TestFixture,
\r
210 EnchantDictionaryAddToSessionNotImplemented_WordAddedToSession)
\r
212 enchant_dict_add_to_session(_dict, "hello", -1);
\r
213 CHECK(IsWordInSession("hello"));
\r
216 TEST_FIXTURE(EnchantDictionaryAddToSessionNotImplemented_TestFixture,
\r
217 EnchantDictionaryAddToSessionNotImplemented_NotPassedOnToProvider)
\r
219 enchant_dict_add_to_session(_dict, "hello", -1);
\r
220 CHECK(!addToSessionCalled);
\r