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
27 * enchant_broker_free
\r
28 * @broker: A non-null #EnchantBroker
\r
30 * Destroys the broker object
\r
32 * Free must only be called once!
\r
35 bool disposeWasCalled;
\r
37 Dispose (EnchantProvider *me)
\r
39 disposeWasCalled = true;
\r
40 MockProviderDispose(me);
\r
43 bool disposeDictionaryCalled;
\r
45 DisposeDictionary (EnchantProvider *me, EnchantDict * dict)
\r
47 disposeDictionaryCalled = true;
\r
48 MockProviderDisposeDictionary(me, dict);
\r
51 static void ProviderConfiguration (EnchantProvider * me, const char *)
\r
53 me->dispose = Dispose;
\r
54 me->request_dict = MockEnGbAndQaaProviderRequestDictionary;
\r
55 me->dispose_dict = DisposeDictionary;
\r
58 struct EnchantBrokerFreeTestFixture: EnchantBrokerTestFixture
\r
61 EnchantBrokerFreeTestFixture():EnchantBrokerTestFixture(ProviderConfiguration)
\r
63 disposeWasCalled = false;
\r
64 disposeDictionaryCalled = false;
\r
69 static void NoDisposeProviderConfiguration (EnchantProvider * me, const char *)
\r
74 struct EnchantBrokerFreeNoDisposeTestFixture: EnchantBrokerTestFixture
\r
77 EnchantBrokerFreeNoDisposeTestFixture():EnchantBrokerTestFixture(NoDisposeProviderConfiguration)
\r
82 /////////////////////////////////////////////////////////////////////////////
\r
83 // Test Normal Operation
\r
85 TEST(EnchantBrokerFree)
\r
88 EnchantBroker* broker = enchant_broker_init ();
\r
89 enchant_broker_free(broker);
\r
93 TEST_FIXTURE(EnchantBrokerFreeTestFixture,
\r
94 EnchantBrokerFree_DisposesProviders)
\r
96 enchant_broker_free(_broker);
\r
97 CHECK(disposeWasCalled);
\r
101 TEST_FIXTURE(EnchantBrokerFreeNoDisposeTestFixture,
\r
102 EnchantBrokerFree_ProviderLacksDispose)
\r
105 enchant_broker_free(_broker);
\r
109 /////////////////////////////////////////////////////////////////////////////
\r
110 // Test Error Conditions
\r
111 TEST_FIXTURE(EnchantBrokerFreeTestFixture,
\r
112 EnchantBrokerFree_NullBroker_DoNothing)
\r
114 enchant_broker_free(NULL);
\r
115 CHECK(!disposeWasCalled);
\r
118 TEST_FIXTURE(EnchantBrokerFreeTestFixture,
\r
119 EnchantBrokerFree_DictionaryNotFreed_FreesDictionary)
\r
121 EnchantDict* dict = enchant_broker_request_dict(_broker, "en_GB");
\r
123 CHECK(!disposeDictionaryCalled);
\r
125 enchant_broker_free(_broker);
\r
127 CHECK(disposeDictionaryCalled);
\r