5c374d9a5e4cdf9db87521b6c1397883788d0ce3
[reactos.git] / rostests / apitests / gdi32 / AddFontResourceEx.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for AddFontResourceEx
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include <stdio.h>
9 #include <wine/test.h>
10 #include <windows.h>
11 #include <libs/pseh/pseh2.h>
12
13 void Test_AddFontResourceExW()
14 {
15 WCHAR szFileName[MAX_PATH];
16 int result;
17
18 /* Test NULL filename */
19 SetLastError(ERROR_SUCCESS);
20
21 /* Windows crashes, need SEH here */
22 _SEH2_TRY
23 {
24 result = AddFontResourceExW(NULL, 0, 0);
25 }
26 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
27 {
28 result = -1;
29 SetLastError(_SEH2_GetExceptionCode());
30 }
31 _SEH2_END
32 ok(result == -1, "AddFontResourceExW should throw an exception!, result == %d\n", result);
33 ok(GetLastError() == 0xc0000005, "GetLastError()==%lx\n", GetLastError());
34
35 /* Test "" filename */
36 SetLastError(ERROR_SUCCESS);
37 result = AddFontResourceExW(L"", 0, 0);
38 ok(result == 0, "AddFontResourceExW(L"", 0, 0) succeeded, result==%d\n", result);
39 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()==%ld\n", GetLastError());
40
41 GetEnvironmentVariableW(L"systemroot", szFileName, MAX_PATH);
42 wcscat(szFileName, L"\\Fonts\\cour.ttf");
43
44 /* Test flags = 0 */
45 SetLastError(ERROR_SUCCESS);
46 result = AddFontResourceExW(szFileName, 0, 0);
47 ok(result == 1, "AddFontResourceExW(L"", 0, 0) failed, result==%d\n", result);
48 ok(GetLastError() == ERROR_SUCCESS, "GetLastError()==%ld\n", GetLastError());
49
50 SetLastError(ERROR_SUCCESS);
51 result = AddFontResourceExW(szFileName, 256, 0);
52 ok(result == 0, "AddFontResourceExW(L"", 0, 0) failed, result==%d\n", result);
53 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()==%ld\n", GetLastError());
54
55 /* Test invalid pointer as last parameter */
56 result = AddFontResourceExW(szFileName, 0, (void*)-1);
57 ok(result != 0, "AddFontResourceExW(L"", 0, 0) failed, result==%d\n", result);
58 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()==%ld\n", GetLastError());
59
60 }
61
62 START_TEST(AddFontResourceEx)
63 {
64 Test_AddFontResourceExW();
65 }
66