From 8d608a1e4aac81bcd99d5693685fc4c99e95702e Mon Sep 17 00:00:00 2001 From: Daniel Lehman Date: Thu, 8 Mar 2018 15:36:17 -0800 Subject: [PATCH 1/2] gdi32/tests: Test how fonts in \Windows\Fonts are stored in registry. Signed-off-by: Daniel Lehman --- dlls/gdi32/tests/font.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c index 6243a6d..af7778e 100644 --- a/dlls/gdi32/tests/font.c +++ b/dlls/gdi32/tests/font.c @@ -27,10 +27,13 @@ #include "wingdi.h" #include "winuser.h" #include "winnls.h" +#include "winreg.h" #include "wine/heap.h" #include "wine/test.h" +#define ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0])) + static inline BOOL match_off_by_n(int a, int b, unsigned int n) { return abs(a - b) <= n; @@ -6824,6 +6827,99 @@ static void test_long_names(void) ReleaseDC(NULL, dc); } +static void test_fonts_key(void) +{ + static const WCHAR winnt_font_reg_key[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\', + 'W','i','n','d','o','w','s',' ','N','T','\\', + 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', + 'F','o','n','t','s','\0'}; + static const WCHAR fontsW[] = {'\\','F','o','n','t','s','\\','*','.','\0'}; + static const WCHAR exts[][4] = {{'o','t','f','\0'}, {'t','t','c','\0'}, {'t','t','f','\0'}}; + static const WCHAR skip_fonts[][16] = { + {'L','S','A','N','S','.','T','T','F','\0'}, + {'L','S','A','N','S','D','.','T','T','F','\0'}, + {'L','S','A','N','S','D','I','.','T','T','F','\0'}, + {'L','S','A','N','S','I','.','T','T','F','\0'}, + {'m','a','r','l','e','t','t','.','t','t','f','\0'}, + }; + WIN32_FIND_DATAW finddata; + WCHAR fonts_dir[MAX_PATH]; + WCHAR **font_names; + DWORD valuelen; + DWORD datalen; + DWORD nnames; + DWORD vlen; + DWORD dlen; + DWORD i, j; + DWORD type; + HANDLE handle; + LPWSTR value; + LPWSTR data; + HKEY hkey; + LONG ret; + + ret = RegOpenKeyW(HKEY_LOCAL_MACHINE, winnt_font_reg_key, &hkey); + ok(ret == ERROR_SUCCESS, "failed to get fonts key (%d)\n", ret); + + RegQueryInfoKeyW(hkey, NULL, NULL, NULL, NULL, NULL, NULL, &nnames, &valuelen, &datalen, NULL, NULL); + valuelen++; + + value = heap_alloc(valuelen * sizeof(WCHAR)); + data = heap_alloc(datalen * sizeof(WCHAR)); + font_names = heap_alloc(nnames * sizeof(*font_names)); + + i = 0; + vlen = valuelen; + dlen = datalen; + while (RegEnumValueW(hkey, i, value, &vlen, NULL, &type, (LPBYTE)data, &dlen) == ERROR_SUCCESS) + { + font_names[i] = heap_alloc(dlen * sizeof(WCHAR)); + memcpy(font_names[i], data, dlen * sizeof(WCHAR)); + i++; + vlen = valuelen; + dlen = datalen; + } + + heap_free(value); + heap_free(data); + RegCloseKey(hkey); + + for (i = 0; i < ARRAY_SIZE(exts); i++) + { + GetWindowsDirectoryW(fonts_dir, sizeof(fonts_dir)); + lstrcatW(fonts_dir, fontsW); + lstrcatW(fonts_dir, exts[i]); + + handle = FindFirstFileW(fonts_dir, &finddata); + if (handle == INVALID_HANDLE_VALUE) + continue; + + do + { + for (j = 0; j < ARRAY_SIZE(skip_fonts); j++) + { + if (!lstrcmpiW(skip_fonts[j], finddata.cFileName)) + break; + } + if (j < ARRAY_SIZE(skip_fonts)) + continue; + + for (j = 0; j < nnames; j++) + { + if (!lstrcmpiW(font_names[j], finddata.cFileName)) + break; + } +todo_wine + ok(j < nnames, "%s exists on disk but not in registry\n", wine_dbgstr_w(finddata.cFileName)); + } while (FindNextFileW(handle, &finddata)); + FindClose(handle); + } + + for (i = 0; i < nnames; i++) + heap_free(font_names[i]); + heap_free(font_names); +} + START_TEST(font) { init(); @@ -6888,6 +6984,7 @@ START_TEST(font) test_bitmap_font_glyph_index(); test_GetCharWidthI(); test_long_names(); + test_fonts_key(); /* These tests should be last test until RemoveFontResource * is properly implemented. -- 1.9.5