Module: wine Branch: master Commit: 98bd248778b8dd0d052e4e68146ac22fd9021af0 URL: https://gitlab.winehq.org/wine/wine/-/commit/98bd248778b8dd0d052e4e68146ac22...
Author: Piotr Caban piotr@codeweavers.com Date: Thu Mar 21 19:27:40 2024 +0100
advapi32/tests: Remove all files created by RegLoadKey tests.
---
dlls/advapi32/tests/registry.c | 56 ++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 16 deletions(-)
diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c index 2430e2330dd..f85c73ed4f2 100644 --- a/dlls/advapi32/tests/registry.c +++ b/dlls/advapi32/tests/registry.c @@ -1542,25 +1542,40 @@ static BOOL set_privileges(LPCSTR privilege, BOOL set) return TRUE; }
-static void test_reg_save_key(void) +static void delete_dir(const char *path) { - DWORD ret; - - if (!set_privileges(SE_BACKUP_NAME, TRUE) || - !set_privileges(SE_RESTORE_NAME, FALSE)) + char file[2 * MAX_PATH], *p; + WIN32_FIND_DATAA fd; + HANDLE hfind; + BOOL r; + + strcpy(file, path); + p = file + strlen(file); + p[0] = '\'; + p[1] = '*'; + p[2] = 0; + hfind = FindFirstFileA(file, &fd); + if (hfind != INVALID_HANDLE_VALUE) { - win_skip("Failed to set SE_BACKUP_NAME privileges, skipping tests\n"); - return; + do + { + if (!strcmp(fd.cFileName, ".") || !strcmp(fd.cFileName, "..")) + continue; + + strcpy(p + 1, fd.cFileName); + r = DeleteFileA(file); + ok(r, "DeleteFile failed on %s: %ld\n", debugstr_a(file), GetLastError()); + } while(FindNextFileA(hfind, &fd)); + FindClose(hfind); }
- ret = RegSaveKeyA(hkey_main, "saved_key", NULL); - ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret); - - set_privileges(SE_BACKUP_NAME, FALSE); + r = RemoveDirectoryA(path); + ok(r, "RemoveDirectory failed: %ld\n", GetLastError()); }
static void test_reg_load_key(void) { + char saved_key[2 * MAX_PATH], *p; UNICODE_STRING key_name; OBJECT_ATTRIBUTES attr; NTSTATUS status; @@ -1568,13 +1583,21 @@ static void test_reg_load_key(void) HKEY key;
if (!set_privileges(SE_RESTORE_NAME, TRUE) || - !set_privileges(SE_BACKUP_NAME, FALSE)) + !set_privileges(SE_BACKUP_NAME, TRUE)) { win_skip("Failed to set SE_RESTORE_NAME privileges, skipping tests\n"); return; }
- ret = RegLoadKeyA(HKEY_LOCAL_MACHINE, "Test", "saved_key"); + GetTempPathA(MAX_PATH, saved_key); + strcat(saved_key, "\wine_reg_test"); + CreateDirectoryA(saved_key, NULL); + strcat(saved_key, "\saved_key"); + + ret = RegSaveKeyA(hkey_main, saved_key, NULL); + ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret); + + ret = RegLoadKeyA(HKEY_LOCAL_MACHINE, "Test", saved_key); ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
ret = RegOpenKeyA(HKEY_LOCAL_MACHINE, "Test", &key); @@ -1600,9 +1623,11 @@ static void test_reg_load_key(void) ok(ret == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %ld\n", ret);
set_privileges(SE_RESTORE_NAME, FALSE); + set_privileges(SE_BACKUP_NAME, FALSE);
- DeleteFileA("saved_key"); - DeleteFileA("saved_key.LOG"); + p = strrchr(saved_key, '\'); + *p = 0; + delete_dir(saved_key); }
/* Helper function to wait for a file blocked by the registry to be available */ @@ -4966,7 +4991,6 @@ START_TEST(registry) test_classesroot(); test_classesroot_enum(); test_classesroot_mask(); - test_reg_save_key(); test_reg_load_key(); test_reg_load_app_key(); test_reg_copy_tree();