So, what do you think? It's not yet commited, should I start being in despair? :-)
----- Forwarded message from Jakob Eriksson jakob@vmlinux.org -----
From: Jakob Eriksson jakob@vmlinux.org To: wine-patches@winehq.com Subject: Fixes to dlls/shlwapi/tests/ Date: Thu, 25 Sep 2003 03:44:11 +0200
Fixes to dlls/shlwapi/tests/shreg.c
Fixes a hang bug which appears when running shlwapi shreg test on Windows XP.
Also fixes a broken test for SHCopyKey, which did not work on neither XP, NT nor Wine. Now it works on NT and XP.
Plus four off-by-one fixes where NT and XP differs.
regards, Jakob
Index: shreg.c =================================================================== RCS file: /home/wine/wine/dlls/shlwapi/tests/shreg.c,v retrieving revision 1.13 diff -u -r1.13 shreg.c --- shreg.c 5 Sep 2003 23:08:30 -0000 1.13 +++ shreg.c 25 Sep 2003 01:39:31 -0000 @@ -32,9 +32,9 @@
/* Keys used for testing */ #define REG_TEST_KEY "Software\Wine\Test" +#define REG_SRC_KEY "Software\Wine\ToBeCopied" #define REG_CURRENT_VERSION "Software\Microsoft\Windows NT\CurrentVersion"
-static HMODULE hshlwapi; typedef DWORD (WINAPI *SHCopyKeyA_func)(HKEY,LPCSTR,HKEY,DWORD); static SHCopyKeyA_func pSHCopyKeyA; typedef DWORD (WINAPI *SHRegGetPathA_func)(HKEY,LPCSTR,LPCSTR,LPSTR,DWORD); @@ -50,35 +50,14 @@
static char * sEmptyBuffer ="0123456789";
-/* delete key and all its subkeys */ -static DWORD delete_key( HKEY hkey ) -{ - WCHAR name[MAX_PATH]; - DWORD ret; - - while (!(ret = RegEnumKeyW(hkey, 0, name, sizeof(name)))) - { - HKEY tmp; - if (!(ret = RegOpenKeyExW( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp ))) - { - ret = delete_key( tmp ); - RegCloseKey( tmp ); - } - if (ret) break; - } - if (ret != ERROR_NO_MORE_ITEMS) return ret; - RegDeleteKeyA( hkey, NULL ); - return 0; -} - -static HKEY create_test_entries(void) +static HKEY create_test_entries( const char *prefix ) { HKEY hKey;
SetEnvironmentVariableA("LONGSYSTEMVAR", "bar"); SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
- ok(!RegCreateKeyA(HKEY_CURRENT_USER, REG_TEST_KEY, &hKey), "RegCreateKeyA failed"); + ok( !RegCreateKeyA( HKEY_CURRENT_USER, prefix, &hKey ), "RegCreateKeyA failed" );
if (hKey) { @@ -170,7 +149,11 @@ */ dwSize = 6; ok(! SHQueryValueExA( hKey, "Test3", NULL, NULL, NULL, &dwSize), "SHQueryValueExA failed"); - ok( dwSize == nUsedBuffer2, "(%lu,%lu)", dwSize, nUsedBuffer2); + ok( + dwSize == nUsedBuffer2 || + (dwSize - 1) == nUsedBuffer2, /* Windows XP sp1 */ + "(%lu,%lu)" , dwSize, nUsedBuffer2 + );
/* @@ -194,7 +177,12 @@ dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize); ok( ERROR_MORE_DATA == dwRet, "ERROR_MORE_DATA"); ok( 0 == strcmp(sEmptyBuffer, buf), "(%s)", buf); - ok( dwSize == nUsedBuffer2, "(%lu,%lu)" , dwSize, nUsedBuffer2); + ok( + dwSize == nUsedBuffer2 || + (dwSize - 1) == nUsedBuffer2, /* Windows XP sp1 */ + "(%lu,%lu)" , dwSize, nUsedBuffer2 + ); + ok( dwType == REG_SZ, "(%lu)" , dwType);
/* @@ -204,9 +192,19 @@ dwSize = sExpLen2 - 4; dwType = -1; ok( ERROR_MORE_DATA == SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize), "Expected ERROR_MORE_DATA"); - ok( 0 == strncmp(sExpTestpath2, buf, sExpLen2 - 4 - 1), "(%s)", buf); - ok( sExpLen2 - 4 - 1 == strlen(buf), "(%s)", buf); - ok( dwSize == nUsedBuffer2, "(%lu,%lu)" , dwSize, nUsedBuffer2); + /* FIXME - what is this above test meant to do exactly? */ + ok( 0 == strlen( buf ), "(%s)", buf ); /* Windows NT 4.0 sp6 and XP sp1 do return empty strings */ + + /* Old, non working test + ok( 0 == strncmp(sExpTestpath2, buf, sExpLen2 - 4 - 1), "(%s)", buf); + ok( sExpLen2 - 4 - 1 == strlen(buf), "(%s)", buf); + */ + + ok( + dwSize == nUsedBuffer2 || + (dwSize - 1) == nUsedBuffer2, /* Windows XP sp1 */ + "(%lu,%lu)" , dwSize, nUsedBuffer2 + ); ok( dwType == REG_SZ, "(%lu)" , dwType);
/* @@ -215,75 +213,104 @@ strcpy(buf, sEmptyBuffer); dwSize = 6; dwType = -1; - dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, NULL, &dwSize); - ok( ERROR_SUCCESS == dwRet, "(%lu)", dwRet); - ok( dwSize == nUsedBuffer2, "(%lu,%lu)" , dwSize, nUsedBuffer2); - ok( dwType == REG_SZ, "(%lu)" , dwType); + dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, NULL, &dwSize ); + ok( ERROR_SUCCESS == dwRet, "(%lu)", dwRet ); + + ok( + dwSize == nUsedBuffer2 || + (dwSize - 1) == nUsedBuffer2, /* Windows XP sp1 */ + "(%lu,%lu)" , dwSize, nUsedBuffer2 + );
+ ok( dwType == REG_SZ, "(%lu)" , dwType );
RegCloseKey(hKey); }
-static void test_SHCopyKey(void) +static void test_SHCopyKey( ) { - HKEY hKeySrc, hKeyDst; + HKEY hKeySrc; + HKEY hKeyDest;
- /* Delete existing destination sub keys */ - hKeyDst = NULL; - if (!RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\CopyDestination", &hKeyDst) && hKeyDst) + /* Requires Internet Explorer 5.0 or later */ + if (NULL == pSHCopyKeyA) { - SHDeleteKeyA(hKeyDst, NULL); - RegCloseKey(hKeyDst); - }
- hKeyDst = NULL; - if (RegCreateKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\CopyDestination", &hKeyDst) || !hKeyDst) - { - ok(0, "didn't open dest"); - return; - } - - hKeySrc = NULL; - if (RegOpenKeyA(HKEY_LOCAL_MACHINE, REG_CURRENT_VERSION, &hKeySrc) || !hKeySrc) - { - ok(0, "didn't open source"); - return; + return; }
+ hKeySrc = create_test_entries( REG_SRC_KEY );
- if (pSHCopyKeyA) - ok (!(*pSHCopyKeyA)(hKeyDst, NULL, hKeySrc, 0), "failed copy"); + /* Delete any existing destination key */ + SHDeleteKey( HKEY_CURRENT_USER, REG_TEST_KEY "\CopyDestination" );
- RegCloseKey(hKeySrc); - RegCloseKey(hKeyDst); - - /* Check we copied the sub keys, i.e. AeDebug from the default wine registry */ - hKeyDst = NULL; - if (RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\CopyDestination\AeDebug", &hKeyDst) || !hKeyDst) - { - ok(0, "didn't open copy"); - return; - } + hKeyDest = NULL; + ok( + ERROR_SUCCESS == + RegCreateKeyA( + HKEY_CURRENT_USER, + REG_TEST_KEY "\CopyDestination", + &hKeyDest + ), + "did not open dest; RegCreateKeyA failed" + ); + ok( NULL != hKeyDest, "hKeyDest is NULL" ); + + ok( + ERROR_SUCCESS == (*pSHCopyKeyA)( hKeySrc, NULL, hKeyDest, 0 ), + "SHCopyKeyA failed" + ); + + + RegCloseKey( hKeySrc ); + RegCloseKey( hKeyDest ); + + + /* Check we copied the keys */ + ok( + ERROR_SUCCESS == + RegOpenKeyA( + HKEY_CURRENT_USER, + REG_TEST_KEY "\CopyDestination", + &hKeyDest + ), + "did not open copy: RegOpenKeyA failed" + ); + ok( NULL != hKeyDest, "did not open dest; hKeyDest is NULL" );
/* And the we copied the values too */ - ok(!SHQueryValueExA(hKeyDst, "Debugger", NULL, NULL, NULL, NULL), "SHQueryValueExA failed"); + ok( + !SHQueryValueExA(hKeyDest, "Test1", NULL, NULL, NULL, NULL), + "SHQueryValueExA failed" + );
- RegCloseKey(hKeyDst); + RegCloseKey( hKeyDest ); }
-START_TEST(shreg) +START_TEST( shreg ) { - HKEY hkey = create_test_entries(); - hshlwapi = GetModuleHandleA("shlwapi.dll"); - if (hshlwapi) - { - pSHCopyKeyA=(SHCopyKeyA_func)GetProcAddress(hshlwapi,"SHCopyKeyA"); - pSHRegGetPathA=(SHRegGetPathA_func)GetProcAddress(hshlwapi,"SHRegGetPathA"); - } - test_SHGetValue(); - test_SHQUeryValueEx(); - test_SHGetRegPath(); - test_SHCopyKey(); - delete_key( hkey ); + HKEY hkey; + HMODULE hshlwapi; + + hshlwapi = GetModuleHandleA( "shlwapi.dll" ); + + if (NULL == hshlwapi) + { + + return; + } + + hkey = create_test_entries( REG_TEST_KEY ); + + pSHCopyKeyA = (SHCopyKeyA_func) GetProcAddress( hshlwapi, "SHCopyKeyA" ); + pSHRegGetPathA = (SHRegGetPathA_func) GetProcAddress( hshlwapi, "SHRegGetPathA" ); + + test_SHGetValue( ); + test_SHQUeryValueEx( ); + test_SHGetRegPath( ); + test_SHCopyKey( ); + + SHDeleteKey( HKEY_CURRENT_USER, REG_TEST_KEY ); + SHDeleteKey( HKEY_CURRENT_USER, REG_SRC_KEY ); }
----- End forwarded message -----