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 )
10 #include <ndk/rtlfuncs.h>
16 NtGdiAddFontResourceW(
17 _In_reads_(cwc
) WCHAR
*pwszFiles
,
22 _In_opt_ DESIGNVECTOR
*pdv
);
24 void Test_NtGdiAddFontResourceW()
26 WCHAR lpszFontPath
[MAX_PATH
];
27 WCHAR lpszFontSearch
[MAX_PATH
];
30 UNICODE_STRING NtAbsPath
;
31 WIN32_FIND_DATAW FindFileData
;
35 // Create "Font" folder Path
36 GetWindowsDirectoryW(lpszFontPath
, MAX_PATH
);
37 StringCbCatW(lpszFontPath
, sizeof(lpszFontPath
), L
"\\Fonts\\");
39 // Search first .ttf file in Fonts Path
40 StringCbCopyW(lpszFontSearch
, sizeof(lpszFontSearch
), lpszFontPath
);
41 StringCbCatW(lpszFontSearch
, sizeof(lpszFontSearch
), L
"*.ttf");
43 hFind
= FindFirstFileW(lpszFontSearch
, &FindFileData
);
45 if (hFind
== INVALID_HANDLE_VALUE
)
47 skip("Unable to find fonts in Font directory!\n");
51 // File found. Create FontPath to File.
52 StringCbCatW(lpszFontPath
, sizeof(lpszFontPath
), FindFileData
.cFileName
);
54 // Fail due "cwc" being zero.
55 SetLastError(0xdeaddead);
56 RtlInitUnicodeString(&NtAbsPath
, NULL
);
57 RtlDosPathNameToNtPathName_U(lpszFontPath
, &NtAbsPath
, NULL
, NULL
);
59 ret
= NtGdiAddFontResourceW(NtAbsPath
.Buffer
, cwc
, 1, 0, 0, 0);
61 ok(ret
== 0, "Expected 0 files added. Added: %d\n", ret
);
62 ok(GetLastError() == 0xdeaddead, "Expected 0xdeaddead. Obtained: 0x%lx\n", GetLastError());
64 RtlFreeUnicodeString(&NtAbsPath
);
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);
73 ok(ret
== 0, "Expected 0 files added. Added: %d\n", ret
);
74 ok(GetLastError() == 0xdeaddead, "Expected 0xdeaddead. Obtained: 0x%lx\n", GetLastError());
76 RtlFreeUnicodeString(&NtAbsPath
);
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);
85 ok(ret
== 1, "Expected 1 files added. Added: %d\n", ret
);
86 ok(GetLastError() == 0xdeaddead, "Expected 0xdeaddead. Obtained: 0x%lx\n", GetLastError());
88 RtlFreeUnicodeString(&NtAbsPath
);
90 // Test an invalid pointer.
91 SetLastError(0xdeadbeef);
92 ret
= NtGdiAddFontResourceW((PVOID
)-4, 123, 1, 0, 0, NULL
);
94 ok(ret
== 0, "Expected 0 files added. Added: %d\n", ret
);
95 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef. Obtained: 0x%lx\n", GetLastError());
98 START_TEST(NtGdiAddFontResource
)
100 Test_NtGdiAddFontResourceW();