[PATCH] =Conformance tests for LoadString to show wrong behavior

Christopher Berner raccoonone at procyongames.com
Wed Feb 27 15:03:45 CST 2008


---
 dlls/user32/tests/resource.c  |   49 +++++++++++++++++++++++++++++++++++++++++
 dlls/user32/tests/resource.rc |    1 +
 2 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/dlls/user32/tests/resource.c b/dlls/user32/tests/resource.c
index 59f86ef..db69f15 100644
--- a/dlls/user32/tests/resource.c
+++ b/dlls/user32/tests/resource.c
@@ -31,6 +31,48 @@ static void init_function_pointers(void)
     pPrivateExtractIconsA = (void*)GetProcAddress(hmod, "PrivateExtractIconsA");
 }
 
+static void test_LoadStringW(void)
+{
+    HINSTANCE hInst = GetModuleHandle(NULL);
+    WCHAR copiedstring[128], returnedstring[128], *resourcepointer = NULL;
+    int length1, length2, retvalue;
+
+    /* Check that the string which is returned by LoadStringW matches 
+       the string at the pointer returned by LoadStringW when called with buflen = 0 */
+    length1 = LoadStringW(hInst, 2, (WCHAR *) &resourcepointer, 0); /* get pointer to resource. */
+    length2 = LoadStringW(hInst, 2, returnedstring, sizeof(returnedstring) /sizeof(WCHAR)); /* get resource string */
+    ok(length2 > 0, "LoadStringW failed to load resource 2, ret %d, err %d \n", length2, GetLastError());
+    todo_wine
+    {
+        ok(length1 == length2, "LoadStringW returned different values dependent on buflen. ret1 %d, ret2 %d \n", 
+            length1, length2);
+        ok(length1 > 0 && resourcepointer != NULL, "LoadStringW failed to get pointer to resource 2, ret %d, err %d \n",
+            length1, GetLastError()); 
+    }
+
+    /* Copy the resource since it is not '\0' terminated, and add '\0' to the end */
+    if(resourcepointer != NULL) /* Check that the resource pointer was loaded to avoid access violation */
+    {
+        memcpy(copiedstring, resourcepointer, length1 * sizeof(WCHAR));
+        copiedstring[length1] = '\0';
+        /* check that strings match */
+        ok(!memcmp(copiedstring, returnedstring, (length2 + 1)*sizeof(WCHAR)),
+            "LoadStringW returned a string that does not match the string pointed to by the pointer it returned. \
+             returnedstring = %ls, copiedstring = %ls", (wchar_t *)returnedstring, (wchar_t *)copiedstring);
+    }
+    todo_wine
+    {
+        /* check that calling LoadStringW with buffer = NULL returns zero */
+        retvalue = LoadStringW(hInst, 2, NULL, 0);
+        ok(!retvalue, "LoadStringW returned a non-zero value when called with buffer = NULL, retvalue = %d",
+            retvalue);
+        /* check again, with a different buflen value, that calling LoadStringW with buffer = NULL returns zero */
+        retvalue = LoadStringW(hInst, 2, NULL, 128);
+        ok(!retvalue, "LoadStringW returned a non-zero value when called with buffer = NULL, retvalue = %d",
+            retvalue);
+    }
+}
+
 static void test_LoadStringA (void)
 {
     HINSTANCE hInst = GetModuleHandle (NULL);
@@ -74,6 +116,12 @@ static void test_LoadStringA (void)
         "LoadString failed: ret %d err %d\n", ret, GetLastError());
     ok( LoadStringA( hInst, MAKELONG( 65534, 0xffff ), buf, sizeof(buf)) == ret,
         "LoadString failed: ret %d err %d\n", ret, GetLastError());
+
+    ret = LoadStringA(hInst, 0, buf, 0);
+    todo_wine
+    {
+        ok( ret == -1, "LoadStringA did not return -1 when called with buflen = 0, got %d, err %d", ret, GetLastError());
+    }
 }
 
 static void test_accel1(void)
@@ -317,6 +365,7 @@ START_TEST(resource)
 {
     init_function_pointers();
     test_LoadStringA ();
+    test_LoadStringW();
     test_accel1();
     test_accel2();
     test_PrivateExtractIcons();
diff --git a/dlls/user32/tests/resource.rc b/dlls/user32/tests/resource.rc
index 31ec68f..f01c6f5 100644
--- a/dlls/user32/tests/resource.rc
+++ b/dlls/user32/tests/resource.rc
@@ -41,6 +41,7 @@ STRINGTABLE
 {
   0 "String resource"
   1 "Another string resource"
+  2 L"This is a wide string resource"
   65534 "Test high id"
 }
 
-- 
1.5.2.5


--------------060602040803020005020507--



More information about the wine-patches mailing list