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
24 #include "../EnchantTestFixture.h"
\r
26 struct EnchantGetRegistryValue_TestFixture : EnchantTestFixture{
\r
28 ~EnchantGetRegistryValue_TestFixture(){
\r
29 ClearRegistryValue(HKEY_CURRENT_USER, L"Software\\Enchant\\Test", L"Value");
\r
30 ClearRegistryValue(HKEY_LOCAL_MACHINE, L"Software\\Enchant\\Test", L"Value");
\r
33 void SetUserRegistryValue(const std::string& value)
\r
35 SetRegistryValue(HKEY_CURRENT_USER, L"Software\\Enchant\\Test", L"Value", value);
\r
38 void SetMachineRegistryValue(const std::string& value)
\r
40 SetRegistryValue(HKEY_LOCAL_MACHINE, L"Software\\Enchant\\Test", L"Value", value);
\r
46 * enchant_get_registry_value
\r
47 * @prefix: Your category, such as "Ispell" or "Myspell"
\r
48 * @key: The tag within your category that you're interested in
\r
50 * Returns: the value if it exists and is not an empty string ("") or %null otherwise. Must be free'd.
\r
52 * Choices: User Machine Result
\r
53 * "hello" "world" "hello"
\r
54 * "hello" NULL "hello"
\r
55 * "hello" "" "hello"
\r
56 * "" "world" "world"
\r
59 * NULL "world" "world"
\r
63 * This API is private to the providers.
\r
66 /////////////////////////////////////////////////////////////////////////////
\r
67 // Test Normal Operation
\r
69 TEST_FIXTURE(EnchantGetRegistryValue_TestFixture,
\r
70 GetRegistryValue_UserAndMachine_ValueFromUser)
\r
72 SetUserRegistryValue("hello");
\r
73 SetMachineRegistryValue("world");
\r
75 char * value = enchant_get_registry_value("Test", "Value");
\r
78 CHECK_EQUAL("hello", value);
\r
83 TEST_FIXTURE(EnchantGetRegistryValue_TestFixture,
\r
84 GetRegistryValue_UserOnly_ValueFromUser)
\r
86 SetUserRegistryValue("hello");
\r
87 char * value = enchant_get_registry_value("Test", "Value");
\r
90 CHECK_EQUAL("hello", value);
\r
95 TEST_FIXTURE(EnchantGetRegistryValue_TestFixture,
\r
96 GetRegistryValue_MachineOnly_ValueFromMachine)
\r
98 SetMachineRegistryValue("world");
\r
99 char * value = enchant_get_registry_value("Test", "Value");
\r
102 CHECK_EQUAL("world", value);
\r
107 TEST_FIXTURE(EnchantGetRegistryValue_TestFixture,
\r
108 GetRegistryValue_UserEmptyAndMachineSet_ValueFromMachine)
\r
110 SetUserRegistryValue("");
\r
111 SetMachineRegistryValue("world");
\r
113 char * value = enchant_get_registry_value("Test", "Value");
\r
116 CHECK_EQUAL("world", value);
\r
121 TEST_FIXTURE(EnchantGetRegistryValue_TestFixture,
\r
122 GetRegistryValue_UserEmptyAndMachineNotSet_Null)
\r
124 SetUserRegistryValue("");
\r
126 char * value = enchant_get_registry_value("Test", "Value");
\r
135 TEST(GetRegistryValue_None_NULL)
\r
137 char * value = enchant_get_registry_value("Test", "Value");
\r
139 CHECK(value == NULL);
\r
143 /////////////////////////////////////////////////////////////////////////////
\r
144 // Test Error Conditions
\r
145 TEST(GetRegistryValue_NullPrefix_NULL)
\r
147 char * value = enchant_get_registry_value(NULL, "Value");
\r
149 CHECK(value == NULL);
\r
152 TEST(GetRegistryValue_NullKey_NULL)
\r
154 char * value = enchant_get_registry_value("Test", NULL);
\r
156 CHECK(value == NULL);
\r
160 TEST_FIXTURE(EnchantGetRegistryValue_TestFixture,
\r
161 GetRegistryValue_NullPrefix_Null)
\r
163 SetUserRegistryValue("hello");
\r
165 char * value = enchant_get_registry_value(NULL, "Value");
\r
167 CHECK(value == NULL);
\r
170 TEST_FIXTURE(EnchantGetRegistryValue_TestFixture,
\r
171 GetRegistryValue_NullKey_Null)
\r
173 SetUserRegistryValue("hello");
\r
175 char * value = enchant_get_registry_value("Test", NULL);
\r
177 CHECK(value == NULL);
\r