Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1 | /* Unit test suite for SHReg* functions |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 2 | * |
| 3 | * Copyright 2002 Juergen Schmied |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | |
| 20 | #include <assert.h> |
| 21 | #include <stdlib.h> |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 22 | #include <stdarg.h> |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 23 | #include <stdio.h> |
| 24 | |
| 25 | #include "wine/test.h" |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 26 | #include "windef.h" |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 27 | #include "winbase.h" |
Francois Gouget | 4c31400 | 2002-05-23 02:40:07 +0000 | [diff] [blame] | 28 | #include "winerror.h" |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 29 | #include "winreg.h" |
| 30 | #include "winuser.h" |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 31 | #include "shlwapi.h" |
| 32 | |
Patrik Stridvall | 7e252cb | 2002-09-12 20:45:22 +0000 | [diff] [blame] | 33 | /* Keys used for testing */ |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 34 | #define REG_TEST_KEY "Software\\Wine\\Test" |
Paul Vriens | 361ee29 | 2005-01-17 15:45:44 +0000 | [diff] [blame] | 35 | #define REG_CURRENT_VERSION "Software\\Microsoft\\Windows\\CurrentVersion" |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 36 | |
Francois Gouget | 3a86019 | 2002-09-16 22:45:22 +0000 | [diff] [blame] | 37 | static HMODULE hshlwapi; |
| 38 | typedef DWORD (WINAPI *SHCopyKeyA_func)(HKEY,LPCSTR,HKEY,DWORD); |
| 39 | static SHCopyKeyA_func pSHCopyKeyA; |
| 40 | typedef DWORD (WINAPI *SHRegGetPathA_func)(HKEY,LPCSTR,LPCSTR,LPSTR,DWORD); |
| 41 | static SHRegGetPathA_func pSHRegGetPathA; |
| 42 | |
Daniel Marmier | 7e0ddbc | 2003-10-07 22:54:17 +0000 | [diff] [blame] | 43 | static const char * sTestpath1 = "%LONGSYSTEMVAR%\\subdir1"; |
| 44 | static const char * sTestpath2 = "%FOO%\\subdir1"; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 45 | |
| 46 | static char sExpTestpath1[MAX_PATH]; |
| 47 | static char sExpTestpath2[MAX_PATH]; |
Eric Pouech | f320e74 | 2002-06-28 17:35:20 +0000 | [diff] [blame] | 48 | static unsigned sExpLen1; |
| 49 | static unsigned sExpLen2; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 50 | |
Daniel Marmier | 7e0ddbc | 2003-10-07 22:54:17 +0000 | [diff] [blame] | 51 | static const char * sEmptyBuffer ="0123456789"; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 52 | |
Alexandre Julliard | 3507999 | 2002-09-12 22:29:58 +0000 | [diff] [blame] | 53 | /* delete key and all its subkeys */ |
James Hawkins | 0fec65d | 2004-11-10 01:30:59 +0000 | [diff] [blame] | 54 | static DWORD delete_key( HKEY hkey, LPSTR parent, LPSTR keyname ) |
Alexandre Julliard | 3507999 | 2002-09-12 22:29:58 +0000 | [diff] [blame] | 55 | { |
James Hawkins | 0fec65d | 2004-11-10 01:30:59 +0000 | [diff] [blame] | 56 | HKEY parentKey; |
Alexandre Julliard | 3507999 | 2002-09-12 22:29:58 +0000 | [diff] [blame] | 57 | DWORD ret; |
| 58 | |
James Hawkins | 0fec65d | 2004-11-10 01:30:59 +0000 | [diff] [blame] | 59 | RegCloseKey(hkey); |
| 60 | |
| 61 | /* open the parent of the key to close */ |
Jon Griffiths | 1f79d57 | 2004-12-15 10:50:01 +0000 | [diff] [blame] | 62 | ret = RegOpenKeyExA( HKEY_CURRENT_USER, parent, 0, KEY_ALL_ACCESS, &parentKey); |
James Hawkins | 0fec65d | 2004-11-10 01:30:59 +0000 | [diff] [blame] | 63 | if (ret != ERROR_SUCCESS) |
| 64 | return ret; |
| 65 | |
Jon Griffiths | 1f79d57 | 2004-12-15 10:50:01 +0000 | [diff] [blame] | 66 | ret = SHDeleteKeyA( parentKey, keyname ); |
James Hawkins | 0fec65d | 2004-11-10 01:30:59 +0000 | [diff] [blame] | 67 | RegCloseKey(parentKey); |
| 68 | |
| 69 | return ret; |
Alexandre Julliard | 3507999 | 2002-09-12 22:29:58 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | static HKEY create_test_entries(void) |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 73 | { |
| 74 | HKEY hKey; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame^] | 75 | DWORD ret; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 76 | |
Eric Pouech | f320e74 | 2002-06-28 17:35:20 +0000 | [diff] [blame] | 77 | SetEnvironmentVariableA("LONGSYSTEMVAR", "bar"); |
| 78 | SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString"); |
| 79 | |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame^] | 80 | ret = RegCreateKeyA(HKEY_CURRENT_USER, REG_TEST_KEY, &hKey); |
| 81 | ok( ERROR_SUCCESS == ret, "RegCreateKeyA failed, ret=%lu\n", ret); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 82 | |
| 83 | if (hKey) |
| 84 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 85 | ok(!RegSetValueExA(hKey,"Test1",0,REG_EXPAND_SZ, sTestpath1, strlen(sTestpath1)+1), "RegSetValueExA failed\n"); |
| 86 | ok(!RegSetValueExA(hKey,"Test2",0,REG_SZ, sTestpath1, strlen(sTestpath1)+1), "RegSetValueExA failed\n"); |
| 87 | ok(!RegSetValueExA(hKey,"Test3",0,REG_EXPAND_SZ, sTestpath2, strlen(sTestpath2)+1), "RegSetValueExA failed\n"); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Eric Pouech | f320e74 | 2002-06-28 17:35:20 +0000 | [diff] [blame] | 90 | sExpLen1 = ExpandEnvironmentStringsA(sTestpath1, sExpTestpath1, sizeof(sExpTestpath1)); |
| 91 | sExpLen2 = ExpandEnvironmentStringsA(sTestpath2, sExpTestpath2, sizeof(sExpTestpath2)); |
| 92 | |
| 93 | ok(sExpLen1 > 0, "Couldn't expand %s\n", sTestpath1); |
| 94 | ok(sExpLen2 > 0, "Couldn't expand %s\n", sTestpath2); |
Alexandre Julliard | 3507999 | 2002-09-12 22:29:58 +0000 | [diff] [blame] | 95 | return hKey; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | static void test_SHGetValue(void) |
| 99 | { |
| 100 | DWORD dwSize; |
| 101 | DWORD dwType; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame^] | 102 | DWORD dwRet; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 103 | char buf[MAX_PATH]; |
| 104 | |
| 105 | strcpy(buf, sEmptyBuffer); |
| 106 | dwSize = MAX_PATH; |
| 107 | dwType = -1; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame^] | 108 | dwRet = SHGetValueA(HKEY_CURRENT_USER, REG_TEST_KEY, "Test1", &dwType, buf, &dwSize); |
| 109 | ok( ERROR_SUCCESS == dwRet, "SHGetValueA failed, ret=%lu\n", dwRet); |
| 110 | ok( 0 == strcmp(sExpTestpath1, buf), "Comparing of (%s) with (%s) failed\n", buf, sExpTestpath1); |
| 111 | ok( REG_SZ == dwType, "Expected REG_SZ, got (%lu)\n", dwType); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 112 | |
| 113 | strcpy(buf, sEmptyBuffer); |
| 114 | dwSize = MAX_PATH; |
| 115 | dwType = -1; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame^] | 116 | dwRet = SHGetValueA(HKEY_CURRENT_USER, REG_TEST_KEY, "Test2", &dwType, buf, &dwSize); |
| 117 | ok( ERROR_SUCCESS == dwRet, "SHGetValueA failed, ret=%lu\n", dwRet); |
| 118 | ok( 0 == strcmp(sTestpath1, buf) , "Comparing of (%s) with (%s) failed\n", buf, sTestpath1); |
| 119 | ok( REG_SZ == dwType , "Expected REG_SZ, got (%lu)\n", dwType); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 122 | static void test_SHGetRegPath(void) |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 123 | { |
| 124 | char buf[MAX_PATH]; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame^] | 125 | DWORD dwRet; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 126 | |
Francois Gouget | 3a86019 | 2002-09-16 22:45:22 +0000 | [diff] [blame] | 127 | if (!pSHRegGetPathA) |
| 128 | return; |
| 129 | |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 130 | strcpy(buf, sEmptyBuffer); |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame^] | 131 | dwRet = (*pSHRegGetPathA)(HKEY_CURRENT_USER, REG_TEST_KEY, "Test1", buf, 0); |
| 132 | ok( ERROR_SUCCESS == dwRet, "SHRegGetPathA failed, ret=%lu\n", dwRet); |
| 133 | ok( 0 == strcmp(sExpTestpath1, buf) , "Comparing (%s) with (%s) failed\n", buf, sExpTestpath1); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static void test_SHQUeryValueEx(void) |
| 137 | { |
| 138 | HKEY hKey; |
| 139 | DWORD dwSize; |
| 140 | DWORD dwType; |
| 141 | char buf[MAX_PATH]; |
| 142 | DWORD dwRet; |
Daniel Marmier | 7e0ddbc | 2003-10-07 22:54:17 +0000 | [diff] [blame] | 143 | const char * sTestedFunction = ""; |
Francois Gouget | 23aa0f6 | 2002-12-18 20:50:49 +0000 | [diff] [blame] | 144 | DWORD nUsedBuffer1,nUsedBuffer2; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 145 | |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame^] | 146 | sTestedFunction = "RegOpenKeyExA"; |
| 147 | dwRet = RegOpenKeyExA(HKEY_CURRENT_USER, REG_TEST_KEY, 0, KEY_QUERY_VALUE, &hKey); |
| 148 | ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%lu\n", sTestedFunction, dwRet); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 149 | |
| 150 | /****** SHQueryValueExA ******/ |
| 151 | |
| 152 | sTestedFunction = "SHQueryValueExA"; |
Alexandre Julliard | 63d29eb | 2002-08-09 01:14:23 +0000 | [diff] [blame] | 153 | nUsedBuffer1 = max(strlen(sExpTestpath1)+1, strlen(sTestpath1)+1); |
| 154 | nUsedBuffer2 = max(strlen(sExpTestpath2)+1, strlen(sTestpath2)+1); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 155 | /* |
| 156 | * Case 1.1 All arguments are NULL |
| 157 | */ |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame^] | 158 | dwRet = SHQueryValueExA( hKey, "Test1", NULL, NULL, NULL, NULL); |
| 159 | ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%lu\n", sTestedFunction, dwRet); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 160 | |
| 161 | /* |
| 162 | * Case 1.2 dwType is set |
| 163 | */ |
| 164 | dwType = -1; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame^] | 165 | dwRet = SHQueryValueExA( hKey, "Test1", NULL, &dwType, NULL, NULL); |
| 166 | ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%lu\n", sTestedFunction, dwRet); |
| 167 | ok( REG_SZ == dwType , "Expected REG_SZ, got (%lu)\n", dwType); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 168 | |
| 169 | /* |
| 170 | * dwSize is set |
| 171 | * dwExpanded < dwUnExpanded |
| 172 | */ |
| 173 | dwSize = 6; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame^] | 174 | dwRet = SHQueryValueExA( hKey, "Test1", NULL, NULL, NULL, &dwSize); |
| 175 | ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%lu\n", sTestedFunction, dwRet); |
| 176 | ok( dwSize == nUsedBuffer1, "Buffer sizes (%lu) and (%lu) are not equal\n", dwSize, nUsedBuffer1); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 177 | |
| 178 | /* |
| 179 | * dwExpanded > dwUnExpanded |
| 180 | */ |
| 181 | dwSize = 6; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame^] | 182 | dwRet = SHQueryValueExA( hKey, "Test3", NULL, NULL, NULL, &dwSize); |
| 183 | ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%lu\n", sTestedFunction, dwRet); |
| 184 | ok( dwSize >= nUsedBuffer2, "Buffer size (%lu) should be >= (%lu)\n", dwSize, nUsedBuffer2); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 185 | |
| 186 | /* |
| 187 | * Case 1 string shrinks during expanding |
| 188 | */ |
| 189 | strcpy(buf, sEmptyBuffer); |
| 190 | dwSize = 6; |
| 191 | dwType = -1; |
| 192 | dwRet = SHQueryValueExA( hKey, "Test1", NULL, &dwType, buf, &dwSize); |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame^] | 193 | ok( ERROR_MORE_DATA == dwRet, "Expected ERROR_MORE_DATA, got (%lu)\n", dwRet); |
| 194 | ok( 0 == strcmp(sEmptyBuffer, buf) , "Comparing (%s) with (%s) failed\n", buf, sEmptyBuffer); |
| 195 | ok( dwSize == nUsedBuffer1, "Buffer sizes (%lu) and (%lu) are not equal\n", dwSize, nUsedBuffer1); |
| 196 | ok( REG_SZ == dwType , "Expected REG_SZ, got (%lu)\n", dwType); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 197 | |
| 198 | /* |
| 199 | * string grows during expanding |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 200 | */ |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 201 | strcpy(buf, sEmptyBuffer); |
| 202 | dwSize = 6; |
| 203 | dwType = -1; |
| 204 | dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize); |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame^] | 205 | ok( ERROR_MORE_DATA == dwRet, "Expected ERROR_MORE_DATA, got (%lu)\n", dwRet); |
| 206 | ok( 0 == strcmp(sEmptyBuffer, buf) , "Comparing (%s) with (%s) failed\n", buf, sEmptyBuffer); |
| 207 | ok( dwSize >= nUsedBuffer2, "Buffer size (%lu) should be >= (%lu)\n", dwSize, nUsedBuffer2); |
| 208 | ok( REG_SZ == dwType , "Expected REG_SZ, got (%lu)\n", dwType); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 209 | |
| 210 | /* |
| 211 | * if the unexpanded string fits into the buffer it can get cut when expanded |
| 212 | */ |
| 213 | strcpy(buf, sEmptyBuffer); |
Eric Pouech | f320e74 | 2002-06-28 17:35:20 +0000 | [diff] [blame] | 214 | dwSize = sExpLen2 - 4; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 215 | dwType = -1; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame^] | 216 | dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize); |
| 217 | ok( ERROR_MORE_DATA == dwRet, "Expected ERROR_MORE_DATA, got (%lu)\n", dwRet); |
| 218 | ok( 0 == strncmp(sExpTestpath2, buf, sExpLen2 - 4 - 1), "Comparing the first (%d) bytes of (%s) and (%s) failed\n", sExpLen2 - 4 - 1, buf, sExpTestpath2); |
| 219 | ok( sExpLen2 - 4 - 1 == strlen(buf), "Expected strlen(%s) to be %d instead of %d\n", buf, sExpLen2 - 4 - 1, strlen(buf)); |
| 220 | ok( dwSize >= nUsedBuffer2, "Buffer size (%lu) should be >= (%lu)\n", dwSize, nUsedBuffer2); |
| 221 | ok( REG_SZ == dwType , "Expected REG_SZ, got (%lu)\n", dwType); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 222 | |
| 223 | /* |
| 224 | * The buffer is NULL but the size is set |
| 225 | */ |
| 226 | strcpy(buf, sEmptyBuffer); |
| 227 | dwSize = 6; |
| 228 | dwType = -1; |
| 229 | dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, NULL, &dwSize); |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame^] | 230 | ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%lu\n", sTestedFunction, dwRet); |
| 231 | ok( dwSize >= nUsedBuffer2, "Buffer size (%lu) should be >= (%lu)\n", dwSize, nUsedBuffer2); |
| 232 | ok( REG_SZ == dwType , "Expected REG_SZ, got (%lu)\n", dwType); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 233 | |
| 234 | RegCloseKey(hKey); |
| 235 | } |
| 236 | |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 237 | static void test_SHCopyKey(void) |
| 238 | { |
| 239 | HKEY hKeySrc, hKeyDst; |
| 240 | |
Patrik Stridvall | 7e252cb | 2002-09-12 20:45:22 +0000 | [diff] [blame] | 241 | /* Delete existing destination sub keys */ |
Francois Gouget | d2667a4 | 2002-12-02 18:10:57 +0000 | [diff] [blame] | 242 | hKeyDst = NULL; |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 243 | if (!RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\CopyDestination", &hKeyDst) && hKeyDst) |
| 244 | { |
| 245 | SHDeleteKeyA(hKeyDst, NULL); |
| 246 | RegCloseKey(hKeyDst); |
| 247 | } |
| 248 | |
Francois Gouget | d2667a4 | 2002-12-02 18:10:57 +0000 | [diff] [blame] | 249 | hKeyDst = NULL; |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 250 | if (RegCreateKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\CopyDestination", &hKeyDst) || !hKeyDst) |
| 251 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 252 | ok(0, "didn't open dest\n"); |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 253 | return; |
| 254 | } |
| 255 | |
Francois Gouget | d2667a4 | 2002-12-02 18:10:57 +0000 | [diff] [blame] | 256 | hKeySrc = NULL; |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 257 | if (RegOpenKeyA(HKEY_LOCAL_MACHINE, REG_CURRENT_VERSION, &hKeySrc) || !hKeySrc) |
| 258 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 259 | ok(0, "didn't open source\n"); |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 260 | return; |
| 261 | } |
| 262 | |
| 263 | |
Francois Gouget | 3a86019 | 2002-09-16 22:45:22 +0000 | [diff] [blame] | 264 | if (pSHCopyKeyA) |
Paul Vriens | 7e8c096 | 2005-01-17 15:33:00 +0000 | [diff] [blame] | 265 | ok (!(*pSHCopyKeyA)(hKeySrc, NULL, hKeyDst, 0), "failed copy\n"); |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 266 | |
| 267 | RegCloseKey(hKeySrc); |
| 268 | RegCloseKey(hKeyDst); |
| 269 | |
Paul Vriens | 361ee29 | 2005-01-17 15:45:44 +0000 | [diff] [blame] | 270 | /* Check we copied the sub keys, i.e. something that's on every windows system (including Wine) */ |
Francois Gouget | d2667a4 | 2002-12-02 18:10:57 +0000 | [diff] [blame] | 271 | hKeyDst = NULL; |
Paul Vriens | 361ee29 | 2005-01-17 15:45:44 +0000 | [diff] [blame] | 272 | if (RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\CopyDestination\\Setup", &hKeyDst) || !hKeyDst) |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 273 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 274 | ok(0, "didn't open copy\n"); |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 275 | return; |
| 276 | } |
| 277 | |
| 278 | /* And the we copied the values too */ |
Paul Vriens | 361ee29 | 2005-01-17 15:45:44 +0000 | [diff] [blame] | 279 | ok(!SHQueryValueExA(hKeyDst, "BootDir", NULL, NULL, NULL, NULL), "SHQueryValueExA failed\n"); |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 280 | |
| 281 | RegCloseKey(hKeyDst); |
| 282 | } |
| 283 | |
Bill Medland | 3f3e292 | 2004-10-14 00:25:29 +0000 | [diff] [blame] | 284 | static void test_SHDeleteKey() |
| 285 | { |
| 286 | HKEY hKeyTest; |
| 287 | int sysfail=1; |
| 288 | if (!RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY, &hKeyTest)) |
| 289 | { |
| 290 | HKEY hKeyS; |
| 291 | if (!RegCreateKey(hKeyTest, "ODBC", &hKeyS)) |
| 292 | { |
| 293 | HKEY hKeyO; |
| 294 | if (!RegCreateKey(hKeyS, "ODBC.INI", &hKeyO)) |
| 295 | { |
| 296 | RegCloseKey (hKeyO); |
| 297 | if (!RegCreateKey(hKeyS, "ODBCINST.INI", &hKeyO)) |
| 298 | { |
| 299 | RegCloseKey (hKeyO); |
| 300 | sysfail = 0; |
| 301 | } |
| 302 | } |
| 303 | RegCloseKey (hKeyS); |
| 304 | } |
| 305 | RegCloseKey (hKeyTest); |
| 306 | } |
| 307 | if (!sysfail) |
| 308 | { |
| 309 | HKEY hKeyS; |
| 310 | DWORD dwRet; |
Jon Griffiths | bcf4392 | 2005-01-03 14:36:47 +0000 | [diff] [blame] | 311 | ok (!SHDeleteKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\ODBC"), "SHDeleteKey failed\n"); |
| 312 | ok ((dwRet = RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\ODBC", &hKeyS)) == ERROR_FILE_NOT_FOUND, "SHDeleteKey did not delete\n"); |
Bill Medland | 3f3e292 | 2004-10-14 00:25:29 +0000 | [diff] [blame] | 313 | if (dwRet == ERROR_SUCCESS) |
| 314 | RegCloseKey (hKeyS); |
| 315 | } |
| 316 | else |
| 317 | ok (0, "Could not set up SHDeleteKey test\n"); |
| 318 | } |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 319 | |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 320 | START_TEST(shreg) |
| 321 | { |
Alexandre Julliard | 3507999 | 2002-09-12 22:29:58 +0000 | [diff] [blame] | 322 | HKEY hkey = create_test_entries(); |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame^] | 323 | |
| 324 | if (!hkey) return; |
| 325 | |
Francois Gouget | 3a86019 | 2002-09-16 22:45:22 +0000 | [diff] [blame] | 326 | hshlwapi = GetModuleHandleA("shlwapi.dll"); |
| 327 | if (hshlwapi) |
| 328 | { |
| 329 | pSHCopyKeyA=(SHCopyKeyA_func)GetProcAddress(hshlwapi,"SHCopyKeyA"); |
| 330 | pSHRegGetPathA=(SHRegGetPathA_func)GetProcAddress(hshlwapi,"SHRegGetPathA"); |
| 331 | } |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 332 | test_SHGetValue(); |
| 333 | test_SHQUeryValueEx(); |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 334 | test_SHGetRegPath(); |
| 335 | test_SHCopyKey(); |
Bill Medland | 3f3e292 | 2004-10-14 00:25:29 +0000 | [diff] [blame] | 336 | test_SHDeleteKey(); |
James Hawkins | 0fec65d | 2004-11-10 01:30:59 +0000 | [diff] [blame] | 337 | delete_key( hkey, "Software\\Wine", "Test" ); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 338 | } |