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