Tizen 2.1 base
[external/enchant.git] / unittests / enchant_providers / Provider / provider_list_dicts.cpp
1 /* Copyright (c) 2008 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-provider.h>\r
24 \r
25 #include "../unittest_enchant_providers.h"\r
26 \r
27 struct ProviderListDicts_TestFixture : Provider_TestFixture\r
28 {\r
29         char ** _dicts;\r
30 \r
31     //Setup\r
32     ProviderListDicts_TestFixture():_dicts(NULL)\r
33     { \r
34     }\r
35     //Teardown\r
36     ~ProviderListDicts_TestFixture()\r
37     {\r
38         if (_dicts && _provider->free_string_list)\r
39                     (*_provider->free_string_list) (_provider, _dicts);\r
40     }\r
41 };\r
42 \r
43 // list_dicts is optional\r
44 \r
45 /////////////////////////////////////////////////////////////////////////////\r
46 // Test Normal Operation\r
47 \r
48 TEST_FIXTURE(ProviderListDicts_TestFixture, \r
49              ProviderListDicts_ListReturnedHasContent)\r
50 {\r
51     if(_provider->list_dicts)\r
52     {\r
53                 size_t n_dicts;\r
54 \r
55                 _dicts = (*_provider->list_dicts) (_provider, &n_dicts);\r
56                 for (size_t i = 0; i < n_dicts; i++)\r
57                 {\r
58                         CHECK(_dicts[i] != NULL);\r
59         }\r
60     }\r
61 }\r
62 \r
63 TEST_FIXTURE(ProviderListDicts_TestFixture, \r
64              ProviderListDicts_ForEachReturned_RequestDictSucceeds)\r
65 {\r
66     if(_provider->list_dicts && _provider->request_dict)\r
67     {\r
68                 size_t n_dicts;\r
69 \r
70                 _dicts = (*_provider->list_dicts) (_provider, &n_dicts);\r
71                 for (size_t i = 0; i < n_dicts; i++)\r
72                 {\r
73                         EnchantDict* dict = (*_provider->request_dict) (_provider, _dicts[i]);\r
74                         CHECK(dict != NULL);\r
75                 if (dict && _provider->dispose_dict)\r
76                     {\r
77                 _provider->dispose_dict(_provider, dict);\r
78                     }\r
79         }\r
80     }\r
81 }\r
82 \r
83 TEST_FIXTURE(ProviderListDicts_TestFixture, \r
84              ProviderListDicts_ForEachReturned_DictExistsSucceeds)\r
85 {\r
86     if(_provider->list_dicts && _provider->dictionary_exists)\r
87     {\r
88                 size_t n_dicts;\r
89 \r
90                 _dicts = (*_provider->list_dicts) (_provider, &n_dicts);\r
91                 for (size_t i = 0; i < n_dicts; i++)\r
92                 {\r
93                         CHECK_EQUAL(1, (*_provider->dictionary_exists) (_provider, _dicts[i]));\r
94         }\r
95     }\r
96 }\r
97 \r