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 #define NOMINMAX //don't want windows to collide with std::min
\r
24 #include <UnitTest++.h>
\r
25 #include <enchant.h>
\r
26 #include "../EnchantDictionaryTestFixture.h"
\r
28 static bool dictCheckCalled;
\r
31 MockDictionaryCheck (EnchantDict * dict, const char *const word, size_t len)
\r
34 dictCheckCalled = true;
\r
35 if(strncmp("hello", word, len)==0)
\r
37 return 0; //good word
\r
39 return 1; // bad word
\r
43 static EnchantDict* MockProviderRequestCheckMockDictionary(EnchantProvider * me, const char *tag)
\r
46 EnchantDict* dict = MockProviderRequestBasicMockDictionary(me, tag);
\r
47 dict->check = MockDictionaryCheck;
\r
51 static void DictionaryCheck_ProviderConfiguration (EnchantProvider * me, const char *)
\r
53 me->request_dict = MockProviderRequestCheckMockDictionary;
\r
54 me->dispose_dict = MockProviderDisposeDictionary;
\r
57 struct EnchantDictionaryRemoveFromSession_TestFixture : EnchantDictionaryTestFixture
\r
60 EnchantDictionaryRemoveFromSession_TestFixture():
\r
61 EnchantDictionaryTestFixture(DictionaryCheck_ProviderConfiguration)
\r
63 dictCheckCalled = false;
\r
68 * enchant_dict_remove_from_session
\r
69 * @dict: A non-null #EnchantDict
\r
70 * @word: The non-null word you wish to exclude from this spell-checking session, in UTF-8 encoding
\r
71 * @len: The byte length of @word, or -1 for strlen (@word)
\r
75 /////////////////////////////////////////////////////////////////////////////
\r
76 // Test Normal Operation
\r
77 TEST_FIXTURE(EnchantDictionaryRemoveFromSession_TestFixture,
\r
78 EnchantDictionaryRemoveFromSession_WordNotAddedToEnchantExcludeFile)
\r
80 enchant_dict_remove_from_session(_dict, "hello", -1);
\r
81 CHECK(!ExcludeFileHasContents());
\r
84 TEST_FIXTURE(EnchantDictionaryRemoveFromSession_TestFixture,
\r
85 EnchantDictionaryRemoveFromSession_WordRemovedFromSession)
\r
87 enchant_dict_add_to_session(_dict, "hello", -1);
\r
88 CHECK(IsWordInSession("hello"));
\r
89 enchant_dict_remove_from_session(_dict, "hello", -1);
\r
90 CHECK(!IsWordInSession("hello"));
\r
93 TEST_FIXTURE(EnchantDictionaryRemoveFromSession_TestFixture,
\r
94 EnchantDictionaryRemoveFromSession_CalledTwice)
\r
96 enchant_dict_add_to_session(_dict, "hello", -1);
\r
97 enchant_dict_remove_from_session(_dict, "hello", -1);
\r
98 enchant_dict_remove_from_session(_dict, "hello", -1);
\r
99 CHECK(!IsWordInSession("hello"));
\r
102 TEST_FIXTURE(EnchantDictionaryRemoveFromSession_TestFixture,
\r
103 EnchantDictionaryRemoveFromSession_WordExcludedFromDictionary)
\r
105 enchant_dict_remove_from_session(_dict, "hello", -1);
\r
106 CHECK(!IsWordInDictionary("hello"));
\r
109 TEST_FIXTURE(EnchantDictionaryRemoveFromSession_TestFixture,
\r
110 EnchantDictionaryRemoveFromSession_InBrokerSession_WordExcludedFromBrokerSession)
\r
112 enchant_dict_add_to_session(_pwl, "hello", -1);
\r
113 CHECK(enchant_dict_is_in_session(_pwl, "hello", -1));
\r
114 enchant_dict_remove_from_session(_pwl, "hello", -1);
\r
115 CHECK(!enchant_dict_is_in_session(_pwl, "hello", -1));
\r
118 TEST_FIXTURE(EnchantDictionaryRemoveFromSession_TestFixture,
\r
119 EnchantDictionaryRemoveFromSession_IsNotPermanent)
\r
121 enchant_dict_remove_from_session(_dict, "hello", -1);
\r
122 CHECK(!IsWordInDictionary("hello"));
\r
124 ReloadTestDictionary();
\r
126 CHECK(IsWordInDictionary("hello"));
\r
129 TEST_FIXTURE(EnchantDictionaryRemoveFromSession_TestFixture,
\r
130 EnchantDictionaryRemoveFromSession_NotGivenAsSuggestion)
\r
132 enchant_dict_remove_from_session(_dict, "aelo", -1);
\r
134 std::vector<const std::string> suggestions = GetSuggestions("helo");
\r
135 CHECK_EQUAL(3, suggestions.size());
\r
136 CHECK_ARRAY_EQUAL(GetExpectedSuggestions("helo",1), suggestions, std::min(3u,suggestions.size()) );
\r
139 TEST_FIXTURE(EnchantDictionaryRemoveFromSession_TestFixture,
\r
140 EnchantDictionaryRemoveFromSession_ThenAddedToSession_GivenAsSuggestion)
\r
142 enchant_dict_remove_from_session(_dict, "aelo", -1);
\r
143 enchant_dict_add_to_session(_dict, "aelo", -1);
\r
145 std::vector<const std::string> suggestions = GetSuggestions("helo");
\r
146 CHECK_EQUAL(4, suggestions.size());
\r
147 CHECK_ARRAY_EQUAL(GetExpectedSuggestions("helo"), suggestions, suggestions.size());
\r
150 TEST_FIXTURE(EnchantDictionaryRemoveFromSession_TestFixture,
\r
151 EnchantDictionaryRemoveFromSession_HasPreviousError_ErrorCleared)
\r
153 SetErrorOnMockDictionary("something bad happened");
\r
155 enchant_dict_remove_from_session(_dict, "hello", -1);
\r
156 CHECK_EQUAL((void*)NULL, (void*)enchant_dict_get_error(_dict));
\r
159 /////////////////////////////////////////////////////////////////////////////
\r
160 // Test Error Conditions
\r
161 TEST_FIXTURE(EnchantDictionaryRemoveFromSession_TestFixture,
\r
162 EnchantDictionaryRemoveFromSession_NullDictionary_NotRemoved)
\r
164 enchant_dict_remove_from_session(NULL, "hello", -1);
\r
165 CHECK(IsWordInDictionary("hello"));
\r
168 TEST_FIXTURE(EnchantDictionaryRemoveFromSession_TestFixture,
\r
169 EnchantDictionaryRemoveFromSession_NullWord_NotRemoved)
\r
171 enchant_dict_remove_from_session(_dict, NULL, -1);
\r
172 CHECK(IsWordInDictionary("hello"));
\r
175 TEST_FIXTURE(EnchantDictionaryRemoveFromSession_TestFixture,
\r
176 EnchantDictionaryRemoveFromSession_EmptyWord_NotRemoved)
\r
178 enchant_dict_remove_from_session(_dict, "", -1);
\r
179 CHECK(IsWordInDictionary("hello"));
\r
182 TEST_FIXTURE(EnchantDictionaryRemoveFromSession_TestFixture,
\r
183 EnchantDictionaryRemoveFromSession_WordSize0_NotRemoved)
\r
185 enchant_dict_remove_from_session(_dict, "hello", 0);
\r
186 CHECK(IsWordInDictionary("hello"));
\r
189 TEST_FIXTURE(EnchantDictionaryRemoveFromSession_TestFixture,
\r
190 EnchantDictionaryRemoveFromSession_InvalidUtf8Word_NotRemoved)
\r
192 enchant_dict_remove_from_session(_dict, "\xa5\xf1\x08", -1);
\r
193 CHECK(IsWordInDictionary("hello"));
\r