[GDI32_APITEST]
[reactos.git] / rostests / apitests / gdi32 / AddFontResource.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for AddFontResource
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include <stdio.h>
9 #include <apitest.h>
10 #include <wingdi.h>
11
12 #define COUNT 26
13
14 void Test_AddFontResourceA()
15 {
16 CHAR szFileNameA[MAX_PATH];
17 CHAR szFileNameFont1A[MAX_PATH];
18 CHAR szFileNameFont2A[MAX_PATH];
19 int result;
20
21 GetCurrentDirectoryA(MAX_PATH,szFileNameA);
22
23 memcpy(szFileNameFont1A,szFileNameA,MAX_PATH );
24 strcat(szFileNameFont1A, "\\bin\\testdata\\test.ttf");
25
26 memcpy(szFileNameFont2A,szFileNameA,MAX_PATH );
27 strcat(szFileNameFont2A, "\\bin\\testdata\\test.otf");
28
29 RtlZeroMemory(szFileNameA,MAX_PATH);
30
31 /*
32 * Start testing Ansi version
33 *
34 */
35
36 /* Testing NULL pointer */
37 SetLastError(ERROR_SUCCESS);
38 result = AddFontResourceA(NULL);
39 ok(result == 0, "AddFontResourceA succeeded, result=%d\n", result);
40 ok(GetLastError() == ERROR_SUCCESS, "GetLastError()=%ld\n", GetLastError());
41
42 /* Testing -1 pointer */
43 SetLastError(ERROR_SUCCESS);
44 result = AddFontResourceA((CHAR*)-1);
45 ok(result == 0, "AddFontResourceA succeeded, result=%d\n", result);
46 ok(GetLastError() == ERROR_SUCCESS, "GetLastError()=%ld\n", GetLastError());
47
48 /* Testing address 1 pointer */
49 SetLastError(ERROR_SUCCESS);
50 result = AddFontResourceA((CHAR*)1);
51 ok(result == 0, "AddFontResourceA succeeded, result=%d\n", result);
52 ok(GetLastError() == ERROR_SUCCESS, "GetLastError()=%ld\n", GetLastError());
53
54 /* Testing address empty string */
55 SetLastError(ERROR_SUCCESS);
56 result = AddFontResourceA("");
57 ok(result == 0, "AddFontResourceA succeeded, result=%d\n", result);
58 ok(GetLastError() == ERROR_INVALID_PARAMETER, "GetLastError()=%ld\n", GetLastError());
59
60 /* Testing one ttf font */
61 SetLastError(ERROR_SUCCESS);
62 result = AddFontResourceA(szFileNameFont1A);
63 ok(result == 1, "AddFontResourceA(\"%s\") failed, result=%d\n", szFileNameFont1A, result);
64 ok(GetLastError() == ERROR_SUCCESS, "GetLastError()=%ld\n", GetLastError());
65
66 /* Testing one otf font */
67 SetLastError(ERROR_SUCCESS);
68 result = AddFontResourceA(szFileNameFont2A);
69 ok(result == 1, "AddFontResourceA failed, result=%d\n", result);
70 ok(GetLastError() == ERROR_SUCCESS, "GetLastError()=%ld\n", GetLastError());
71
72 /* Testing two fonts */
73 SetLastError(ERROR_SUCCESS);
74 sprintf(szFileNameA,"%s|%s",szFileNameFont1A, szFileNameFont2A);
75 result = AddFontResourceA(szFileNameA);
76 ok(result == 0, "AddFontResourceA succeeded, result=%d\n", result);
77 ok(GetLastError() == ERROR_SUCCESS, "GetLastError()=%ld\n", GetLastError());
78
79 SetLastError(ERROR_SUCCESS);
80 sprintf(szFileNameA,"%s |%s",szFileNameFont1A, szFileNameFont2A);
81 result = AddFontResourceA(szFileNameA);
82 ok(result == 0, "AddFontResourceA succeeded, result=%d\n", result);
83 ok(GetLastError() == ERROR_SUCCESS, "GetLastError()=%ld\n", GetLastError());
84
85 SetLastError(ERROR_SUCCESS);
86 sprintf(szFileNameA,"%s | %s",szFileNameFont1A, szFileNameFont2A);
87 result = AddFontResourceA(szFileNameA);
88 ok(result == 0, "AddFontResourceA succeeded, result=%d\n", result);
89 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError()=%ld\n", GetLastError());
90
91
92 GetCurrentDirectoryA(MAX_PATH, szFileNameA);
93 strcpy(szFileNameFont1A, szFileNameA);
94 strcat(szFileNameFont1A, "\\bin\\testdata\\test.pfm");
95
96 strcpy(szFileNameFont2A, szFileNameA);
97 strcat(szFileNameFont2A, "\\bin\\testdata\\test.pfb");
98
99 SetLastError(ERROR_SUCCESS);
100
101 sprintf(szFileNameA,"%s|%s", szFileNameFont1A, szFileNameFont2A);
102 result = AddFontResourceA(szFileNameA);
103 ok(result == 1, "AddFontResourceA(\"%s|%s\") failed, result=%d\n",
104 szFileNameFont1A, szFileNameFont2A, result);
105 ok(GetLastError() == ERROR_SUCCESS, "GetLastError()=%ld\n", GetLastError());
106
107 sprintf(szFileNameA,"%s | %s", szFileNameFont1A, szFileNameFont2A);
108 result = AddFontResourceA(szFileNameA);
109 ok(result == 0, "AddFontResourceA(\"%s | %s\") succeeded, result=%d\n",
110 szFileNameFont1A, szFileNameFont2A, result);
111 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError()=%ld\n", GetLastError());
112
113 sprintf(szFileNameA,"%s|%s", szFileNameFont2A, szFileNameFont1A);
114 result = AddFontResourceA(szFileNameA);
115 ok(result == 0, "AddFontResourceA(\"%s|%s\") succeeded, result=%d\n",
116 szFileNameFont2A, szFileNameFont1A, result);
117 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError()=%ld\n", GetLastError());
118
119
120 }
121
122 START_TEST(AddFontResource)
123 {
124 Test_AddFontResourceA();
125 }
126