[IPHLPAPI_APITEST]
[reactos.git] / rostests / apitests / gdi32 / CreateIconIndirect.c
1
2 #include <apitest.h>
3
4 #include <wingdi.h>
5 #include <winuser.h>
6
7
8 // FIXME user32
9
10 void
11 Test_GetIconInfo(BOOL fIcon)
12 {
13 HICON hicon;
14 ICONINFO iconinfo, iconinfo2;
15 BITMAP bitmap;
16
17 iconinfo.fIcon = fIcon;
18 iconinfo.xHotspot = 0;
19 iconinfo.yHotspot = 0;
20 iconinfo.hbmMask = NULL;
21 iconinfo.hbmColor = NULL;
22
23 hicon = CreateIconIndirect(&iconinfo);
24 ok(hicon == 0, "should fail\n");
25
26 iconinfo.hbmMask = CreateBitmap(8, 16, 1, 1, NULL);
27 hicon = CreateIconIndirect(&iconinfo);
28 ok(hicon != 0, "should not fail\n");
29
30 ok(GetIconInfo(hicon, &iconinfo2), "\n");
31 ok(iconinfo2.fIcon == iconinfo.fIcon, "\n");
32 if (fIcon)
33 {
34 ok(iconinfo2.xHotspot == 4, "%ld\n", iconinfo2.xHotspot);
35 ok(iconinfo2.yHotspot == 4, "%ld\n", iconinfo2.yHotspot);
36 }
37 else
38 {
39 ok(iconinfo2.xHotspot == 0, "%ld\n", iconinfo2.xHotspot);
40 ok(iconinfo2.yHotspot == 0, "%ld\n", iconinfo2.yHotspot);
41 }
42 ok(iconinfo2.hbmMask != NULL, "\n");
43 ok(iconinfo2.hbmMask != iconinfo.hbmMask, "\n");
44 ok(iconinfo2.hbmColor == NULL, "\n");
45
46 ok(GetIconInfo(hicon, &iconinfo2), "\n");
47 ok(iconinfo2.fIcon == iconinfo.fIcon, "\n");
48 if (fIcon)
49 {
50 ok(iconinfo2.xHotspot == 4, "%ld\n", iconinfo2.xHotspot);
51 ok(iconinfo2.yHotspot == 4, "%ld\n", iconinfo2.yHotspot);
52 }
53 else
54 {
55 ok(iconinfo2.xHotspot == 0, "%ld\n", iconinfo2.xHotspot);
56 ok(iconinfo2.yHotspot == 0, "%ld\n", iconinfo2.yHotspot);
57 }
58 ok(iconinfo2.hbmMask != NULL, "\n");
59 ok(iconinfo2.hbmMask != iconinfo.hbmMask, "\n");
60 ok(iconinfo2.hbmColor == NULL, "\n");
61
62 iconinfo.hbmColor = CreateBitmap(2, 2, 1, 1, NULL);
63 hicon = CreateIconIndirect(&iconinfo);
64 ok(hicon != 0, "should not fail\n");
65
66 ok(GetIconInfo(hicon, &iconinfo2), "\n");
67 ok(iconinfo2.fIcon == iconinfo.fIcon, "\n");
68 if (fIcon)
69 {
70 ok(iconinfo2.xHotspot == 4, "%ld\n", iconinfo2.xHotspot);
71 ok(iconinfo2.yHotspot == 8, "%ld\n", iconinfo2.yHotspot);
72 }
73 else
74 {
75 ok(iconinfo2.xHotspot == 0, "%ld\n", iconinfo2.xHotspot);
76 ok(iconinfo2.yHotspot == 0, "%ld\n", iconinfo2.yHotspot);
77 }
78 ok(iconinfo2.hbmMask != NULL, "\n");
79 ok(iconinfo2.hbmMask != iconinfo.hbmMask, "\n");
80 ok(iconinfo2.hbmColor != NULL, "\n");
81 ok(iconinfo2.hbmMask != iconinfo.hbmColor, "\n");
82
83 ok(GetObject(iconinfo2.hbmMask, sizeof(bitmap), &bitmap), "GetObject failed\n");
84 ok(bitmap.bmType == 0, "\n");
85 ok(bitmap.bmWidth == 8, "\n");
86 ok(bitmap.bmHeight == 16, "\n");
87 ok(bitmap.bmWidthBytes == 2, "\n");
88 ok(bitmap.bmPlanes == 1, "\n");
89 ok(bitmap.bmBitsPixel == 1, "\n");
90 ok(bitmap.bmBits == NULL, "\n");
91
92 ok(GetObject(iconinfo2.hbmColor, sizeof(bitmap), &bitmap), "GetObject failed\n");
93 ok(bitmap.bmType == 0, "\n");
94 ok(bitmap.bmWidth == 8, "\n");
95 ok(bitmap.bmHeight == 16, "\n");
96 ok(bitmap.bmWidthBytes == 8 * bitmap.bmBitsPixel / 8, "\n");
97 ok(bitmap.bmPlanes == 1, "\n");
98 ok(bitmap.bmBitsPixel == 32, "\n");
99 ok(bitmap.bmBits == NULL, "\n");
100
101 DeleteObject(iconinfo.hbmMask);
102 iconinfo.hbmMask = NULL;
103 hicon = CreateIconIndirect(&iconinfo);
104 ok(hicon == 0, "should fail\n");
105
106 DeleteObject(iconinfo.hbmColor);
107 iconinfo.hbmColor = CreateCompatibleBitmap(GetDC(0), 16, 16);
108 hicon = CreateIconIndirect(&iconinfo);
109 ok(hicon == 0, "should fail\n");
110
111 iconinfo.hbmMask = CreateCompatibleBitmap(GetDC(0), 8, 16);
112 hicon = CreateIconIndirect(&iconinfo);
113 ok(hicon != 0, "should not fail\n");
114
115 ok(GetIconInfo(hicon, &iconinfo2), "\n");
116
117 ok(GetObject(iconinfo2.hbmMask, sizeof(bitmap), &bitmap), "GetObject failed\n");
118 ok(bitmap.bmType == 0, "\n");
119 ok(bitmap.bmWidth == 8, "%ld\n", bitmap.bmWidth);
120 ok(bitmap.bmHeight == 16, "%ld\n", bitmap.bmHeight);
121 ok(bitmap.bmWidthBytes == 2, "%ld\n", bitmap.bmWidthBytes);
122 ok(bitmap.bmPlanes == 1, "%d\n", bitmap.bmPlanes);
123 ok(bitmap.bmBitsPixel == 1, "%d\n", bitmap.bmBitsPixel);
124 ok(bitmap.bmBits == NULL, "\n");
125
126 ok(GetObject(iconinfo2.hbmColor, sizeof(bitmap), &bitmap), "GetObject failed\n");
127 ok(bitmap.bmType == 0, "\n");
128 ok(bitmap.bmWidth == 8, "%ld\n", bitmap.bmWidth);
129 ok(bitmap.bmHeight == 16, "%ld\n", bitmap.bmHeight);
130 ok(bitmap.bmWidthBytes == 32, "%ld\n", bitmap.bmWidthBytes);
131 ok(bitmap.bmPlanes == 1, "%d\n", bitmap.bmPlanes);
132 ok(bitmap.bmBitsPixel == 32, "%d\n", bitmap.bmBitsPixel);
133 ok(bitmap.bmBits == NULL, "\n");
134
135
136 }
137
138
139 START_TEST(CreateIconIndirect)
140 {
141 HCURSOR hcursor;
142 HICON hicon;
143 ICONINFO iconinfo2;
144 BITMAP bitmap;
145 DWORD data[] = {0, 0, 0, 0, 0, 0};
146
147 Test_GetIconInfo(0);
148 Test_GetIconInfo(1);
149
150 hcursor = LoadCursor(NULL, IDC_APPSTARTING);
151 ok(hcursor != 0, "should not fail\n");
152 ok(GetIconInfo(hcursor, &iconinfo2), "\n");
153 ok(iconinfo2.fIcon == 0, "\n");
154 ok(iconinfo2.xHotspot == 0, "%ld\n", iconinfo2.xHotspot);
155 ok(iconinfo2.yHotspot == 8, "%ld\n", iconinfo2.yHotspot);
156 ok(iconinfo2.hbmMask != NULL, "\n");
157 ok(iconinfo2.hbmColor != NULL, "\n");
158
159 ok(GetObject(iconinfo2.hbmMask, sizeof(bitmap), &bitmap), "GetObject failed\n");
160 ok(bitmap.bmType == 0, "\n");
161 ok(bitmap.bmWidth == 32, "%ld\n", bitmap.bmWidth);
162 ok(bitmap.bmHeight == 32, "\n");
163 ok(bitmap.bmWidthBytes == 4, "\n");
164 ok(bitmap.bmPlanes == 1, "\n");
165 ok(bitmap.bmBitsPixel == 1, "\n");
166 ok(bitmap.bmBits == NULL, "\n");
167
168 ok(GetObject(iconinfo2.hbmColor, sizeof(bitmap), &bitmap), "GetObject failed\n");
169 ok(bitmap.bmType == 0, "\n");
170 ok(bitmap.bmWidth == 32, "\n");
171 ok(bitmap.bmHeight == 32, "\n");
172 ok(bitmap.bmWidthBytes == 32 * bitmap.bmBitsPixel / 8, "\n");
173 ok(bitmap.bmPlanes == 1, "\n");
174 ok(bitmap.bmBitsPixel == 32, "\n");
175 ok(bitmap.bmBits == NULL, "\n");
176
177 hcursor = CreateCursor(NULL, 1, 2, 4, 4, data, data);
178 ok(hcursor != 0, "should not fail\n");
179 ok(GetIconInfo(hcursor, &iconinfo2), "\n");
180 ok(iconinfo2.fIcon == 0, "\n");
181 ok(iconinfo2.xHotspot == 1, "%ld\n", iconinfo2.xHotspot);
182 ok(iconinfo2.yHotspot == 2, "%ld\n", iconinfo2.yHotspot);
183 ok(iconinfo2.hbmMask != NULL, "\n");
184 ok(iconinfo2.hbmColor == NULL, "\n");
185
186 ok(GetObject(iconinfo2.hbmMask, sizeof(bitmap), &bitmap), "GetObject failed\n");
187 ok(bitmap.bmType == 0, "\n");
188 ok(bitmap.bmWidth == 4, "%ld\n", bitmap.bmWidth);
189 ok(bitmap.bmHeight == 8, "%ld\n", bitmap.bmHeight);
190 ok(bitmap.bmWidthBytes == 2, "%ld\n", bitmap.bmWidthBytes);
191 ok(bitmap.bmPlanes == 1, "\n");
192 ok(bitmap.bmBitsPixel == 1, "\n");
193 ok(bitmap.bmBits == NULL, "\n");
194
195
196 hicon = CreateIcon(0, 4, 4, 1, 1, (PBYTE)data, (PBYTE)data);
197 ok(hicon != 0, "should not fail\n");
198
199 ok(GetIconInfo(hicon, &iconinfo2), "\n");
200 ok(iconinfo2.fIcon == 0, "\n");
201 ok(iconinfo2.xHotspot == 2, "%ld\n", iconinfo2.xHotspot);
202 ok(iconinfo2.yHotspot == 2, "%ld\n", iconinfo2.yHotspot);
203 ok(iconinfo2.hbmMask != NULL, "\n");
204 ok(iconinfo2.hbmColor == NULL, "\n");
205
206 }
207
208