From 3507999f3d909aae7901d1baa441ab928d73de67 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 12 Sep 2002 22:29:58 +0000 Subject: [PATCH] Delete registry key at exit. --- dlls/shlwapi/tests/shreg.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/dlls/shlwapi/tests/shreg.c b/dlls/shlwapi/tests/shreg.c index 460259d1e99..5c2497a5d97 100644 --- a/dlls/shlwapi/tests/shreg.c +++ b/dlls/shlwapi/tests/shreg.c @@ -42,7 +42,28 @@ static unsigned sExpLen2; static char * sEmptyBuffer ="0123456789"; -static void create_test_entrys(void) +/* delete key and all its subkeys */ +static DWORD delete_key( HKEY hkey ) +{ + WCHAR name[MAX_PATH]; + DWORD ret; + + while (!(ret = RegEnumKeyW(hkey, 0, name, sizeof(name)))) + { + HKEY tmp; + if (!(ret = RegOpenKeyExW( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp ))) + { + ret = delete_key( tmp ); + RegCloseKey( tmp ); + } + if (ret) break; + } + if (ret != ERROR_NO_MORE_ITEMS) return ret; + RegDeleteKeyA( hkey, NULL ); + return 0; +} + +static HKEY create_test_entries(void) { HKEY hKey; @@ -56,7 +77,6 @@ static void create_test_entrys(void) ok(!RegSetValueExA(hKey,"Test1",0,REG_EXPAND_SZ, sTestpath1, strlen(sTestpath1)+1), "RegSetValueExA failed"); ok(!RegSetValueExA(hKey,"Test2",0,REG_SZ, sTestpath1, strlen(sTestpath1)+1), "RegSetValueExA failed"); ok(!RegSetValueExA(hKey,"Test3",0,REG_EXPAND_SZ, sTestpath2, strlen(sTestpath2)+1), "RegSetValueExA failed"); - RegCloseKey(hKey); } sExpLen1 = ExpandEnvironmentStringsA(sTestpath1, sExpTestpath1, sizeof(sExpTestpath1)); @@ -64,6 +84,7 @@ static void create_test_entrys(void) ok(sExpLen1 > 0, "Couldn't expand %s\n", sTestpath1); ok(sExpLen2 > 0, "Couldn't expand %s\n", sTestpath2); + return hKey; } static void test_SHGetValue(void) @@ -243,9 +264,10 @@ static void test_SHCopyKey(void) START_TEST(shreg) { - create_test_entrys(); + HKEY hkey = create_test_entries(); test_SHGetValue(); test_SHQUeryValueEx(); test_SHGetRegPath(); test_SHCopyKey(); + delete_key( hkey ); }