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