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-provider.h>
\r
25 #include "../EnchantBrokerTestFixture.h"
\r
27 struct EnchantBrokerSetErrorTests : EnchantBrokerTestFixture
\r
30 EnchantBrokerSetErrorTests()
\r
32 provider = GetMockProvider();
\r
35 std::string GetErrorMessage(){
\r
36 char* error = enchant_broker_get_error(_broker);
\r
40 return std::string(error);
\r
43 EnchantProvider* provider;
\r
47 * enchant_provider_set_error
\r
48 * @provider: A non-null provider
\r
49 * @err: A non-null error message
\r
51 * Sets the current runtime error to @err. This API is private to
\r
55 /////////////////////////////////////////////////////////////////////////////
\r
56 // Test Normal Operation
\r
58 TEST_FIXTURE(EnchantBrokerSetErrorTests,
\r
59 SetErrorMessageOnProvider)
\r
61 std::string expectedErrorMessage("Error message to display");
\r
62 enchant_provider_set_error(provider, expectedErrorMessage.c_str());
\r
64 CHECK_EQUAL(expectedErrorMessage, GetErrorMessage());
\r
67 /////////////////////////////////////////////////////////////////////////////
\r
68 // Test Error Conditions
\r
69 TEST_FIXTURE(EnchantBrokerSetErrorTests,
\r
70 SetErrorMessageOnProvider_NullProvider_NoErrorSet)
\r
72 enchant_provider_set_error(NULL, "Error message to display");
\r
74 CHECK_EQUAL(std::string(), GetErrorMessage());
\r
77 TEST_FIXTURE(EnchantBrokerSetErrorTests,
\r
78 SetErrorMessageOnProvider_NullError_NoErrorSet)
\r
80 enchant_provider_set_error(provider, NULL);
\r
82 CHECK_EQUAL(std::string(), GetErrorMessage());
\r
85 TEST_FIXTURE(EnchantBrokerSetErrorTests,
\r
86 SetErrorMessageOnProvider_InvalidUtf8ErrorMessage_NoErrorSet)
\r
88 enchant_provider_set_error(provider, "\xa5\xf1\x08");
\r
90 CHECK_EQUAL(std::string(), GetErrorMessage());
\r
93 TEST_FIXTURE(EnchantBrokerSetErrorTests,
\r
94 SetErrorMessageOnProvider_MessageCopied)
\r
96 std::string expectedErrorMessage("Error message to display");
\r
97 enchant_provider_set_error(provider, expectedErrorMessage.c_str());
\r
99 expectedErrorMessage[0] = 'e';
\r
100 CHECK(expectedErrorMessage != GetErrorMessage());
\r