ReactOS  0.4.14-dev-293-g2b39b42
NtGdiAddFontResource.c
Go to the documentation of this file.
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 "precomp.h"
9 
10 #include <ndk/rtlfuncs.h>
11 
12 INT
15  _In_reads_(cwc) WCHAR *pwszFiles,
16  _In_ ULONG cwc,
17  _In_ ULONG cFiles,
18  _In_ FLONG f,
19  _In_ DWORD dwPidTid,
21 
23 {
24  WCHAR lpszFontPath[MAX_PATH];
25  WCHAR lpszFontSearch[MAX_PATH];
26 
27  INT ret;
28  UNICODE_STRING NtAbsPath;
29  WIN32_FIND_DATAW FindFileData;
30  HANDLE hFind;
31  ULONG cwc;
32 
33  // Create "Font" folder Path
34  GetWindowsDirectoryW(lpszFontPath, MAX_PATH);
35  StringCbCatW(lpszFontPath, sizeof(lpszFontPath), L"\\Fonts\\");
36 
37  // Search first .ttf file in Fonts Path
38  StringCbCopyW(lpszFontSearch, sizeof(lpszFontSearch), lpszFontPath);
39  StringCbCatW(lpszFontSearch, sizeof(lpszFontSearch), L"*.ttf");
40 
41  hFind = FindFirstFileW(lpszFontSearch, &FindFileData);
42 
43  if (hFind == INVALID_HANDLE_VALUE)
44  {
45  skip("Unable to find fonts in Font directory!\n");
46  return;
47  }
48 
49  // File found. Create FontPath to File.
50  StringCbCatW(lpszFontPath, sizeof(lpszFontPath), FindFileData.cFileName);
51 
52  // Fail due "cwc" being zero.
53  SetLastError(0xdeaddead);
54  RtlInitUnicodeString(&NtAbsPath, NULL);
55  RtlDosPathNameToNtPathName_U(lpszFontPath, &NtAbsPath, NULL, NULL);
56  cwc = 0;
57  ret = NtGdiAddFontResourceW(NtAbsPath.Buffer, cwc, 1, 0, 0, 0);
58 
59  ok(ret == 0, "Expected 0 files added. Added: %d\n", ret);
60  ok(GetLastError() == 0xdeaddead, "Expected 0xdeaddead. Obtained: 0x%lx\n", GetLastError());
61 
62  RtlFreeUnicodeString(&NtAbsPath);
63 
64  // "cwc" must count the null terminator. Otherwise fails.
65  SetLastError(0xdeaddead);
66  RtlInitUnicodeString(&NtAbsPath, NULL);
67  RtlDosPathNameToNtPathName_U(lpszFontPath, &NtAbsPath, NULL, NULL);
68  cwc = NtAbsPath.Length / sizeof(WCHAR);
69  ret = NtGdiAddFontResourceW(NtAbsPath.Buffer, cwc, 1, 0, 0, 0);
70 
71  ok(ret == 0, "Expected 0 files added. Added: %d\n", ret);
72  ok(GetLastError() == 0xdeaddead, "Expected 0xdeaddead. Obtained: 0x%lx\n", GetLastError());
73 
74  RtlFreeUnicodeString(&NtAbsPath);
75 
76  // Correct "cwc" value.
77  SetLastError(0xdeaddead);
78  RtlInitUnicodeString(&NtAbsPath, NULL);
79  RtlDosPathNameToNtPathName_U(lpszFontPath, &NtAbsPath, NULL, NULL);
80  cwc = NtAbsPath.Length / sizeof(WCHAR) + 1;
81  ret = NtGdiAddFontResourceW(NtAbsPath.Buffer, cwc, 1, 0, 0, 0);
82 
83  ok(ret == 1, "Expected 1 files added. Added: %d\n", ret);
84  ok(GetLastError() == 0xdeaddead, "Expected 0xdeaddead. Obtained: 0x%lx\n", GetLastError());
85 
86  RtlFreeUnicodeString(&NtAbsPath);
87 
88  // Test an invalid pointer.
89  SetLastError(0xdeadbeef);
90  ret = NtGdiAddFontResourceW((PVOID)-4, 123, 1, 0, 0, NULL);
91 
92  ok(ret == 0, "Expected 0 files added. Added: %d\n", ret);
93  ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef. Obtained: 0x%lx\n", GetLastError());
94 }
95 
96 START_TEST(NtGdiAddFontResource)
97 {
99 }
_In_ ULONG_PTR _In_opt_ DESIGNVECTOR * pdv
Definition: winddi.h:3723
#define _In_reads_(size)
Definition: no_sal2.h:228
INT APIENTRY NtGdiAddFontResourceW(_In_reads_(cwc) WCHAR *pwszFiles, _In_ ULONG cwc, _In_ ULONG cFiles, _In_ FLONG f, _In_ DWORD dwPidTid, _In_opt_ DESIGNVECTOR *pdv)
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
int32_t INT
Definition: typedefs.h:56
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
#define _In_opt_
Definition: no_sal2.h:213
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2351
smooth NULL
Definition: ftsmooth.c:416
unsigned long FLONG
Definition: ntbasedef.h:373
GLfloat f
Definition: glext.h:7540
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define SetLastError(x)
Definition: compat.h:409
int ret
static const WCHAR L[]
Definition: oid.c:1250
#define _In_
Definition: no_sal2.h:204
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
START_TEST(NtGdiAddFontResource)
void Test_NtGdiAddFontResourceW()
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
#define APIENTRY
Definition: api.h:79
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToNtPathName_U(_In_opt_z_ PCWSTR DosPathName, _Out_ PUNICODE_STRING NtPathName, _Out_opt_ PCWSTR *NtFileNamePart, _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo)
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320