Tizen 2.1 base
[external/enchant.git] / unittests / broker / enchant_broker_free_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 /**\r
27  * enchant_broker_free\r
28  * @broker: A non-null #EnchantBroker\r
29  *\r
30  * Destroys the broker object\r
31  *\r
32  * Free must only be called once!\r
33  */\r
34 \r
35 bool disposeWasCalled;\r
36 static void\r
37 Dispose (EnchantProvider *me)\r
38 {\r
39     disposeWasCalled = true;\r
40     MockProviderDispose(me);\r
41 }\r
42 \r
43 bool disposeDictionaryCalled;\r
44 static void\r
45 DisposeDictionary (EnchantProvider *me, EnchantDict * dict)\r
46 {\r
47     disposeDictionaryCalled = true;\r
48     MockProviderDisposeDictionary(me, dict);\r
49 }\r
50 \r
51 static void ProviderConfiguration (EnchantProvider * me, const char *)\r
52 {\r
53      me->dispose = Dispose;\r
54      me->request_dict = MockEnGbAndQaaProviderRequestDictionary;\r
55      me->dispose_dict = DisposeDictionary;\r
56 }\r
57 \r
58 struct EnchantBrokerFreeTestFixture: EnchantBrokerTestFixture\r
59 {\r
60     //Setup\r
61     EnchantBrokerFreeTestFixture():EnchantBrokerTestFixture(ProviderConfiguration)\r
62     {\r
63         disposeWasCalled = false;\r
64         disposeDictionaryCalled = false;\r
65     }\r
66 };\r
67 \r
68 \r
69 static void NoDisposeProviderConfiguration (EnchantProvider * me, const char *)\r
70 {\r
71      me->dispose = NULL;\r
72 }\r
73 \r
74 struct EnchantBrokerFreeNoDisposeTestFixture: EnchantBrokerTestFixture\r
75 {\r
76     //Setup\r
77     EnchantBrokerFreeNoDisposeTestFixture():EnchantBrokerTestFixture(NoDisposeProviderConfiguration)\r
78     {  }\r
79 };\r
80 \r
81 \r
82 /////////////////////////////////////////////////////////////////////////////\r
83 // Test Normal Operation\r
84 \r
85 TEST(EnchantBrokerFree)\r
86 {\r
87     testResults_;\r
88     EnchantBroker* broker = enchant_broker_init ();\r
89     enchant_broker_free(broker);\r
90     broker = NULL;\r
91 }\r
92 \r
93 TEST_FIXTURE(EnchantBrokerFreeTestFixture,\r
94              EnchantBrokerFree_DisposesProviders)\r
95 {\r
96     enchant_broker_free(_broker);\r
97     CHECK(disposeWasCalled);\r
98     _broker = NULL;\r
99 }\r
100 \r
101 TEST_FIXTURE(EnchantBrokerFreeNoDisposeTestFixture,\r
102              EnchantBrokerFree_ProviderLacksDispose)\r
103 {\r
104     testResults_;\r
105     enchant_broker_free(_broker);\r
106     _broker = NULL;\r
107 }\r
108 \r
109 /////////////////////////////////////////////////////////////////////////////\r
110 // Test Error Conditions\r
111 TEST_FIXTURE(EnchantBrokerFreeTestFixture,\r
112              EnchantBrokerFree_NullBroker_DoNothing)\r
113 {\r
114     enchant_broker_free(NULL);\r
115     CHECK(!disposeWasCalled);\r
116 }\r
117 \r
118 TEST_FIXTURE(EnchantBrokerFreeTestFixture,\r
119              EnchantBrokerFree_DictionaryNotFreed_FreesDictionary)\r
120 {\r
121     EnchantDict* dict = enchant_broker_request_dict(_broker, "en_GB");\r
122     CHECK(dict);\r
123     CHECK(!disposeDictionaryCalled);\r
124 \r
125     enchant_broker_free(_broker);\r
126     _broker = NULL;\r
127     CHECK(disposeDictionaryCalled);\r
128 }\r