Add RegOpenKey, RegCloseKey tests.
This commit is contained in:
parent
5cb9507ec1
commit
d5e2b7c843
|
@ -277,6 +277,11 @@ DWORD WINAPI RegOpenKeyExW( HKEY hkey, LPCWSTR name, DWORD reserved, REGSAM acce
|
|||
OBJECT_ATTRIBUTES attr;
|
||||
UNICODE_STRING nameW;
|
||||
|
||||
if (!name || !*name) {
|
||||
*retkey = hkey;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
|
||||
|
||||
attr.Length = sizeof(attr);
|
||||
|
@ -316,6 +321,11 @@ DWORD WINAPI RegOpenKeyExA( HKEY hkey, LPCSTR name, DWORD reserved, REGSAM acces
|
|||
STRING nameA;
|
||||
NTSTATUS status;
|
||||
|
||||
if (!name || !*name) {
|
||||
*retkey = hkey;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
if (!is_version_nt()) access = KEY_ALL_ACCESS; /* Win95 ignores the access mask */
|
||||
|
||||
if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
|
||||
|
@ -845,7 +855,8 @@ DWORD WINAPI RegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDWOR
|
|||
*/
|
||||
DWORD WINAPI RegCloseKey( HKEY hkey )
|
||||
{
|
||||
if (!hkey || hkey >= (HKEY)0x80000000) return ERROR_SUCCESS;
|
||||
if (!hkey) return ERROR_INVALID_PARAMETER;
|
||||
if (hkey >= (HKEY)0x80000000) return ERROR_SUCCESS;
|
||||
return RtlNtStatusToDosError( NtClose( hkey ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -254,12 +254,104 @@ static void test_query_value_ex()
|
|||
ok(type == REG_SZ, "type %ld is not REG_SZ\n", type);
|
||||
}
|
||||
|
||||
static void test_reg_open_key()
|
||||
{
|
||||
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;
|
||||
|
||||
/* 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 && hkResult != NULL,
|
||||
"expected hkResult != hkPreserve and 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");
|
||||
|
||||
/* only send NULL hKey
|
||||
* the value of hkResult remains unchanged
|
||||
*/
|
||||
hkResult = hkPreserve;
|
||||
ret = RegOpenKeyA(NULL, "Software\\Wine\\Test", &hkResult);
|
||||
ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %ld\n", ret);
|
||||
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);
|
||||
}
|
||||
|
||||
static void test_reg_close_key()
|
||||
{
|
||||
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 */
|
||||
ret = RegCloseKey(hkHandle);
|
||||
ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %ld\n", ret);
|
||||
|
||||
/* try to close a NULL handle */
|
||||
ret = RegCloseKey(NULL);
|
||||
ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %ld\n", ret);
|
||||
}
|
||||
|
||||
START_TEST(registry)
|
||||
{
|
||||
setup_main_key();
|
||||
create_test_entries();
|
||||
test_enum_value();
|
||||
test_query_value_ex();
|
||||
test_reg_open_key();
|
||||
test_reg_close_key();
|
||||
|
||||
/* cleanup */
|
||||
delete_key( hkey_main );
|
||||
|
|
Loading…
Reference in New Issue