ReactOS  0.4.15-dev-321-g2d9b385
SHLimitInputEdit.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4  * PURPOSE: Test for SHLimitInputEdit
5  * PROGRAMMER: Katayama Hirofumi MZ
6  */
7 
8 #include "shelltest.h"
9 #include <shobjidl.h>
10 #include <shlwapi.h>
11 
13  : public IShellFolder
14  , public IItemNameLimits
15 {
16 public:
18 
19  CShellFolder(INT iMaxNameLen = 0, BOOL bDisabled = FALSE)
20  : m_cRefs(1)
21  , m_iMaxNameLen(iMaxNameLen)
22  , m_bDisabled(bDisabled)
23  {
24  trace("CShellFolder\n");
25  }
26 
27  virtual ~CShellFolder()
28  {
29  trace("~CShellFolder\n");
30  }
31 
32  /*** IUnknown methods ***/
33 
37 
38  /*** IShellFolder methods ***/
39 
41  HWND hwnd,
42  IBindCtx *pbc,
43  LPWSTR pszDisplayName,
44  ULONG *pchEaten,
45  PIDLIST_RELATIVE *ppidl,
46  ULONG *pdwAttributes)
47  {
48  trace("ParseDisplayName\n");
49  return E_NOTIMPL;
50  }
51 
53  HWND hwnd,
54  SHCONTF grfFlags,
55  IEnumIDList **ppenumIDList)
56  {
57  trace("EnumObjects\n");
58  return E_NOTIMPL;
59  }
60 
62  PCUIDLIST_RELATIVE pidl,
63  IBindCtx *pbc,
64  REFIID riid,
65  void **ppv)
66  {
67  trace("BindToObject\n");
68  return E_NOTIMPL;
69  }
70 
72  PCUIDLIST_RELATIVE pidl,
73  IBindCtx *pbc,
74  REFIID riid,
75  void **ppv)
76  {
77  trace("BindToStorage\n");
78  return E_NOTIMPL;
79  }
80 
82  LPARAM lParam,
83  PCUIDLIST_RELATIVE pidl1,
84  PCUIDLIST_RELATIVE pidl2)
85  {
86  trace("CompareIDs\n");
87  return E_NOTIMPL;
88  }
89 
91  HWND hwndOwner,
92  REFIID riid,
93  void **ppv)
94  {
95  trace("CreateViewObject\n");
96  return E_NOTIMPL;
97  }
98 
100  UINT cidl,
101  PCUITEMID_CHILD_ARRAY apidl,
102  SFGAOF *rgfInOut)
103  {
104  trace("GetAttributesOf\n");
105  return E_NOTIMPL;
106  }
107 
109  HWND hwndOwner,
110  UINT cidl,
111  PCUITEMID_CHILD_ARRAY apidl,
112  REFIID riid,
113  UINT *rgfReserved,
114  void **ppv)
115  {
116  trace("GetUIObjectOf\n");
117  return E_NOTIMPL;
118  }
119 
121  PCUITEMID_CHILD pidl,
122  SHGDNF uFlags,
123  STRRET *pName)
124  {
125  trace("GetDisplayNameOf\n");
126  return E_NOTIMPL;
127  }
128 
130  HWND hwnd,
131  PCUITEMID_CHILD pidl,
132  LPCWSTR pszName,
133  SHGDNF uFlags,
134  PITEMID_CHILD *ppidlOut)
135  {
136  trace("SetNameOf\n");
137  return E_NOTIMPL;
138  }
139 
140  /*** IItemNameLimits methods ***/
141 
143  LPCWSTR pszName,
144  int *piMaxNameLen);
145 
147  LPWSTR *ppwszValidChars,
148  LPWSTR *ppwszInvalidChars);
149 
150 protected:
153 };
154 
156 {
157  trace("QueryInterface\n");
158 
159  if (!ppvObject)
160  return E_POINTER;
161 
162  if (IsEqualIID(riid, IID_IShellFolder) || IsEqualIID(riid, IID_IUnknown))
163  {
164  trace("IID_IShellFolder\n");
165  *ppvObject = static_cast<IShellFolder *>(this);
166  AddRef();
167  return S_OK;
168  }
169  if (IsEqualIID(riid, IID_IItemNameLimits))
170  {
171  trace("IID_IItemNameLimits\n");
172  *ppvObject = static_cast<IItemNameLimits *>(this);
173  AddRef();
174  return S_OK;
175  }
176 
177  return E_NOINTERFACE;
178 }
179 
181 {
182  trace("AddRef\n");
183  return ++m_cRefs;
184 }
185 
187 {
188  trace("Release\n");
189 
190  if (--m_cRefs == 0)
191  {
192  //delete this;
193  return 0;
194  }
195  return m_cRefs;
196 }
197 
199  LPCWSTR pszName,
200  int *piMaxNameLen)
201 {
202  trace("GetMaxLength('%S', %p (%d))\n", pszName, piMaxNameLen, *piMaxNameLen);
203 
204  if (!piMaxNameLen)
205  return E_POINTER;
206 
207  *piMaxNameLen = m_iMaxNameLen;
208  return S_OK;
209 }
210 
212  LPWSTR *ppwszValidChars,
213  LPWSTR *ppwszInvalidChars)
214 {
215  trace("GetValidCharacters(%p, %p)\n", ppwszValidChars, ppwszInvalidChars);
216 
217  if (m_bDisabled)
218  return E_NOTIMPL;
219 
220  if (ppwszInvalidChars)
221  {
222  SHStrDupW(L"/:*?\"<>|", ppwszInvalidChars);
223  }
224  if (ppwszValidChars)
225  {
226  *ppwszValidChars = NULL;
227  }
228  return S_OK;
229 }
230 
231 static BOOL CALLBACK
233  HWND hwnd,
234  LPCWSTR lpszString,
235  HANDLE hData)
236 {
237  trace("PropEnumProc: '%S' --> %p\n", lpszString, hData);
238  return TRUE;
239 }
240 
241 static void
243 {
244  HRESULT hr;
245 
246  _SEH2_TRY
247  {
248  hr = SHLimitInputEdit(hEdt1, NULL);
249  }
251  {
252  hr = 0xDEAD;
253  }
254  _SEH2_END;
255 
256  ok_int(hr, 0xDEAD);
257 }
258 
259 static INT_PTR CALLBACK
261 {
262  if (uMsg != WM_INITDIALOG)
263  return FALSE;
264 
265  HWND hEdt1 = GetDlgItem(hwnd, edt1);
266  INT n;
267  HRESULT hr;
268  WCHAR szText[64];
269 
270  DoNullFolderTest(hEdt1);
271 
272  {
273  CShellFolder sf(123, FALSE);
274 
275  ok_long(sf.m_cRefs, 1);
276 
277  SendMessageW(hEdt1, EM_LIMITTEXT, 234, 0);
278 
279  trace("GWLP_WNDPROC: %p\n", (void *)GetWindowLongPtr(hEdt1, GWLP_WNDPROC));
280 
281  hr = SHLimitInputEdit(hEdt1, &sf);
282  ok_int(hr, S_OK);
283 
284  ok_long(sf.m_cRefs, 1);
285 
286  trace("GWLP_WNDPROC: %p\n", (void *)GetWindowLongPtr(hEdt1, GWLP_WNDPROC));
287 
288  EnumPropsW(hEdt1, PropEnumProc);
289 
290  n = (INT)SendMessageW(hEdt1, EM_GETLIMITTEXT, 0, 0);
291  ok_int(n, 234);
292  }
293 
294  {
295  CShellFolder sf(345, TRUE);
296 
297  hr = SHLimitInputEdit(hEdt1, &sf);
298  ok_int(hr, E_NOTIMPL);
299 
300  n = (INT)SendMessageW(hEdt1, EM_GETLIMITTEXT, 0, 0);
301  ok_int(n, 234);
302  }
303 
304  {
305  CShellFolder sf(999, FALSE);
306 
307  ok_long(sf.m_cRefs, 1);
308 
309  SetWindowTextW(hEdt1, L"TEST/TEST");
310  hr = SHLimitInputEdit(hEdt1, &sf);
311  ok_int(hr, S_OK);
313  ok_wstr(szText, L"TEST/TEST");
314 
315  ok_long(sf.m_cRefs, 1);
316 
317  n = (INT)SendMessageW(hEdt1, EM_GETLIMITTEXT, 0, 0);
318  ok_int(n, 234);
319 
320  SetWindowTextW(hEdt1, L"");
321  SendMessageW(hEdt1, WM_CHAR, L'A', 1);
323  ok_wstr(szText, L"A");
324 
325  SendMessageW(hEdt1, WM_CHAR, L'/', 1);
327  ok_wstr(szText, L"A");
328 
329  SendMessageW(hEdt1, WM_CHAR, L'/', 1);
331  ok_wstr(szText, L"A");
332 
333  SendMessageW(hEdt1, WM_CHAR, L'A', 1);
335  ok_wstr(szText, L"AA");
336  }
337 
338  {
339  CShellFolder sf(4, FALSE);
340 
341  ok_long(sf.m_cRefs, 1);
342 
343  SetWindowTextW(hEdt1, L"ABC");
344  hr = SHLimitInputEdit(hEdt1, &sf);
345 
346  SendMessageW(hEdt1, WM_CHAR, L'D', 1);
348  ok_wstr(szText, L"DABC");
349 
350  SendMessageW(hEdt1, WM_CHAR, L'E', 1);
352  ok_wstr(szText, L"DEABC");
353 
354  ok_long(sf.m_cRefs, 1);
355  }
356 
358  return TRUE;
359 }
360 
362 {
363  HRESULT hr;
364 
365  _SEH2_TRY
366  {
368  }
370  {
371  hr = 0xDEAD;
372  }
373  _SEH2_END;
374  ok_int(hr, 0xDEAD);
375 
376  _SEH2_TRY
377  {
378  hr = SHLimitInputEdit((HWND)0xDEAD, NULL);
379  }
381  {
382  hr = 0xDEAD;
383  }
384  _SEH2_END;
385  ok_int(hr, 0xDEAD);
386 
388 }
#define EM_LIMITTEXT
Definition: winuser.h:1982
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define REFIID
Definition: guiddef.h:118
#define TRUE
Definition: types.h:120
#define E_NOINTERFACE
Definition: winerror.h:2364
#define IDABORT
Definition: winuser.h:826
HRESULT WINAPI SHLimitInputEdit(HWND hWnd, IShellFolder *psf)
Definition: shellord.c:2689
#define WM_CHAR
Definition: winuser.h:1699
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
STDMETHODIMP GetValidCharacters(LPWSTR *ppwszValidChars, LPWSTR *ppwszInvalidChars)
REFIID riid
Definition: precomp.h:44
#define INT
Definition: polytest.cpp:20
#define CALLBACK
Definition: compat.h:27
REFIID LPVOID * ppv
Definition: atlbase.h:39
GLdouble n
Definition: glext.h:7729
STDMETHODIMP CreateViewObject(HWND hwndOwner, REFIID riid, void **ppv)
const ITEMID_CHILD UNALIGNED * PCUITEMID_CHILD
Definition: shtypes.idl:70
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
START_TEST(SHLimitInputEdit)
UINT_PTR WPARAM
Definition: windef.h:207
HRESULT WINAPI SHStrDupW(LPCWSTR src, LPWSTR *dest)
Definition: string.c:2004
UINT uFlags
Definition: api.c:59
int32_t INT_PTR
Definition: typedefs.h:63
#define ok_long(expression, result)
Definition: atltest.h:133
int32_t INT
Definition: typedefs.h:57
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
DWORD SHCONTF
Definition: shobjidl.idl:187
_SEH2_TRY
Definition: create.c:4250
STDMETHODIMP CompareIDs(LPARAM lParam, PCUIDLIST_RELATIVE pidl1, PCUIDLIST_RELATIVE pidl2)
STDMETHODIMP BindToObject(PCUIDLIST_RELATIVE pidl, IBindCtx *pbc, REFIID riid, void **ppv)
STDMETHODIMP EnumObjects(HWND hwnd, SHCONTF grfFlags, IEnumIDList **ppenumIDList)
const PCUITEMID_CHILD * PCUITEMID_CHILD_ARRAY
Definition: shtypes.idl:71
static const WCHAR szText[]
Definition: dialog.c:139
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
STDMETHODIMP_(ULONG) AddRef()
#define STDMETHODIMP
Definition: basetyps.h:43
ULONG Release()
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
#define ok_int(expression, result)
Definition: atltest.h:134
LONG_PTR LPARAM
Definition: windef.h:208
virtual ~CShellFolder()
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4374
static BOOL CALLBACK PropEnumProc(HWND hwnd, LPCWSTR lpszString, HANDLE hData)
static LPSTR pName
Definition: security.c:75
#define trace
Definition: atltest.h:70
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
static void DoNullFolderTest(HWND hEdt1)
LONG HRESULT
Definition: typedefs.h:78
#define _countof(array)
Definition: sndvol32.h:68
const GUID IID_IUnknown
#define EM_GETLIMITTEXT
Definition: richedit.h:74
STDMETHODIMP ParseDisplayName(HWND hwnd, IBindCtx *pbc, LPWSTR pszDisplayName, ULONG *pchEaten, PIDLIST_RELATIVE *ppidl, ULONG *pdwAttributes)
static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
ULONG AddRef()
CShellFolder(INT iMaxNameLen=0, BOOL bDisabled=FALSE)
#define edt1
Definition: dlgs.h:65
STDMETHODIMP GetMaxLength(LPCWSTR pszName, int *piMaxNameLen)
static const WCHAR L[]
Definition: oid.c:1250
STDMETHODIMP_(ULONG) CShellFolder
#define ok_wstr(x, y)
Definition: atltest.h:130
REFIID LPVOID * ppvObject
Definition: precomp.h:44
STDMETHODIMP GetAttributesOf(UINT cidl, PCUITEMID_CHILD_ARRAY apidl, SFGAOF *rgfInOut)
#define GWLP_WNDPROC
Definition: treelist.c:66
SFGAO_STORAGEANCESTOR typedef ULONG SFGAOF
Definition: shobjidl.idl:218
STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject)
int WINAPI EnumPropsW(_In_ HWND, _In_ PROPENUMPROCW)
#define S_OK
Definition: intsafe.h:59
_SEH2_END
Definition: create.c:4424
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1412
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define E_NOTIMPL
Definition: ddrawi.h:99
unsigned int UINT
Definition: ndis.h:50
STDMETHODIMP GetUIObjectOf(HWND hwndOwner, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, REFIID riid, UINT *rgfReserved, void **ppv)
const ITEMIDLIST_RELATIVE UNALIGNED * PCUIDLIST_RELATIVE
Definition: shtypes.idl:57
STDMETHODIMP BindToStorage(PCUIDLIST_RELATIVE pidl, IBindCtx *pbc, REFIID riid, void **ppv)
STDMETHODIMP GetDisplayNameOf(PCUITEMID_CHILD pidl, SHGDNF uFlags, STRRET *pName)
unsigned int ULONG
Definition: retypes.h:1
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define GetWindowLongPtr
Definition: treelist.c:73
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define E_POINTER
Definition: winerror.h:2365
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
STDMETHODIMP SetNameOf(HWND hwnd, PCUITEMID_CHILD pidl, LPCWSTR pszName, SHGDNF uFlags, PITEMID_CHILD *ppidlOut)
DWORD SHGDNF
Definition: shobjidl.idl:169