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> |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 21 | #include <stdarg.h> |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 22 | #include <stdio.h> |
| 23 | |
| 24 | #include "wine/test.h" |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 25 | #include "windef.h" |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 26 | #include "winbase.h" |
Francois Gouget | 4c31400 | 2002-05-23 02:40:07 +0000 | [diff] [blame] | 27 | #include "winerror.h" |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 28 | #include "winreg.h" |
| 29 | #include "winuser.h" |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 30 | #include "shlwapi.h" |
| 31 | |
Patrik Stridvall | 7e252cb | 2002-09-12 20:45:22 +0000 | [diff] [blame] | 32 | /* Keys used for testing */ |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 33 | #define REG_TEST_KEY "Software\\Wine\\Test" |
Paul Vriens | 361ee29 | 2005-01-17 15:45:44 +0000 | [diff] [blame] | 34 | #define REG_CURRENT_VERSION "Software\\Microsoft\\Windows\\CurrentVersion" |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 35 | |
Francois Gouget | 3a86019 | 2002-09-16 22:45:22 +0000 | [diff] [blame] | 36 | static HMODULE hshlwapi; |
| 37 | typedef DWORD (WINAPI *SHCopyKeyA_func)(HKEY,LPCSTR,HKEY,DWORD); |
| 38 | static SHCopyKeyA_func pSHCopyKeyA; |
| 39 | typedef DWORD (WINAPI *SHRegGetPathA_func)(HKEY,LPCSTR,LPCSTR,LPSTR,DWORD); |
| 40 | static SHRegGetPathA_func pSHRegGetPathA; |
| 41 | |
Daniel Marmier | 7e0ddbc | 2003-10-07 22:54:17 +0000 | [diff] [blame] | 42 | static const char * sTestpath1 = "%LONGSYSTEMVAR%\\subdir1"; |
| 43 | static const char * sTestpath2 = "%FOO%\\subdir1"; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 44 | |
Paul Vriens | a3d0eeb | 2005-01-31 11:29:59 +0000 | [diff] [blame] | 45 | static const char * sEnvvar1 = "bar"; |
| 46 | static const char * sEnvvar2 = "ImARatherLongButIndeedNeededString"; |
| 47 | |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 48 | static char sExpTestpath1[MAX_PATH]; |
| 49 | static char sExpTestpath2[MAX_PATH]; |
Eric Pouech | f320e74 | 2002-06-28 17:35:20 +0000 | [diff] [blame] | 50 | static unsigned sExpLen1; |
| 51 | static unsigned sExpLen2; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 52 | |
Daniel Marmier | 7e0ddbc | 2003-10-07 22:54:17 +0000 | [diff] [blame] | 53 | static const char * sEmptyBuffer ="0123456789"; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 54 | |
Alexandre Julliard | 3507999 | 2002-09-12 22:29:58 +0000 | [diff] [blame] | 55 | /* delete key and all its subkeys */ |
James Hawkins | 0fec65d | 2004-11-10 01:30:59 +0000 | [diff] [blame] | 56 | static DWORD delete_key( HKEY hkey, LPSTR parent, LPSTR keyname ) |
Alexandre Julliard | 3507999 | 2002-09-12 22:29:58 +0000 | [diff] [blame] | 57 | { |
James Hawkins | 0fec65d | 2004-11-10 01:30:59 +0000 | [diff] [blame] | 58 | HKEY parentKey; |
Alexandre Julliard | 3507999 | 2002-09-12 22:29:58 +0000 | [diff] [blame] | 59 | DWORD ret; |
| 60 | |
James Hawkins | 0fec65d | 2004-11-10 01:30:59 +0000 | [diff] [blame] | 61 | RegCloseKey(hkey); |
| 62 | |
| 63 | /* open the parent of the key to close */ |
Jon Griffiths | 1f79d57 | 2004-12-15 10:50:01 +0000 | [diff] [blame] | 64 | ret = RegOpenKeyExA( HKEY_CURRENT_USER, parent, 0, KEY_ALL_ACCESS, &parentKey); |
James Hawkins | 0fec65d | 2004-11-10 01:30:59 +0000 | [diff] [blame] | 65 | if (ret != ERROR_SUCCESS) |
| 66 | return ret; |
| 67 | |
Jon Griffiths | 1f79d57 | 2004-12-15 10:50:01 +0000 | [diff] [blame] | 68 | ret = SHDeleteKeyA( parentKey, keyname ); |
James Hawkins | 0fec65d | 2004-11-10 01:30:59 +0000 | [diff] [blame] | 69 | RegCloseKey(parentKey); |
| 70 | |
| 71 | return ret; |
Alexandre Julliard | 3507999 | 2002-09-12 22:29:58 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | static HKEY create_test_entries(void) |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 75 | { |
| 76 | HKEY hKey; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 77 | DWORD ret; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 78 | |
Paul Vriens | a3d0eeb | 2005-01-31 11:29:59 +0000 | [diff] [blame] | 79 | SetEnvironmentVariableA("LONGSYSTEMVAR", sEnvvar1); |
| 80 | SetEnvironmentVariableA("FOO", sEnvvar2); |
Eric Pouech | f320e74 | 2002-06-28 17:35:20 +0000 | [diff] [blame] | 81 | |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 82 | ret = RegCreateKeyA(HKEY_CURRENT_USER, REG_TEST_KEY, &hKey); |
| 83 | ok( ERROR_SUCCESS == ret, "RegCreateKeyA failed, ret=%lu\n", ret); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 84 | |
| 85 | if (hKey) |
| 86 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 87 | ok(!RegSetValueExA(hKey,"Test1",0,REG_EXPAND_SZ, sTestpath1, strlen(sTestpath1)+1), "RegSetValueExA failed\n"); |
| 88 | ok(!RegSetValueExA(hKey,"Test2",0,REG_SZ, sTestpath1, strlen(sTestpath1)+1), "RegSetValueExA failed\n"); |
| 89 | 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] | 90 | } |
| 91 | |
Eric Pouech | f320e74 | 2002-06-28 17:35:20 +0000 | [diff] [blame] | 92 | sExpLen1 = ExpandEnvironmentStringsA(sTestpath1, sExpTestpath1, sizeof(sExpTestpath1)); |
| 93 | sExpLen2 = ExpandEnvironmentStringsA(sTestpath2, sExpTestpath2, sizeof(sExpTestpath2)); |
| 94 | |
| 95 | ok(sExpLen1 > 0, "Couldn't expand %s\n", sTestpath1); |
Paul Vriens | 8933070 | 2005-02-03 19:38:58 +0000 | [diff] [blame] | 96 | trace("sExplen1 = (%d)\n", sExpLen1); |
Eric Pouech | f320e74 | 2002-06-28 17:35:20 +0000 | [diff] [blame] | 97 | ok(sExpLen2 > 0, "Couldn't expand %s\n", sTestpath2); |
Paul Vriens | 8933070 | 2005-02-03 19:38:58 +0000 | [diff] [blame] | 98 | trace("sExplen2 = (%d)\n", sExpLen2); |
| 99 | |
Alexandre Julliard | 3507999 | 2002-09-12 22:29:58 +0000 | [diff] [blame] | 100 | return hKey; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | static void test_SHGetValue(void) |
| 104 | { |
| 105 | DWORD dwSize; |
| 106 | DWORD dwType; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 107 | DWORD dwRet; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 108 | char buf[MAX_PATH]; |
| 109 | |
| 110 | strcpy(buf, sEmptyBuffer); |
| 111 | dwSize = MAX_PATH; |
| 112 | dwType = -1; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 113 | dwRet = SHGetValueA(HKEY_CURRENT_USER, REG_TEST_KEY, "Test1", &dwType, buf, &dwSize); |
| 114 | ok( ERROR_SUCCESS == dwRet, "SHGetValueA failed, ret=%lu\n", dwRet); |
| 115 | ok( 0 == strcmp(sExpTestpath1, buf), "Comparing of (%s) with (%s) failed\n", buf, sExpTestpath1); |
| 116 | ok( REG_SZ == dwType, "Expected REG_SZ, got (%lu)\n", dwType); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 117 | |
| 118 | strcpy(buf, sEmptyBuffer); |
| 119 | dwSize = MAX_PATH; |
| 120 | dwType = -1; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 121 | dwRet = SHGetValueA(HKEY_CURRENT_USER, REG_TEST_KEY, "Test2", &dwType, buf, &dwSize); |
| 122 | ok( ERROR_SUCCESS == dwRet, "SHGetValueA failed, ret=%lu\n", dwRet); |
| 123 | ok( 0 == strcmp(sTestpath1, buf) , "Comparing of (%s) with (%s) failed\n", buf, sTestpath1); |
| 124 | ok( REG_SZ == dwType , "Expected REG_SZ, got (%lu)\n", dwType); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 127 | static void test_SHGetRegPath(void) |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 128 | { |
| 129 | char buf[MAX_PATH]; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 130 | DWORD dwRet; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 131 | |
Francois Gouget | 3a86019 | 2002-09-16 22:45:22 +0000 | [diff] [blame] | 132 | if (!pSHRegGetPathA) |
| 133 | return; |
| 134 | |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 135 | strcpy(buf, sEmptyBuffer); |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 136 | dwRet = (*pSHRegGetPathA)(HKEY_CURRENT_USER, REG_TEST_KEY, "Test1", buf, 0); |
| 137 | ok( ERROR_SUCCESS == dwRet, "SHRegGetPathA failed, ret=%lu\n", dwRet); |
| 138 | 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] | 139 | } |
| 140 | |
| 141 | static void test_SHQUeryValueEx(void) |
| 142 | { |
| 143 | HKEY hKey; |
| 144 | DWORD dwSize; |
| 145 | DWORD dwType; |
| 146 | char buf[MAX_PATH]; |
| 147 | DWORD dwRet; |
Daniel Marmier | 7e0ddbc | 2003-10-07 22:54:17 +0000 | [diff] [blame] | 148 | const char * sTestedFunction = ""; |
Francois Gouget | 23aa0f6 | 2002-12-18 20:50:49 +0000 | [diff] [blame] | 149 | DWORD nUsedBuffer1,nUsedBuffer2; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 150 | |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 151 | sTestedFunction = "RegOpenKeyExA"; |
| 152 | dwRet = RegOpenKeyExA(HKEY_CURRENT_USER, REG_TEST_KEY, 0, KEY_QUERY_VALUE, &hKey); |
| 153 | ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%lu\n", sTestedFunction, dwRet); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 154 | |
| 155 | /****** SHQueryValueExA ******/ |
| 156 | |
| 157 | sTestedFunction = "SHQueryValueExA"; |
Alexandre Julliard | 63d29eb | 2002-08-09 01:14:23 +0000 | [diff] [blame] | 158 | nUsedBuffer1 = max(strlen(sExpTestpath1)+1, strlen(sTestpath1)+1); |
| 159 | nUsedBuffer2 = max(strlen(sExpTestpath2)+1, strlen(sTestpath2)+1); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 160 | /* |
| 161 | * Case 1.1 All arguments are NULL |
| 162 | */ |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 163 | dwRet = SHQueryValueExA( hKey, "Test1", NULL, NULL, NULL, NULL); |
| 164 | ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%lu\n", sTestedFunction, dwRet); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 165 | |
| 166 | /* |
| 167 | * Case 1.2 dwType is set |
| 168 | */ |
| 169 | dwType = -1; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 170 | dwRet = SHQueryValueExA( hKey, "Test1", NULL, &dwType, NULL, NULL); |
| 171 | ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%lu\n", sTestedFunction, dwRet); |
| 172 | ok( REG_SZ == dwType , "Expected REG_SZ, got (%lu)\n", dwType); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 173 | |
| 174 | /* |
| 175 | * dwSize is set |
| 176 | * dwExpanded < dwUnExpanded |
| 177 | */ |
| 178 | dwSize = 6; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 179 | dwRet = SHQueryValueExA( hKey, "Test1", NULL, NULL, NULL, &dwSize); |
| 180 | ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%lu\n", sTestedFunction, dwRet); |
| 181 | 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] | 182 | |
| 183 | /* |
| 184 | * dwExpanded > dwUnExpanded |
| 185 | */ |
| 186 | dwSize = 6; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 187 | dwRet = SHQueryValueExA( hKey, "Test3", NULL, NULL, NULL, &dwSize); |
| 188 | ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%lu\n", sTestedFunction, dwRet); |
| 189 | ok( dwSize >= nUsedBuffer2, "Buffer size (%lu) should be >= (%lu)\n", dwSize, nUsedBuffer2); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 190 | |
| 191 | /* |
| 192 | * Case 1 string shrinks during expanding |
| 193 | */ |
| 194 | strcpy(buf, sEmptyBuffer); |
| 195 | dwSize = 6; |
| 196 | dwType = -1; |
| 197 | dwRet = SHQueryValueExA( hKey, "Test1", NULL, &dwType, buf, &dwSize); |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 198 | ok( ERROR_MORE_DATA == dwRet, "Expected ERROR_MORE_DATA, got (%lu)\n", dwRet); |
| 199 | ok( 0 == strcmp(sEmptyBuffer, buf) , "Comparing (%s) with (%s) failed\n", buf, sEmptyBuffer); |
| 200 | ok( dwSize == nUsedBuffer1, "Buffer sizes (%lu) and (%lu) are not equal\n", dwSize, nUsedBuffer1); |
| 201 | ok( REG_SZ == dwType , "Expected REG_SZ, got (%lu)\n", dwType); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 202 | |
| 203 | /* |
| 204 | * string grows during expanding |
Paul Vriens | a3d0eeb | 2005-01-31 11:29:59 +0000 | [diff] [blame] | 205 | * dwSize is smaller then the size of the unexpanded string |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 206 | */ |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 207 | strcpy(buf, sEmptyBuffer); |
| 208 | dwSize = 6; |
| 209 | dwType = -1; |
| 210 | dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize); |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 211 | ok( ERROR_MORE_DATA == dwRet, "Expected ERROR_MORE_DATA, got (%lu)\n", dwRet); |
| 212 | ok( 0 == strcmp(sEmptyBuffer, buf) , "Comparing (%s) with (%s) failed\n", buf, sEmptyBuffer); |
| 213 | ok( dwSize >= nUsedBuffer2, "Buffer size (%lu) should be >= (%lu)\n", dwSize, nUsedBuffer2); |
| 214 | ok( REG_SZ == dwType , "Expected REG_SZ, got (%lu)\n", dwType); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 215 | |
Paul Vriens | a3d0eeb | 2005-01-31 11:29:59 +0000 | [diff] [blame] | 216 | /* |
| 217 | * string grows during expanding |
| 218 | * dwSize is larger then the size of the unexpanded string but smaller than the part before the backslash |
| 219 | * if the unexpanded string fits into the buffer it can get cut when expanded |
| 220 | */ |
| 221 | strcpy(buf, sEmptyBuffer); |
| 222 | dwSize = strlen(sEnvvar2) - 2; |
| 223 | dwType = -1; |
| 224 | dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize); |
| 225 | ok( ERROR_MORE_DATA == dwRet, "Expected ERROR_MORE_DATA, got (%lu)\n", dwRet); |
| 226 | |
| 227 | todo_wine |
| 228 | { |
| 229 | ok( (0 == strcmp("", buf)) | (0 == strcmp(sTestpath2, buf)), |
| 230 | "Expected empty or unexpanded string (win98), got (%s)\n", buf); |
| 231 | } |
| 232 | |
| 233 | ok( dwSize >= nUsedBuffer2, "Buffer size (%lu) should be >= (%lu)\n", dwSize, nUsedBuffer2); |
| 234 | ok( REG_SZ == dwType , "Expected REG_SZ, got (%lu)\n", dwType); |
| 235 | |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 236 | /* |
Paul Vriens | a3d0eeb | 2005-01-31 11:29:59 +0000 | [diff] [blame] | 237 | * string grows during expanding |
| 238 | * dwSize is larger then the size of the part before the backslash but smaller then the expanded string |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 239 | * if the unexpanded string fits into the buffer it can get cut when expanded |
| 240 | */ |
| 241 | strcpy(buf, sEmptyBuffer); |
Eric Pouech | f320e74 | 2002-06-28 17:35:20 +0000 | [diff] [blame] | 242 | dwSize = sExpLen2 - 4; |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 243 | dwType = -1; |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 244 | dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize); |
| 245 | ok( ERROR_MORE_DATA == dwRet, "Expected ERROR_MORE_DATA, got (%lu)\n", dwRet); |
Paul Vriens | a3d0eeb | 2005-01-31 11:29:59 +0000 | [diff] [blame] | 246 | |
| 247 | todo_wine |
| 248 | { |
| 249 | ok( (0 == strcmp("", buf)) | (0 == strcmp(sEnvvar2, buf)), |
Jakob Eriksson | a4fe0d6 | 2005-03-22 18:18:14 +0000 | [diff] [blame] | 250 | "Expected empty or first part of the string \"%s\", got \"%s\"\n", sEnvvar2, buf); |
Paul Vriens | a3d0eeb | 2005-01-31 11:29:59 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 253 | ok( dwSize >= nUsedBuffer2, "Buffer size (%lu) should be >= (%lu)\n", dwSize, nUsedBuffer2); |
| 254 | ok( REG_SZ == dwType , "Expected REG_SZ, got (%lu)\n", dwType); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 255 | |
| 256 | /* |
| 257 | * The buffer is NULL but the size is set |
| 258 | */ |
| 259 | strcpy(buf, sEmptyBuffer); |
| 260 | dwSize = 6; |
| 261 | dwType = -1; |
| 262 | dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, NULL, &dwSize); |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 263 | ok( ERROR_SUCCESS == dwRet, "%s failed, ret=%lu\n", sTestedFunction, dwRet); |
| 264 | ok( dwSize >= nUsedBuffer2, "Buffer size (%lu) should be >= (%lu)\n", dwSize, nUsedBuffer2); |
| 265 | ok( REG_SZ == dwType , "Expected REG_SZ, got (%lu)\n", dwType); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 266 | |
| 267 | RegCloseKey(hKey); |
| 268 | } |
| 269 | |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 270 | static void test_SHCopyKey(void) |
| 271 | { |
| 272 | HKEY hKeySrc, hKeyDst; |
Paul Vriens | 8933070 | 2005-02-03 19:38:58 +0000 | [diff] [blame] | 273 | DWORD dwRet; |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 274 | |
Patrik Stridvall | 7e252cb | 2002-09-12 20:45:22 +0000 | [diff] [blame] | 275 | /* Delete existing destination sub keys */ |
Francois Gouget | d2667a4 | 2002-12-02 18:10:57 +0000 | [diff] [blame] | 276 | hKeyDst = NULL; |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 277 | if (!RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\CopyDestination", &hKeyDst) && hKeyDst) |
| 278 | { |
| 279 | SHDeleteKeyA(hKeyDst, NULL); |
| 280 | RegCloseKey(hKeyDst); |
| 281 | } |
| 282 | |
Francois Gouget | d2667a4 | 2002-12-02 18:10:57 +0000 | [diff] [blame] | 283 | hKeyDst = NULL; |
Paul Vriens | 8933070 | 2005-02-03 19:38:58 +0000 | [diff] [blame] | 284 | dwRet = RegCreateKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\CopyDestination", &hKeyDst); |
| 285 | if (dwRet || !hKeyDst) |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 286 | { |
Paul Vriens | 8933070 | 2005-02-03 19:38:58 +0000 | [diff] [blame] | 287 | ok( 0, "Destination couldn't be created, RegCreateKeyA returned (%lu)\n", dwRet); |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 288 | return; |
| 289 | } |
| 290 | |
Francois Gouget | d2667a4 | 2002-12-02 18:10:57 +0000 | [diff] [blame] | 291 | hKeySrc = NULL; |
Paul Vriens | 8933070 | 2005-02-03 19:38:58 +0000 | [diff] [blame] | 292 | dwRet = RegOpenKeyA(HKEY_LOCAL_MACHINE, REG_CURRENT_VERSION, &hKeySrc); |
| 293 | if (dwRet || !hKeySrc) |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 294 | { |
Paul Vriens | 8933070 | 2005-02-03 19:38:58 +0000 | [diff] [blame] | 295 | ok( 0, "Source couldn't be opened, RegOpenKeyA returned (%lu)\n", dwRet); |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 296 | return; |
| 297 | } |
| 298 | |
| 299 | |
Francois Gouget | 3a86019 | 2002-09-16 22:45:22 +0000 | [diff] [blame] | 300 | if (pSHCopyKeyA) |
Paul Vriens | 8933070 | 2005-02-03 19:38:58 +0000 | [diff] [blame] | 301 | { |
| 302 | dwRet = (*pSHCopyKeyA)(hKeySrc, NULL, hKeyDst, 0); |
| 303 | ok ( ERROR_SUCCESS == dwRet, "Copy failed, ret=(%lu)\n", dwRet); |
| 304 | } |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 305 | |
| 306 | RegCloseKey(hKeySrc); |
| 307 | RegCloseKey(hKeyDst); |
| 308 | |
Paul Vriens | 361ee29 | 2005-01-17 15:45:44 +0000 | [diff] [blame] | 309 | /* 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] | 310 | hKeyDst = NULL; |
Paul Vriens | 8933070 | 2005-02-03 19:38:58 +0000 | [diff] [blame] | 311 | dwRet = RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\CopyDestination\\Setup", &hKeyDst); |
| 312 | if (dwRet || !hKeyDst) |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 313 | { |
Paul Vriens | 8933070 | 2005-02-03 19:38:58 +0000 | [diff] [blame] | 314 | ok ( 0, "Copy couldn't be opened, RegOpenKeyA returned (%lu)\n", dwRet); |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 315 | return; |
| 316 | } |
| 317 | |
| 318 | /* And the we copied the values too */ |
Paul Vriens | 361ee29 | 2005-01-17 15:45:44 +0000 | [diff] [blame] | 319 | ok(!SHQueryValueExA(hKeyDst, "BootDir", NULL, NULL, NULL, NULL), "SHQueryValueExA failed\n"); |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 320 | |
| 321 | RegCloseKey(hKeyDst); |
| 322 | } |
| 323 | |
Stefan Huehner | ac6f562 | 2005-06-20 14:18:03 +0000 | [diff] [blame^] | 324 | static void test_SHDeleteKey(void) |
Bill Medland | 3f3e292 | 2004-10-14 00:25:29 +0000 | [diff] [blame] | 325 | { |
Paul Vriens | 8933070 | 2005-02-03 19:38:58 +0000 | [diff] [blame] | 326 | HKEY hKeyTest, hKeyS; |
| 327 | DWORD dwRet; |
| 328 | int sysfail = 1; |
| 329 | |
Bill Medland | 3f3e292 | 2004-10-14 00:25:29 +0000 | [diff] [blame] | 330 | if (!RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY, &hKeyTest)) |
| 331 | { |
Bill Medland | 3f3e292 | 2004-10-14 00:25:29 +0000 | [diff] [blame] | 332 | if (!RegCreateKey(hKeyTest, "ODBC", &hKeyS)) |
| 333 | { |
| 334 | HKEY hKeyO; |
Paul Vriens | 8933070 | 2005-02-03 19:38:58 +0000 | [diff] [blame] | 335 | |
Bill Medland | 3f3e292 | 2004-10-14 00:25:29 +0000 | [diff] [blame] | 336 | if (!RegCreateKey(hKeyS, "ODBC.INI", &hKeyO)) |
| 337 | { |
| 338 | RegCloseKey (hKeyO); |
Paul Vriens | 8933070 | 2005-02-03 19:38:58 +0000 | [diff] [blame] | 339 | |
Bill Medland | 3f3e292 | 2004-10-14 00:25:29 +0000 | [diff] [blame] | 340 | if (!RegCreateKey(hKeyS, "ODBCINST.INI", &hKeyO)) |
| 341 | { |
| 342 | RegCloseKey (hKeyO); |
| 343 | sysfail = 0; |
| 344 | } |
| 345 | } |
| 346 | RegCloseKey (hKeyS); |
| 347 | } |
| 348 | RegCloseKey (hKeyTest); |
| 349 | } |
Paul Vriens | 8933070 | 2005-02-03 19:38:58 +0000 | [diff] [blame] | 350 | |
Bill Medland | 3f3e292 | 2004-10-14 00:25:29 +0000 | [diff] [blame] | 351 | if (!sysfail) |
| 352 | { |
Paul Vriens | 8933070 | 2005-02-03 19:38:58 +0000 | [diff] [blame] | 353 | |
| 354 | dwRet = SHDeleteKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\ODBC"); |
| 355 | ok ( ERROR_SUCCESS == dwRet, "SHDeleteKey failed, ret=(%lu)\n", dwRet); |
| 356 | |
| 357 | dwRet = RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\ODBC", &hKeyS); |
| 358 | ok ( ERROR_FILE_NOT_FOUND == dwRet, "SHDeleteKey did not delete\n"); |
| 359 | |
Bill Medland | 3f3e292 | 2004-10-14 00:25:29 +0000 | [diff] [blame] | 360 | if (dwRet == ERROR_SUCCESS) |
| 361 | RegCloseKey (hKeyS); |
| 362 | } |
| 363 | else |
Paul Vriens | 8933070 | 2005-02-03 19:38:58 +0000 | [diff] [blame] | 364 | ok( 0, "Could not set up SHDeleteKey test\n"); |
Bill Medland | 3f3e292 | 2004-10-14 00:25:29 +0000 | [diff] [blame] | 365 | } |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 366 | |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 367 | START_TEST(shreg) |
| 368 | { |
Alexandre Julliard | 3507999 | 2002-09-12 22:29:58 +0000 | [diff] [blame] | 369 | HKEY hkey = create_test_entries(); |
Paul Vriens | 14b9635 | 2005-01-21 16:18:00 +0000 | [diff] [blame] | 370 | |
| 371 | if (!hkey) return; |
| 372 | |
Francois Gouget | 3a86019 | 2002-09-16 22:45:22 +0000 | [diff] [blame] | 373 | hshlwapi = GetModuleHandleA("shlwapi.dll"); |
| 374 | if (hshlwapi) |
| 375 | { |
| 376 | pSHCopyKeyA=(SHCopyKeyA_func)GetProcAddress(hshlwapi,"SHCopyKeyA"); |
| 377 | pSHRegGetPathA=(SHRegGetPathA_func)GetProcAddress(hshlwapi,"SHRegGetPathA"); |
| 378 | } |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 379 | test_SHGetValue(); |
| 380 | test_SHQUeryValueEx(); |
Jon Griffiths | f5b34b5 | 2002-09-12 18:02:14 +0000 | [diff] [blame] | 381 | test_SHGetRegPath(); |
| 382 | test_SHCopyKey(); |
Bill Medland | 3f3e292 | 2004-10-14 00:25:29 +0000 | [diff] [blame] | 383 | test_SHDeleteKey(); |
James Hawkins | 0fec65d | 2004-11-10 01:30:59 +0000 | [diff] [blame] | 384 | delete_key( hkey, "Software\\Wine", "Test" ); |
Juergen Schmied | c74a791 | 2002-05-09 19:48:07 +0000 | [diff] [blame] | 385 | } |