1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * PURPOSE:         Test for NtUserGetIconInfo
5  * PROGRAMMERS:
6  */
7 
8 #include "../win32nt.h"
9 #include "../resource.h"
10 
11 START_TEST(NtUserGetIconInfo)
12 {
13     HICON hIcon;
14     ICONINFO iinfo;
15     HBITMAP mask, color;
16     UNICODE_STRING hInstStr;
17     UNICODE_STRING ResourceStr;
18     DWORD bpp = 0;
19 
20     ZeroMemory(&iinfo, sizeof(ICONINFO));
21 
22     /* BASIC TESTS */
23     hIcon = (HICON) NtUserCallOneParam(0, _ONEPARAM_ROUTINE_CREATEEMPTYCUROBJECT);
24     TEST(hIcon != NULL);
25 
26     /* Last param is unknown */
27     TEST(NtUserGetIconInfo(hIcon, &iinfo, NULL, NULL, NULL, FALSE) == FALSE);
28     TEST(NtUserGetIconInfo(hIcon, &iinfo, NULL, NULL, NULL, TRUE) == FALSE);
29 
30     TEST(NtUserDestroyCursor(hIcon, 0) == TRUE);
31 
32     mask = CreateBitmap(16,16,1,1,NULL);
33     color = CreateBitmap(16,16,1,16,NULL);
34 
35     iinfo.hbmMask = mask;
36     iinfo.hbmColor = color ;
37     iinfo.fIcon = TRUE;
38     iinfo.xHotspot = 8;
39     iinfo.yHotspot = 8;
40 
41     hIcon = CreateIconIndirect(&iinfo);
42     TEST(hIcon!=NULL);
43 
44     // TODO : test last parameter...
45     TEST(NtUserGetIconInfo(hIcon, &iinfo, NULL, NULL, NULL, FALSE) == TRUE);
46 
47     TEST(iinfo.hbmMask != NULL);
48     TEST(iinfo.hbmColor != NULL);
49     TEST(iinfo.fIcon == TRUE);
50     TEST(iinfo.yHotspot == 8);
51     TEST(iinfo.xHotspot == 8);
52 
53     TEST(iinfo.hbmMask != mask);
54     TEST(iinfo.hbmColor != color);
55 
56     /* Does it make a difference? */
57     TEST(NtUserGetIconInfo(hIcon, &iinfo, NULL, NULL, NULL, TRUE) == TRUE);
58 
59     TEST(iinfo.hbmMask != NULL);
60     TEST(iinfo.hbmColor != NULL);
61     TEST(iinfo.fIcon == TRUE);
62     TEST(iinfo.yHotspot == 8);
63     TEST(iinfo.xHotspot == 8);
64 
65     TEST(iinfo.hbmMask != mask);
66     TEST(iinfo.hbmColor != color);
67 
68     DeleteObject(mask);
69     DeleteObject(color);
70 
71     DestroyIcon(hIcon);
72 
73     /* Test full param, with local icon */
74     hIcon = LoadImageA(GetModuleHandle(NULL),
75                        MAKEINTRESOURCE(IDI_ICON),
76                        IMAGE_ICON,
77                        0,
78                        0,
79                        LR_DEFAULTSIZE);
80 
81     TEST(hIcon != NULL);
82 
83     RtlInitUnicodeString(&hInstStr, NULL);
84     RtlInitUnicodeString(&ResourceStr, NULL);
85 
86     TEST(NtUserGetIconInfo(hIcon,
87                            &iinfo,
88                            &hInstStr,
89                            &ResourceStr,
90                            &bpp,
91                            FALSE) == TRUE);
92 
93     ok(hInstStr.Buffer == NULL, "hInstStr.buffer : %p\n", hInstStr.Buffer);
94     TEST((LPCTSTR)ResourceStr.Buffer == MAKEINTRESOURCE(IDI_ICON));
95     TEST(bpp == 32);
96 
97     /* Last param doesn't seem to matter*/
98     TEST(NtUserGetIconInfo(hIcon,
99                            &iinfo,
100                            &hInstStr,
101                            &ResourceStr,
102                            &bpp,
103                            TRUE) == TRUE);
104 
105     ok(hInstStr.Buffer == NULL, "hInstStr.buffer : %p\n", hInstStr.Buffer);
106     TEST((LPCTSTR)ResourceStr.Buffer == MAKEINTRESOURCE(IDI_ICON));
107     TEST(bpp == 32);
108 
109     DestroyIcon(hIcon);
110 
111     /* Test full param, with foreign icon */
112     hIcon = LoadImageA(GetModuleHandleA("shell32.dll"),
113                        MAKEINTRESOURCE(293),
114                        IMAGE_ICON,
115                        0,
116                        0,
117                        LR_DEFAULTSIZE);
118 
119     TEST(hIcon != NULL);
120 
121     hInstStr.Buffer = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
122     hInstStr.MaximumLength = MAX_PATH;
123     hInstStr.Length = 0;
124     RtlInitUnicodeString(&ResourceStr, NULL);
125 
126     TEST(NtUserGetIconInfo(hIcon,
127                            &iinfo,
128                            &hInstStr,
129                            &ResourceStr,
130                            &bpp,
131                            FALSE) == TRUE);
132 
133     TEST(hInstStr.Length != 0);
134     hInstStr.Buffer[hInstStr.Length] = 0;
135     printf("%s,%i: hInstStr.buffer : %S\n", __FUNCTION__, __LINE__, hInstStr.Buffer);
136     TEST((LPCTSTR)ResourceStr.Buffer == MAKEINTRESOURCE(293));
137     TEST(ResourceStr.Length == 0);
138     TEST(ResourceStr.MaximumLength == 0);
139     TEST(bpp == 32);
140 
141     ZeroMemory(hInstStr.Buffer, MAX_PATH*sizeof(WCHAR));
142     hInstStr.Length = 0;
143     RtlInitUnicodeString(&ResourceStr, NULL);
144 
145     TEST(NtUserGetIconInfo(hIcon,
146                            &iinfo,
147                            &hInstStr,
148                            &ResourceStr,
149                            &bpp,
150                            TRUE) == TRUE);
151 
152     TEST(hInstStr.Length != 0);
153     hInstStr.Buffer[hInstStr.Length] = 0;
154     printf("%s,%i: hInstStr.buffer : %S\n", __FUNCTION__, __LINE__, hInstStr.Buffer);
155     TEST((LPCTSTR)ResourceStr.Buffer == MAKEINTRESOURCE(293));
156     TEST(bpp == 32);
157 
158     DestroyIcon(hIcon);
159 
160 }
161