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 #include <UnitTest++.h>
\r
23 #include <enchant.h>
\r
24 #include "../EnchantBrokerTestFixture.h"
\r
26 * enchant_broker_free_dict
\r
27 * @broker: A non-null #EnchantBroker
\r
28 * @dict: A non-null #EnchantDict
\r
30 * Releases the dictionary when you are done using it
\r
32 * Must only be called once per dictionary request
\r
35 EnchantDict* dictionaryToBeFreed=NULL;
\r
37 DisposeDictionary (EnchantProvider *me, EnchantDict * dict)
\r
39 dictionaryToBeFreed = dict;
\r
40 MockProviderDisposeDictionary(me, dict);
\r
43 static void ProviderConfiguration (EnchantProvider * me, const char *)
\r
45 me->request_dict = MockEnGbAndQaaProviderRequestDictionary;
\r
46 me->dispose_dict = DisposeDictionary;
\r
49 struct EnchantBrokerFreeDictTestFixture: EnchantBrokerTestFixture
\r
52 EnchantBrokerFreeDictTestFixture():EnchantBrokerTestFixture(ProviderConfiguration)
\r
54 _dictionary = RequestDictionary("en-GB");
\r
55 dictionaryToBeFreed=NULL;
\r
59 ~EnchantBrokerFreeDictTestFixture()
\r
61 FreeDictionary(_dictionary);
\r
64 EnchantDict* _dictionary;
\r
67 static void NoDisposeProviderConfiguration (EnchantProvider * me, const char *)
\r
69 me->request_dict = MockEnGbAndQaaProviderRequestDictionary;
\r
72 struct EnchantBrokerFreeDictNoDisposeTestFixture: EnchantBrokerTestFixture
\r
75 EnchantBrokerFreeDictNoDisposeTestFixture():EnchantBrokerTestFixture(NoDisposeProviderConfiguration)
\r
77 _dictionary = enchant_broker_request_dict(_broker, "en-GB");
\r
78 dictionaryToBeFreed=NULL;
\r
82 ~EnchantBrokerFreeDictNoDisposeTestFixture(){
\r
83 FreeDictionary(_dictionary);
\r
86 EnchantDict* _dictionary;
\r
89 /////////////////////////////////////////////////////////////////////////////
\r
90 // Test Normal Operation
\r
92 TEST_FIXTURE(EnchantBrokerFreeDictTestFixture,
\r
93 EnchantBrokerFreeDict)
\r
95 enchant_broker_free_dict(_broker, _dictionary);
\r
96 CHECK_EQUAL(_dictionary, dictionaryToBeFreed);
\r
100 TEST_FIXTURE(EnchantBrokerFreeDictTestFixture,
\r
101 EnchantBrokerFreeDict_HasPreviousError_ErrorCleared)
\r
104 SetErrorOnMockProvider("something bad happened");
\r
106 enchant_broker_free_dict(_broker, _dictionary);
\r
107 _dictionary = NULL;
\r
109 CHECK_EQUAL((void*)NULL, (void*)enchant_broker_get_error(_broker));
\r
112 TEST_FIXTURE(EnchantBrokerFreeDictTestFixture,
\r
113 EnchantBrokerFreeDict_HasTwoInstances_NoCrash)
\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
121 /////////////////////////////////////////////////////////////////////////////
\r
122 // Test Error Conditions
\r
123 TEST_FIXTURE(EnchantBrokerFreeDictTestFixture,
\r
124 EnchantBrokerFreeDict_NullBroker_DoNothing)
\r
126 enchant_broker_free_dict(NULL, _dictionary);
\r
127 CHECK_EQUAL((EnchantDict*)NULL, dictionaryToBeFreed);
\r
130 TEST_FIXTURE(EnchantBrokerFreeDictTestFixture,
\r
131 EnchantBrokerFreeDict_NullDict_DoNothing)
\r
133 enchant_broker_free_dict(_broker, NULL);
\r
134 CHECK_EQUAL((EnchantDict*)NULL, dictionaryToBeFreed);
\r
137 TEST_FIXTURE(EnchantBrokerFreeDictNoDisposeTestFixture,
\r
138 EnchantBrokerFreeDict_NotOnProvider_DoNothing)
\r
141 enchant_broker_free_dict(_broker, _dictionary);
\r
142 _dictionary = NULL;
\r