Robert Shearman : advapi32: Add tests for RegQueryValueEx to show that it sets the data

Alexandre Julliard julliard at wine.codeweavers.com
Wed Aug 16 10:17:57 CDT 2006


Module: wine
Branch: master
Commit: bc590e87a6f9c7421ec3386a7c09a63a3e55dead
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=bc590e87a6f9c7421ec3386a7c09a63a3e55dead

Author: Robert Shearman <rob at codeweavers.com>
Date:   Wed Aug 16 13:00:59 2006 +0100

advapi32: Add tests for RegQueryValueEx to show that it sets the data
size to 0 when a buffer isn't present and that it sets the type to
REG_NONE on Win9x.

---

 dlls/advapi32/registry.c       |   11 ++++++++++-
 dlls/advapi32/tests/registry.c |   14 ++++++++++++++
 2 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c
index 81ed484..84ba75e 100644
--- a/dlls/advapi32/registry.c
+++ b/dlls/advapi32/registry.c
@@ -1142,7 +1142,11 @@ LONG WINAPI RegQueryValueExW( HKEY hkey,
     RtlInitUnicodeString( &name_str, name );
 
     if (data) total_size = min( sizeof(buffer), *count + info_size );
-    else total_size = info_size;
+    else
+    {
+        total_size = info_size;
+        if (count) *count = 0;
+    }
 
     status = NtQueryValueKey( hkey, &name_str, KeyValuePartialInformation,
                               buffer, total_size, &total_size );
@@ -1224,6 +1228,11 @@ LONG WINAPI RegQueryValueExA( HKEY hkey,
     if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
     if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
 
+    if (!data && count) *count = 0;
+
+    /* this matches Win9x behaviour - NT sets *type to a random value */
+    if (type) *type = REG_NONE;
+
     RtlInitAnsiString( &nameA, name );
     if ((status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString,
                                                 &nameA, FALSE )))
diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c
index 577838d..3622618 100644
--- a/dlls/advapi32/tests/registry.c
+++ b/dlls/advapi32/tests/registry.c
@@ -333,11 +333,25 @@ static void test_query_value_ex(void)
     DWORD ret;
     DWORD size;
     DWORD type;
+    BYTE buffer[10];
     
     ret = RegQueryValueExA(hkey_main, "TP1_SZ", NULL, &type, NULL, &size);
     ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
     ok(size == strlen(sTestpath1) + 1, "(%ld,%ld)\n", (DWORD)strlen(sTestpath1) + 1, size);
     ok(type == REG_SZ, "type %ld is not REG_SZ\n", type);
+
+    type = 0xdeadbeef;
+    size = 0xdeadbeef;
+    ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Non Existent Value", NULL, &type, NULL, &size);
+    ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %ld\n", ret);
+    ok(size == 0, "size should have been set to 0 instead of %ld\n", size);
+    ok(type == (DWORD)HKEY_CLASSES_ROOT /* NT */ || type == 0 /* Win9x */,
+        "type should have been set to 0x80000000 or 0 instead of 0x%lx\n", type);
+
+    size = sizeof(buffer);
+    ret = RegQueryValueExA(HKEY_CLASSES_ROOT, "Non Existent Value", NULL, &type, buffer, &size);
+    ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %ld\n", ret);
+    ok(size == sizeof(buffer), "size shouldn't have been changed to %ld\n", size);
 }
 
 static void test_get_value(void)




More information about the wine-cvs mailing list