Tizen 2.1 base
[external/enchant.git] / unittests / broker / enchant_broker_free_dict_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 "../EnchantBrokerTestFixture.h"\r
25 /**\r
26  * enchant_broker_free_dict\r
27  * @broker: A non-null #EnchantBroker\r
28  * @dict: A non-null #EnchantDict\r
29  *\r
30  * Releases the dictionary when you are done using it\r
31  * \r
32  * Must only be called once per dictionary request\r
33  */\r
34 \r
35 EnchantDict* dictionaryToBeFreed=NULL;\r
36 static void\r
37 DisposeDictionary (EnchantProvider *me, EnchantDict * dict)\r
38 {\r
39     dictionaryToBeFreed = dict;\r
40     MockProviderDisposeDictionary(me, dict);\r
41 }\r
42 \r
43 static void ProviderConfiguration (EnchantProvider * me, const char *)\r
44 {\r
45      me->request_dict = MockEnGbAndQaaProviderRequestDictionary;\r
46      me->dispose_dict = DisposeDictionary;\r
47 }\r
48 \r
49 struct EnchantBrokerFreeDictTestFixture: EnchantBrokerTestFixture\r
50 {\r
51     //Setup\r
52     EnchantBrokerFreeDictTestFixture():EnchantBrokerTestFixture(ProviderConfiguration)\r
53     {\r
54         _dictionary = RequestDictionary("en-GB");\r
55         dictionaryToBeFreed=NULL;\r
56     }\r
57 \r
58     //Teardown\r
59     ~EnchantBrokerFreeDictTestFixture()\r
60     {\r
61         FreeDictionary(_dictionary);\r
62     }\r
63 \r
64     EnchantDict* _dictionary;\r
65 };\r
66 \r
67 static void NoDisposeProviderConfiguration (EnchantProvider * me, const char *)\r
68 {\r
69      me->request_dict = MockEnGbAndQaaProviderRequestDictionary;\r
70 }\r
71 \r
72 struct EnchantBrokerFreeDictNoDisposeTestFixture: EnchantBrokerTestFixture\r
73 {\r
74     //Setup\r
75     EnchantBrokerFreeDictNoDisposeTestFixture():EnchantBrokerTestFixture(NoDisposeProviderConfiguration)\r
76     {\r
77         _dictionary = enchant_broker_request_dict(_broker, "en-GB");\r
78         dictionaryToBeFreed=NULL;\r
79     }\r
80 \r
81     //Teardown\r
82     ~EnchantBrokerFreeDictNoDisposeTestFixture(){\r
83         FreeDictionary(_dictionary);\r
84     }\r
85 \r
86     EnchantDict* _dictionary;\r
87 };\r
88 \r
89 /////////////////////////////////////////////////////////////////////////////\r
90 // Test Normal Operation\r
91 \r
92 TEST_FIXTURE(EnchantBrokerFreeDictTestFixture, \r
93              EnchantBrokerFreeDict)\r
94 {\r
95     enchant_broker_free_dict(_broker, _dictionary);\r
96     CHECK_EQUAL(_dictionary, dictionaryToBeFreed);\r
97     _dictionary = NULL;\r
98 }\r
99 \r
100 TEST_FIXTURE(EnchantBrokerFreeDictTestFixture, \r
101              EnchantBrokerFreeDict_HasPreviousError_ErrorCleared)\r
102 {\r
103   \r
104     SetErrorOnMockProvider("something bad happened");\r
105 \r
106     enchant_broker_free_dict(_broker, _dictionary);\r
107     _dictionary = NULL;\r
108 \r
109     CHECK_EQUAL((void*)NULL, (void*)enchant_broker_get_error(_broker));\r
110 }\r
111 \r
112 TEST_FIXTURE(EnchantBrokerFreeDictTestFixture, \r
113              EnchantBrokerFreeDict_HasTwoInstances_NoCrash)\r
114 {\r
115     EnchantDict* dictionary1 = enchant_broker_request_dict(_broker, "en-GB");\r
116     EnchantDict* dictionary2 = enchant_broker_request_dict(_broker, "en-GB");\r
117     enchant_broker_free_dict(_broker, dictionary1);\r
118     enchant_broker_free_dict(_broker, dictionary2);\r
119 }\r
120 \r
121 /////////////////////////////////////////////////////////////////////////////\r
122 // Test Error Conditions\r
123 TEST_FIXTURE(EnchantBrokerFreeDictTestFixture, \r
124              EnchantBrokerFreeDict_NullBroker_DoNothing)\r
125 {\r
126     enchant_broker_free_dict(NULL, _dictionary);\r
127     CHECK_EQUAL((EnchantDict*)NULL, dictionaryToBeFreed);\r
128 }\r
129 \r
130 TEST_FIXTURE(EnchantBrokerFreeDictTestFixture, \r
131              EnchantBrokerFreeDict_NullDict_DoNothing)\r
132 {\r
133     enchant_broker_free_dict(_broker, NULL);\r
134     CHECK_EQUAL((EnchantDict*)NULL, dictionaryToBeFreed);\r
135 }\r
136 \r
137 TEST_FIXTURE(EnchantBrokerFreeDictNoDisposeTestFixture, \r
138              EnchantBrokerFreeDict_NotOnProvider_DoNothing)\r
139 {\r
140     testResults_;\r
141     enchant_broker_free_dict(_broker, _dictionary);\r
142     _dictionary = NULL;\r
143 }\r