ReactOS  0.4.13-dev-544-gede3fdd
GetGlyphIndices.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 GetGlyphIndices
5 * PROGRAMMERS: Ged Murphy
6 */
7 
8 #include "precomp.h"
9 
10 #define ok_lasterrornotchanged() \
11  ok_err(0x12345)
12 
13 #define MAX_BMP_GLYPHS 0xFFFF
14 
16 {
17  HRSRC hRsrc;
18  LPVOID Data;
19 
20  hRsrc = FindResourceW(GetModuleHandleW(NULL), FontName, (LPCWSTR)RT_RCDATA);
21  if (!hRsrc) return NULL;
22 
24  if (!Data) return NULL;
25 
27  if (*Size == 0) return NULL;
28 
29  return Data;
30 }
31 
32 static BOOL ExtractTTFFile(LPCWSTR FontName, LPWSTR TempFile)
33 {
34  WCHAR TempPath[MAX_PATH];
35  HANDLE hFile;
36  void *Data;
37  DWORD Size;
38  BOOL ret;
39 
40  Data = GetResource(FontName, &Size);
41  if (!Data) return FALSE;
42 
43  GetTempPathW(MAX_PATH, TempPath);
44  GetTempFileNameW(TempPath, L"ttf", 0, TempFile);
45 
47  if (hFile == INVALID_HANDLE_VALUE) return FALSE;
48 
50 
52  return ret;
53 }
54 
55 static BOOL InstallTempFont(LPWSTR TempFile)
56 {
57  if (ExtractTTFFile(L"ReactOSTestTahoma.ttf", TempFile))
58  {
59  if (AddFontResourceExW(TempFile, FR_PRIVATE, 0) > 0)
60  {
61  return TRUE;
62  }
63  }
64 
65  return FALSE;
66 }
67 
68 static VOID RemoveTempFont(LPWSTR TempFile)
69 {
70  BOOL Success;
71  Success = RemoveFontResourceExW(TempFile, FR_PRIVATE, 0);
72  ok(Success, "RemoveFontResourceEx() failed, we're leaving fonts installed : %lu\n", GetLastError());
73  DeleteFileW(TempFile);
74 }
75 
76 static HFONT IntCreateFont(LPWSTR FontName)
77 {
78  LOGFONTW Font = { 0 };
79  Font.lfCharSet = DEFAULT_CHARSET;
80  wcsncpy(Font.lfFaceName, FontName, sizeof(Font.lfFaceName) / sizeof(Font.lfFaceName[0]));
81  return CreateFontIndirectW(&Font);
82 }
83 
84 START_TEST(GetGlyphIndices)
85 {
86  WCHAR Glyphs[MAX_BMP_GLYPHS];
87  WORD Indices[MAX_BMP_GLYPHS];
88  WCHAR Single[2] = { L' ', UNICODE_NULL };
89  WCHAR TempTTFFile[MAX_PATH];
90  HFONT hFont;
91  HDC hdc;
92  int i;
93  DWORD ret;
94  static const WCHAR s_invalids[] = {0xFEFE, 0xFEFF, 0xFFFE, 0};
95 
96  if (!InstallTempFont(TempTTFFile))
97  {
98  skip("Failed to create ttf file for testing\n");
99  return;
100  }
101 
103  ok(hdc != 0, "CreateCompatibleDC failed, skipping tests.\n");
104  if (!hdc) return;
105 
106  hFont = IntCreateFont(L"ReactOSTestTahoma");
107  ok(hFont != NULL, "Failed to open the test font");
109 
110  SetLastError(0x12345);
111 
112  /* Test NULL DC */
113  ok_int(GetGlyphIndicesW(NULL, Single, 1, Indices, 0), GDI_ERROR);
115 
116  /* Test invalid DC */
117  ok_int(GetGlyphIndicesW((HDC)(ULONG_PTR)0x12345, Single, 1, Indices, 0), GDI_ERROR);
119 
120  /* Test invalid params */
125  ok_int(GetGlyphIndicesW(hdc, NULL, 0, Indices, 0), GDI_ERROR);
127  ok_int(GetGlyphIndicesW(hdc, NULL, 1, Indices, 0), GDI_ERROR);
129  ok_int(GetGlyphIndicesW(hdc, NULL, 32, Indices, 0), GDI_ERROR);
135  ok_int(GetGlyphIndicesW(hdc, Glyphs, 32, NULL, 0), GDI_ERROR);
137  ok_int(GetGlyphIndicesW(hdc, Single, 0, Indices, 0), GDI_ERROR);
139  ok_int(GetGlyphIndicesW(hdc, Single, 1, Indices, 0xFFFFFFFF), 1);
141 
142  /* Test an exceptional case that does not seem to return an error */
143  /* In this case, it returns the number of glyphs */
144  ret = GetGlyphIndicesW(hdc, NULL, 0, NULL, 0);
145  ok(ret == 988,
146  "GetGlyphIndicesW(hdc, NULL, 0, NULL, 0) return expected 988, but got %ld\n", ret);
148 
149  /* Test a single valid char */
150  Single[0] = L'a';
151  ok_int(GetGlyphIndicesW(hdc, Single, 1, Indices, 0), 1);
153  ok_int(Indices[0], 68);
154 
155  /* Setup an array of all possible BMP glyphs */
156  for (i = 0; i < 4; i++)
157  Glyphs[i] = (WCHAR)i;
158 
159  /* Test a string of valid chars */
160  StringCchCopyW(Glyphs, MAX_BMP_GLYPHS, L"0123");
161  ok_int(GetGlyphIndicesW(hdc, Glyphs, 4, Indices, 0), 4);
163  ok_int(Indices[0], 19);
164  ok_int(Indices[1], 20);
165  ok_int(Indices[2], 21);
166  ok_int(Indices[3], 22);
167 
168  ok_int(GetGlyphIndicesW(hdc, s_invalids, 3, Indices, 0), 3);
170  ok_int(Indices[0], 0);
171  ok_int(Indices[1], 0);
172  ok_int(Indices[2], 0);
173 
174  ok_int(GetGlyphIndicesW(hdc, s_invalids, 3, Indices, GGI_MARK_NONEXISTING_GLYPHS), 3);
176  ok_int(Indices[0], 0xFFFF);
177  ok_int(Indices[1], 0xFFFF);
178  ok_int(Indices[2], 0xFFFF);
179 
180  /* Setup an array of all possible BMP glyphs */
181  for (i = 0; i < MAX_BMP_GLYPHS; i++)
182  Glyphs[i] = (WCHAR)i;
183 
184  /* Get all the glyphs */
186  Glyphs,
188  Indices,
190 
191  /* The first 32 are invalid and should contain 0xffff */
192  for (i = 0; i < 32; i++)
193  ok_int(Indices[i], 0xffff);
194 
195  /* These are the first 2 valid chars */
196  ok(Indices[32] != 0xffff, "ascii char ' ' should be a valid char");
197  ok(Indices[33] != 0xffff, "ascii char '!' should be a valid char");
198 
199  RemoveTempFont(TempTTFFile);
200 }
201 
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
static VOID RemoveTempFont(LPWSTR TempFile)
Definition: halp.h:205
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
static BOOL InstallTempFont(LPWSTR TempFile)
#define ok_int(x, y)
Definition: sprintf.c:21
static HDC
Definition: imagelist.c:92
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
static BOOL ExtractTTFFile(LPCWSTR FontName, LPWSTR TempFile)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define DEFAULT_CHARSET
Definition: wingdi.h:383
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
HFONT hFont
Definition: main.c:53
uint32_t ULONG_PTR
Definition: typedefs.h:63
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2079
#define UNICODE_NULL
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
#define ok(value,...)
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
smooth NULL
Definition: ftsmooth.c:416
HFONT WINAPI CreateFontIndirectW(_In_ const LOGFONTW *)
#define ok_lasterrornotchanged()
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
#define MAX_BMP_GLYPHS
INT WINAPI AddFontResourceExW(_In_ LPCWSTR pszFilename, _In_ DWORD fl, _Reserved_ PVOID pvReserved)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
#define GGI_MARK_NONEXISTING_GLYPHS
Definition: wingdi.h:1067
#define RT_RCDATA
Definition: pedump.c:372
int ret
static HFONT IntCreateFont(LPWSTR FontName)
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
HDC hdc
Definition: main.c:9
static LPVOID GetResource(LPCWSTR FontName, LPDWORD Size)
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
_In_ HANDLE hFile
Definition: mswsock.h:90
START_TEST(GetGlyphIndices)
#define CREATE_ALWAYS
Definition: disk.h:72
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
#define CreateFileW
Definition: compat.h:400
#define skip(...)
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
uint32_t * LPDWORD
Definition: typedefs.h:57
DWORD WINAPI GetGlyphIndicesW(_In_ HDC hdc, _In_reads_(c) LPCWSTR lpstr, _In_ int c, _Out_writes_(c) LPWORD pgi, _In_ DWORD fl)
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:845
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BOOL WINAPI RemoveFontResourceExW(LPCWSTR lpFileName, DWORD fl, PVOID pdv)
Definition: font.c:2098
#define GDI_ERROR
Definition: wingdi.h:1291