* Addendum to r58214.
[reactos.git] / rostests / apitests / gdi32 / CreateIconIndirect.c
1
2 #include <wine/test.h>
3 #include <wingdi.h>
4 #include <winuser.h>
5
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
138 START_TEST(CreateIconIndirect)
139 {
140 HCURSOR hcursor;
141 HICON hicon;
142 ICONINFO iconinfo2;
143 BITMAP bitmap;
144 DWORD data[] = {0, 0, 0, 0, 0, 0};
145
146 Test_GetIconInfo(0);
147 Test_GetIconInfo(1);
148
149 hcursor = LoadCursor(NULL, IDC_APPSTARTING);
150 ok(hcursor != 0, "should not fail\n");
151 ok(GetIconInfo(hcursor, &iconinfo2), "\n");
152 ok(iconinfo2.fIcon == 0, "\n");
153 ok(iconinfo2.xHotspot == 0, "%ld\n", iconinfo2.xHotspot);
154 ok(iconinfo2.yHotspot == 8, "%ld\n", iconinfo2.yHotspot);
155 ok(iconinfo2.hbmMask != NULL, "\n");
156 ok(iconinfo2.hbmColor != NULL, "\n");
157
158 ok(GetObject(iconinfo2.hbmMask, sizeof(bitmap), &bitmap), "GetObject failed\n");
159 ok(bitmap.bmType == 0, "\n");
160 ok(bitmap.bmWidth == 32, "%ld\n", bitmap.bmWidth);
161 ok(bitmap.bmHeight == 32, "\n");
162 ok(bitmap.bmWidthBytes == 4, "\n");
163 ok(bitmap.bmPlanes == 1, "\n");
164 ok(bitmap.bmBitsPixel == 1, "\n");
165 ok(bitmap.bmBits == NULL, "\n");
166
167 ok(GetObject(iconinfo2.hbmColor, sizeof(bitmap), &bitmap), "GetObject failed\n");
168 ok(bitmap.bmType == 0, "\n");
169 ok(bitmap.bmWidth == 32, "\n");
170 ok(bitmap.bmHeight == 32, "\n");
171 ok(bitmap.bmWidthBytes == 32 * bitmap.bmBitsPixel / 8, "\n");
172 ok(bitmap.bmPlanes == 1, "\n");
173 ok(bitmap.bmBitsPixel == 32, "\n");
174 ok(bitmap.bmBits == NULL, "\n");
175
176 hcursor = CreateCursor(NULL, 1, 2, 4, 4, data, data);
177 ok(hcursor != 0, "should not fail\n");
178 ok(GetIconInfo(hcursor, &iconinfo2), "\n");
179 ok(iconinfo2.fIcon == 0, "\n");
180 ok(iconinfo2.xHotspot == 1, "%ld\n", iconinfo2.xHotspot);
181 ok(iconinfo2.yHotspot == 2, "%ld\n", iconinfo2.yHotspot);
182 ok(iconinfo2.hbmMask != NULL, "\n");
183 ok(iconinfo2.hbmColor == NULL, "\n");
184
185 ok(GetObject(iconinfo2.hbmMask, sizeof(bitmap), &bitmap), "GetObject failed\n");
186 ok(bitmap.bmType == 0, "\n");
187 ok(bitmap.bmWidth == 4, "%ld\n", bitmap.bmWidth);
188 ok(bitmap.bmHeight == 8, "%ld\n", bitmap.bmHeight);
189 ok(bitmap.bmWidthBytes == 2, "%ld\n", bitmap.bmWidthBytes);
190 ok(bitmap.bmPlanes == 1, "\n");
191 ok(bitmap.bmBitsPixel == 1, "\n");
192 ok(bitmap.bmBits == NULL, "\n");
193
194
195 hicon = CreateIcon(0, 4, 4, 1, 1, (PBYTE)data, (PBYTE)data);
196 ok(hicon != 0, "should not fail\n");
197
198 ok(GetIconInfo(hicon, &iconinfo2), "\n");
199 ok(iconinfo2.fIcon == 0, "\n");
200 ok(iconinfo2.xHotspot == 2, "%ld\n", iconinfo2.xHotspot);
201 ok(iconinfo2.yHotspot == 2, "%ld\n", iconinfo2.yHotspot);
202 ok(iconinfo2.hbmMask != NULL, "\n");
203 ok(iconinfo2.hbmColor == NULL, "\n");
204
205 }
206
207