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 struct EnchantBrokerRequestPwlDictionary_TestFixture : EnchantBrokerTestFixture
\r
29 EnchantBrokerRequestPwlDictionary_TestFixture()
\r
32 _pwlFile = GetTemporaryFilename("epwl");
\r
36 ~EnchantBrokerRequestPwlDictionary_TestFixture()
\r
38 FreeDictionary(_dict);
\r
39 DeleteFile(_pwlFile);
\r
43 std::string _pwlFile;
\r
47 * enchant_broker_request_pwl_dict
\r
49 * PWL is a personal wordlist file, 1 entry per line
\r
55 /////////////////////////////////////////////////////////////////////////////
\r
56 // Test Normal Operation
\r
58 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture,
\r
59 EnchantBrokerRequestPwlDictionary_FileExists)
\r
61 CreateFile(_pwlFile);
\r
62 _dict = enchant_broker_request_pwl_dict(_broker, _pwlFile.c_str());
\r
66 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture,
\r
67 EnchantBrokerRequestPwlDictionary_FileDoesNotExist_SucceedsCreatesFile)
\r
69 _dict = enchant_broker_request_pwl_dict(_broker, _pwlFile.c_str());
\r
70 CHECK(FileExists(_pwlFile));
\r
74 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture,
\r
75 EnchantBrokerRequestPwlDictionary_CalledTwice_ReturnsSame)
\r
77 _dict = enchant_broker_request_pwl_dict(_broker, _pwlFile.c_str());
\r
78 EnchantDict* dict = enchant_broker_request_pwl_dict(_broker, _pwlFile.c_str());
\r
79 CHECK_EQUAL(_dict, dict);
\r
82 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture,
\r
83 EnchantBrokerRequestPwlDictionary_HasPreviousError_ErrorCleared)
\r
85 SetErrorOnMockProvider("something bad happened");
\r
87 _dict = enchant_broker_request_pwl_dict(_broker, _pwlFile.c_str());
\r
89 CHECK_EQUAL((void*)NULL, (void*)enchant_broker_get_error(_broker));
\r
94 /////////////////////////////////////////////////////////////////////////////
\r
95 // Test Error Conditions
\r
96 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture,
\r
97 EnchantBrokerRequestPwlDictionary_NullBroker_NULL)
\r
99 _dict = enchant_broker_request_pwl_dict(NULL, _pwlFile.c_str());
\r
101 CHECK_EQUAL((void*)NULL, (void*)_dict);
\r
104 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture,
\r
105 EnchantBrokerRequestPwlDictionary_NullFilename_NULL)
\r
107 _dict = enchant_broker_request_pwl_dict(_broker, NULL);
\r
109 CHECK_EQUAL((void*)NULL, (void*)_dict);
\r
112 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture,
\r
113 EnchantBrokerRequestPwlDictionary_EmptyFilename_NULL)
\r
115 _dict = enchant_broker_request_pwl_dict(_broker, "");
\r
117 CHECK_EQUAL((void*)NULL, _dict);
\r
120 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture,
\r
121 EnchantBrokerRequestPwlDictionary_IllegalFilename_NULL)
\r
123 // Colon is illegal for Windows and Mac but okay for Linux;
\r
124 #if defined(XP_TARGET_COCOA) || defined(_WIN32)
\r
125 _dict = enchant_broker_request_pwl_dict(_broker, ":");
\r
127 CHECK((void*)enchant_broker_get_error(_broker));
\r
131 #if defined(_WIN32)
\r
132 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture,
\r
133 EnchantBrokerRequestPwlDictionary_IllegalUtf8InFilename_NULL)
\r
135 _dict = enchant_broker_request_pwl_dict(_broker, "abc\xa5\xf1\x08");
\r