Rob Shearman : advapi32: Add tests for RegSetValueA/W.

Alexandre Julliard julliard at winehq.org
Mon Feb 18 08:50:42 CST 2008


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

Author: Rob Shearman <rob at codeweavers.com>
Date:   Sat Feb 16 15:36:00 2008 +0000

advapi32: Add tests for RegSetValueA/W.

Fix RegSetValueA/W to return ERROR_INVALID_PARAMETER if NULL data is 
passed in.

---

 dlls/advapi32/registry.c       |    4 +-
 dlls/advapi32/tests/registry.c |   59 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c
index 1931ece..dbc7723 100644
--- a/dlls/advapi32/registry.c
+++ b/dlls/advapi32/registry.c
@@ -1078,7 +1078,7 @@ LSTATUS WINAPI RegSetValueW( HKEY hkey, LPCWSTR name, DWORD type, LPCWSTR data,
 
     TRACE("(%p,%s,%d,%s,%d)\n", hkey, debugstr_w(name), type, debugstr_w(data), count );
 
-    if (type != REG_SZ) return ERROR_INVALID_PARAMETER;
+    if (type != REG_SZ || !data) return ERROR_INVALID_PARAMETER;
 
     if (name && name[0])  /* need to create the subkey */
     {
@@ -1104,7 +1104,7 @@ LSTATUS WINAPI RegSetValueA( HKEY hkey, LPCSTR name, DWORD type, LPCSTR data, DW
 
     TRACE("(%p,%s,%d,%s,%d)\n", hkey, debugstr_a(name), type, debugstr_a(data), count );
 
-    if (type != REG_SZ) return ERROR_INVALID_PARAMETER;
+    if (type != REG_SZ || !data) return ERROR_INVALID_PARAMETER;
 
     if (name && name[0])  /* need to create the subkey */
     {
diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c
index 562ebaa..c3f4b2b 100644
--- a/dlls/advapi32/tests/registry.c
+++ b/dlls/advapi32/tests/registry.c
@@ -295,12 +295,42 @@ static void test_set_value(void)
     static const WCHAR emptyW[] = {0};
     static const WCHAR string1W[] = {'T','h','i','s','N','e','v','e','r','B','r','e','a','k','s', 0};
     static const WCHAR string2W[] = {'T','h','i','s', 0 ,'B','r','e','a','k','s', 0 , 0 ,'A', 0 , 0 , 0 , 'L','o','t', 0 , 0 , 0 , 0, 0};
+    static const WCHAR substring2W[] = {'T','h','i','s',0};
 
     static const char name1A[] =   "CleanSingleString";
     static const char name2A[] =   "SomeIntraZeroedString";
     static const char emptyA[] = "";
     static const char string1A[] = "ThisNeverBreaks";
     static const char string2A[] = "This\0Breaks\0\0A\0\0\0Lot\0\0\0\0";
+    static const char substring2A[] = "This";
+
+    ret = RegSetValueA(hkey_main, NULL, REG_SZ, NULL, 0);
+    ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueA should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
+
+    ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, sizeof(string1A));
+    ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
+    test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
+    test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
+
+    /* RegSetValueA ignores the size passed in */
+    ret = RegSetValueA(hkey_main, NULL, REG_SZ, string1A, 4);
+    ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
+    test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
+    test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
+
+    /* stops at first null */
+    ret = RegSetValueA(hkey_main, NULL, REG_SZ, string2A, sizeof(string2A));
+    ok(ret == ERROR_SUCCESS, "RegSetValueA failed: %d, GLE=%d\n", ret, GetLastError());
+    test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
+    test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
+
+    /* only REG_SZ is supported */
+    ret = RegSetValueA(hkey_main, NULL, REG_BINARY, string2A, sizeof(string2A));
+    ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueA should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
+    ret = RegSetValueA(hkey_main, NULL, REG_EXPAND_SZ, string2A, sizeof(string2A));
+    ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueA should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
+    ret = RegSetValueA(hkey_main, NULL, REG_MULTI_SZ, string2A, sizeof(string2A));
+    ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueA should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
 
     /* Test RegSetValueExA with a 'zero-byte' string (as Office 2003 does).
      * Surprisingly enough we're supposed to get zero bytes out of it.
@@ -334,6 +364,35 @@ static void test_set_value(void)
     /* 9x doesn't support W-calls, so don't test them then */
     if(GLE == ERROR_CALL_NOT_IMPLEMENTED) return; 
 
+
+    ret = RegSetValueW(hkey_main, NULL, REG_SZ, NULL, 0);
+    ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have failed with ERROR_INVALID_PARAMETER instead of %d\n", ret);
+
+    ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, sizeof(string1W));
+    ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
+    test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
+    test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
+
+    /* RegSetValueA ignores the size passed in */
+    ret = RegSetValueW(hkey_main, NULL, REG_SZ, string1W, 4 * sizeof(string1W[0]));
+    ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
+    test_hkey_main_Value_A(NULL, string1A, sizeof(string1A));
+    test_hkey_main_Value_W(NULL, string1W, sizeof(string1W));
+
+    /* stops at first null */
+    ret = RegSetValueW(hkey_main, NULL, REG_SZ, string2W, sizeof(string2W));
+    ok(ret == ERROR_SUCCESS, "RegSetValueW failed: %d, GLE=%d\n", ret, GetLastError());
+    test_hkey_main_Value_A(NULL, substring2A, sizeof(substring2A));
+    test_hkey_main_Value_W(NULL, substring2W, sizeof(substring2W));
+
+    /* only REG_SZ is supported */
+    ret = RegSetValueW(hkey_main, NULL, REG_BINARY, string2W, sizeof(string2W));
+    ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
+    ret = RegSetValueW(hkey_main, NULL, REG_EXPAND_SZ, string2W, sizeof(string2W));
+    ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
+    ret = RegSetValueW(hkey_main, NULL, REG_MULTI_SZ, string2W, sizeof(string2W));
+    ok(ret == ERROR_INVALID_PARAMETER, "RegSetValueW should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
+
     /* test RegSetValueExW with normal string */
     ret = RegSetValueExW(hkey_main, name1W, 0, REG_SZ, (const BYTE *)string1W, sizeof(string1W));
     ok(ret == ERROR_SUCCESS, "RegSetValueExW failed: %d, GLE=%d\n", ret, GetLastError());




More information about the wine-cvs mailing list