From: Stefan Leichter <Stefan.Leichter@camline.com>
Subject: [2/2] gdi32/tests: Added tests for GetFontResourceInfoW (try 2)
Message-Id: <201212162253.39114.Stefan.Leichter@camline.com>
Date: Sun, 16 Dec 2012 22:53:39 +0100

---
 dlls/gdi32/tests/font.c |  186 
+++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 186 insertions(+), 0 deletions(-)

diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c
index 8508d70..4eca34e 100644
--- a/dlls/gdi32/tests/font.c
+++ b/dlls/gdi32/tests/font.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#include <stdio.h>
 #include <stdarg.h>
 #include <assert.h>
 
@@ -36,6 +37,9 @@
 #define near_match(a, b) (abs((a) - (b)) <= 6)
 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
 
+/* see http://www.undocprint.org/winspool/getfontresourceinfo */
+#define QFR_DESCRIPTION 1
+
 static LONG  (WINAPI *pGdiGetCharDimensions)(HDC hdc, LPTEXTMETRICW lptm, LONG *height);
 static DWORD (WINAPI *pGdiGetCodePage)(HDC hdc);
 static BOOL  (WINAPI *pGetCharABCWidthsI)(HDC hdc, UINT first, UINT count, LPWORD glyphs, LPABC abc);
@@ -50,6 +54,7 @@ static HFONT (WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDV *);
 static HANDLE (WINAPI *pAddFontMemResourceEx)(PVOID, DWORD, PVOID, DWORD *);
 static BOOL  (WINAPI *pRemoveFontMemResourceEx)(HANDLE);
 static INT   (WINAPI *pAddFontResourceExA)(LPCSTR, DWORD, PVOID);
+static DWORD (WINAPI *pGetFontResourceInfoW)(LPWSTR, LPDWORD, LPVOID, DWORD);
 static BOOL  (WINAPI *pRemoveFontResourceExA)(LPCSTR, DWORD, PVOID);
 
 static HMODULE hgdi32 = 0;
@@ -74,6 +79,7 @@ static void init(void)
     pAddFontMemResourceEx = (void *)GetProcAddress(hgdi32, "AddFontMemResourceEx");
     pRemoveFontMemResourceEx = (void *)GetProcAddress(hgdi32, "RemoveFontMemResourceEx");
     pAddFontResourceExA = (void *)GetProcAddress(hgdi32, "AddFontResourceExA");
+    pGetFontResourceInfoW = (void *)GetProcAddress(hgdi32, "GetFontResourceInfoW");
     pRemoveFontResourceExA = (void *)GetProcAddress(hgdi32, "RemoveFontResourceExA");
 
     system_lang_id = PRIMARYLANGID(GetSystemDefaultLangID());
@@ -4745,6 +4751,185 @@ static void test_stock_fonts(void)
     }
 }
 
+static void test_GetFontResourceInfoW(void)
+{
+    static WCHAR arial[] = {'A','r','i','a','l',0};
+    static WCHAR arialAsterisk[] = {'A','r','i','a','*',0};
+    static WCHAR arialTtf[] = {'A','r','i','a','l','.','t','t','f',0};
+    static WCHAR bs[] = {'\\',0};
+    static WCHAR sysrootArialTtf[] = {'%','S','y','s','t','e','m','R','o','o','t','%','\\','F','o','n','t','s','\\','A','r','i','a','l','.','t','t','f',0};
+    WCHAR cwdArialTtf[MAX_PATH];
+    WCHAR pathArialTtf[MAX_PATH];
+    BOOL  resultB;
+    DWORD required, size;
+    DWORD resultDW;
+    BYTE  buffer[MAX_PATH];
+
+    if(!pGetFontResourceInfoW)
+    {
+        skip("function GetFontResourceInfoW not present\n");
+        return;
+    }
+    
+    if (!is_truetype_font_installed("Arial"))
+    {
+        skip("Arial not installed\n");
+        return;
+    }
+
+	/* if first parameter is null, function fails always */
+    size = 0;
+    resultB = pGetFontResourceInfoW(NULL, &size, NULL, QFR_DESCRIPTION);
+    ok(!resultB, "GetFontResourceInfoW succeeded\n");
+
+    size = 0;
+    resultB = pGetFontResourceInfoW(NULL, &size, buffer, QFR_DESCRIPTION);
+    ok(!resultB, "GetFontResourceInfoW succeeded\n");
+
+    size = MAX_PATH / sizeof(WCHAR);
+    resultB = pGetFontResourceInfoW(NULL, &size, buffer, QFR_DESCRIPTION);
+    ok(!resultB, "GetFontResourceInfoW succeeded\n");
+
+    /* if second parameter is null function crashes */
+
+    /* if third parameter is null, value of the second parameter
+       must be zero else the function fails */
+    size = 0;
+    resultB = pGetFontResourceInfoW(arialTtf, &size, NULL, QFR_DESCRIPTION);
+    todo_wine
+    ok(resultB, "GetFontResourceInfoW failed with %d(%x)\n", GetLastError(), GetLastError());
+    todo_wine
+    ok(size != 0, "expected size to change\n");
+    required = size;
+
+    if(!resultB)
+    {
+        todo_wine
+        ok(0, "Don't know how to test GetFontResourceInfoW on this system\n");
+        return;
+    }
+
+    size = 2;
+    resultB = pGetFontResourceInfoW(arialTtf, &size, NULL, QFR_DESCRIPTION);
+    ok(!resultB, "GetFontResourceInfoW succeeded\n");
+
+    size = required + 10;
+    resultB = pGetFontResourceInfoW(arialTtf, &size, NULL, QFR_DESCRIPTION);
+    ok(!resultB, "GetFontResourceInfoW succeeded\n");
+
+    /* if the buffer is big enough the function succeeds,
+     * but the function reports as buffer size one character
+     * not than required. Check if this character is modified  
+     */
+    memset(buffer, (int) '\0', sizeof(buffer));
+    size = MAX_PATH / sizeof(WCHAR);
+    SetLastError(0xdeadbeef);
+    resultB = pGetFontResourceInfoW(arialTtf, &size, buffer, QFR_DESCRIPTION);
+    ok(resultB, "GetFontResourceInfoW failed with %d(%x)\n", GetLastError(), GetLastError());
+    ok(size == required, "expected size %d, got %d\n", required, size);
+    ok(size == sizeof(WCHAR) * (2 + lstrlenW((WCHAR*)buffer)),
+       "unexpected buffer size/content got %d,%s\n", size, wine_dbgstr_w((WCHAR*)buffer));
+    ok(!lstrcmpW(arial, (WCHAR*) buffer), "expected buffer value %s, got %s\n",
+        wine_dbgstr_w(arial), wine_dbgstr_w((WCHAR*)buffer));
+    if(resultB)
+    {
+        WCHAR *ptr = (WCHAR*)buffer;
+        winetest_trace("Got %s %04x\n", wine_dbgstr_w((WCHAR*)buffer),
+                       *(ptr + lstrlenW(ptr) + 1));
+    }
+
+    memset(buffer, 0x5a, sizeof(buffer));
+    size = MAX_PATH / sizeof(WCHAR);
+    SetLastError(0xdeadbeef);
+    resultB = pGetFontResourceInfoW(arialTtf, &size, buffer, QFR_DESCRIPTION);
+    ok(resultB, "GetFontResourceInfoW failed with %d(%x)\n", GetLastError(), GetLastError());
+    ok(size == required, "expected size %d, got %d\n", required, size);
+    ok(size == sizeof(WCHAR) * (2 + lstrlenW((WCHAR*)buffer)),
+       "unexpected buffer size/content got %d,%s\n", size, wine_dbgstr_w((WCHAR*)buffer));
+    ok(!lstrcmpW(arial, (WCHAR*) buffer), "expected buffer value %s, got %s\n",
+        wine_dbgstr_w(arial), wine_dbgstr_w((WCHAR*)buffer));
+    if(resultB)
+    {
+        WCHAR *ptr = (WCHAR*)buffer;
+        ptr += lstrlenW(ptr) + 1;
+        ok(*ptr == 0, "expected a second null terminator, got %04x\n", *ptr);
+    }
+
+    memset(buffer, (int) '\0', sizeof(buffer));
+    size = required + 10;
+    SetLastError(0xdeadbeef);
+    resultB = pGetFontResourceInfoW(arialTtf, &size, buffer, QFR_DESCRIPTION);
+    ok(resultB, "GetFontResourceInfoW failed with %d(%x)\n", GetLastError(), GetLastError());
+    ok(size == required, "expected size %d, got %d\n", required, size);
+    ok(size == sizeof(WCHAR) * (2 + lstrlenW((WCHAR*)buffer)),
+       "unexpected buffer size/content got %d,%s\n", size, wine_dbgstr_w((WCHAR*)buffer));
+    ok(!lstrcmpW(arial, (WCHAR*) buffer), "expected buffer value %s, got %s\n",
+        wine_dbgstr_w(arial), wine_dbgstr_w((WCHAR*)buffer));
+
+    /* test different filenames */
+    size = 0;
+    SetLastError(0xdeadbeef);
+    resultB = pGetFontResourceInfoW(arial, &size, NULL, QFR_DESCRIPTION);
+    ok(!resultB, "GetFontResourceInfoW succeeded\n");
+    ok(ERROR_FILE_NOT_FOUND == GetLastError(), "expected error ERROR_FILE_NOT_FOUND, got %d/%x\n",
+                                                GetLastError(), GetLastError());
+
+    size = 0;
+    SetLastError(0xdeadbeef);
+    resultB = pGetFontResourceInfoW(arialAsterisk, &size, NULL, QFR_DESCRIPTION);
+    ok(!resultB, "GetFontResourceInfoW succeeded\n");
+    ok(ERROR_FILE_NOT_FOUND == GetLastError(), "expected error ERROR_FILE_NOT_FOUND, got %d/%x\n",
+                                                GetLastError(), GetLastError());
+
+    resultDW = ExpandEnvironmentStringsW(sysrootArialTtf, pathArialTtf, MAX_PATH);
+    if(!resultDW)
+    {
+        ok(0, "ExpandEnvironmentStringsW failed\n");
+        return;
+    }
+
+    memset(buffer, (int) '\0', sizeof(buffer));
+    size = MAX_PATH / sizeof(WCHAR);
+    SetLastError(0xdeadbeef);
+    resultB = pGetFontResourceInfoW(pathArialTtf, &size, buffer, QFR_DESCRIPTION);
+    ok(resultB, "GetFontResourceInfoW failed with %d(%x)\n", GetLastError(), GetLastError());
+    ok(size == required, "expected size %d, got %d\n", required, size);
+    ok(size == sizeof(WCHAR) * (2 + lstrlenW((WCHAR*)buffer)),
+       "unexpected buffer size/content got %d,%s\n", size, wine_dbgstr_w((WCHAR*)buffer));
+    ok(!lstrcmpW(arial, (WCHAR*) buffer), "expected buffer value %s, got %s\n",
+        wine_dbgstr_w(arial), wine_dbgstr_w((WCHAR*)buffer));
+
+    resultDW = GetCurrentDirectoryW(MAX_PATH, cwdArialTtf);
+    if(!resultDW)
+    {
+        ok(0, "GetCurrentDirectoryW failed\n");
+        return;
+    }
+
+    lstrcatW(cwdArialTtf,bs);
+    lstrcatW(cwdArialTtf,arialTtf);
+    resultB = CopyFileW(pathArialTtf, cwdArialTtf, FALSE);
+    if(!resultB)
+    {
+        ok(0, "CopyFileW %s -> %s failed\n", wine_dbgstr_w(pathArialTtf), wine_dbgstr_w(cwdArialTtf));
+        return;
+    }
+    winetest_trace("Testing with: %s\n", wine_dbgstr_w(cwdArialTtf));
+
+    size = 0;
+    SetLastError(0xdeadbeef);
+    resultB = pGetFontResourceInfoW(cwdArialTtf, &size, NULL, QFR_DESCRIPTION);
+    ok(!resultB, "GetFontResourceInfoW succeeded\n");
+
+    memset(buffer, (int) '\0', sizeof(buffer));
+    size = MAX_PATH / sizeof(WCHAR);
+    SetLastError(0xdeadbeef);
+    resultB = pGetFontResourceInfoW(cwdArialTtf, &size, buffer, QFR_DESCRIPTION);
+    ok(!resultB, "GetFontResourceInfoW succeeded\n");
+
+    DeleteFileW(cwdArialTtf);
+}
+
 START_TEST(font)
 {
     init();
@@ -4806,4 +4991,5 @@ START_TEST(font)
      */
     test_vertical_font();
     test_CreateScalableFontResource();
+    test_GetFontResourceInfoW();
 }