Add RegOpenKey, RegCloseKey tests.
diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c index ffb823c..a102719 100644 --- a/dlls/advapi32/registry.c +++ b/dlls/advapi32/registry.c
@@ -277,6 +277,11 @@ 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 @@ 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 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 ) ); }
diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c index 9dba1b6..84704a2 100644 --- a/dlls/advapi32/tests/registry.c +++ b/dlls/advapi32/tests/registry.c
@@ -254,12 +254,104 @@ 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 );