[IPHLPAPI_APITEST]
[reactos.git] / rostests / apitests / user32 / SetProp.c
1 /*
2 * PROJECT: ReactOS API tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for SetProp
5 * PROGRAMMERS: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8 #include <apitest.h>
9
10 #include <winuser.h>
11 #include "helper.h"
12
13 static ATOM Atom1, Atom2, Atom3;
14
15 static
16 BOOL
17 CALLBACK
18 EnumFunc(
19 _In_ HWND hWnd,
20 _In_ PCWSTR lpszString,
21 _In_ HANDLE hData)
22 {
23 if (HIWORD(lpszString))
24 ok(0, "Unexpected EnumFunc call: %p, '%ls', %p\n", hWnd, lpszString, hData);
25 else
26 ok(0, "Unexpected EnumFunc call: %p, 0x%04x, %p\n", hWnd, (USHORT)(ULONG_PTR)lpszString, hData);
27 return TRUE;
28 }
29
30 static
31 BOOL
32 CALLBACK
33 EnumFuncEx(
34 _In_ HWND hWnd,
35 _In_ PWSTR lpszString,
36 _In_ HANDLE hData,
37 _In_ ULONG_PTR dwData)
38 {
39 if (dwData == 0)
40 {
41 if (HIWORD(lpszString))
42 ok(0, "Unexpected EnumFuncEx call: %p, '%ls', %p\n", hWnd, lpszString, hData);
43 else
44 ok(0, "Unexpected EnumFuncEx call: %p, 0x%04x, %p\n", hWnd, (USHORT)(ULONG_PTR)lpszString, hData);
45 }
46 else
47 {
48 if (HIWORD(lpszString))
49 {
50 if (!wcscmp(lpszString, L"PropTestAtom1"))
51 ok(hData == &Atom1, "EnumFuncEx: %p, '%ls', %p; expected %p\n", hWnd, lpszString, hData, &Atom1);
52 else if (!wcscmp(lpszString, L"PropTestAtom2"))
53 ok(hData == &Atom2, "EnumFuncEx: %p, '%ls', %p; expected %p\n", hWnd, lpszString, hData, &Atom2);
54 else
55 ok(0, "Unexpected EnumFuncEx call: %p, '%ls', %p\n", hWnd, lpszString, hData);
56 }
57 else
58 ok(0, "Unexpected EnumFuncEx call: %p, 0x%04x, %p\n", hWnd, (USHORT)(ULONG_PTR)lpszString, hData);
59 }
60 return TRUE;
61 }
62
63 START_TEST(SetProp)
64 {
65 HWND hWnd;
66 MSG msg;
67 UINT Atom;
68 HANDLE Prop;
69 LRESULT Result;
70 ATOM SysICAtom;
71 ATOM SysICSAtom;
72 HICON hIcon;
73 HICON hIcon2;
74
75 Atom1 = GlobalAddAtomW(L"PropTestAtom1");
76 ok(Atom1 != 0, "PropTestAtom1 is 0x%04x\n", Atom1);
77 ok(Atom1 >= 0xc000, "PropTestAtom1 is 0x%04x\n", Atom1);
78 ok(Atom1 >= 0xc018, "PropTestAtom1 is 0x%04x\n", Atom1);
79
80 /* These are not in the global atom table */
81 Atom = GlobalFindAtomW(L"SysIC");
82 ok(Atom == 0, "SysIC atom is 0x%04x\n", Atom);
83 Atom = GlobalFindAtomW(L"SysICS");
84 ok(Atom == 0, "SysICS atom is 0x%04x\n", Atom);
85
86 SetCursorPos(0, 0);
87
88 RegisterSimpleClass(DefWindowProcW, L"PropTest");
89
90 hWnd = CreateWindowExW(0, L"PropTest", NULL, 0, 10, 10, 20, 20, NULL, NULL, 0, NULL);
91
92 Result = EnumPropsW(hWnd, EnumFunc);
93 if (0) // Windows returns an uninitialized value here
94 ok(Result == TRUE, "EnumProps returned %Iu\n", Result);
95 Result = EnumPropsExW(hWnd, EnumFuncEx, 0);
96 if (0) // Windows returns an uninitialized value here
97 ok(Result == TRUE, "EnumPropsEx returned %Iu\n", Result);
98
99 Atom2 = GlobalAddAtomW(L"PropTestAtom2");
100 ok(Atom2 != 0, "PropTestAtom2 is 0x%04x\n", Atom2);
101 ok(Atom2 >= 0xc000, "PropTestAtom2 is 0x%04x\n", Atom2);
102 ok(Atom2 >= 0xc018, "PropTestAtom2 is 0x%04x\n", Atom2);
103
104 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
105 DispatchMessageA(&msg);
106
107 Result = EnumPropsExW(hWnd, EnumFuncEx, 0);
108 if (0) // Windows returns an uninitialized value here
109 ok(Result == TRUE, "EnumPropsEx returned %Iu\n", Result);
110
111 Result = SetPropW(hWnd, (PCWSTR)MAKEINTATOM(Atom1), &Atom1);
112 ok(Result == TRUE, "SetProp returned %Iu\n", Result);
113 Result = SetPropW(hWnd, (PCWSTR)MAKEINTATOM(Atom2), &Atom3);
114 ok(Result == TRUE, "SetProp returned %Iu\n", Result);
115 Prop = GetPropW(hWnd, (PCWSTR)MAKEINTATOM(Atom2));
116 ok(Prop == &Atom3, "GetProp returned %p, expected %p\n", Prop, &Atom3);
117 Result = SetPropW(hWnd, (PCWSTR)MAKEINTATOM(Atom2), &Atom2);
118 ok(Result == TRUE, "SetProp returned %Iu\n", Result);
119 Prop = GetPropW(hWnd, (PCWSTR)MAKEINTATOM(Atom2));
120 ok(Prop == &Atom2, "GetProp returned %p, expected %p\n", Prop, &Atom2);
121 Prop = GetPropW(hWnd, L"PropTestAtom2");
122 ok(Prop == &Atom2, "GetProp returned %p, expected %p\n", Prop, &Atom2);
123 Prop = GetPropA(hWnd, "PropTestAtom2");
124 ok(Prop == &Atom2, "GetProp returned %p, expected %p\n", Prop, &Atom2);
125
126 Result = EnumPropsExW(hWnd, EnumFuncEx, 1);
127 ok(Result == TRUE, "EnumPropsEx returned %Iu\n", Result);
128
129 hIcon = LoadImageW(NULL, (PCWSTR)MAKEINTRESOURCE(OIC_NOTE), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
130 ok(hIcon != NULL, "LoadImage failed with %lu\n", GetLastError());
131 /* Should not have any icon */
132 hIcon2 = (HICON)SendMessageW(hWnd, WM_GETICON, ICON_BIG, 0);
133 ok(hIcon2 == NULL, "WM_GETICON returned %p, expected NULL\n", hIcon2);
134 hIcon2 = (HICON)SendMessageW(hWnd, WM_GETICON, ICON_SMALL, 0);
135 ok(hIcon2 == NULL, "WM_GETICON returned %p, expected NULL\n", hIcon2);
136
137 /* Set big icon, should also set small icon */
138 Result = SendMessageW(hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
139 ok(Result == 0, "WM_SETICON returned 0x%Ix\n", Result);
140
141 hIcon2 = (HICON)SendMessageW(hWnd, WM_GETICON, ICON_BIG, 0);
142 ok(hIcon2 == hIcon, "WM_GETICON returned %p, expected %p\n", hIcon2, hIcon);
143 hIcon2 = (HICON)SendMessageW(hWnd, WM_GETICON, ICON_SMALL, 0);
144 ok(hIcon2 != hIcon && hIcon != NULL, "WM_GETICON returned %p, expected not %p and not NULL\n", hIcon2, hIcon);
145
146 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
147 DispatchMessageA(&msg);
148
149 /* We should have only the props that we explicitly set */
150 for (Atom = 0x0000; Atom <= 0xffff; Atom++)
151 {
152 Prop = GetPropW(hWnd, (PCWSTR)MAKEINTATOM(Atom));
153 if (Atom == Atom1)
154 ok(Prop == &Atom1, "Window %p Prop 0x%04x = %p, expected %p\n", hWnd, Atom, Prop, &Atom1);
155 else if (Atom == Atom2)
156 ok(Prop == &Atom2, "Window %p Prop 0x%04x = %p, expected %p\n", hWnd, Atom, Prop, &Atom2);
157 else
158 ok(Prop == NULL, "Window %p Prop 0x%04x = %p\n", hWnd, Atom, Prop);
159 }
160
161 /* In particular we shouldn't see these from WM_SETICON */
162 SysICAtom = RegisterWindowMessageW(L"SysIC");
163 Prop = GetPropW(hWnd, (PCWSTR)MAKEINTATOM(SysICAtom));
164 ok(Prop == NULL, "SysIC prop (0x%04x) is %p\n", SysICAtom, Prop);
165
166 SysICSAtom = RegisterWindowMessageW(L"SysICS");
167 Prop = GetPropW(hWnd, (PCWSTR)MAKEINTATOM(SysICSAtom));
168 ok(Prop == NULL, "SysICS prop (0x%04x) is %p\n", SysICSAtom, Prop);
169
170 GlobalDeleteAtom(Atom1);
171 GlobalDeleteAtom(Atom2);
172
173 DestroyWindow(hWnd);
174
175 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
176 DispatchMessageA(&msg);
177 }