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