ReactOS 0.4.15-dev-7674-gc0b4db1
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;
19
21 if (!hRsrc) return NULL;
22
24 if (!Data) return NULL;
25
27 if (*Size == 0) return NULL;
28
29 return Data;
30}
31
32static BOOL ExtractTTFFile(LPCWSTR FontName, LPWSTR TempFile)
33{
34 WCHAR TempPath[MAX_PATH];
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
55static 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
68static VOID RemoveTempFont(LPWSTR TempFile)
69{
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
76static 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]));
82}
83
84START_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];
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
#define ok_lasterrornotchanged()
static BOOL InstallTempFont(LPWSTR TempFile)
static BOOL ExtractTTFFile(LPCWSTR FontName, LPWSTR TempFile)
static HFONT IntCreateFont(LPWSTR FontName)
#define MAX_BMP_GLYPHS
static VOID RemoveTempFont(LPWSTR TempFile)
static LPVOID GetResource(LPCWSTR FontName, LPDWORD Size)
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
HFONT hFont
Definition: main.c:53
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2080
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
@ Success
Definition: eventcreate.c:712
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
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
@ Single
Definition: halhw.h:165
#define CREATE_ALWAYS
Definition: disk.h:72
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:92
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
_In_ HANDLE hFile
Definition: mswsock.h:90
#define GENERIC_WRITE
Definition: nt_native.h:90
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
#define RT_RCDATA
Definition: pedump.c:372
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
uint32_t * LPDWORD
Definition: typedefs.h:59
uint32_t ULONG_PTR
Definition: typedefs.h:65
int ret
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
BOOL WINAPI RemoveFontResourceExW(LPCWSTR lpFileName, DWORD fl, PVOID pdv)
Definition: font.c:2098
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
DWORD WINAPI GetGlyphIndicesW(_In_ HDC hdc, _In_reads_(c) LPCWSTR lpstr, _In_ int c, _Out_writes_(c) LPWORD pgi, _In_ DWORD fl)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define DEFAULT_CHARSET
Definition: wingdi.h:384
#define GDI_ERROR
Definition: wingdi.h:1309
HFONT WINAPI CreateFontIndirectW(_In_ const LOGFONTW *)
INT WINAPI AddFontResourceExW(_In_ LPCWSTR pszFilename, _In_ DWORD fl, _Reserved_ PVOID pvReserved)
#define GGI_MARK_NONEXISTING_GLYPHS
Definition: wingdi.h:1085
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185