ReactOS 0.4.15-dev-5664-g3bf4ef6
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{
16public:
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
63 IBindCtx *pbc,
65 void **ppv)
66 {
67 trace("BindToObject\n");
68 return E_NOTIMPL;
69 }
70
73 IBindCtx *pbc,
75 void **ppv)
76 {
77 trace("BindToStorage\n");
78 return E_NOTIMPL;
79 }
80
85 {
86 trace("CompareIDs\n");
87 return E_NOTIMPL;
88 }
89
91 HWND hwndOwner,
93 void **ppv)
94 {
95 trace("CreateViewObject\n");
96 return E_NOTIMPL;
97 }
98
100 UINT cidl,
102 SFGAOF *rgfInOut)
103 {
104 trace("GetAttributesOf\n");
105 return E_NOTIMPL;
106 }
107
109 HWND hwndOwner,
110 UINT cidl,
112 REFIID riid,
113 UINT *rgfReserved,
114 void **ppv)
115 {
116 trace("GetUIObjectOf\n");
117 return E_NOTIMPL;
118 }
119
121 PCUITEMID_CHILD pidl,
123 STRRET *pName)
124 {
125 trace("GetDisplayNameOf\n");
126 return E_NOTIMPL;
127 }
128
130 HWND hwnd,
131 PCUITEMID_CHILD pidl,
132 LPCWSTR pszName,
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
150protected:
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
231static 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
241static void
243{
244 HRESULT hr;
245
247 {
248 hr = SHLimitInputEdit(hEdt1, NULL);
249 }
251 {
252 hr = 0xDEAD;
253 }
254 _SEH2_END;
255
256 ok_int(hr, 0xDEAD);
257}
258
259static 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);
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);
312 GetWindowTextW(hEdt1, szText, _countof(szText));
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);
322 GetWindowTextW(hEdt1, szText, _countof(szText));
323 ok_wstr(szText, L"A");
324
325 SendMessageW(hEdt1, WM_CHAR, L'/', 1);
326 GetWindowTextW(hEdt1, szText, _countof(szText));
327 ok_wstr(szText, L"A");
328
329 SendMessageW(hEdt1, WM_CHAR, L'/', 1);
330 GetWindowTextW(hEdt1, szText, _countof(szText));
331 ok_wstr(szText, L"A");
332
333 SendMessageW(hEdt1, WM_CHAR, L'A', 1);
334 GetWindowTextW(hEdt1, szText, _countof(szText));
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);
347 GetWindowTextW(hEdt1, szText, _countof(szText));
348 ok_wstr(szText, L"DABC");
349
350 SendMessageW(hEdt1, WM_CHAR, L'E', 1);
351 GetWindowTextW(hEdt1, szText, _countof(szText));
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
366 {
368 }
370 {
371 hr = 0xDEAD;
372 }
373 _SEH2_END;
374 ok_int(hr, 0xDEAD);
375
377 {
378 hr = SHLimitInputEdit((HWND)0xDEAD, NULL);
379 }
381 {
382 hr = 0xDEAD;
383 }
384 _SEH2_END;
385 ok_int(hr, 0xDEAD);
386
388}
static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
static void DoNullFolderTest(HWND hEdt1)
static BOOL CALLBACK PropEnumProc(HWND hwnd, LPCWSTR lpszString, HANDLE hData)
#define ok_long(expression, result)
Definition: atltest.h:133
#define trace
Definition: atltest.h:70
#define ok_wstr(x, y)
Definition: atltest.h:130
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
#define STDMETHODIMP
Definition: basetyps.h:43
#define STDMETHODIMP_(t)
Definition: basetyps.h:44
const GUID IID_IUnknown
STDMETHODIMP GetUIObjectOf(HWND hwndOwner, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, REFIID riid, UINT *rgfReserved, void **ppv)
STDMETHODIMP SetNameOf(HWND hwnd, PCUITEMID_CHILD pidl, LPCWSTR pszName, SHGDNF uFlags, PITEMID_CHILD *ppidlOut)
STDMETHODIMP ParseDisplayName(HWND hwnd, IBindCtx *pbc, LPWSTR pszDisplayName, ULONG *pchEaten, PIDLIST_RELATIVE *ppidl, ULONG *pdwAttributes)
STDMETHODIMP_(ULONG) AddRef()
STDMETHODIMP BindToStorage(PCUIDLIST_RELATIVE pidl, IBindCtx *pbc, REFIID riid, void **ppv)
STDMETHODIMP_(ULONG) Release()
STDMETHODIMP GetMaxLength(LPCWSTR pszName, int *piMaxNameLen)
STDMETHODIMP CreateViewObject(HWND hwndOwner, REFIID riid, void **ppv)
STDMETHODIMP GetAttributesOf(UINT cidl, PCUITEMID_CHILD_ARRAY apidl, SFGAOF *rgfInOut)
STDMETHODIMP CompareIDs(LPARAM lParam, PCUIDLIST_RELATIVE pidl1, PCUIDLIST_RELATIVE pidl2)
STDMETHODIMP GetDisplayNameOf(PCUITEMID_CHILD pidl, SHGDNF uFlags, STRRET *pName)
STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject)
STDMETHODIMP EnumObjects(HWND hwnd, SHCONTF grfFlags, IEnumIDList **ppenumIDList)
STDMETHODIMP GetValidCharacters(LPWSTR *ppwszValidChars, LPWSTR *ppwszInvalidChars)
CShellFolder(INT iMaxNameLen=0, BOOL bDisabled=FALSE)
STDMETHODIMP BindToObject(PCUIDLIST_RELATIVE pidl, IBindCtx *pbc, REFIID riid, void **ppv)
virtual ~CShellFolder()
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define E_NOTIMPL
Definition: ddrawi.h:99
#define edt1
Definition: dlgs.h:65
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
UINT uFlags
Definition: api.c:59
#define CALLBACK
Definition: compat.h:35
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
HRESULT WINAPI SHStrDupW(LPCWSTR src, LPWSTR *dest)
Definition: string.c:2004
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
unsigned int BOOL
Definition: ntddk_ex.h:94
GLdouble n
Definition: glext.h:7729
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
ULONG SFGAOF
Definition: shobjidl.idl:222
DWORD SHGDNF
Definition: shobjidl.idl:169
DWORD SHCONTF
Definition: shobjidl.idl:187
ULONG AddRef()
ULONG Release()
#define S_OK
Definition: intsafe.h:52
unsigned int ULONG
Definition: retypes.h:1
static LPSTR pName
Definition: security.c:75
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
#define INT
Definition: polytest.cpp:20
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define REFIID
Definition: guiddef.h:118
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define EM_GETLIMITTEXT
Definition: richedit.h:74
HRESULT WINAPI SHLimitInputEdit(HWND hWnd, IShellFolder *psf)
Definition: shellord.c:2780
HRESULT hr
Definition: shlfolder.c:183
const PCUITEMID_CHILD * PCUITEMID_CHILD_ARRAY
Definition: shtypes.idl:71
const ITEMID_CHILD UNALIGNED * PCUITEMID_CHILD
Definition: shtypes.idl:70
const ITEMIDLIST_RELATIVE UNALIGNED * PCUIDLIST_RELATIVE
Definition: shtypes.idl:57
#define _countof(array)
Definition: sndvol32.h:68
#define GetWindowLongPtr
Definition: treelist.c:73
#define GWLP_WNDPROC
Definition: treelist.c:66
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1412
_In_ void _In_ PCCERT_CONTEXT _In_opt_ LPFILETIME _In_ DWORD _In_ DWORD _Outptr_opt_ void ** ppvObject
Definition: wincrypt.h:6082
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define E_NOINTERFACE
Definition: winerror.h:2364
#define E_POINTER
Definition: winerror.h:2365
#define EM_LIMITTEXT
Definition: winuser.h:1990
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4389
int WINAPI EnumPropsW(_In_ HWND, _In_ PROPENUMPROCW)
#define WM_INITDIALOG
Definition: winuser.h:1729
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
#define IDABORT
Definition: winuser.h:826
#define WM_CHAR
Definition: winuser.h:1707
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185