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