1 /* 2 * PROJECT: ReactOS API tests 3 * LICENSE: GPL - See COPYING in the top level directory 4 * PURPOSE: Test for NtGdiAddFontResourceW 5 * PROGRAMMERS: Víctor Martínez Calvo ( victor.martinez@reactos.org ) 6 */ 7 8 #include <apitest.h> 9 #include <wingdi.h> 10 #include <ndk/rtlfuncs.h> 11 #include <strsafe.h> 12 13 14 INT 15 APIENTRY 16 NtGdiAddFontResourceW( 17 _In_reads_(cwc) WCHAR *pwszFiles, 18 _In_ ULONG cwc, 19 _In_ ULONG cFiles, 20 _In_ FLONG f, 21 _In_ DWORD dwPidTid, 22 _In_opt_ DESIGNVECTOR *pdv); 23 24 void Test_NtGdiAddFontResourceW() 25 { 26 WCHAR lpszFontPath[MAX_PATH]; 27 WCHAR lpszFontSearch[MAX_PATH]; 28 29 INT ret; 30 UNICODE_STRING NtAbsPath; 31 WIN32_FIND_DATAW FindFileData; 32 HANDLE hFind; 33 ULONG cwc; 34 35 // Create "Font" folder Path 36 GetWindowsDirectoryW(lpszFontPath, MAX_PATH); 37 StringCbCatW(lpszFontPath, sizeof(lpszFontPath), L"\\Fonts\\"); 38 39 // Search first .ttf file in Fonts Path 40 StringCbCopyW(lpszFontSearch, sizeof(lpszFontSearch), lpszFontPath); 41 StringCbCatW(lpszFontSearch, sizeof(lpszFontSearch), L"*.ttf"); 42 43 hFind = FindFirstFileW(lpszFontSearch, &FindFileData); 44 45 if (hFind == INVALID_HANDLE_VALUE) 46 { 47 skip("Unable to find fonts in Font directory!\n"); 48 return; 49 } 50 51 // File found. Create FontPath to File. 52 StringCbCatW(lpszFontPath, sizeof(lpszFontPath), FindFileData.cFileName); 53 54 // Fail due "cwc" being zero. 55 SetLastError(0xdeaddead); 56 RtlInitUnicodeString(&NtAbsPath, NULL); 57 RtlDosPathNameToNtPathName_U(lpszFontPath, &NtAbsPath, NULL, NULL); 58 cwc = 0; 59 ret = NtGdiAddFontResourceW(NtAbsPath.Buffer, cwc, 1, 0, 0, 0); 60 61 ok(ret == 0, "Expected 0 files added. Added: %d\n", ret); 62 ok(GetLastError() == 0xdeaddead, "Expected 0xdeaddead. Obtained: 0x%lx\n", GetLastError()); 63 64 RtlFreeUnicodeString(&NtAbsPath); 65 66 // "cwc" must count the null terminator. Otherwise fails. 67 SetLastError(0xdeaddead); 68 RtlInitUnicodeString(&NtAbsPath, NULL); 69 RtlDosPathNameToNtPathName_U(lpszFontPath, &NtAbsPath, NULL, NULL); 70 cwc = NtAbsPath.Length / sizeof(WCHAR); 71 ret = NtGdiAddFontResourceW(NtAbsPath.Buffer, cwc, 1, 0, 0, 0); 72 73 ok(ret == 0, "Expected 0 files added. Added: %d\n", ret); 74 ok(GetLastError() == 0xdeaddead, "Expected 0xdeaddead. Obtained: 0x%lx\n", GetLastError()); 75 76 RtlFreeUnicodeString(&NtAbsPath); 77 78 // Correct "cwc" value. 79 SetLastError(0xdeaddead); 80 RtlInitUnicodeString(&NtAbsPath, NULL); 81 RtlDosPathNameToNtPathName_U(lpszFontPath, &NtAbsPath, NULL, NULL); 82 cwc = NtAbsPath.Length / sizeof(WCHAR) + 1; 83 ret = NtGdiAddFontResourceW(NtAbsPath.Buffer, cwc, 1, 0, 0, 0); 84 85 ok(ret == 1, "Expected 1 files added. Added: %d\n", ret); 86 ok(GetLastError() == 0xdeaddead, "Expected 0xdeaddead. Obtained: 0x%lx\n", GetLastError()); 87 88 RtlFreeUnicodeString(&NtAbsPath); 89 90 // Test an invalid pointer. 91 SetLastError(0xdeadbeef); 92 ret = NtGdiAddFontResourceW((PVOID)-4, 123, 1, 0, 0, NULL); 93 94 ok(ret == 0, "Expected 0 files added. Added: %d\n", ret); 95 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef. Obtained: 0x%lx\n", GetLastError()); 96 } 97 98 START_TEST(NtGdiAddFontResource) 99 { 100 Test_NtGdiAddFontResourceW(); 101 } 102