2002-07-10 05:30:14 +02:00
|
|
|
/*
|
|
|
|
* Unit tests for registry functions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-07-10 05:30:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-07-10 05:30:14 +02:00
|
|
|
#include "wine/test.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-09-17 02:04:35 +02:00
|
|
|
#include "winbase.h"
|
2002-07-10 05:30:14 +02:00
|
|
|
#include "winreg.h"
|
2005-09-15 11:31:05 +02:00
|
|
|
#include "winsvc.h"
|
2002-07-10 05:30:14 +02:00
|
|
|
#include "winerror.h"
|
|
|
|
|
|
|
|
static HKEY hkey_main;
|
2006-06-09 22:46:56 +02:00
|
|
|
static DWORD GLE;
|
2002-07-10 05:30:14 +02:00
|
|
|
|
2004-11-19 19:13:30 +01:00
|
|
|
static const char * sTestpath1 = "%LONGSYSTEMVAR%\\subdir1";
|
|
|
|
static const char * sTestpath2 = "%FOO%\\subdir1";
|
|
|
|
|
2002-07-10 05:30:14 +02:00
|
|
|
/* delete key and all its subkeys */
|
|
|
|
static DWORD delete_key( HKEY hkey )
|
|
|
|
{
|
2003-01-13 19:29:31 +01:00
|
|
|
char name[MAX_PATH];
|
2002-07-10 05:30:14 +02:00
|
|
|
DWORD ret;
|
|
|
|
|
2003-01-13 19:29:31 +01:00
|
|
|
while (!(ret = RegEnumKeyA(hkey, 0, name, sizeof(name))))
|
2002-07-10 05:30:14 +02:00
|
|
|
{
|
2002-09-12 22:46:06 +02:00
|
|
|
HKEY tmp;
|
2003-01-13 19:29:31 +01:00
|
|
|
if (!(ret = RegOpenKeyExA( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp )))
|
2002-09-12 22:46:06 +02:00
|
|
|
{
|
|
|
|
ret = delete_key( tmp );
|
|
|
|
RegCloseKey( tmp );
|
|
|
|
}
|
|
|
|
if (ret) break;
|
2002-07-10 05:30:14 +02:00
|
|
|
}
|
|
|
|
if (ret != ERROR_NO_MORE_ITEMS) return ret;
|
2005-04-13 16:40:58 +02:00
|
|
|
RegDeleteKeyA( hkey, "" );
|
2002-07-10 05:30:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setup_main_key(void)
|
|
|
|
{
|
|
|
|
if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main )) delete_key( hkey_main );
|
|
|
|
|
2005-01-27 12:15:00 +01:00
|
|
|
assert (!RegCreateKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main ));
|
2002-07-10 05:30:14 +02:00
|
|
|
}
|
|
|
|
|
2006-06-09 22:46:56 +02:00
|
|
|
static void test_hkey_main_Value_A(LPCSTR name, LPCSTR string)
|
|
|
|
{
|
|
|
|
DWORD ret, type, cbData;
|
|
|
|
DWORD str_byte_len, full_byte_len;
|
|
|
|
|
|
|
|
ret = RegQueryValueExA(hkey_main, name, NULL, &type, NULL, &cbData);
|
|
|
|
GLE = GetLastError();
|
|
|
|
ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %ld, GLE=%ld\n", ret, GLE);
|
|
|
|
if(GLE == ERROR_CALL_NOT_IMPLEMENTED) return;
|
|
|
|
|
|
|
|
str_byte_len = lstrlenA(string) + 1;
|
|
|
|
full_byte_len = sizeof(string);
|
|
|
|
ok(type == REG_SZ, "RegQueryValueExA returned type %ld\n", type);
|
|
|
|
ok(cbData == full_byte_len || cbData == str_byte_len,
|
|
|
|
"cbData=%ld instead of %ld or %ld\n", cbData, full_byte_len, str_byte_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_hkey_main_Value_W(LPCWSTR name, LPCWSTR string)
|
|
|
|
{
|
|
|
|
DWORD ret, type, cbData;
|
|
|
|
DWORD str_byte_len, full_byte_len;
|
|
|
|
|
|
|
|
ret = RegQueryValueExW(hkey_main, name, NULL, &type, NULL, &cbData);
|
|
|
|
GLE = GetLastError();
|
|
|
|
ok(ret == ERROR_SUCCESS, "RegQueryValueExW failed: %ld, GLE=%ld\n", ret, GLE);
|
|
|
|
if(GLE == ERROR_CALL_NOT_IMPLEMENTED) return;
|
|
|
|
|
|
|
|
str_byte_len = (lstrlenW(string) + 1) * sizeof(WCHAR);
|
|
|
|
full_byte_len = sizeof(string);
|
|
|
|
ok(type == REG_SZ, "RegQueryValueExW returned type %ld\n", type);
|
|
|
|
ok(cbData == full_byte_len || cbData == str_byte_len,
|
|
|
|
"cbData=%ld instead of %ld or %ld\n", cbData, full_byte_len, str_byte_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_set_value(void)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
const WCHAR name1W[] = {'C','l','e','a','n','S','i','n','g','l','e','S','t','r','i','n','g', 0};
|
|
|
|
const WCHAR name2W[] = {'S','o','m','e','I','n','t','r','a','Z','e','r','o','e','d','S','t','r','i','n','g', 0};
|
|
|
|
const WCHAR string1W[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
|
|
|
|
const WCHAR string2W[] = {'T','h','i','s', 0 ,'B','r','e','a','k','s', 0 , 0 ,'A', 0 , 0 , 0 , 0 ,'L','o','t', 0 , 0 , 0 , 0};
|
|
|
|
|
|
|
|
const char name1A[] = "CleanSingleString";
|
|
|
|
const char name2A[] = "SomeIntraZeroedString";
|
|
|
|
const char string1A[] = "ThisNeverBreaks";
|
|
|
|
const char string2A[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
|
|
|
|
|
|
|
|
/* test RegSetValueExA with normal string */
|
|
|
|
ret = RegSetValueExA(hkey_main, name1A, 0, REG_SZ, (LPBYTE)string1A, sizeof(string1A));
|
|
|
|
ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %ld, GLE=%ld\n", ret, GetLastError());
|
|
|
|
test_hkey_main_Value_A(name1A, string1A);
|
|
|
|
test_hkey_main_Value_W(name1W, string1W);
|
|
|
|
|
|
|
|
/* test RegSetValueExA with intrazeroed string */
|
|
|
|
ret = RegSetValueExA(hkey_main, name2A, 0, REG_SZ, (LPBYTE)string2A, sizeof(string2A));
|
|
|
|
ok(ret == ERROR_SUCCESS, "RegSetValueExA failed: %ld, GLE=%ld\n", ret, GetLastError());
|
|
|
|
test_hkey_main_Value_A(name1A, string1A);
|
|
|
|
test_hkey_main_Value_W(name1W, string1W);
|
|
|
|
|
|
|
|
/* 9x doesn't support W-calls, so don't test them then */
|
|
|
|
if(GLE == ERROR_CALL_NOT_IMPLEMENTED) return;
|
|
|
|
|
|
|
|
/* test RegSetValueExW with normal string */
|
|
|
|
ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (LPBYTE)string1W, sizeof(string1W));
|
|
|
|
ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %ld, GLE=%ld\n", ret, GetLastError());
|
|
|
|
test_hkey_main_Value_A(name1A, string1A);
|
|
|
|
test_hkey_main_Value_W(name1W, string1W);
|
|
|
|
|
|
|
|
/* test RegSetValueExW with intrazeroed string */
|
|
|
|
ret = RegSetValueExW(hkey_main, name2W, 0, REG_SZ, (LPBYTE)string2W, sizeof(string2W));
|
|
|
|
ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %ld, GLE=%ld\n", ret, GetLastError());
|
|
|
|
test_hkey_main_Value_A(name1A, string1A);
|
|
|
|
test_hkey_main_Value_W(name1W, string1W);
|
|
|
|
}
|
|
|
|
|
2004-11-19 19:13:30 +01:00
|
|
|
static void create_test_entries(void)
|
|
|
|
{
|
2005-07-03 13:19:03 +02:00
|
|
|
DWORD qw[2] = { 0x12345678, 0x87654321 };
|
|
|
|
|
2004-11-19 19:13:30 +01:00
|
|
|
SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
|
|
|
|
SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
|
|
|
|
|
2005-07-18 12:30:51 +02:00
|
|
|
ok(!RegSetValueExA(hkey_main,"TP1_EXP_SZ",0,REG_EXPAND_SZ, (LPBYTE)sTestpath1, strlen(sTestpath1)+1),
|
2004-11-19 19:13:30 +01:00
|
|
|
"RegSetValueExA failed\n");
|
2005-07-18 12:30:51 +02:00
|
|
|
ok(!RegSetValueExA(hkey_main,"TP1_SZ",0,REG_SZ, (LPBYTE)sTestpath1, strlen(sTestpath1)+1),
|
2004-11-19 19:13:30 +01:00
|
|
|
"RegSetValueExA failed\n");
|
2005-07-18 12:30:51 +02:00
|
|
|
ok(!RegSetValueExA(hkey_main,"TP2_EXP_SZ",0,REG_EXPAND_SZ, (LPBYTE)sTestpath2, strlen(sTestpath2)+1),
|
2004-11-19 19:13:30 +01:00
|
|
|
"RegSetValueExA failed\n");
|
2005-07-06 21:08:05 +02:00
|
|
|
ok(!RegSetValueExA(hkey_main,"DWORD",0,REG_DWORD, (LPBYTE)qw, 4),
|
2005-07-03 13:19:03 +02:00
|
|
|
"RegSetValueExA failed\n");
|
2005-07-06 21:08:05 +02:00
|
|
|
ok(!RegSetValueExA(hkey_main,"BIN32",0,REG_BINARY, (LPBYTE)qw, 4),
|
2005-07-03 13:19:03 +02:00
|
|
|
"RegSetValueExA failed\n");
|
2005-07-06 21:08:05 +02:00
|
|
|
ok(!RegSetValueExA(hkey_main,"BIN64",0,REG_BINARY, (LPBYTE)qw, 8),
|
2005-07-03 13:19:03 +02:00
|
|
|
"RegSetValueExA failed\n");
|
2004-11-19 19:13:30 +01:00
|
|
|
}
|
|
|
|
|
2002-07-10 05:30:14 +02:00
|
|
|
static void test_enum_value(void)
|
|
|
|
{
|
|
|
|
DWORD res;
|
2005-04-11 14:52:32 +02:00
|
|
|
HKEY test_key;
|
2002-07-10 05:30:14 +02:00
|
|
|
char value[20], data[20];
|
|
|
|
WCHAR valueW[20], dataW[20];
|
|
|
|
DWORD val_count, data_count, type;
|
|
|
|
static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
|
|
|
|
static const WCHAR testW[] = {'T','e','s','t',0};
|
|
|
|
static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',0};
|
|
|
|
|
2005-04-11 14:52:32 +02:00
|
|
|
/* create the working key for new 'Test' value */
|
|
|
|
res = RegCreateKeyA( hkey_main, "TestKey", &test_key );
|
|
|
|
ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res);
|
|
|
|
|
2004-07-24 04:32:50 +02:00
|
|
|
/* check NULL data with zero length */
|
2005-04-11 14:52:32 +02:00
|
|
|
res = RegSetValueExA( test_key, "Test", 0, REG_SZ, NULL, 0 );
|
2004-07-24 04:32:50 +02:00
|
|
|
if (GetVersion() & 0x80000000)
|
|
|
|
ok( res == ERROR_INVALID_PARAMETER, "RegSetValueExA returned %ld\n", res );
|
|
|
|
else
|
|
|
|
ok( !res, "RegSetValueExA returned %ld\n", res );
|
2005-04-11 14:52:32 +02:00
|
|
|
res = RegSetValueExA( test_key, "Test", 0, REG_EXPAND_SZ, NULL, 0 );
|
2005-03-24 20:02:38 +01:00
|
|
|
ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %ld\n", res );
|
2005-04-11 14:52:32 +02:00
|
|
|
res = RegSetValueExA( test_key, "Test", 0, REG_BINARY, NULL, 0 );
|
2005-03-24 20:02:38 +01:00
|
|
|
ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %ld\n", res );
|
2004-07-24 04:32:50 +02:00
|
|
|
|
2005-04-11 14:52:32 +02:00
|
|
|
res = RegSetValueExA( test_key, "Test", 0, REG_SZ, (BYTE *)"foobar", 7 );
|
2004-01-26 21:23:25 +01:00
|
|
|
ok( res == 0, "RegSetValueExA failed error %ld\n", res );
|
2002-07-10 05:30:14 +02:00
|
|
|
|
|
|
|
/* overflow both name and data */
|
|
|
|
val_count = 2;
|
|
|
|
data_count = 2;
|
|
|
|
type = 1234;
|
|
|
|
strcpy( value, "xxxxxxxxxx" );
|
|
|
|
strcpy( data, "xxxxxxxxxx" );
|
2005-07-06 21:08:05 +02:00
|
|
|
res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
|
2004-01-26 21:23:25 +01:00
|
|
|
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
|
|
|
|
ok( val_count == 2, "val_count set to %ld\n", val_count );
|
|
|
|
ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
|
|
|
|
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
|
|
|
|
ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
|
|
|
|
ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
|
2002-07-10 05:30:14 +02:00
|
|
|
|
|
|
|
/* overflow name */
|
|
|
|
val_count = 3;
|
|
|
|
data_count = 20;
|
|
|
|
type = 1234;
|
|
|
|
strcpy( value, "xxxxxxxxxx" );
|
|
|
|
strcpy( data, "xxxxxxxxxx" );
|
2005-07-06 21:08:05 +02:00
|
|
|
res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
|
2004-01-26 21:23:25 +01:00
|
|
|
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
|
2003-01-13 19:29:31 +01:00
|
|
|
/* Win9x returns 2 as specified by MSDN but NT returns 3... */
|
2004-01-26 21:23:25 +01:00
|
|
|
ok( val_count == 2 || val_count == 3, "val_count set to %ld\n", val_count );
|
|
|
|
ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
|
|
|
|
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
|
2006-06-02 20:55:08 +02:00
|
|
|
/* v5.1.2600.0 (XP Home and Proffesional) does not touch value or data in this case */
|
|
|
|
ok( !strcmp( value, "Te" ) || !strcmp( value, "xxxxxxxxxx" ),
|
|
|
|
"value set to '%s' instead of 'Te' or 'xxxxxxxxxx'\n", value );
|
|
|
|
ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ),
|
|
|
|
"data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
|
2002-07-10 05:30:14 +02:00
|
|
|
|
|
|
|
/* overflow empty name */
|
|
|
|
val_count = 0;
|
|
|
|
data_count = 20;
|
|
|
|
type = 1234;
|
|
|
|
strcpy( value, "xxxxxxxxxx" );
|
|
|
|
strcpy( data, "xxxxxxxxxx" );
|
2005-07-06 21:08:05 +02:00
|
|
|
res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
|
2004-01-26 21:23:25 +01:00
|
|
|
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
|
|
|
|
ok( val_count == 0, "val_count set to %ld\n", val_count );
|
|
|
|
ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
|
|
|
|
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
|
|
|
|
ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
|
2006-06-02 20:55:08 +02:00
|
|
|
/* v5.1.2600.0 (XP Home and Professional) does not touch data in this case */
|
|
|
|
ok( !strcmp( data, "foobar" ) || !strcmp( data, "xxxxxxx" ),
|
|
|
|
"data set to '%s' instead of 'foobar' or 'xxxxxxx'\n", data );
|
2002-07-10 05:30:14 +02:00
|
|
|
|
|
|
|
/* overflow data */
|
|
|
|
val_count = 20;
|
|
|
|
data_count = 2;
|
|
|
|
type = 1234;
|
|
|
|
strcpy( value, "xxxxxxxxxx" );
|
|
|
|
strcpy( data, "xxxxxxxxxx" );
|
2005-07-06 21:08:05 +02:00
|
|
|
res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
|
2004-01-26 21:23:25 +01:00
|
|
|
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
|
|
|
|
ok( val_count == 20, "val_count set to %ld\n", val_count );
|
|
|
|
ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
|
|
|
|
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
|
|
|
|
ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
|
|
|
|
ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
|
2002-07-10 05:30:14 +02:00
|
|
|
|
|
|
|
/* no overflow */
|
|
|
|
val_count = 20;
|
|
|
|
data_count = 20;
|
|
|
|
type = 1234;
|
|
|
|
strcpy( value, "xxxxxxxxxx" );
|
|
|
|
strcpy( data, "xxxxxxxxxx" );
|
2005-07-06 21:08:05 +02:00
|
|
|
res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, (LPBYTE)data, &data_count );
|
2004-01-26 21:23:25 +01:00
|
|
|
ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res );
|
|
|
|
ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
|
|
|
|
ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
|
|
|
|
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
|
|
|
|
ok( !strcmp( value, "Test" ), "value is '%s' instead of Test\n", value );
|
|
|
|
ok( !strcmp( data, "foobar" ), "data is '%s' instead of foobar\n", data );
|
2002-07-10 05:30:14 +02:00
|
|
|
|
|
|
|
/* Unicode tests */
|
|
|
|
|
2003-01-13 19:29:31 +01:00
|
|
|
SetLastError(0);
|
2005-04-11 14:52:32 +02:00
|
|
|
res = RegSetValueExW( test_key, testW, 0, REG_SZ, (const BYTE *)foobarW, 7*sizeof(WCHAR) );
|
2003-01-13 19:29:31 +01:00
|
|
|
if (res==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
|
2005-04-11 14:52:32 +02:00
|
|
|
return;
|
2004-01-26 21:23:25 +01:00
|
|
|
ok( res == 0, "RegSetValueExW failed error %ld\n", res );
|
2002-07-10 05:30:14 +02:00
|
|
|
|
|
|
|
/* overflow both name and data */
|
|
|
|
val_count = 2;
|
|
|
|
data_count = 2;
|
|
|
|
type = 1234;
|
|
|
|
memcpy( valueW, xxxW, sizeof(xxxW) );
|
|
|
|
memcpy( dataW, xxxW, sizeof(xxxW) );
|
2005-04-11 14:52:32 +02:00
|
|
|
res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
|
2004-01-26 21:23:25 +01:00
|
|
|
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
|
|
|
|
ok( val_count == 2, "val_count set to %ld\n", val_count );
|
|
|
|
ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
|
|
|
|
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
|
|
|
|
ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
|
|
|
|
ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
|
2002-07-10 05:30:14 +02:00
|
|
|
|
|
|
|
/* overflow name */
|
|
|
|
val_count = 3;
|
|
|
|
data_count = 20;
|
|
|
|
type = 1234;
|
|
|
|
memcpy( valueW, xxxW, sizeof(xxxW) );
|
|
|
|
memcpy( dataW, xxxW, sizeof(xxxW) );
|
2005-04-11 14:52:32 +02:00
|
|
|
res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
|
2004-01-26 21:23:25 +01:00
|
|
|
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
|
|
|
|
ok( val_count == 3, "val_count set to %ld\n", val_count );
|
|
|
|
ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
|
|
|
|
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
|
|
|
|
ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
|
|
|
|
ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
|
2002-07-10 05:30:14 +02:00
|
|
|
|
|
|
|
/* overflow data */
|
|
|
|
val_count = 20;
|
|
|
|
data_count = 2;
|
|
|
|
type = 1234;
|
|
|
|
memcpy( valueW, xxxW, sizeof(xxxW) );
|
|
|
|
memcpy( dataW, xxxW, sizeof(xxxW) );
|
2005-04-11 14:52:32 +02:00
|
|
|
res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
|
2004-01-26 21:23:25 +01:00
|
|
|
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
|
|
|
|
ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
|
|
|
|
ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
|
|
|
|
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
|
|
|
|
ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
|
|
|
|
ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
|
2002-07-10 05:30:14 +02:00
|
|
|
|
|
|
|
/* no overflow */
|
|
|
|
val_count = 20;
|
|
|
|
data_count = 20;
|
|
|
|
type = 1234;
|
|
|
|
memcpy( valueW, xxxW, sizeof(xxxW) );
|
|
|
|
memcpy( dataW, xxxW, sizeof(xxxW) );
|
2005-04-11 14:52:32 +02:00
|
|
|
res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
|
2004-01-26 21:23:25 +01:00
|
|
|
ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res );
|
|
|
|
ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
|
|
|
|
ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
|
|
|
|
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
|
|
|
|
ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
|
|
|
|
ok( !memcmp( dataW, foobarW, sizeof(foobarW) ), "data is not 'foobar'\n" );
|
2002-07-10 05:30:14 +02:00
|
|
|
}
|
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static void test_query_value_ex(void)
|
2004-11-19 19:13:30 +01:00
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
DWORD size;
|
|
|
|
DWORD type;
|
|
|
|
|
2005-07-18 12:30:51 +02:00
|
|
|
ret = RegQueryValueExA(hkey_main, "TP1_SZ", NULL, &type, NULL, &size);
|
2004-11-19 19:13:30 +01:00
|
|
|
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
|
|
|
|
ok(size == strlen(sTestpath1) + 1, "(%ld,%ld)\n", (DWORD)strlen(sTestpath1) + 1, size);
|
|
|
|
ok(type == REG_SZ, "type %ld is not REG_SZ\n", type);
|
|
|
|
}
|
|
|
|
|
2005-07-03 13:19:03 +02:00
|
|
|
static void test_get_value(void)
|
|
|
|
{
|
|
|
|
HMODULE hadvapi32;
|
|
|
|
DWORD (WINAPI *pRegGetValueA)(HKEY,LPCSTR,LPCSTR,DWORD,LPDWORD,PVOID,LPDWORD);
|
|
|
|
|
|
|
|
DWORD ret;
|
|
|
|
DWORD size;
|
|
|
|
DWORD type;
|
|
|
|
DWORD dw, qw[2];
|
|
|
|
CHAR buf[80];
|
|
|
|
CHAR expanded[] = "bar\\subdir1";
|
|
|
|
|
|
|
|
/* This function was introduced with Windows 2003 SP1 */
|
|
|
|
hadvapi32 = LoadLibraryA("advapi32.dll");
|
|
|
|
if(!hadvapi32)
|
|
|
|
{
|
|
|
|
ok(0, "error=%ld\n", GetLastError());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pRegGetValueA = (PVOID)GetProcAddress(hadvapi32, "RegGetValueA");
|
|
|
|
if(!pRegGetValueA)
|
|
|
|
return;
|
2005-07-18 12:30:51 +02:00
|
|
|
|
2005-07-03 13:19:03 +02:00
|
|
|
/* Query REG_DWORD using RRF_RT_REG_DWORD (ok) */
|
|
|
|
size = type = dw = 0xdeadbeef;
|
|
|
|
ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_DWORD, &type, &dw, &size);
|
|
|
|
ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
|
|
|
|
ok(size == 4, "size=%ld\n", size);
|
|
|
|
ok(type == REG_DWORD, "type=%ld\n", type);
|
|
|
|
ok(dw == 0x12345678, "dw=%ld\n", dw);
|
|
|
|
|
|
|
|
/* Query by subkey-name */
|
|
|
|
ret = pRegGetValueA(HKEY_CURRENT_USER, "Software\\Wine\\Test", "DWORD", RRF_RT_REG_DWORD, NULL, NULL, NULL);
|
|
|
|
ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
|
|
|
|
|
|
|
|
/* Query REG_DWORD using RRF_RT_REG_BINARY (restricted) */
|
|
|
|
size = type = dw = 0xdeadbeef;
|
|
|
|
ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_BINARY, &type, &dw, &size);
|
|
|
|
ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%ld\n", ret);
|
|
|
|
/* Although the function failed all values are retrieved */
|
|
|
|
ok(size == 4, "size=%ld\n", size);
|
|
|
|
ok(type == REG_DWORD, "type=%ld\n", type);
|
|
|
|
ok(dw == 0x12345678, "dw=%ld\n", dw);
|
|
|
|
|
|
|
|
/* Test RRF_ZEROONFAILURE */
|
|
|
|
type = dw = 0xdeadbeef; size = 4;
|
|
|
|
ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_REG_SZ|RRF_ZEROONFAILURE, &type, &dw, &size);
|
|
|
|
ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%ld\n", ret);
|
|
|
|
/* Again all values are retrieved ... */
|
|
|
|
ok(size == 4, "size=%ld\n", size);
|
|
|
|
ok(type == REG_DWORD, "type=%ld\n", type);
|
|
|
|
/* ... except the buffer, which is zeroed out */
|
|
|
|
ok(dw == 0, "dw=%ld\n", dw);
|
|
|
|
|
|
|
|
/* Query REG_DWORD using RRF_RT_DWORD (ok) */
|
|
|
|
size = type = dw = 0xdeadbeef;
|
|
|
|
ret = pRegGetValueA(hkey_main, NULL, "DWORD", RRF_RT_DWORD, &type, &dw, &size);
|
|
|
|
ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
|
|
|
|
ok(size == 4, "size=%ld\n", size);
|
|
|
|
ok(type == REG_DWORD, "type=%ld\n", type);
|
|
|
|
ok(dw == 0x12345678, "dw=%ld\n", dw);
|
|
|
|
|
|
|
|
/* Query 32-bit REG_BINARY using RRF_RT_DWORD (ok) */
|
|
|
|
size = type = dw = 0xdeadbeef;
|
|
|
|
ret = pRegGetValueA(hkey_main, NULL, "BIN32", RRF_RT_DWORD, &type, &dw, &size);
|
|
|
|
ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
|
|
|
|
ok(size == 4, "size=%ld\n", size);
|
|
|
|
ok(type == REG_BINARY, "type=%ld\n", type);
|
|
|
|
ok(dw == 0x12345678, "dw=%ld\n", dw);
|
|
|
|
|
|
|
|
/* Query 64-bit REG_BINARY using RRF_RT_DWORD (type mismatch) */
|
|
|
|
qw[0] = qw[1] = size = type = 0xdeadbeef;
|
|
|
|
ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_DWORD, &type, qw, &size);
|
|
|
|
ok(ret == ERROR_DATATYPE_MISMATCH, "ret=%ld\n", ret);
|
|
|
|
ok(size == 8, "size=%ld\n", size);
|
|
|
|
ok(type == REG_BINARY, "type=%ld\n", type);
|
|
|
|
ok(qw[0] == 0x12345678 &&
|
|
|
|
qw[1] == 0x87654321, "qw={%ld,%ld}\n", qw[0], qw[1]);
|
|
|
|
|
|
|
|
/* Query 64-bit REG_BINARY using 32-bit buffer (buffer too small) */
|
|
|
|
type = dw = 0xdeadbeef; size = 4;
|
|
|
|
ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_REG_BINARY, &type, &dw, &size);
|
|
|
|
ok(ret == ERROR_MORE_DATA, "ret=%ld\n", ret);
|
|
|
|
ok(dw == 0xdeadbeef, "dw=%ld\n", dw);
|
|
|
|
ok(size == 8, "size=%ld\n", size);
|
|
|
|
|
|
|
|
/* Query 64-bit REG_BINARY using RRF_RT_QWORD (ok) */
|
|
|
|
qw[0] = qw[1] = size = type = 0xdeadbeef;
|
|
|
|
ret = pRegGetValueA(hkey_main, NULL, "BIN64", RRF_RT_QWORD, &type, qw, &size);
|
|
|
|
ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
|
|
|
|
ok(size == 8, "size=%ld\n", size);
|
|
|
|
ok(type == REG_BINARY, "type=%ld\n", type);
|
|
|
|
ok(qw[0] == 0x12345678 &&
|
|
|
|
qw[1] == 0x87654321, "qw={%ld,%ld}\n", qw[0], qw[1]);
|
|
|
|
|
2005-07-18 12:30:51 +02:00
|
|
|
/* Query REG_SZ using RRF_RT_REG_SZ (ok) */
|
2005-07-03 13:19:03 +02:00
|
|
|
buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
|
2005-07-18 12:30:51 +02:00
|
|
|
ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ, &type, buf, &size);
|
2005-07-03 13:19:03 +02:00
|
|
|
ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
|
2006-06-13 13:56:18 +02:00
|
|
|
ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%ld\n", lstrlenA(sTestpath1), size);
|
2005-07-03 13:19:03 +02:00
|
|
|
ok(type == REG_SZ, "type=%ld\n", type);
|
2005-07-18 12:30:51 +02:00
|
|
|
ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
|
2005-07-03 13:19:03 +02:00
|
|
|
|
2005-07-18 12:30:51 +02:00
|
|
|
/* Query REG_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (ok) */
|
2005-07-03 13:19:03 +02:00
|
|
|
buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
|
2005-07-18 12:30:51 +02:00
|
|
|
ret = pRegGetValueA(hkey_main, NULL, "TP1_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, &type, buf, &size);
|
2005-07-03 13:19:03 +02:00
|
|
|
ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
|
2006-06-13 13:56:18 +02:00
|
|
|
ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%ld\n", lstrlenA(sTestpath1), size);
|
2005-07-03 13:19:03 +02:00
|
|
|
ok(type == REG_SZ, "type=%ld\n", type);
|
|
|
|
ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
|
|
|
|
|
2005-07-18 12:30:51 +02:00
|
|
|
/* Query REG_EXPAND_SZ using RRF_RT_REG_SZ (ok, expands) */
|
2005-07-03 13:19:03 +02:00
|
|
|
buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
|
2005-07-18 12:30:51 +02:00
|
|
|
ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ, &type, buf, &size);
|
|
|
|
ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
|
2006-06-02 20:55:08 +02:00
|
|
|
/* At least v5.2.3790.1830 (2003 SP1) returns the unexpanded sTestpath1 length + 1 here. */
|
|
|
|
ok((size == strlen(expanded)+1) || (size == strlen(sTestpath1)+1),
|
2006-06-13 13:56:18 +02:00
|
|
|
"strlen(expanded)=%d, strlen(sTestpath1)=%d, size=%ld\n", lstrlenA(expanded), lstrlenA(sTestpath1), size);
|
2005-07-18 12:30:51 +02:00
|
|
|
ok(type == REG_SZ, "type=%ld\n", type);
|
|
|
|
ok(!strcmp(expanded, buf), "expanded=\"%s\" buf=\"%s\"\n", expanded, buf);
|
|
|
|
|
|
|
|
/* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND (ok, doesn't expand) */
|
|
|
|
buf[0] = 0; type = 0xdeadbeef; size = sizeof(buf);
|
|
|
|
ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ|RRF_NOEXPAND, &type, buf, &size);
|
2005-07-03 13:19:03 +02:00
|
|
|
ok(ret == ERROR_SUCCESS, "ret=%ld\n", ret);
|
2006-06-13 13:56:18 +02:00
|
|
|
ok(size == strlen(sTestpath1)+1, "strlen(sTestpath1)=%d size=%ld\n", lstrlenA(sTestpath1), size);
|
2005-07-03 13:19:03 +02:00
|
|
|
ok(type == REG_EXPAND_SZ, "type=%ld\n", type);
|
|
|
|
ok(!strcmp(sTestpath1, buf), "sTestpath=\"%s\" buf=\"%s\"\n", sTestpath1, buf);
|
2005-07-18 12:30:51 +02:00
|
|
|
|
|
|
|
/* Query REG_EXPAND_SZ using RRF_RT_REG_SZ|RRF_NOEXPAND (type mismatch) */
|
|
|
|
ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_SZ|RRF_NOEXPAND, NULL, NULL, NULL);
|
|
|
|
ok(ret == ERROR_UNSUPPORTED_TYPE, "ret=%ld\n", ret);
|
|
|
|
|
|
|
|
/* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
|
|
|
|
ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ, NULL, NULL, NULL);
|
|
|
|
ok(ret == ERROR_INVALID_PARAMETER, "ret=%ld\n", ret);
|
2005-07-03 13:19:03 +02:00
|
|
|
}
|
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static void test_reg_open_key(void)
|
2005-02-21 21:37:26 +01:00
|
|
|
{
|
|
|
|
DWORD ret = 0;
|
|
|
|
HKEY hkResult = NULL;
|
|
|
|
HKEY hkPreserve = NULL;
|
|
|
|
|
|
|
|
/* successful open */
|
|
|
|
ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
|
|
|
|
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
|
|
|
|
ok(hkResult != NULL, "expected hkResult != NULL\n");
|
|
|
|
hkPreserve = hkResult;
|
|
|
|
|
2005-06-12 12:42:13 +02:00
|
|
|
/* these tests fail on Win9x, but we want to be compatible with NT, so
|
|
|
|
* run them if we can */
|
|
|
|
if (!(GetVersion() & 0x80000000))
|
|
|
|
{
|
|
|
|
/* open same key twice */
|
|
|
|
ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
|
|
|
|
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
|
|
|
|
ok(hkResult != hkPreserve, "epxected hkResult != hkPreserve\n");
|
|
|
|
ok(hkResult != NULL, "hkResult != NULL\n");
|
|
|
|
RegCloseKey(hkResult);
|
|
|
|
|
|
|
|
/* open nonexistent key
|
|
|
|
* check that hkResult is set to NULL
|
|
|
|
*/
|
|
|
|
hkResult = hkPreserve;
|
|
|
|
ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
|
|
|
|
ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %ld\n", ret);
|
|
|
|
ok(hkResult == NULL, "expected hkResult == NULL\n");
|
|
|
|
|
|
|
|
/* open the same nonexistent key again to make sure the key wasn't created */
|
|
|
|
hkResult = hkPreserve;
|
|
|
|
ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
|
|
|
|
ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %ld\n", ret);
|
|
|
|
ok(hkResult == NULL, "expected hkResult == NULL\n");
|
|
|
|
|
|
|
|
/* send in NULL lpSubKey
|
|
|
|
* check that hkResult receives the value of hKey
|
|
|
|
*/
|
|
|
|
hkResult = hkPreserve;
|
|
|
|
ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, &hkResult);
|
|
|
|
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
|
|
|
|
ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
|
|
|
|
|
|
|
|
/* send empty-string in lpSubKey */
|
|
|
|
hkResult = hkPreserve;
|
|
|
|
ret = RegOpenKeyA(HKEY_CURRENT_USER, "", &hkResult);
|
|
|
|
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
|
|
|
|
ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
|
|
|
|
|
|
|
|
/* send in NULL lpSubKey and NULL hKey
|
|
|
|
* hkResult is set to NULL
|
|
|
|
*/
|
|
|
|
hkResult = hkPreserve;
|
|
|
|
ret = RegOpenKeyA(NULL, NULL, &hkResult);
|
|
|
|
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
|
|
|
|
ok(hkResult == NULL, "expected hkResult == NULL\n");
|
|
|
|
}
|
2005-02-21 21:37:26 +01:00
|
|
|
|
|
|
|
/* only send NULL hKey
|
|
|
|
* the value of hkResult remains unchanged
|
|
|
|
*/
|
|
|
|
hkResult = hkPreserve;
|
|
|
|
ret = RegOpenKeyA(NULL, "Software\\Wine\\Test", &hkResult);
|
2005-03-24 20:02:38 +01:00
|
|
|
ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
|
|
|
|
"expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %ld\n", ret);
|
2005-02-21 21:37:26 +01:00
|
|
|
ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n");
|
|
|
|
RegCloseKey(hkResult);
|
|
|
|
|
|
|
|
/* send in NULL hkResult */
|
|
|
|
ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", NULL);
|
|
|
|
ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %ld\n", ret);
|
2005-12-08 13:49:02 +01:00
|
|
|
|
|
|
|
/* beginning backslash character */
|
|
|
|
ret = RegOpenKeyA(HKEY_CURRENT_USER, "\\Software\\Wine\\Test", &hkResult);
|
|
|
|
ok(ret == ERROR_BAD_PATHNAME || /* NT/2k/XP */
|
|
|
|
ret == ERROR_FILE_NOT_FOUND /* Win9x,ME */
|
|
|
|
, "expected ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %ld\n", ret);
|
2005-02-21 21:37:26 +01:00
|
|
|
}
|
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static void test_reg_create_key(void)
|
2005-06-16 22:34:34 +02:00
|
|
|
{
|
|
|
|
LONG ret;
|
|
|
|
HKEY hkey1, hkey2;
|
|
|
|
ret = RegCreateKeyExA(hkey_main, "Subkey1", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
|
|
|
|
ok(!ret, "RegCreateKeyExA failed with error %ld\n", ret);
|
|
|
|
/* should succeed: all versions of Windows ignore the access rights
|
|
|
|
* to the parent handle */
|
|
|
|
ret = RegCreateKeyExA(hkey1, "Subkey2", 0, NULL, 0, KEY_SET_VALUE, NULL, &hkey2, NULL);
|
|
|
|
ok(!ret, "RegCreateKeyExA failed with error %ld\n", ret);
|
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
RegDeleteKey(hkey2, NULL);
|
|
|
|
RegDeleteKey(hkey1, NULL);
|
2005-12-08 13:49:02 +01:00
|
|
|
|
|
|
|
/* beginning backslash character */
|
|
|
|
ret = RegCreateKeyExA(hkey_main, "\\Subkey3", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
|
|
|
|
if (!(GetVersion() & 0x80000000))
|
|
|
|
ok(ret == ERROR_BAD_PATHNAME, "expected ERROR_BAD_PATHNAME, got %ld\n", ret);
|
|
|
|
else {
|
|
|
|
ok(!ret, "RegCreateKeyExA failed with error %ld\n", ret);
|
|
|
|
RegDeleteKey(hkey1, NULL);
|
|
|
|
}
|
2005-06-16 22:34:34 +02:00
|
|
|
}
|
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static void test_reg_close_key(void)
|
2005-02-21 21:37:26 +01:00
|
|
|
{
|
|
|
|
DWORD ret = 0;
|
|
|
|
HKEY hkHandle;
|
|
|
|
|
|
|
|
/* successfully close key
|
|
|
|
* hkHandle remains changed after call to RegCloseKey
|
|
|
|
*/
|
|
|
|
ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkHandle);
|
|
|
|
ret = RegCloseKey(hkHandle);
|
|
|
|
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
|
|
|
|
|
|
|
|
/* try to close the key twice */
|
2005-03-24 20:02:38 +01:00
|
|
|
ret = RegCloseKey(hkHandle); /* Windows 95 doesn't mind. */
|
2005-03-25 11:26:18 +01:00
|
|
|
ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_SUCCESS,
|
|
|
|
"expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %ld\n", ret);
|
|
|
|
|
2005-02-21 21:37:26 +01:00
|
|
|
/* try to close a NULL handle */
|
|
|
|
ret = RegCloseKey(NULL);
|
2005-03-24 20:02:38 +01:00
|
|
|
ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
|
|
|
|
"expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %ld\n", ret);
|
2005-02-21 21:37:26 +01:00
|
|
|
}
|
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static void test_reg_delete_key(void)
|
2005-04-16 12:49:10 +02:00
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
ret = RegDeleteKey(hkey_main, NULL);
|
2005-07-18 11:08:24 +02:00
|
|
|
ok(ret == ERROR_INVALID_PARAMETER ||
|
|
|
|
ret == ERROR_ACCESS_DENIED ||
|
|
|
|
ret == ERROR_BADKEY, /* Win95 */
|
|
|
|
"ret=%ld\n", ret);
|
2005-04-16 12:49:10 +02:00
|
|
|
}
|
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static void test_reg_save_key(void)
|
2005-03-23 12:59:06 +01:00
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
ret = RegSaveKey(hkey_main, "saved_key", NULL);
|
|
|
|
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
|
|
|
|
}
|
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static void test_reg_load_key(void)
|
2005-03-23 12:59:06 +01:00
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
HKEY hkHandle;
|
|
|
|
|
|
|
|
ret = RegLoadKey(HKEY_LOCAL_MACHINE, "Test", "saved_key");
|
|
|
|
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
|
|
|
|
|
|
|
|
ret = RegOpenKey(HKEY_LOCAL_MACHINE, "Test", &hkHandle);
|
|
|
|
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
|
|
|
|
|
2005-04-19 11:47:10 +02:00
|
|
|
RegCloseKey(hkHandle);
|
|
|
|
}
|
|
|
|
|
2005-06-20 16:18:03 +02:00
|
|
|
static void test_reg_unload_key(void)
|
2005-04-19 11:47:10 +02:00
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
ret = RegUnLoadKey(HKEY_LOCAL_MACHINE, "Test");
|
|
|
|
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
|
|
|
|
|
2005-03-23 12:59:06 +01:00
|
|
|
DeleteFile("saved_key");
|
2005-10-27 20:29:07 +02:00
|
|
|
DeleteFile("saved_key.LOG");
|
2005-03-23 12:59:06 +01:00
|
|
|
}
|
|
|
|
|
2005-04-19 14:00:04 +02:00
|
|
|
static BOOL set_privileges(LPCSTR privilege, BOOL set)
|
|
|
|
{
|
|
|
|
TOKEN_PRIVILEGES tp;
|
|
|
|
HANDLE hToken;
|
|
|
|
LUID luid;
|
|
|
|
|
|
|
|
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if(!LookupPrivilegeValue(NULL, privilege, &luid))
|
|
|
|
{
|
|
|
|
CloseHandle(hToken);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
tp.PrivilegeCount = 1;
|
|
|
|
tp.Privileges[0].Luid = luid;
|
|
|
|
|
|
|
|
if (set)
|
|
|
|
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
|
|
|
else
|
|
|
|
tp.Privileges[0].Attributes = 0;
|
|
|
|
|
|
|
|
AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
|
|
|
|
if (GetLastError() != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
CloseHandle(hToken);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(hToken);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-09-15 11:31:05 +02:00
|
|
|
/* tests that show that RegConnectRegistry and
|
|
|
|
OpenSCManager accept computer names without the
|
|
|
|
\\ prefix (what MSDN says). */
|
|
|
|
static void test_regconnectregistry( void)
|
|
|
|
{
|
|
|
|
CHAR compName[MAX_COMPUTERNAME_LENGTH + 1];
|
2005-11-04 12:15:59 +01:00
|
|
|
CHAR netwName[MAX_COMPUTERNAME_LENGTH + 3]; /* 2 chars for double backslash */
|
2005-09-15 11:31:05 +02:00
|
|
|
DWORD len = sizeof(compName) ;
|
|
|
|
BOOL ret;
|
|
|
|
LONG retl;
|
|
|
|
HKEY hkey;
|
|
|
|
SC_HANDLE schnd;
|
2005-11-04 12:15:59 +01:00
|
|
|
DWORD GLE;
|
2005-09-15 11:31:05 +02:00
|
|
|
|
|
|
|
ret = GetComputerNameA(compName, &len);
|
|
|
|
ok( ret, "GetComputerName failed err = %ld\n", GetLastError());
|
|
|
|
if( !ret) return;
|
|
|
|
|
2005-11-04 12:15:59 +01:00
|
|
|
lstrcpyA(netwName, "\\\\");
|
|
|
|
lstrcpynA(netwName+2, compName, MAX_COMPUTERNAME_LENGTH + 1);
|
|
|
|
|
2005-09-15 11:31:05 +02:00
|
|
|
retl = RegConnectRegistryA( compName, HKEY_LOCAL_MACHINE, &hkey);
|
2005-11-04 12:15:59 +01:00
|
|
|
ok( !retl || retl == ERROR_DLL_INIT_FAILED, "RegConnectRegistryA failed err = %ld\n", retl);
|
|
|
|
if( !retl) RegCloseKey( hkey);
|
|
|
|
|
|
|
|
retl = RegConnectRegistryA( netwName, HKEY_LOCAL_MACHINE, &hkey);
|
|
|
|
ok( !retl || retl == ERROR_DLL_INIT_FAILED, "RegConnectRegistryA failed err = %ld\n", retl);
|
2005-09-15 11:31:05 +02:00
|
|
|
if( !retl) RegCloseKey( hkey);
|
|
|
|
|
|
|
|
schnd = OpenSCManagerA( compName, NULL, GENERIC_READ);
|
2005-11-04 12:15:59 +01:00
|
|
|
GLE = GetLastError();
|
|
|
|
ok( schnd != NULL || GLE==ERROR_CALL_NOT_IMPLEMENTED,
|
|
|
|
"OpenSCManagerA failed err = %ld\n", GLE);
|
|
|
|
CloseServiceHandle( schnd);
|
|
|
|
|
|
|
|
schnd = OpenSCManagerA( netwName, NULL, GENERIC_READ);
|
|
|
|
GLE = GetLastError();
|
|
|
|
ok( schnd != NULL || GLE==ERROR_CALL_NOT_IMPLEMENTED,
|
|
|
|
"OpenSCManagerA failed err = %ld\n", GLE);
|
2005-09-15 11:31:05 +02:00
|
|
|
CloseServiceHandle( schnd);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-07-10 05:30:14 +02:00
|
|
|
START_TEST(registry)
|
|
|
|
{
|
|
|
|
setup_main_key();
|
2006-06-09 22:46:56 +02:00
|
|
|
test_set_value();
|
2004-11-19 19:13:30 +01:00
|
|
|
create_test_entries();
|
2002-07-10 05:30:14 +02:00
|
|
|
test_enum_value();
|
2004-11-19 19:13:30 +01:00
|
|
|
test_query_value_ex();
|
2005-07-03 13:19:03 +02:00
|
|
|
test_get_value();
|
2005-02-21 21:37:26 +01:00
|
|
|
test_reg_open_key();
|
2005-06-16 22:34:34 +02:00
|
|
|
test_reg_create_key();
|
2005-02-21 21:37:26 +01:00
|
|
|
test_reg_close_key();
|
2005-04-16 12:49:10 +02:00
|
|
|
test_reg_delete_key();
|
2005-04-19 14:00:04 +02:00
|
|
|
|
|
|
|
/* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
|
|
|
|
if (set_privileges(SE_BACKUP_NAME, TRUE) &&
|
|
|
|
set_privileges(SE_RESTORE_NAME, TRUE))
|
|
|
|
{
|
|
|
|
test_reg_save_key();
|
|
|
|
test_reg_load_key();
|
|
|
|
test_reg_unload_key();
|
|
|
|
|
|
|
|
set_privileges(SE_BACKUP_NAME, FALSE);
|
|
|
|
set_privileges(SE_RESTORE_NAME, FALSE);
|
|
|
|
}
|
2002-07-10 05:30:14 +02:00
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
delete_key( hkey_main );
|
2005-09-15 11:31:05 +02:00
|
|
|
|
|
|
|
test_regconnectregistry();
|
2002-07-10 05:30:14 +02:00
|
|
|
}
|