Tizen 2.1 base
[external/enchant.git] / unittests / broker / enchant_broker_request_pwl_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 struct EnchantBrokerRequestPwlDictionary_TestFixture : EnchantBrokerTestFixture\r
27 {\r
28     //Setup\r
29     EnchantBrokerRequestPwlDictionary_TestFixture()\r
30     { \r
31         _dict = NULL;\r
32         _pwlFile = GetTemporaryFilename("epwl");\r
33     }\r
34 \r
35     //Teardown\r
36     ~EnchantBrokerRequestPwlDictionary_TestFixture()\r
37     {\r
38         FreeDictionary(_dict);\r
39         DeleteFile(_pwlFile);\r
40     }\r
41 \r
42     EnchantDict* _dict;\r
43     std::string _pwlFile;\r
44 };\r
45 \r
46 /**\r
47  * enchant_broker_request_pwl_dict\r
48  *\r
49  * PWL is a personal wordlist file, 1 entry per line\r
50  *\r
51  * Returns: \r
52  */\r
53 \r
54 \r
55 /////////////////////////////////////////////////////////////////////////////\r
56 // Test Normal Operation\r
57 \r
58 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture, \r
59              EnchantBrokerRequestPwlDictionary_FileExists)\r
60 {\r
61     CreateFile(_pwlFile);\r
62     _dict = enchant_broker_request_pwl_dict(_broker, _pwlFile.c_str());\r
63     CHECK(_dict);\r
64 }\r
65 \r
66 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture, \r
67              EnchantBrokerRequestPwlDictionary_FileDoesNotExist_SucceedsCreatesFile)\r
68 {\r
69     _dict = enchant_broker_request_pwl_dict(_broker, _pwlFile.c_str());\r
70     CHECK(FileExists(_pwlFile));\r
71     CHECK(_dict);\r
72 }\r
73 \r
74 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture, \r
75              EnchantBrokerRequestPwlDictionary_CalledTwice_ReturnsSame)\r
76 {\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
80 }\r
81 \r
82 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture, \r
83              EnchantBrokerRequestPwlDictionary_HasPreviousError_ErrorCleared)\r
84 {\r
85   SetErrorOnMockProvider("something bad happened");\r
86 \r
87   _dict = enchant_broker_request_pwl_dict(_broker, _pwlFile.c_str());\r
88 \r
89   CHECK_EQUAL((void*)NULL, (void*)enchant_broker_get_error(_broker));\r
90 }\r
91 \r
92 \r
93 \r
94 /////////////////////////////////////////////////////////////////////////////\r
95 // Test Error Conditions\r
96 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture,\r
97              EnchantBrokerRequestPwlDictionary_NullBroker_NULL)\r
98 {\r
99     _dict = enchant_broker_request_pwl_dict(NULL, _pwlFile.c_str());\r
100 \r
101     CHECK_EQUAL((void*)NULL, (void*)_dict);\r
102 }\r
103 \r
104 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture,\r
105              EnchantBrokerRequestPwlDictionary_NullFilename_NULL)\r
106 {\r
107     _dict = enchant_broker_request_pwl_dict(_broker, NULL);\r
108 \r
109     CHECK_EQUAL((void*)NULL, (void*)_dict);\r
110 }\r
111 \r
112 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture,\r
113              EnchantBrokerRequestPwlDictionary_EmptyFilename_NULL)\r
114 {\r
115     _dict = enchant_broker_request_pwl_dict(_broker, "");\r
116 \r
117     CHECK_EQUAL((void*)NULL, _dict);\r
118 }\r
119 \r
120 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture,\r
121              EnchantBrokerRequestPwlDictionary_IllegalFilename_NULL)\r
122 {\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
126     CHECK(!_dict);\r
127     CHECK((void*)enchant_broker_get_error(_broker));\r
128 #endif\r
129 }\r
130 \r
131 #if defined(_WIN32)\r
132 TEST_FIXTURE(EnchantBrokerRequestPwlDictionary_TestFixture,\r
133              EnchantBrokerRequestPwlDictionary_IllegalUtf8InFilename_NULL)\r
134 {\r
135     _dict = enchant_broker_request_pwl_dict(_broker, "abc\xa5\xf1\x08");\r
136     CHECK(!_dict);\r
137 }\r
138 #endif\r