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