2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for GetGlyphIndices
5 * PROGRAMMERS: Ged Murphy
10 #define ok_lasterrornotchanged() \
13 #define MAX_BMP_GLYPHS 0xFFFF
15 static LPVOID
GetResource(LPCWSTR FontName
, LPDWORD Size
)
20 hRsrc
= FindResourceW(GetModuleHandleW(NULL
), FontName
, (LPCWSTR
)RT_RCDATA
);
21 if (!hRsrc
) return NULL
;
23 Data
= LockResource(LoadResource(GetModuleHandleW(NULL
), hRsrc
));
24 if (!Data
) return NULL
;
26 *Size
= SizeofResource(GetModuleHandleW(NULL
), hRsrc
);
27 if (*Size
== 0) return NULL
;
32 static BOOL
ExtractTTFFile(LPCWSTR FontName
, LPWSTR TempFile
)
34 WCHAR TempPath
[MAX_PATH
];
40 Data
= GetResource(FontName
, &Size
);
41 if (!Data
) return FALSE
;
43 GetTempPathW(MAX_PATH
, TempPath
);
44 GetTempFileNameW(TempPath
, L
"ttf", 0, TempFile
);
46 hFile
= CreateFileW(TempFile
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, 0);
47 if (hFile
== INVALID_HANDLE_VALUE
) return FALSE
;
49 ret
= WriteFile(hFile
, Data
, Size
, &Size
, NULL
);
55 static BOOL
InstallTempFont(LPWSTR TempFile
)
57 if (ExtractTTFFile(L
"ReactOSTestTahoma.ttf", TempFile
))
59 if (AddFontResourceExW(TempFile
, FR_PRIVATE
, 0) > 0)
68 static VOID
RemoveTempFont(LPWSTR TempFile
)
71 Success
= RemoveFontResourceExW(TempFile
, FR_PRIVATE
, 0);
72 ok(Success
, "RemoveFontResourceEx() failed, we're leaving fonts installed : %lu\n", GetLastError());
73 DeleteFileW(TempFile
);
76 static HFONT
IntCreateFont(LPWSTR FontName
)
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
);
84 START_TEST(GetGlyphIndices
)
86 WCHAR Glyphs
[MAX_BMP_GLYPHS
];
87 WORD Indices
[MAX_BMP_GLYPHS
];
88 WCHAR Single
[2] = { L
' ', UNICODE_NULL
};
89 WCHAR TempTTFFile
[MAX_PATH
];
94 if (!InstallTempFont(TempTTFFile
))
96 skip("Failed to create ttf file for testing\n");
100 hdc
= CreateCompatibleDC(NULL
);
101 ok(hdc
!= 0, "CreateCompatibleDC failed, skipping tests.\n");
104 hFont
= IntCreateFont(L
"ReactOSTestTahoma");
105 ok(hFont
!= NULL
, "Failed to open the test font");
106 SelectObject(hdc
, hFont
);
108 SetLastError(0x12345);
111 ok_int(GetGlyphIndicesW(NULL
, Single
, 1, Indices
, 0), GDI_ERROR
);
112 ok_lasterrornotchanged();
114 /* Test invalid DC */
115 ok_int(GetGlyphIndicesW((HDC
)(ULONG_PTR
)0x12345, Single
, 1, Indices
, 0), GDI_ERROR
);
116 ok_lasterrornotchanged();
118 /* Test invalid params */
119 ok_int(GetGlyphIndicesW(hdc
, NULL
, 0, Indices
, 0), GDI_ERROR
);
120 ok_lasterrornotchanged();
121 ok_int(GetGlyphIndicesW(hdc
, NULL
, 1, Indices
, 0), GDI_ERROR
);
122 ok_lasterrornotchanged();
123 ok_int(GetGlyphIndicesW(hdc
, Single
, 0, NULL
, 0), GDI_ERROR
);
124 ok_lasterrornotchanged();
125 ok_int(GetGlyphIndicesW(hdc
, Single
, 0, Indices
, 0), GDI_ERROR
);
126 ok_lasterrornotchanged();
127 ok_int(GetGlyphIndicesW(hdc
, Single
, 1, NULL
, 0), GDI_ERROR
);
128 ok_lasterrornotchanged();
130 /* Test an exceptional case that does not seem to return an error */
131 // FIXME: What does the returned value exactly means?
132 ok(GetGlyphIndicesW(hdc
, NULL
, 0, NULL
, 0) != 0,
133 "GetGlyphIndicesW(hdc, NULL, 0, NULL, 0) return expected not zero, but got zero!\n");
134 ok_lasterrornotchanged();
136 /* Test a single valid char */
138 ok_int(GetGlyphIndicesW(hdc
, Single
, 1, Indices
, 0), 1);
139 ok_lasterrornotchanged();
140 ok_int(Indices
[0], 68);
142 /* Setup an array of all possible BMP glyphs */
143 for (i
= 0; i
< 4; i
++)
144 Glyphs
[i
] = (WCHAR
)i
;
146 /* Test a string of valid chars */
147 StringCchCopyW(Glyphs
, MAX_BMP_GLYPHS
, L
"0123");
148 ok_int(GetGlyphIndicesW(hdc
, Glyphs
, 4, Indices
, 0), 4);
149 ok_lasterrornotchanged();
150 ok_int(Indices
[0], 19);
151 ok_int(Indices
[1], 20);
152 ok_int(Indices
[2], 21);
153 ok_int(Indices
[3], 22);
155 /* Setup an array of all possible BMP glyphs */
156 for (i
= 0; i
< MAX_BMP_GLYPHS
; i
++)
157 Glyphs
[i
] = (WCHAR
)i
;
159 /* Get all the glyphs */
160 ok_int(GetGlyphIndicesW(hdc
,
164 GGI_MARK_NONEXISTING_GLYPHS
), MAX_BMP_GLYPHS
);
166 /* The first 32 are invalid and should contain 0xffff */
167 for (i
= 0; i
< 32; i
++)
168 ok_int(Indices
[i
], 0xffff);
170 /* These are the first 2 valid chars */
171 ok(Indices
[32] != 0xffff, "ascii char ' ' should be a valid char");
172 ok(Indices
[33] != 0xffff, "ascii char '!' should be a valid char");
174 RemoveTempFont(TempTTFFile
);