ReactOS  0.4.15-dev-3017-g1d9542d
shell32_apitest_sub.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
4  * PURPOSE: Test for SHChangeNotify
5  * COPYRIGHT: Copyright 2020 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6  */
7 
8 #include "shelltest.h"
9 #include <shlwapi.h>
10 #include <stdio.h>
11 #include "SHChangeNotify.h"
12 
13 static HWND s_hwnd = NULL;
14 static const WCHAR s_szName[] = L"SHChangeNotify testcase";
15 static INT s_nMode;
16 
18 static UINT s_uRegID = 0;
19 
21 
24 
25 static BOOL
27 {
28  s_hwnd = hwnd;
29 
30  DoInitPaths();
31 
34 
35  INT nSources;
36  switch (s_nMode)
37  {
38  case 0:
40  nSources = SHCNRF_ShellLevel;
41  break;
42 
43  case 1:
46  break;
47 
48  case 2:
51  break;
52 
53  case 3:
56  break;
57 
58  case 4:
61  break;
62 
63  case 5:
66  s_entry.pidl = NULL;
67  break;
68 
69  default:
70  return FALSE;
71  }
72  LONG fEvents = SHCNE_ALLEVENTS;
74  1, &s_entry);
75  return s_uRegID != 0;
76 }
77 
78 static void
80 {
81  switch (id)
82  {
83  case IDOK:
84  case IDCANCEL:
86  break;
87  }
88 }
89 
90 static void
92 {
94  s_uRegID = 0;
95 
97  s_pidl = NULL;
98 
99  PostQuitMessage(0);
100  s_hwnd = NULL;
101 }
102 
103 static void
105 {
106  if (pidl1)
108  else
109  s_path1[0] = 0;
110 
111  if (pidl2)
113  else
114  s_path2[0] = 0;
115 
116  switch (lEvent)
117  {
118  case SHCNE_RENAMEITEM:
120  break;
121  case SHCNE_CREATE:
122  s_counters[TYPE_CREATE] = 1;
123  break;
124  case SHCNE_DELETE:
125  s_counters[TYPE_DELETE] = 1;
126  break;
127  case SHCNE_MKDIR:
128  s_counters[TYPE_MKDIR] = 1;
129  break;
130  case SHCNE_RMDIR:
131  s_counters[TYPE_RMDIR] = 1;
132  break;
133  case SHCNE_MEDIAINSERTED:
134  break;
135  case SHCNE_MEDIAREMOVED:
136  break;
137  case SHCNE_DRIVEREMOVED:
138  break;
139  case SHCNE_DRIVEADD:
140  break;
141  case SHCNE_NETSHARE:
142  break;
143  case SHCNE_NETUNSHARE:
144  break;
145  case SHCNE_ATTRIBUTES:
146  break;
147  case SHCNE_UPDATEDIR:
149  break;
150  case SHCNE_UPDATEITEM:
152  break;
154  break;
155  case SHCNE_UPDATEIMAGE:
156  break;
157  case SHCNE_DRIVEADDGUI:
158  break;
159  case SHCNE_RENAMEFOLDER:
161  break;
162  case SHCNE_FREESPACE:
163  break;
165  break;
166  case SHCNE_ASSOCCHANGED:
167  break;
168  default:
169  break;
170  }
171 }
172 
173 static INT_PTR
175 {
176  LONG lEvent;
177  PIDLIST_ABSOLUTE *pidlAbsolute;
178  HANDLE hLock = SHChangeNotification_Lock((HANDLE)wParam, (DWORD)lParam, &pidlAbsolute, &lEvent);
179  if (hLock)
180  {
181  DoShellNotify(hwnd, pidlAbsolute[0], pidlAbsolute[1], lEvent);
183  }
184  else
185  {
186  pidlAbsolute = (PIDLIST_ABSOLUTE *)wParam;
187  DoShellNotify(hwnd, pidlAbsolute[0], pidlAbsolute[1], lParam);
188  }
189  return TRUE;
190 }
191 
192 static LRESULT
194 {
195  if (s_uRegID == 0)
196  return 0xFFFFFFFF;
197 
198  DWORD dwFlags = 0;
199  for (size_t i = 0; i < _countof(s_counters); ++i)
200  {
201  if (s_counters[i])
202  dwFlags |= (1 << i);
203  }
204  return dwFlags;
205 }
206 
207 static void
209 {
210  WCHAR szText[MAX_PATH * 2];
212  lstrcatW(szText, L"|");
214 
215  if (FILE *fp = fopen(TEMP_FILE, "wb"))
216  {
217  fwrite(szText, (lstrlenW(szText) + 1) * sizeof(WCHAR), 1, fp);
218  fflush(fp);
219  fclose(fp);
220  }
221 }
222 
223 static LRESULT CALLBACK
225 {
226  switch (uMsg)
227  {
228  case WM_CREATE:
229  return (OnCreate(hwnd) ? 0 : -1);
230 
231  case WM_COMMAND:
233  break;
234 
235  case WM_SHELL_NOTIFY:
236  return OnShellNotify(hwnd, wParam, lParam);
237 
238  case WM_DESTROY:
239  OnDestroy(hwnd);
240  break;
241 
242  case WM_GET_NOTIFY_FLAGS:
243  return OnGetNotifyFlags(hwnd);
244 
245  case WM_CLEAR_FLAGS:
246  ZeroMemory(&s_counters, sizeof(s_counters));
247  break;
248 
249  case WM_SET_PATHS:
250  DoSetPaths(hwnd);
251  break;
252 
253  default:
254  return DefWindowProcW(hwnd, uMsg, wParam, lParam);
255  }
256  return 0;
257 }
258 
261  HINSTANCE hPrevInstance,
262  LPWSTR lpCmdLine,
263  INT nCmdShow)
264 {
265  if (lstrcmpiW(lpCmdLine, L"") == 0 || lstrcmpiW(lpCmdLine, L"TEST") == 0)
266  return 0;
267 
268  s_nMode = _wtoi(lpCmdLine);
269 
270  WNDCLASSW wc;
271  ZeroMemory(&wc, sizeof(wc));
272  wc.lpfnWndProc = WindowProc;
276  wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
277  wc.lpszClassName = s_szName;
278  if (!RegisterClassW(&wc))
279  return -1;
280 
282  CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
284  if (!hwnd)
285  return -1;
286 
289 
290  MSG msg;
291  while (GetMessageW(&msg, NULL, 0, 0))
292  {
295  }
296 
297  return 0;
298 }
#define SHCNE_MKDIR
Definition: shlobj.h:1732
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define SHCNE_ATTRIBUTES
Definition: shlobj.h:1740
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define SHCNE_RMDIR
Definition: shlobj.h:1733
#define IDOK
Definition: winuser.h:824
static void OnDestroy(HWND hwnd)
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
#define SHCNE_UPDATEIMAGE
Definition: shlobj.h:1744
EXTERN_C BOOL WINAPI SHChangeNotification_Unlock(HANDLE hLock)
#define SHCNE_NETUNSHARE
Definition: shlobj.h:1739
void DoInitPaths(void)
#define TRUE
Definition: types.h:120
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
static LRESULT OnGetNotifyFlags(HWND hwnd)
#define SHCNE_RENAMEFOLDER
Definition: shlobj.h:1746
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1294
#define CALLBACK
Definition: compat.h:35
BOOL WINAPI UpdateWindow(_In_ HWND)
#define ZeroMemory
Definition: winbase.h:1664
#define SHCNRF_RecursiveInterrupt
Definition: shlobj.h:1776
#define IDI_APPLICATION
Definition: winuser.h:699
UINT_PTR WPARAM
Definition: windef.h:207
static BOOL OnCreate(HWND hwnd)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
int32_t INT_PTR
Definition: typedefs.h:64
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
#define SHCNE_RENAMEITEM
Definition: shlobj.h:1729
#define lstrlenW
Definition: compat.h:609
BOOL WINAPI DestroyWindow(_In_ HWND)
static WCHAR s_dir1[MAX_PATH]
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4291
int32_t INT
Definition: typedefs.h:58
WPARAM wParam
Definition: combotst.c:138
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
int WINAPI lstrcmpiW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:194
static void OnCommand(HWND hwnd, UINT id)
static INT s_nMode
ATOM WINAPI RegisterClassW(_In_ CONST WNDCLASSW *)
HINSTANCE hInstance
Definition: charmap.c:20
#define COLOR_3DFACE
Definition: winuser.h:919
#define FALSE
Definition: types.h:117
static const WCHAR szText[]
Definition: dialog.c:139
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
unsigned int BOOL
Definition: ntddk_ex.h:94
#define SHCNE_ALLEVENTS
Definition: shlobj.h:1753
long LONG
Definition: pedump.c:60
#define WM_CLEAR_FLAGS
WNDPROC lpfnWndProc
Definition: winuser.h:3152
#define CW_USEDEFAULT
Definition: winuser.h:225
#define SHCNRF_InterruptLevel
Definition: shlobj.h:1774
LPCWSTR lpszClassName
Definition: winuser.h:3160
LONG_PTR LPARAM
Definition: windef.h:208
static WCHAR s_path1[MAX_PATH]
#define WM_SET_PATHS
static const WCHAR s_szName[]
static void DoShellNotify(HWND hwnd, PIDLIST_ABSOLUTE pidl1, PIDLIST_ABSOLUTE pidl2, LONG lEvent)
#define WM_DESTROY
Definition: winuser.h:1591
static LPITEMIDLIST s_pidl
#define SHCNE_MEDIAREMOVED
Definition: shlobj.h:1735
__wchar_t WCHAR
Definition: xmlstorage.h:180
EXTERN_C BOOL WINAPI SHChangeNotifyDeregister(ULONG hNotify)
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
#define SHCNRF_ShellLevel
Definition: shlobj.h:1775
static BYTE s_counters[TYPE_RENAMEFOLDER+1]
static WCHAR s_path2[MAX_PATH]
#define WM_SHELL_NOTIFY
unsigned long DWORD
Definition: ntddk_ex.h:95
HICON hIcon
Definition: winuser.h:3156
#define WM_GET_NOTIFY_FLAGS
static const WCHAR L[]
Definition: oid.c:1250
#define SHCNE_EXTENDED_EVENT
Definition: shlobj.h:1749
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
HANDLE lEvent
Definition: tftpd.cpp:56
PCIDLIST_ABSOLUTE pidl
Definition: shlobj.h:1725
static SHChangeNotifyEntry s_entry
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
#define WM_COMMAND
Definition: winuser.h:1722
#define SHCNE_FREESPACE
Definition: shlobj.h:1747
INT APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nCmdShow)
unsigned char BYTE
Definition: xxhash.c:193
#define LoadCursor
Definition: winuser.h:5787
#define SHCNRF_NewDelivery
Definition: shlobj.h:1777
HCURSOR hCursor
Definition: winuser.h:3157
#define SW_SHOWNORMAL
Definition: winuser.h:764
#define TEMP_FILE
Definition: SHChangeNotify.h:3
#define lstrcpyW
Definition: compat.h:608
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
#define SHCNE_DELETE
Definition: shlobj.h:1731
HBRUSH hbrBackground
Definition: winuser.h:3158
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
#define SHCNE_UPDATEDIR
Definition: shlobj.h:1741
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
EXTERN_C HANDLE WINAPI SHChangeNotification_Lock(HANDLE hTicket, DWORD dwOwnerPID, LPITEMIDLIST **lppidls, LPLONG lpwEventId)
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
#define SHCNE_NETSHARE
Definition: shlobj.h:1738
#define SHCNE_MEDIAINSERTED
Definition: shlobj.h:1734
HINSTANCE hInstance
Definition: winuser.h:3155
#define SHCNE_DRIVEADD
Definition: shlobj.h:1737
static UINT s_uRegID
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
#define WM_CREATE
Definition: winuser.h:1590
static INT_PTR OnShellNotify(HWND hwnd, WPARAM wParam, LPARAM lParam)
EXTERN_C ULONG WINAPI SHChangeNotifyRegister(HWND hwnd, INT fSources, LONG wEventMask, UINT uMsg, INT cItems, SHChangeNotifyEntry *lpItems)
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
static void DoSetPaths(HWND hwnd)
#define SHCNE_SERVERDISCONNECT
Definition: shlobj.h:1743
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
#define SHCNE_CREATE
Definition: shlobj.h:1730
#define LoadIcon
Definition: winuser.h:5788
#define SHCNE_UPDATEITEM
Definition: shlobj.h:1742
LPITEMIDLIST WINAPI ILCreateFromPathW(LPCWSTR path)
Definition: pidl.c:982
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define IDCANCEL
Definition: winuser.h:825
static HWND s_hwnd
LONG_PTR LRESULT
Definition: windef.h:209
#define SHCNE_DRIVEADDGUI
Definition: shlobj.h:1745
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define SHCNE_DRIVEREMOVED
Definition: shlobj.h:1736
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define APIENTRY
Definition: api.h:79
#define SHCNE_ASSOCCHANGED
Definition: shlobj.h:1750