Tizen 2.1 base
[external/enchant.git] / unittests / dictionary / enchant_dict_is_added_tests.cpp
1 /* Copyright (c) 2007 Eric Scott Albright\r
2  * \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
9  * \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
12  * \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
19  * THE SOFTWARE.\r
20  */\r
21 \r
22 #include <UnitTest++.h>\r
23 #include <enchant.h>\r
24 #include "../EnchantDictionaryTestFixture.h"\r
25 \r
26 struct EnchantDictionaryIsAdded_TestFixture : EnchantDictionaryTestFixture\r
27 {};\r
28 \r
29 /**\r
30  * enchant_dict_is_added\r
31  * @dict: A non-null #EnchantDict\r
32  * @word: The word you wish to see if it's in your session\r
33  * @len: the byte length of @word, or -1 for strlen (@word)\r
34  */\r
35 \r
36 /////////////////////////////////////////////////////////////////////////////\r
37 // Test Normal Operation\r
38 TEST_FIXTURE(EnchantDictionaryIsAdded_TestFixture, \r
39              EnchantDictionaryIsAdded_AddedToSession_1)\r
40 {\r
41     enchant_dict_add_to_session(_dict, "hello", -1);\r
42 \r
43     CHECK_EQUAL(1, enchant_dict_is_added(_dict, "hello", -1));\r
44 }\r
45 \r
46 TEST_FIXTURE(EnchantDictionaryIsAdded_TestFixture, \r
47              EnchantDictionaryIsAdded_Added_1)\r
48 {\r
49     enchant_dict_add(_dict, "hello", -1);\r
50 \r
51     CHECK_EQUAL(1, enchant_dict_is_added(_dict, "hello", -1));\r
52 }\r
53 \r
54 TEST_FIXTURE(EnchantDictionaryIsAdded_TestFixture, \r
55              EnchantDictionaryIsAdded_NotAdded_0)\r
56 {\r
57     CHECK_EQUAL(0, enchant_dict_is_added(_dict, "hello", -1));\r
58 }\r
59 \r
60 TEST_FIXTURE(EnchantDictionaryIsAdded_TestFixture, \r
61              EnchantDictionaryIsAdded_OnBrokerPwl_AddedToSession_1)\r
62 {\r
63     enchant_dict_add_to_session(_pwl, "hello", -1);\r
64 \r
65     CHECK_EQUAL(1, enchant_dict_is_added(_pwl, "hello", -1));\r
66 }\r
67 \r
68 TEST_FIXTURE(EnchantDictionaryIsAdded_TestFixture, \r
69              EnchantDictionaryIsAdded_OnBrokerPwl_Added_1)\r
70 {\r
71     enchant_dict_add(_pwl, "hello", -1);\r
72 \r
73     CHECK_EQUAL(1, enchant_dict_is_added(_pwl, "hello", -1));\r
74 }\r
75 \r
76 TEST_FIXTURE(EnchantDictionaryIsAdded_TestFixture, \r
77              EnchantDictionaryIsAdded_OnBrokerPwl_NotAdded_0)\r
78 {\r
79     CHECK_EQUAL(0, enchant_dict_is_added(_pwl, "hello", -1));\r
80 }\r
81 \r
82 TEST_FIXTURE(EnchantDictionaryIsAdded_TestFixture, \r
83              EnchantDictionaryIsAdded_HasPreviousError_ErrorCleared)\r
84 {\r
85     SetErrorOnMockDictionary("something bad happened");\r
86 \r
87     enchant_dict_is_added(_dict, "hello", -1);\r
88     CHECK_EQUAL((void*)NULL, (void*)enchant_dict_get_error(_dict));\r
89 }\r
90 \r
91 /////////////////////////////////////////////////////////////////////////////\r
92 // Test Error Conditions\r
93 TEST_FIXTURE(EnchantDictionaryIsAdded_TestFixture,\r
94              EnchantDictionaryIsAdded_NullDictionary_0)\r
95 {\r
96     CHECK_EQUAL(0, enchant_dict_is_added(NULL, "hello", -1));\r
97 }\r
98 \r
99 TEST_FIXTURE(EnchantDictionaryIsAdded_TestFixture,\r
100              EnchantDictionaryIsAdded_NullWord_0)\r
101 {\r
102     CHECK_EQUAL(0, enchant_dict_is_added(_dict, NULL, -1));\r
103 }\r
104 \r
105 TEST_FIXTURE(EnchantDictionaryIsAdded_TestFixture,\r
106              EnchantDictionaryIsAdded_EmptyWord_0)\r
107 {\r
108     CHECK_EQUAL(0, enchant_dict_is_added(_dict, "", -1));\r
109 }\r
110 \r
111 TEST_FIXTURE(EnchantDictionaryIsAdded_TestFixture,\r
112              EnchantDictionaryIsAdded_WordSize0_0)\r
113 {\r
114     CHECK_EQUAL(0, enchant_dict_is_added(_dict, "hello", 0));\r
115 }\r
116 \r
117 TEST_FIXTURE(EnchantDictionaryIsAdded_TestFixture,\r
118              EnchantDictionaryIsAdded_InvalidUtf8Word_0)\r
119 {\r
120     CHECK_EQUAL(0, enchant_dict_is_added(_dict, "\xa5\xf1\x08", -1));\r
121 }\r
122 \r
123 TEST_FIXTURE(EnchantDictionaryIsAdded_TestFixture, \r
124              EnchantDictionaryIsAdded_WordExistsInPwlAndExclude_0)\r
125 {\r
126     ExternalAddWordToDictionary("hello");\r
127     ExternalAddWordToExclude("hello");\r
128 \r
129         ReloadTestDictionary();\r
130         CHECK_EQUAL(0, enchant_dict_is_added(_dict, "hello", -1));\r
131 }\r
132 \r