2002-06-01 01:06:46 +02:00
|
|
|
/* Unit test suite for SHReg* functions
|
2002-05-09 21:48:07 +02:00
|
|
|
*
|
|
|
|
* Copyright 2002 Juergen Schmied
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-05-09 21:48:07 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-05-09 21:48:07 +02:00
|
|
|
#include "winbase.h"
|
2002-05-23 04:40:07 +02:00
|
|
|
#include "winerror.h"
|
2002-05-09 21:48:07 +02:00
|
|
|
#include "winreg.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "shlwapi.h"
|
|
|
|
|
2002-09-12 22:45:22 +02:00
|
|
|
/* Keys used for testing */
|
2002-09-12 20:02:14 +02:00
|
|
|
#define REG_TEST_KEY "Software\\Wine\\Test"
|
|
|
|
#define REG_CURRENT_VERSION "Software\\Microsoft\\Windows NT\\CurrentVersion"
|
|
|
|
|
2002-09-17 00:45:22 +02:00
|
|
|
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);
|
|
|
|
static SHRegGetPathA_func pSHRegGetPathA;
|
|
|
|
|
2003-10-08 00:54:17 +02:00
|
|
|
static const char * sTestpath1 = "%LONGSYSTEMVAR%\\subdir1";
|
|
|
|
static const char * sTestpath2 = "%FOO%\\subdir1";
|
2002-05-09 21:48:07 +02:00
|
|
|
|
|
|
|
static char sExpTestpath1[MAX_PATH];
|
|
|
|
static char sExpTestpath2[MAX_PATH];
|
2002-06-28 19:35:20 +02:00
|
|
|
static unsigned sExpLen1;
|
|
|
|
static unsigned sExpLen2;
|
2002-05-09 21:48:07 +02:00
|
|
|
|
2003-10-08 00:54:17 +02:00
|
|
|
static const char * sEmptyBuffer ="0123456789";
|
2002-05-09 21:48:07 +02:00
|
|
|
|
2002-09-13 00:29:58 +02:00
|
|
|
/* delete key and all its subkeys */
|
2004-11-10 02:30:59 +01:00
|
|
|
static DWORD delete_key( HKEY hkey, LPSTR parent, LPSTR keyname )
|
2002-09-13 00:29:58 +02:00
|
|
|
{
|
2004-11-10 02:30:59 +01:00
|
|
|
HKEY parentKey;
|
2002-09-13 00:29:58 +02:00
|
|
|
DWORD ret;
|
|
|
|
|
2004-11-10 02:30:59 +01:00
|
|
|
RegCloseKey(hkey);
|
|
|
|
|
|
|
|
/* open the parent of the key to close */
|
2004-12-15 11:50:01 +01:00
|
|
|
ret = RegOpenKeyExA( HKEY_CURRENT_USER, parent, 0, KEY_ALL_ACCESS, &parentKey);
|
2004-11-10 02:30:59 +01:00
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
|
2004-12-15 11:50:01 +01:00
|
|
|
ret = SHDeleteKeyA( parentKey, keyname );
|
2004-11-10 02:30:59 +01:00
|
|
|
RegCloseKey(parentKey);
|
|
|
|
|
|
|
|
return ret;
|
2002-09-13 00:29:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HKEY create_test_entries(void)
|
2002-05-09 21:48:07 +02:00
|
|
|
{
|
|
|
|
HKEY hKey;
|
|
|
|
|
2002-06-28 19:35:20 +02:00
|
|
|
SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
|
|
|
|
SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
|
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(!RegCreateKeyA(HKEY_CURRENT_USER, REG_TEST_KEY, &hKey), "RegCreateKeyA failed\n");
|
2002-05-09 21:48:07 +02:00
|
|
|
|
|
|
|
if (hKey)
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(!RegSetValueExA(hKey,"Test1",0,REG_EXPAND_SZ, sTestpath1, strlen(sTestpath1)+1), "RegSetValueExA failed\n");
|
|
|
|
ok(!RegSetValueExA(hKey,"Test2",0,REG_SZ, sTestpath1, strlen(sTestpath1)+1), "RegSetValueExA failed\n");
|
|
|
|
ok(!RegSetValueExA(hKey,"Test3",0,REG_EXPAND_SZ, sTestpath2, strlen(sTestpath2)+1), "RegSetValueExA failed\n");
|
2002-05-09 21:48:07 +02:00
|
|
|
}
|
|
|
|
|
2002-06-28 19:35:20 +02:00
|
|
|
sExpLen1 = ExpandEnvironmentStringsA(sTestpath1, sExpTestpath1, sizeof(sExpTestpath1));
|
|
|
|
sExpLen2 = ExpandEnvironmentStringsA(sTestpath2, sExpTestpath2, sizeof(sExpTestpath2));
|
|
|
|
|
|
|
|
ok(sExpLen1 > 0, "Couldn't expand %s\n", sTestpath1);
|
|
|
|
ok(sExpLen2 > 0, "Couldn't expand %s\n", sTestpath2);
|
2002-09-13 00:29:58 +02:00
|
|
|
return hKey;
|
2002-05-09 21:48:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_SHGetValue(void)
|
|
|
|
{
|
|
|
|
DWORD dwSize;
|
|
|
|
DWORD dwType;
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
|
|
|
|
strcpy(buf, sEmptyBuffer);
|
|
|
|
dwSize = MAX_PATH;
|
|
|
|
dwType = -1;
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(! SHGetValueA(HKEY_CURRENT_USER, REG_TEST_KEY, "Test1", &dwType, buf, &dwSize), "SHGetValueA failed\n");
|
|
|
|
ok( 0 == strcmp(sExpTestpath1, buf), "(%s,%s)\n", buf, sExpTestpath1);
|
|
|
|
ok( REG_SZ == dwType, "(%lx)\n", dwType);
|
2002-05-09 21:48:07 +02:00
|
|
|
|
|
|
|
strcpy(buf, sEmptyBuffer);
|
|
|
|
dwSize = MAX_PATH;
|
|
|
|
dwType = -1;
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(! SHGetValueA(HKEY_CURRENT_USER, REG_TEST_KEY, "Test2", &dwType, buf, &dwSize), "SHGetValueA failed\n");
|
|
|
|
ok( 0 == strcmp(sTestpath1, buf) , "(%s)\n", buf);
|
|
|
|
ok( REG_SZ == dwType , "(%lx)\n", dwType);
|
2002-05-09 21:48:07 +02:00
|
|
|
}
|
|
|
|
|
2002-09-12 20:02:14 +02:00
|
|
|
static void test_SHGetRegPath(void)
|
2002-05-09 21:48:07 +02:00
|
|
|
{
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
|
2002-09-17 00:45:22 +02:00
|
|
|
if (!pSHRegGetPathA)
|
|
|
|
return;
|
|
|
|
|
2002-05-09 21:48:07 +02:00
|
|
|
strcpy(buf, sEmptyBuffer);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(! (*pSHRegGetPathA)(HKEY_CURRENT_USER, REG_TEST_KEY, "Test1", buf, 0), "SHRegGetPathA failed\n");
|
|
|
|
ok( 0 == strcmp(sExpTestpath1, buf) , "(%s)\n", buf);
|
2002-05-09 21:48:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_SHQUeryValueEx(void)
|
|
|
|
{
|
|
|
|
HKEY hKey;
|
|
|
|
DWORD dwSize;
|
|
|
|
DWORD dwType;
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
DWORD dwRet;
|
2003-10-08 00:54:17 +02:00
|
|
|
const char * sTestedFunction = "";
|
2002-12-18 21:50:49 +01:00
|
|
|
DWORD nUsedBuffer1,nUsedBuffer2;
|
2002-05-09 21:48:07 +02:00
|
|
|
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(! RegOpenKeyExA(HKEY_CURRENT_USER, REG_TEST_KEY, 0, KEY_QUERY_VALUE, &hKey), "test4 RegOpenKey\n");
|
2002-05-09 21:48:07 +02:00
|
|
|
|
|
|
|
/****** SHQueryValueExA ******/
|
|
|
|
|
|
|
|
sTestedFunction = "SHQueryValueExA";
|
2002-08-09 03:14:23 +02:00
|
|
|
nUsedBuffer1 = max(strlen(sExpTestpath1)+1, strlen(sTestpath1)+1);
|
|
|
|
nUsedBuffer2 = max(strlen(sExpTestpath2)+1, strlen(sTestpath2)+1);
|
2002-05-09 21:48:07 +02:00
|
|
|
/*
|
|
|
|
* Case 1.1 All arguments are NULL
|
|
|
|
*/
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(! SHQueryValueExA( hKey, "Test1", NULL, NULL, NULL, NULL), "SHQueryValueExA failed\n");
|
2002-05-09 21:48:07 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Case 1.2 dwType is set
|
|
|
|
*/
|
|
|
|
dwType = -1;
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(! SHQueryValueExA( hKey, "Test1", NULL, &dwType, NULL, NULL), "SHQueryValueExA failed\n");
|
|
|
|
ok( dwType == REG_SZ, "(%lu)\n", dwType);
|
2002-05-09 21:48:07 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* dwSize is set
|
|
|
|
* dwExpanded < dwUnExpanded
|
|
|
|
*/
|
|
|
|
dwSize = 6;
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(! SHQueryValueExA( hKey, "Test1", NULL, NULL, NULL, &dwSize), "SHQueryValueExA failed\n");
|
|
|
|
ok( dwSize == nUsedBuffer1, "(%lu,%lu)\n", dwSize, nUsedBuffer1);
|
2002-05-09 21:48:07 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* dwExpanded > dwUnExpanded
|
|
|
|
*/
|
|
|
|
dwSize = 6;
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(! SHQueryValueExA( hKey, "Test3", NULL, NULL, NULL, &dwSize), "SHQueryValueExA failed\n");
|
2004-11-19 18:56:08 +01:00
|
|
|
ok( dwSize >= nUsedBuffer2, "(%lu,%lu)\n", dwSize, nUsedBuffer2);
|
2002-05-09 21:48:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Case 1 string shrinks during expanding
|
|
|
|
*/
|
|
|
|
strcpy(buf, sEmptyBuffer);
|
|
|
|
dwSize = 6;
|
|
|
|
dwType = -1;
|
|
|
|
dwRet = SHQueryValueExA( hKey, "Test1", NULL, &dwType, buf, &dwSize);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( dwRet == ERROR_MORE_DATA, "(%lu)\n", dwRet);
|
|
|
|
ok( 0 == strcmp(sEmptyBuffer, buf), "(%s)\n", buf);
|
|
|
|
ok( dwType == REG_SZ, "(%lu)\n" , dwType);
|
|
|
|
ok( dwSize == nUsedBuffer1, "(%lu,%lu)\n" , dwSize, nUsedBuffer1);
|
2002-05-09 21:48:07 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* string grows during expanding
|
2002-06-01 01:06:46 +02:00
|
|
|
*/
|
2002-05-09 21:48:07 +02:00
|
|
|
strcpy(buf, sEmptyBuffer);
|
|
|
|
dwSize = 6;
|
|
|
|
dwType = -1;
|
|
|
|
dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( ERROR_MORE_DATA == dwRet, "ERROR_MORE_DATA\n");
|
|
|
|
ok( 0 == strcmp(sEmptyBuffer, buf), "(%s)\n", buf);
|
2004-11-19 18:56:08 +01:00
|
|
|
ok( dwSize >= nUsedBuffer2, "(%lu,%lu)\n" , dwSize, nUsedBuffer2);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( dwType == REG_SZ, "(%lu)\n" , dwType);
|
2002-05-09 21:48:07 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if the unexpanded string fits into the buffer it can get cut when expanded
|
|
|
|
*/
|
|
|
|
strcpy(buf, sEmptyBuffer);
|
2002-06-28 19:35:20 +02:00
|
|
|
dwSize = sExpLen2 - 4;
|
2002-05-09 21:48:07 +02:00
|
|
|
dwType = -1;
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( ERROR_MORE_DATA == SHQueryValueExA( hKey, "Test3", NULL, &dwType, buf, &dwSize), "Expected ERROR_MORE_DATA\n");
|
|
|
|
ok( 0 == strncmp(sExpTestpath2, buf, sExpLen2 - 4 - 1), "(%s)\n", buf);
|
|
|
|
ok( sExpLen2 - 4 - 1 == strlen(buf), "(%s)\n", buf);
|
2004-11-19 18:56:08 +01:00
|
|
|
ok( dwSize >= nUsedBuffer2, "(%lu,%lu)\n" , dwSize, nUsedBuffer2);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( dwType == REG_SZ, "(%lu)\n" , dwType);
|
2002-05-09 21:48:07 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The buffer is NULL but the size is set
|
|
|
|
*/
|
|
|
|
strcpy(buf, sEmptyBuffer);
|
|
|
|
dwSize = 6;
|
|
|
|
dwType = -1;
|
|
|
|
dwRet = SHQueryValueExA( hKey, "Test3", NULL, &dwType, NULL, &dwSize);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( ERROR_SUCCESS == dwRet, "(%lu)\n", dwRet);
|
2004-11-19 18:56:08 +01:00
|
|
|
ok( dwSize >= nUsedBuffer2, "(%lu,%lu)\n" , dwSize, nUsedBuffer2);
|
2004-01-27 21:13:03 +01:00
|
|
|
ok( dwType == REG_SZ, "(%lu)\n" , dwType);
|
2002-05-09 21:48:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
|
2002-09-12 20:02:14 +02:00
|
|
|
static void test_SHCopyKey(void)
|
|
|
|
{
|
|
|
|
HKEY hKeySrc, hKeyDst;
|
|
|
|
|
2002-09-12 22:45:22 +02:00
|
|
|
/* Delete existing destination sub keys */
|
2002-12-02 19:10:57 +01:00
|
|
|
hKeyDst = NULL;
|
2002-09-12 20:02:14 +02:00
|
|
|
if (!RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\CopyDestination", &hKeyDst) && hKeyDst)
|
|
|
|
{
|
|
|
|
SHDeleteKeyA(hKeyDst, NULL);
|
|
|
|
RegCloseKey(hKeyDst);
|
|
|
|
}
|
|
|
|
|
2002-12-02 19:10:57 +01:00
|
|
|
hKeyDst = NULL;
|
2002-09-12 20:02:14 +02:00
|
|
|
if (RegCreateKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\CopyDestination", &hKeyDst) || !hKeyDst)
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(0, "didn't open dest\n");
|
2002-09-12 20:02:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-12-02 19:10:57 +01:00
|
|
|
hKeySrc = NULL;
|
2002-09-12 20:02:14 +02:00
|
|
|
if (RegOpenKeyA(HKEY_LOCAL_MACHINE, REG_CURRENT_VERSION, &hKeySrc) || !hKeySrc)
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(0, "didn't open source\n");
|
2002-09-12 20:02:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-17 00:45:22 +02:00
|
|
|
if (pSHCopyKeyA)
|
2004-01-27 21:13:03 +01:00
|
|
|
ok (!(*pSHCopyKeyA)(hKeyDst, NULL, hKeySrc, 0), "failed copy\n");
|
2002-09-12 20:02:14 +02:00
|
|
|
|
|
|
|
RegCloseKey(hKeySrc);
|
|
|
|
RegCloseKey(hKeyDst);
|
|
|
|
|
|
|
|
/* Check we copied the sub keys, i.e. AeDebug from the default wine registry */
|
2002-12-02 19:10:57 +01:00
|
|
|
hKeyDst = NULL;
|
2002-09-12 20:02:14 +02:00
|
|
|
if (RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY "\\CopyDestination\\AeDebug", &hKeyDst) || !hKeyDst)
|
|
|
|
{
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(0, "didn't open copy\n");
|
2002-09-12 20:02:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* And the we copied the values too */
|
2004-01-27 21:13:03 +01:00
|
|
|
ok(!SHQueryValueExA(hKeyDst, "Debugger", NULL, NULL, NULL, NULL), "SHQueryValueExA failed\n");
|
2002-09-12 20:02:14 +02:00
|
|
|
|
|
|
|
RegCloseKey(hKeyDst);
|
|
|
|
}
|
|
|
|
|
2004-10-14 02:25:29 +02:00
|
|
|
static void test_SHDeleteKey()
|
|
|
|
{
|
|
|
|
HKEY hKeyTest;
|
|
|
|
int sysfail=1;
|
|
|
|
if (!RegOpenKeyA(HKEY_CURRENT_USER, REG_TEST_KEY, &hKeyTest))
|
|
|
|
{
|
|
|
|
HKEY hKeyS;
|
|
|
|
if (!RegCreateKey(hKeyTest, "ODBC", &hKeyS))
|
|
|
|
{
|
|
|
|
HKEY hKeyO;
|
|
|
|
if (!RegCreateKey(hKeyS, "ODBC.INI", &hKeyO))
|
|
|
|
{
|
|
|
|
RegCloseKey (hKeyO);
|
|
|
|
if (!RegCreateKey(hKeyS, "ODBCINST.INI", &hKeyO))
|
|
|
|
{
|
|
|
|
RegCloseKey (hKeyO);
|
|
|
|
sysfail = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey (hKeyS);
|
|
|
|
}
|
|
|
|
RegCloseKey (hKeyTest);
|
|
|
|
}
|
|
|
|
if (!sysfail)
|
|
|
|
{
|
|
|
|
HKEY hKeyS;
|
|
|
|
DWORD dwRet;
|
|
|
|
ok (!SHDeleteKey(HKEY_CURRENT_USER, REG_TEST_KEY "\\ODBC"), "SHDeleteKey failed\n");
|
|
|
|
ok ((dwRet = RegOpenKey(HKEY_CURRENT_USER, REG_TEST_KEY "\\ODBC", &hKeyS)) == ERROR_FILE_NOT_FOUND, "SHDeleteKey did not delete\n");
|
|
|
|
if (dwRet == ERROR_SUCCESS)
|
|
|
|
RegCloseKey (hKeyS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok (0, "Could not set up SHDeleteKey test\n");
|
|
|
|
}
|
2002-09-12 20:02:14 +02:00
|
|
|
|
2002-05-09 21:48:07 +02:00
|
|
|
START_TEST(shreg)
|
|
|
|
{
|
2002-09-13 00:29:58 +02:00
|
|
|
HKEY hkey = create_test_entries();
|
2002-09-17 00:45:22 +02:00
|
|
|
hshlwapi = GetModuleHandleA("shlwapi.dll");
|
|
|
|
if (hshlwapi)
|
|
|
|
{
|
|
|
|
pSHCopyKeyA=(SHCopyKeyA_func)GetProcAddress(hshlwapi,"SHCopyKeyA");
|
|
|
|
pSHRegGetPathA=(SHRegGetPathA_func)GetProcAddress(hshlwapi,"SHRegGetPathA");
|
|
|
|
}
|
2002-05-09 21:48:07 +02:00
|
|
|
test_SHGetValue();
|
|
|
|
test_SHQUeryValueEx();
|
2002-09-12 20:02:14 +02:00
|
|
|
test_SHGetRegPath();
|
|
|
|
test_SHCopyKey();
|
2004-10-14 02:25:29 +02:00
|
|
|
test_SHDeleteKey();
|
2004-11-10 02:30:59 +01:00
|
|
|
delete_key( hkey, "Software\\Wine", "Test" );
|
2002-05-09 21:48:07 +02:00
|
|
|
}
|