Tizen 2.1 base
[external/enchant.git] / unittests / provider / enchant_provider_dict_set_error_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-provider.h>\r
24 #include "../EnchantDictionaryTestFixture.h"\r
25 \r
26 struct EnchantDictionarySetErrorTests : EnchantDictionaryTestFixture\r
27 {\r
28   //Setup\r
29   std::string GetErrorMessage(){\r
30       char* error = enchant_dict_get_error(_dict);\r
31       if(error == NULL){\r
32           error = "";\r
33       }\r
34       return std::string(error);\r
35   }\r
36 };\r
37 \r
38 /**\r
39  * enchant_dict_set_error\r
40  * @dict: A non-null dictionary\r
41  * @err: A non-null error message\r
42  *\r
43  * Sets the current runtime error to @err. This API is private to the\r
44  * providers.\r
45  */\r
46 \r
47 /////////////////////////////////////////////////////////////////////////////\r
48 // Test Normal Operation\r
49 \r
50 TEST_FIXTURE(EnchantDictionarySetErrorTests, \r
51              SetErrorMessageOnDictionary)\r
52 {\r
53     std::string expectedErrorMessage("Error message to display");\r
54     enchant_dict_set_error(_dict, expectedErrorMessage.c_str());\r
55 \r
56     CHECK_EQUAL(expectedErrorMessage, GetErrorMessage());\r
57 }\r
58 \r
59 /////////////////////////////////////////////////////////////////////////////\r
60 // Test Error Conditions\r
61 TEST_FIXTURE(EnchantDictionarySetErrorTests, \r
62              SetErrorMessageOnDictionary_NullDictionary_NoErrorSet)\r
63 {\r
64     enchant_dict_set_error(NULL, "Error message to display");\r
65 \r
66     CHECK_EQUAL(std::string(), GetErrorMessage());\r
67 }\r
68 \r
69 TEST_FIXTURE(EnchantDictionarySetErrorTests, \r
70              SetErrorMessageOnDictionary_NullError_NoErrorSet)\r
71 {\r
72     enchant_dict_set_error(_dict, NULL);\r
73 \r
74     CHECK_EQUAL(std::string(), GetErrorMessage());\r
75 }\r
76 \r
77 TEST_FIXTURE(EnchantDictionarySetErrorTests,\r
78              SetErrorMessageOnDictionary_InvalidUtf8ErrorMessage_NoErrorSet)\r
79 {\r
80     enchant_dict_set_error(_dict, "\xa5\xf1\x08");\r
81 \r
82     CHECK_EQUAL(std::string(), GetErrorMessage());\r
83 }\r
84 \r
85 TEST_FIXTURE(EnchantDictionarySetErrorTests, \r
86              SetErrorMessageOnDictionary_MessageCopied)\r
87 {\r
88     std::string expectedErrorMessage("Error message to display");\r
89     enchant_dict_set_error(_dict, expectedErrorMessage.c_str());\r
90 \r
91     expectedErrorMessage[0] = 'e';\r
92     CHECK(expectedErrorMessage != GetErrorMessage());\r
93 }