2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for GetGlyphIndices
5 * PROGRAMMERS: Ged Murphy
14 #define ok_lasterrornotchanged() \
17 #define MAX_BMP_GLYPHS 0xFFFF
19 static LPVOID
GetResource(LPCWSTR FontName
, LPDWORD Size
)
24 hRsrc
= FindResourceW(GetModuleHandleW(NULL
), FontName
, (LPCWSTR
)RT_RCDATA
);
25 if (!hRsrc
) return NULL
;
27 Data
= LockResource(LoadResource(GetModuleHandleW(NULL
), hRsrc
));
28 if (!Data
) return NULL
;
30 *Size
= SizeofResource(GetModuleHandleW(NULL
), hRsrc
);
31 if (*Size
== 0) return NULL
;
36 static BOOL
ExtractTTFFile(LPCWSTR FontName
, LPWSTR TempFile
)
38 WCHAR TempPath
[MAX_PATH
];
44 Data
= GetResource(FontName
, &Size
);
45 if (!Data
) return FALSE
;
47 GetTempPathW(MAX_PATH
, TempPath
);
48 GetTempFileNameW(TempPath
, L
"ttf", 0, TempFile
);
50 hFile
= CreateFileW(TempFile
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, 0);
51 if (hFile
== INVALID_HANDLE_VALUE
) return FALSE
;
53 ret
= WriteFile(hFile
, Data
, Size
, &Size
, NULL
);
59 static BOOL
InstallTempFont(LPWSTR TempFile
)
61 if (ExtractTTFFile(L
"ReactOSTestTahoma.ttf", TempFile
))
63 if (AddFontResourceExW(TempFile
, FR_PRIVATE
, 0) > 0)
72 static VOID
RemoveTempFont(LPWSTR TempFile
)
75 Success
= RemoveFontResourceExW(TempFile
, FR_PRIVATE
, 0);
76 ok(Success
, "RemoveFontResourceEx() failed, we're leaving fonts installed : %lu\n", GetLastError());
77 DeleteFileW(TempFile
);
80 static HFONT
IntCreateFont(LPWSTR FontName
)
82 LOGFONTW Font
= { 0 };
83 Font
.lfCharSet
= DEFAULT_CHARSET
;
84 wcsncpy(Font
.lfFaceName
, FontName
, sizeof(Font
.lfFaceName
) / sizeof(Font
.lfFaceName
[0]));
85 return CreateFontIndirectW(&Font
);
88 START_TEST(GetGlyphIndices
)
90 WCHAR Glyphs
[MAX_BMP_GLYPHS
];
91 WORD Indices
[MAX_BMP_GLYPHS
];
92 WCHAR Single
[2] = { L
' ', UNICODE_NULL
};
93 WCHAR TempTTFFile
[MAX_PATH
];
98 if (!InstallTempFont(TempTTFFile
))
100 skip("Failed to create ttf file for testing\n");
104 hdc
= CreateCompatibleDC(NULL
);
105 ok(hdc
!= 0, "CreateCompatibleDC failed, skipping tests.\n");
108 hFont
= IntCreateFont(L
"ReactOSTestTahoma");
109 ok(hFont
!= NULL
, "Failed to open the test font");
110 SelectObject(hdc
, hFont
);
112 SetLastError(0x12345);
115 ok_int(GetGlyphIndicesW(NULL
, Single
, 1, Indices
, 0), GDI_ERROR
);
116 ok_lasterrornotchanged();
118 /* Test invalid DC */
119 ok_int(GetGlyphIndicesW((HDC
)(ULONG_PTR
)0x12345, Single
, 1, Indices
, 0), GDI_ERROR
);
120 ok_lasterrornotchanged();
122 /* Test invalid params */
123 ok_int(GetGlyphIndicesW(hdc
, NULL
, 0, Indices
, 0), GDI_ERROR
);
124 ok_lasterrornotchanged();
125 ok_int(GetGlyphIndicesW(hdc
, NULL
, 1, Indices
, 0), GDI_ERROR
);
126 ok_lasterrornotchanged();
127 ok_int(GetGlyphIndicesW(hdc
, Single
, 1, NULL
, 0), GDI_ERROR
);
128 ok_lasterrornotchanged();
130 /* Test a single valid char */
132 ok_int(GetGlyphIndicesW(hdc
, Single
, 1, Indices
, 0), 1);
133 ok_lasterrornotchanged();
134 ok_int(Indices
[0], 68);
136 /* Setup an array of all possible BMP glyphs */
137 for (i
= 0; i
< 4; i
++)
138 Glyphs
[i
] = (WCHAR
)i
;
140 /* Test a string of valid chars */
141 StringCchCopyW(Glyphs
, MAX_BMP_GLYPHS
, L
"0123");
142 ok_int(GetGlyphIndicesW(hdc
, Glyphs
, 4, Indices
, 0), 4);
143 ok_lasterrornotchanged();
144 ok_int(Indices
[0], 19);
145 ok_int(Indices
[1], 20);
146 ok_int(Indices
[2], 21);
147 ok_int(Indices
[3], 22);
149 /* Setup an array of all possible BMP glyphs */
150 for (i
= 0; i
< MAX_BMP_GLYPHS
; i
++)
151 Glyphs
[i
] = (WCHAR
)i
;
153 /* Get all the glyphs */
154 ok_int(GetGlyphIndicesW(hdc
,
158 GGI_MARK_NONEXISTING_GLYPHS
), MAX_BMP_GLYPHS
);
160 /* The first 32 are invalid and should contain 0xffff */
161 for (i
= 0; i
< 32; i
++)
162 ok_int(Indices
[i
], 0xffff);
164 /* These are the first 2 valid chars */
165 ok(Indices
[32] != 0xffff, "ascii char ' ' should be a valid char");
166 ok(Indices
[33] != 0xffff, "ascii char '!' should be a valid char");
168 RemoveTempFont(TempTTFFile
);