-- v2: advapi32/test: Add tests for RegLoadAppKey.
From: Santino Mazza smazza@codeweavers.com
Signed-off-by: Santino Mazza smazza@codeweavers.com --- dlls/advapi32/tests/registry.c | 53 ++++++++++++++++++++++++++++++++++ dlls/kernelbase/registry.c | 6 ++-- 2 files changed, 55 insertions(+), 4 deletions(-)
diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c index df56b0968ee..53230eeacca 100644 --- a/dlls/advapi32/tests/registry.c +++ b/dlls/advapi32/tests/registry.c @@ -1600,6 +1600,58 @@ static void test_reg_unload_key(void) DeleteFileA("saved_key.LOG"); }
+static void test_reg_load_app_key(void) +{ + DWORD ret; + HKEY childkey; + DWORD size1; + DWORD size2; + HANDLE hivefile; + HKEY key1 = NULL; + + /* in win 7 we cannot delete the hive file while the process is running */ + /* thats why we don't delete it at the end of the test */ + DeleteFileA("saved_app_key"); + DeleteFileA("saved_app_key.LOG"); + + if (!set_privileges(SE_BACKUP_NAME, TRUE) || + !set_privileges(SE_RESTORE_NAME, FALSE)) + { + win_skip("Failed to set SE_BACKUP_NAME privileges, skipping tests\n"); + return; + } + + ret = RegSaveKeyA(hkey_main, "saved_app_key", NULL); + if (ret != ERROR_SUCCESS) + { + win_skip("Failed to save test key 0x%lx\n", ret); + return; + } + + set_privileges(SE_BACKUP_NAME, FALSE); + set_privileges(SE_RESTORE_NAME, FALSE); + + /* Test simple key load */ + /* Check if the changes are saved to the file */ + hivefile = CreateFileA("saved_app_key", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, NULL); + size1 = GetFileSize(hivefile, NULL); + CloseHandle(hivefile); + + ret = RegLoadAppKeyA("saved_app_key", &key1, KEY_READ | KEY_WRITE, 0, 0); + todo_wine ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret); + todo_wine ok(key1 != NULL, "got a null key\n"); + + ret = RegCreateKeyA(key1, "testkey", &childkey); + RegCloseKey(key1); + + hivefile = CreateFileA("saved_app_key", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, NULL); + size2 = GetFileSize(hivefile, NULL); + todo_wine ok(size2 > size1, "Expected file to increase size. %ld <= %ld\n", size2, size1); + CloseHandle(hivefile); +} + /* tests that show that RegConnectRegistry and OpenSCManager accept computer names without the \ prefix (what MSDN says). */ @@ -4485,6 +4537,7 @@ START_TEST(registry) test_classesroot_mask(); test_reg_save_key(); test_reg_load_key(); + test_reg_load_app_key(); test_reg_unload_key(); test_reg_copy_tree(); test_reg_delete_tree(); diff --git a/dlls/kernelbase/registry.c b/dlls/kernelbase/registry.c index 91462d80e06..b05d5b2cf9d 100644 --- a/dlls/kernelbase/registry.c +++ b/dlls/kernelbase/registry.c @@ -3092,8 +3092,7 @@ LSTATUS WINAPI RegLoadAppKeyA(const char *file, HKEY *result, REGSAM sam, DWORD if (!file || reserved) return ERROR_INVALID_PARAMETER;
- *result = (HKEY)0xdeadbeef; - return ERROR_SUCCESS; + return STATUS_NOT_IMPLEMENTED; }
/****************************************************************************** @@ -3107,8 +3106,7 @@ LSTATUS WINAPI RegLoadAppKeyW(const WCHAR *file, HKEY *result, REGSAM sam, DWORD if (!file || reserved) return ERROR_INVALID_PARAMETER;
- *result = (HKEY)0xdeadbeef; - return ERROR_SUCCESS; + return STATUS_NOT_IMPLEMENTED; }
Huw Davies (@huw) commented about dlls/advapi32/tests/registry.c:
DeleteFileA("saved_key.LOG");
}
+static void test_reg_load_app_key(void) +{
- DWORD ret;
- HKEY childkey;
- DWORD size1;
- DWORD size2;
- HANDLE hivefile;
- HKEY key1 = NULL;
Although it's a matter of style, we'd generally declare variables of the same type on the same line (room permitting).
Additionally, the commit message prefix should be 'advapi32/test**s**:'
Huw Davies (@huw) commented about dlls/advapi32/tests/registry.c:
DeleteFileA("saved_key.LOG");
}
+static void test_reg_load_app_key(void) +{
- DWORD ret;
- HKEY childkey;
- DWORD size1;
- DWORD size2;
- HANDLE hivefile;
- HKEY key1 = NULL;
- /* in win 7 we cannot delete the hive file while the process is running */
- /* thats why we don't delete it at the end of the test */
- DeleteFileA("saved_app_key");
- DeleteFileA("saved_app_key.LOG");
This is unfortunate.
One way to cope with this would be to run these tests in a sub-process and then cleanup in the main process once that sub-process finishes. See instances of `winetest_get_mainargs()` for how to handle process creation in the tests.
Huw Davies (@huw) commented about dlls/advapi32/tests/registry.c:
- HANDLE hivefile;
- HKEY key1 = NULL;
- /* in win 7 we cannot delete the hive file while the process is running */
- /* thats why we don't delete it at the end of the test */
- DeleteFileA("saved_app_key");
- DeleteFileA("saved_app_key.LOG");
- if (!set_privileges(SE_BACKUP_NAME, TRUE) ||
!set_privileges(SE_RESTORE_NAME, FALSE))
- {
win_skip("Failed to set SE_BACKUP_NAME privileges, skipping tests\n");
return;
- }
- ret = RegSaveKeyA(hkey_main, "saved_app_key", NULL);
Rather than dump a hard-coded file in the current directory, please create it in the temp directory. See how this is done using e.g. `GetTempPath()` and `GetTempFileName()` in `test_RegLoadMUIString()`.
On Fri Sep 2 08:28:19 2022 +0000, Huw Davies wrote:
This is unfortunate. One way to cope with this would be to run these tests in a sub-process and then cleanup in the main process once that sub-process finishes. See instances of `winetest_get_mainargs()` for how to handle process creation in the tests.
I've tried doing this, but after the child process ends and I try to delete the hive file from the main process it still throws the sharing violation error. Is it really needed to delete the file when I use temp files?