shell32: Assign a default view mode value for IShellView.
[wine.git] / dlls / shell32 / tests / shlview.c
blobd25d626f8299524406795568cbd5f46e02b4a805
1 /*
2 * Unit test of the IShellView
4 * Copyright 2010 Nikolay Sivov for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
25 #define CONST_VTABLE
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wtypes.h"
30 #include "shellapi.h"
32 #include "shlguid.h"
33 #include "shlobj.h"
34 #include "shobjidl.h"
35 #include "shlwapi.h"
36 #include "ocidl.h"
37 #include "oleauto.h"
39 #include "initguid.h"
41 #include "wine/test.h"
43 #include "msg.h"
45 #define LISTVIEW_SEQ_INDEX 0
46 #define NUM_MSG_SEQUENCES 1
48 DEFINE_GUID(IID_IPersistHistory, 0x91a565c1, 0xe38f, 0x11d0, 0x94, 0xbf, 0x00, 0xa0, 0xc9, 0x05, 0x5c, 0xbf);
50 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
52 static LRESULT WINAPI listview_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
54 WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
55 static LONG defwndproc_counter = 0;
56 struct message msg = { 0 };
57 LRESULT ret;
59 msg.message = message;
60 msg.flags = sent|wparam|lparam;
61 if (defwndproc_counter) msg.flags |= defwinproc;
62 msg.wParam = wParam;
63 msg.lParam = lParam;
64 add_message(sequences, LISTVIEW_SEQ_INDEX, &msg);
66 defwndproc_counter++;
67 ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
68 defwndproc_counter--;
69 return ret;
72 static HWND subclass_listview(HWND hwnd)
74 WNDPROC oldproc;
75 HWND listview;
77 /* listview is a first child */
78 listview = FindWindowExA(hwnd, NULL, WC_LISTVIEWA, NULL);
79 if(!listview)
81 /* .. except for some versions of Windows XP, where things
82 are slightly more complicated. */
83 HWND hwnd_tmp;
84 hwnd_tmp = FindWindowExA(hwnd, NULL, "DUIViewWndClassName", NULL);
85 hwnd_tmp = FindWindowExA(hwnd_tmp, NULL, "DirectUIHWND", NULL);
86 hwnd_tmp = FindWindowExA(hwnd_tmp, NULL, "CtrlNotifySink", NULL);
87 listview = FindWindowExA(hwnd_tmp, NULL, WC_LISTVIEWA, NULL);
90 oldproc = (WNDPROC)SetWindowLongPtrA(listview, GWLP_WNDPROC,
91 (LONG_PTR)listview_subclass_proc);
92 SetWindowLongPtrA(listview, GWLP_USERDATA, (LONG_PTR)oldproc);
94 return listview;
97 static UINT get_msg_count(struct msg_sequence **seq, int sequence_index, UINT message)
99 struct msg_sequence *msg_seq = seq[sequence_index];
100 UINT i, count = 0;
102 for(i = 0; i < msg_seq->count ; i++)
103 if(msg_seq->sequence[i].message == message)
104 count++;
106 return count;
109 /* Checks that every message in the sequence seq is also present in
110 * the UINT array msgs */
111 static void verify_msgs_in_(struct msg_sequence *seq, const UINT *msgs,
112 const char *file, int line)
114 UINT i, j, msg, failcount = 0;
115 for(i = 0; i < seq->count; i++)
117 BOOL found = FALSE;
118 msg = seq->sequence[i].message;
119 for(j = 0; msgs[j] != 0; j++)
120 if(msgs[j] == msg) found = TRUE;
122 if(!found)
124 failcount++;
125 trace("Unexpected message %d\n", msg);
128 ok_(file, line) (!failcount, "%d failures.\n", failcount);
129 flush_sequences(sequences, NUM_MSG_SEQUENCES);
132 #define verify_msgs_in(seq, msgs) \
133 verify_msgs_in_(seq, msgs, __FILE__, __LINE__)
135 /* dummy IDataObject implementation */
136 typedef struct {
137 IDataObject IDataObject_iface;
138 LONG ref;
139 } IDataObjectImpl;
141 static const IDataObjectVtbl IDataObjectImpl_Vtbl;
143 static inline IDataObjectImpl *impl_from_IDataObject(IDataObject *iface)
145 return CONTAINING_RECORD(iface, IDataObjectImpl, IDataObject_iface);
148 static IDataObject* IDataObjectImpl_Construct(void)
150 IDataObjectImpl *obj;
152 obj = malloc(sizeof(*obj));
153 obj->IDataObject_iface.lpVtbl = &IDataObjectImpl_Vtbl;
154 obj->ref = 1;
156 return &obj->IDataObject_iface;
159 static HRESULT WINAPI IDataObjectImpl_QueryInterface(IDataObject *iface, REFIID riid, void **ppvObj)
161 IDataObjectImpl *This = impl_from_IDataObject(iface);
163 if (IsEqualIID(riid, &IID_IUnknown) ||
164 IsEqualIID(riid, &IID_IDataObject))
166 *ppvObj = &This->IDataObject_iface;
169 if(*ppvObj)
171 IDataObject_AddRef(iface);
172 return S_OK;
175 return E_NOINTERFACE;
178 static ULONG WINAPI IDataObjectImpl_AddRef(IDataObject * iface)
180 IDataObjectImpl *This = impl_from_IDataObject(iface);
181 return InterlockedIncrement(&This->ref);
184 static ULONG WINAPI IDataObjectImpl_Release(IDataObject * iface)
186 IDataObjectImpl *This = impl_from_IDataObject(iface);
187 ULONG ref = InterlockedDecrement(&This->ref);
189 if (!ref)
190 free(This);
192 return ref;
195 static HRESULT WINAPI IDataObjectImpl_GetData(IDataObject *iface, FORMATETC *pformat, STGMEDIUM *pmedium)
197 return E_NOTIMPL;
200 static HRESULT WINAPI IDataObjectImpl_GetDataHere(IDataObject *iface, FORMATETC *pformat, STGMEDIUM *pmedium)
202 return E_NOTIMPL;
205 static HRESULT WINAPI IDataObjectImpl_QueryGetData(IDataObject *iface, FORMATETC *pformat)
207 return E_NOTIMPL;
210 static HRESULT WINAPI IDataObjectImpl_GetCanonicalFormatEtc(
211 IDataObject *iface, FORMATETC *pformatIn, FORMATETC *pformatOut)
213 return E_NOTIMPL;
216 static HRESULT WINAPI IDataObjectImpl_SetData(
217 IDataObject *iface, FORMATETC *pformat, STGMEDIUM *pmedium, BOOL release)
219 return E_NOTIMPL;
222 static HRESULT WINAPI IDataObjectImpl_EnumFormatEtc(
223 IDataObject *iface, DWORD direction, IEnumFORMATETC **ppenumFormatEtc)
225 return E_NOTIMPL;
228 static HRESULT WINAPI IDataObjectImpl_DAdvise(
229 IDataObject *iface, FORMATETC *pformatetc, DWORD advf, IAdviseSink *pSink, DWORD *pConnection)
231 return E_NOTIMPL;
234 static HRESULT WINAPI IDataObjectImpl_DUnadvise(IDataObject *iface, DWORD connection)
236 return E_NOTIMPL;
239 static HRESULT WINAPI IDataObjectImpl_EnumDAdvise(IDataObject *iface, IEnumSTATDATA **ppenumAdvise)
241 return E_NOTIMPL;
244 static const IDataObjectVtbl IDataObjectImpl_Vtbl =
246 IDataObjectImpl_QueryInterface,
247 IDataObjectImpl_AddRef,
248 IDataObjectImpl_Release,
249 IDataObjectImpl_GetData,
250 IDataObjectImpl_GetDataHere,
251 IDataObjectImpl_QueryGetData,
252 IDataObjectImpl_GetCanonicalFormatEtc,
253 IDataObjectImpl_SetData,
254 IDataObjectImpl_EnumFormatEtc,
255 IDataObjectImpl_DAdvise,
256 IDataObjectImpl_DUnadvise,
257 IDataObjectImpl_EnumDAdvise
260 /* dummy IShellBrowser implementation */
261 typedef struct {
262 IShellBrowser IShellBrowser_iface;
263 LONG ref;
264 } IShellBrowserImpl;
266 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl;
268 static inline IShellBrowserImpl *impl_from_IShellBrowser(IShellBrowser *iface)
270 return CONTAINING_RECORD(iface, IShellBrowserImpl, IShellBrowser_iface);
273 static IShellBrowser* IShellBrowserImpl_Construct(void)
275 IShellBrowserImpl *browser;
277 browser = malloc(sizeof(*browser));
278 browser->IShellBrowser_iface.lpVtbl = &IShellBrowserImpl_Vtbl;
279 browser->ref = 1;
281 return &browser->IShellBrowser_iface;
284 static HRESULT WINAPI IShellBrowserImpl_QueryInterface(IShellBrowser *iface,
285 REFIID riid,
286 LPVOID *ppvObj)
288 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
290 *ppvObj = NULL;
292 if(IsEqualIID(riid, &IID_IUnknown) ||
293 IsEqualIID(riid, &IID_IOleWindow) ||
294 IsEqualIID(riid, &IID_IShellBrowser))
296 *ppvObj = &This->IShellBrowser_iface;
299 if(*ppvObj)
301 IShellBrowser_AddRef(iface);
302 return S_OK;
305 return E_NOINTERFACE;
308 static ULONG WINAPI IShellBrowserImpl_AddRef(IShellBrowser * iface)
310 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
311 return InterlockedIncrement(&This->ref);
314 static ULONG WINAPI IShellBrowserImpl_Release(IShellBrowser * iface)
316 IShellBrowserImpl *This = impl_from_IShellBrowser(iface);
317 ULONG ref = InterlockedDecrement(&This->ref);
319 if (!ref)
320 free(This);
322 return ref;
325 static HRESULT WINAPI IShellBrowserImpl_GetWindow(IShellBrowser *iface,
326 HWND *phwnd)
328 if (phwnd) *phwnd = GetDesktopWindow();
329 return S_OK;
332 static HRESULT WINAPI IShellBrowserImpl_ContextSensitiveHelp(IShellBrowser *iface,
333 BOOL fEnterMode)
335 return E_NOTIMPL;
338 static HRESULT WINAPI IShellBrowserImpl_BrowseObject(IShellBrowser *iface,
339 LPCITEMIDLIST pidl,
340 UINT wFlags)
342 return E_NOTIMPL;
345 static HRESULT WINAPI IShellBrowserImpl_EnableModelessSB(IShellBrowser *iface,
346 BOOL fEnable)
349 return E_NOTIMPL;
352 static HRESULT WINAPI IShellBrowserImpl_GetControlWindow(IShellBrowser *iface,
353 UINT id,
354 HWND *lphwnd)
357 return E_NOTIMPL;
360 static HRESULT WINAPI IShellBrowserImpl_GetViewStateStream(IShellBrowser *iface,
361 DWORD mode,
362 LPSTREAM *pStrm)
365 return E_NOTIMPL;
368 static HRESULT WINAPI IShellBrowserImpl_InsertMenusSB(IShellBrowser *iface,
369 HMENU hmenuShared,
370 LPOLEMENUGROUPWIDTHS lpMenuWidths)
373 return E_NOTIMPL;
376 static HRESULT WINAPI IShellBrowserImpl_OnViewWindowActive(IShellBrowser *iface,
377 IShellView *ppshv)
380 return E_NOTIMPL;
383 static HRESULT WINAPI IShellBrowserImpl_QueryActiveShellView(IShellBrowser *iface,
384 IShellView **ppshv)
387 return E_NOTIMPL;
390 static HRESULT WINAPI IShellBrowserImpl_RemoveMenusSB(IShellBrowser *iface,
391 HMENU hmenuShared)
394 return E_NOTIMPL;
397 static HRESULT WINAPI IShellBrowserImpl_SendControlMsg(IShellBrowser *iface,
398 UINT id,
399 UINT uMsg,
400 WPARAM wParam,
401 LPARAM lParam,
402 LRESULT *pret)
405 return E_NOTIMPL;
408 static HRESULT WINAPI IShellBrowserImpl_SetMenuSB(IShellBrowser *iface,
409 HMENU hmenuShared,
410 HOLEMENU holemenuReserved,
411 HWND hwndActiveObject)
414 return E_NOTIMPL;
417 static HRESULT WINAPI IShellBrowserImpl_SetStatusTextSB(IShellBrowser *iface,
418 LPCOLESTR lpszStatusText)
421 return E_NOTIMPL;
424 static HRESULT WINAPI IShellBrowserImpl_SetToolbarItems(IShellBrowser *iface,
425 LPTBBUTTON lpButtons,
426 UINT nButtons,
427 UINT uFlags)
430 return E_NOTIMPL;
433 static HRESULT WINAPI IShellBrowserImpl_TranslateAcceleratorSB(IShellBrowser *iface,
434 LPMSG lpmsg,
435 WORD wID)
438 return E_NOTIMPL;
441 static const IShellBrowserVtbl IShellBrowserImpl_Vtbl =
443 IShellBrowserImpl_QueryInterface,
444 IShellBrowserImpl_AddRef,
445 IShellBrowserImpl_Release,
446 IShellBrowserImpl_GetWindow,
447 IShellBrowserImpl_ContextSensitiveHelp,
448 IShellBrowserImpl_InsertMenusSB,
449 IShellBrowserImpl_SetMenuSB,
450 IShellBrowserImpl_RemoveMenusSB,
451 IShellBrowserImpl_SetStatusTextSB,
452 IShellBrowserImpl_EnableModelessSB,
453 IShellBrowserImpl_TranslateAcceleratorSB,
454 IShellBrowserImpl_BrowseObject,
455 IShellBrowserImpl_GetViewStateStream,
456 IShellBrowserImpl_GetControlWindow,
457 IShellBrowserImpl_SendControlMsg,
458 IShellBrowserImpl_QueryActiveShellView,
459 IShellBrowserImpl_OnViewWindowActive,
460 IShellBrowserImpl_SetToolbarItems
463 static const struct message empty_seq[] = {
464 { 0 }
467 static const struct message folderview_getspacing_seq[] = {
468 { LVM_GETITEMSPACING, wparam|sent, FALSE },
469 { 0 }
472 static const struct message folderview_getselectionmarked_seq[] = {
473 { LVM_GETSELECTIONMARK, sent },
474 { 0 }
477 static const struct message folderview_getfocused_seq[] = {
478 { LVM_GETNEXTITEM, sent|wparam|lparam|optional, -1, LVNI_FOCUSED },
479 { 0 }
482 static HRESULT WINAPI shellbrowser_QueryInterface(IShellBrowser *iface, REFIID riid, void **ppv)
484 *ppv = NULL;
486 if (IsEqualGUID(&IID_IShellBrowser, riid) ||
487 IsEqualGUID(&IID_IOleWindow, riid) ||
488 IsEqualGUID(&IID_IUnknown, riid))
490 *ppv = iface;
493 if (*ppv)
495 IUnknown_AddRef((IUnknown*)*ppv);
496 return S_OK;
499 return E_NOINTERFACE;
502 static ULONG WINAPI shellbrowser_AddRef(IShellBrowser *iface)
504 return 2;
507 static ULONG WINAPI shellbrowser_Release(IShellBrowser *iface)
509 return 1;
512 static HRESULT WINAPI shellbrowser_GetWindow(IShellBrowser *iface, HWND *phwnd)
514 *phwnd = GetDesktopWindow();
515 return S_OK;
518 static HRESULT WINAPI shellbrowser_ContextSensitiveHelp(IShellBrowser *iface, BOOL mode)
520 ok(0, "unexpected\n");
521 return E_NOTIMPL;
524 static HRESULT WINAPI shellbrowser_InsertMenusSB(IShellBrowser *iface, HMENU hmenuShared,
525 OLEMENUGROUPWIDTHS *menuwidths)
527 return E_NOTIMPL;
530 static HRESULT WINAPI shellbrowser_SetMenuSB(IShellBrowser *iface, HMENU hmenuShared,
531 HOLEMENU holemenuReserved, HWND hwndActiveObject)
533 return E_NOTIMPL;
536 static HRESULT WINAPI shellbrowser_RemoveMenusSB(IShellBrowser *iface, HMENU hmenuShared)
538 return E_NOTIMPL;
541 static HRESULT WINAPI shellbrowser_SetStatusTextSB(IShellBrowser *iface, LPCOLESTR text)
543 ok(0, "unexpected\n");
544 return E_NOTIMPL;
547 static HRESULT WINAPI shellbrowser_EnableModelessSB(IShellBrowser *iface, BOOL enable)
549 ok(0, "unexpected\n");
550 return E_NOTIMPL;
553 static HRESULT WINAPI shellbrowser_TranslateAcceleratorSB(IShellBrowser *iface, MSG *pmsg, WORD wID)
555 ok(0, "unexpected\n");
556 return E_NOTIMPL;
559 static HRESULT WINAPI shellbrowser_BrowseObject(IShellBrowser *iface, LPCITEMIDLIST pidl, UINT flags)
561 ok(0, "unexpected\n");
562 return E_NOTIMPL;
565 static HRESULT WINAPI shellbrowser_GetViewStateStream(IShellBrowser *iface, DWORD mode, IStream **stream)
567 return E_NOTIMPL;
570 static HRESULT WINAPI shellbrowser_GetControlWindow(IShellBrowser *iface, UINT id, HWND *phwnd)
572 return E_NOTIMPL;
575 static HRESULT WINAPI shellbrowser_SendControlMsg(IShellBrowser *iface, UINT id, UINT uMsg,
576 WPARAM wParam, LPARAM lParam, LRESULT *pret)
578 return E_NOTIMPL;
581 static HRESULT WINAPI shellbrowser_QueryActiveShellView(IShellBrowser *iface, IShellView **view)
583 ok(0, "unexpected\n");
584 return E_NOTIMPL;
587 static HRESULT WINAPI shellbrowser_OnViewWindowActive(IShellBrowser *iface, IShellView *view)
589 ok(0, "unexpected\n");
590 return E_NOTIMPL;
593 static HRESULT WINAPI shellbrowser_SetToolbarItems(IShellBrowser *iface, LPTBBUTTONSB buttons,
594 UINT count, UINT flags)
596 return E_NOTIMPL;
599 static const IShellBrowserVtbl shellbrowservtbl = {
600 shellbrowser_QueryInterface,
601 shellbrowser_AddRef,
602 shellbrowser_Release,
603 shellbrowser_GetWindow,
604 shellbrowser_ContextSensitiveHelp,
605 shellbrowser_InsertMenusSB,
606 shellbrowser_SetMenuSB,
607 shellbrowser_RemoveMenusSB,
608 shellbrowser_SetStatusTextSB,
609 shellbrowser_EnableModelessSB,
610 shellbrowser_TranslateAcceleratorSB,
611 shellbrowser_BrowseObject,
612 shellbrowser_GetViewStateStream,
613 shellbrowser_GetControlWindow,
614 shellbrowser_SendControlMsg,
615 shellbrowser_QueryActiveShellView,
616 shellbrowser_OnViewWindowActive,
617 shellbrowser_SetToolbarItems
620 static IShellBrowser test_shellbrowser = { &shellbrowservtbl };
622 static void test_CreateViewWindow(void)
624 IShellFolder *desktop;
625 HWND hwnd_view, hwnd2;
626 FOLDERSETTINGS settings;
627 IShellView *view;
628 IDropTarget *dt;
629 HRESULT hr;
630 RECT r = {0};
631 ULONG ref1, ref2;
632 IUnknown *unk;
634 hr = SHGetDesktopFolder(&desktop);
635 ok(hr == S_OK, "got (0x%08lx)\n", hr);
637 hr = IShellFolder_CreateViewObject(desktop, NULL, &IID_IShellView, (void**)&view);
638 ok(hr == S_OK, "got (0x%08lx)\n", hr);
640 hr = IShellView_QueryInterface(view, &IID_CDefView, (void **)&unk);
641 ok(hr == S_OK, "got (0x%08lx)\n", hr);
642 ok(unk == (IUnknown *)view, "got %p\n", unk);
643 IUnknown_Release(unk);
645 if (0)
647 /* crashes on native */
648 IShellView_CreateViewWindow(view, NULL, &settings, NULL, NULL, NULL);
651 settings.ViewMode = FVM_ICON;
652 settings.fFlags = 0;
653 hwnd_view = (HWND)0xdeadbeef;
654 hr = IShellView_CreateViewWindow(view, NULL, &settings, NULL, NULL, &hwnd_view);
655 ok(hr == E_UNEXPECTED, "got (0x%08lx)\n", hr);
656 ok(hwnd_view == 0, "got %p\n", hwnd_view);
658 hwnd_view = (HWND)0xdeadbeef;
659 hr = IShellView_CreateViewWindow(view, NULL, &settings, NULL, &r, &hwnd_view);
660 ok(hr == E_UNEXPECTED, "got (0x%08lx)\n", hr);
661 ok(hwnd_view == 0, "got %p\n", hwnd_view);
663 hwnd_view = NULL;
664 hr = IShellView_CreateViewWindow(view, NULL, &settings, &test_shellbrowser, &r, &hwnd_view);
665 ok(hr == S_OK || broken(hr == S_FALSE), "got (0x%08lx)\n", hr);
666 ok(hwnd_view != 0, "got %p\n", hwnd_view);
668 hwnd2 = (HWND)0xdeadbeef;
669 hr = IShellView_CreateViewWindow(view, NULL, &settings, &test_shellbrowser, &r, &hwnd2);
670 ok(hr == E_UNEXPECTED, "got (0x%08lx)\n", hr);
671 ok(hwnd2 == NULL, "got %p\n", hwnd2);
673 /* ::DragLeave without drag operation */
674 hr = IShellView_QueryInterface(view, &IID_IDropTarget, (void**)&dt);
675 ok(hr == S_OK, "got (0x%08lx)\n", hr);
676 hr = IDropTarget_DragLeave(dt);
677 ok(hr == S_OK, "got (0x%08lx)\n", hr);
678 IDropTarget_Release(dt);
680 IShellView_AddRef(view);
681 ref1 = IShellView_Release(view);
682 hr = IShellView_DestroyViewWindow(view);
683 ok(hr == S_OK, "got (0x%08lx)\n", hr);
684 ok(!IsWindow(hwnd_view), "hwnd %p still valid\n", hwnd_view);
685 ref2 = IShellView_Release(view);
686 ok(ref1 > ref2, "expected %lu > %lu\n", ref1, ref2);
687 ref1 = ref2;
689 /* Show that releasing the shell view does not destroy the window */
690 hr = IShellFolder_CreateViewObject(desktop, NULL, &IID_IShellView, (void**)&view);
691 ok(hr == S_OK, "got (0x%08lx)\n", hr);
692 hwnd_view = NULL;
693 hr = IShellView_CreateViewWindow(view, NULL, &settings, &test_shellbrowser, &r, &hwnd_view);
694 ok(hr == S_OK || broken(hr == S_FALSE), "got (0x%08lx)\n", hr);
695 ok(hwnd_view != NULL, "got %p\n", hwnd_view);
696 ok(IsWindow(hwnd_view), "hwnd %p still valid\n", hwnd_view);
697 ref2 = IShellView_Release(view);
698 ok(ref2 != 0, "ref2 = %lu\n", ref2);
699 ok(ref2 > ref1, "expected %lu > %lu\n", ref2, ref1);
700 ok(IsWindow(hwnd_view), "hwnd %p still valid\n", hwnd_view);
701 DestroyWindow(hwnd_view);
703 IShellFolder_Release(desktop);
706 static void test_IFolderView(void)
708 IShellFolder *desktop, *folder;
709 FOLDERSETTINGS settings;
710 IShellView *view;
711 IShellBrowser *browser;
712 IFolderView2 *fv2;
713 IFolderView *fv;
714 IUnknown *unk;
715 HWND hwnd_view, hwnd_list;
716 PITEMID_CHILD pidl;
717 HRESULT hr;
718 INT ret, count;
719 POINT pt;
720 RECT r;
722 hr = SHGetDesktopFolder(&desktop);
723 ok(hr == S_OK, "got (0x%08lx)\n", hr);
725 hr = IShellFolder_CreateViewObject(desktop, NULL, &IID_IShellView, (void**)&view);
726 ok(hr == S_OK, "got (0x%08lx)\n", hr);
728 hr = IShellView_QueryInterface(view, &IID_IFolderView, (void**)&fv);
729 if (hr != S_OK)
731 win_skip("IFolderView not supported by desktop folder\n");
732 IShellView_Release(view);
733 IShellFolder_Release(desktop);
734 return;
737 /* call methods before window creation */
738 hr = IFolderView_GetSpacing(fv, NULL);
739 ok(hr == S_FALSE || broken(hr == S_OK) /* win7 */, "got (0x%08lx)\n", hr);
741 pidl = (void*)0xdeadbeef;
742 hr = IFolderView_Item(fv, 0, &pidl);
743 ok(hr == E_INVALIDARG || broken(hr == E_FAIL) /* < Vista */, "got (0x%08lx)\n", hr);
744 ok(pidl == 0 || broken(pidl == (void*)0xdeadbeef) /* < Vista */, "got %p\n", pidl);
746 if (0)
748 /* crashes on Vista and Win2k8 - List not created yet case */
749 IFolderView_GetSpacing(fv, &pt);
751 /* crashes on XP */
752 IFolderView_GetSelectionMarkedItem(fv, NULL);
753 IFolderView_GetFocusedItem(fv, NULL);
755 /* crashes on Vista+ */
756 IFolderView_Item(fv, 0, NULL);
759 browser = IShellBrowserImpl_Construct();
761 settings.ViewMode = FVM_ICON;
762 settings.fFlags = 0;
763 hwnd_view = (HWND)0xdeadbeef;
764 SetRect(&r, 0, 0, 100, 100);
765 hr = IShellView_CreateViewWindow(view, NULL, &settings, browser, &r, &hwnd_view);
766 ok(hr == S_OK, "got (0x%08lx)\n", hr);
767 ok(IsWindow(hwnd_view), "got %p\n", hwnd_view);
769 hwnd_list = subclass_listview(hwnd_view);
770 if (!hwnd_list)
772 win_skip("Failed to subclass ListView control\n");
773 IShellBrowser_Release(browser);
774 IFolderView_Release(fv);
775 IShellView_Release(view);
776 IShellFolder_Release(desktop);
777 return;
780 /* IFolderView::GetSpacing */
781 flush_sequences(sequences, NUM_MSG_SEQUENCES);
782 hr = IFolderView_GetSpacing(fv, NULL);
783 ok(hr == S_OK, "got (0x%08lx)\n", hr);
784 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, empty_seq, "IFolderView::GetSpacing, empty", FALSE);
786 flush_sequences(sequences, NUM_MSG_SEQUENCES);
787 hr = IFolderView_GetSpacing(fv, &pt);
788 ok(hr == S_OK, "got (0x%08lx)\n", hr);
789 /* fails with empty sequence on win7 for unknown reason */
790 if (sequences[LISTVIEW_SEQ_INDEX]->count)
792 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, folderview_getspacing_seq, "IFolderView::GetSpacing", FALSE);
793 ok(pt.x > 0, "got %ld\n", pt.x);
794 ok(pt.y > 0, "got %ld\n", pt.y);
795 ret = SendMessageA(hwnd_list, LVM_GETITEMSPACING, 0, 0);
796 ok(pt.x == LOWORD(ret) && pt.y == HIWORD(ret), "got (%d, %d)\n", LOWORD(ret), HIWORD(ret));
799 /* IFolderView::ItemCount */
800 if (0)
802 /* crashes on XP */
803 IFolderView_ItemCount(fv, SVGIO_ALLVIEW, NULL);
806 flush_sequences(sequences, NUM_MSG_SEQUENCES);
807 IFolderView_ItemCount(fv, SVGIO_ALLVIEW, &count);
809 /* IFolderView::GetSelectionMarkedItem */
810 if (0)
812 /* crashes on XP */
813 IFolderView_GetSelectionMarkedItem(fv, NULL);
816 flush_sequences(sequences, NUM_MSG_SEQUENCES);
817 hr = IFolderView_GetSelectionMarkedItem(fv, &ret);
818 if (count)
819 ok(hr == S_OK, "got (0x%08lx)\n", hr);
820 else
821 ok(hr == S_FALSE, "got (0x%08lx)\n", hr);
822 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, folderview_getselectionmarked_seq,
823 "IFolderView::GetSelectionMarkedItem", FALSE);
825 /* IFolderView::GetFocusedItem */
826 flush_sequences(sequences, NUM_MSG_SEQUENCES);
827 hr = IFolderView_GetFocusedItem(fv, &ret);
828 if (count)
829 ok(hr == S_OK, "got (0x%08lx)\n", hr);
830 else
831 ok(hr == S_FALSE, "got (0x%08lx)\n", hr);
832 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, folderview_getfocused_seq,
833 "IFolderView::GetFocusedItem", FALSE);
835 /* IFolderView::GetFolder, just return pointer */
836 if (0)
838 /* crashes on XP */
839 IFolderView_GetFolder(fv, NULL, (void**)&folder);
840 IFolderView_GetFolder(fv, NULL, NULL);
843 hr = IFolderView_GetFolder(fv, &IID_IShellFolder, NULL);
844 ok(hr == E_POINTER, "got (0x%08lx)\n", hr);
846 hr = IFolderView_GetFolder(fv, &IID_IShellFolder, (void**)&folder);
847 ok(hr == S_OK, "got (0x%08lx)\n", hr);
848 ok(desktop == folder, "\n");
849 if (folder) IShellFolder_Release(folder);
851 hr = IFolderView_GetFolder(fv, &IID_IUnknown, (void**)&unk);
852 ok(hr == S_OK, "got (0x%08lx)\n", hr);
853 if (unk) IUnknown_Release(unk);
855 hr = IFolderView_QueryInterface(fv, &IID_IFolderView2, (void**)&fv2);
856 if (hr != S_OK)
857 win_skip("IFolderView2 is not supported.\n");
858 if (fv2) IFolderView2_Release(fv2);
860 hr = IShellView_DestroyViewWindow(view);
861 ok(hr == S_OK, "got (0x%08lx)\n", hr);
862 ok(!IsWindow(hwnd_view), "hwnd %p still valid\n", hwnd_view);
864 IShellBrowser_Release(browser);
865 IFolderView_Release(fv);
866 IShellView_Release(view);
867 IShellFolder_Release(desktop);
870 static void test_GetItemObject(void)
872 IShellFolder *desktop;
873 IShellView *view;
874 IUnknown *unk;
875 HRESULT hr;
877 hr = SHGetDesktopFolder(&desktop);
878 ok(hr == S_OK, "got (0x%08lx)\n", hr);
880 hr = IShellFolder_CreateViewObject(desktop, NULL, &IID_IShellView, (void**)&view);
881 ok(hr == S_OK, "got (0x%08lx)\n", hr);
883 /* from documentation three interfaces are supported for SVGIO_BACKGROUND:
884 IContextMenu, IDispatch, IPersistHistory */
885 hr = IShellView_GetItemObject(view, SVGIO_BACKGROUND, &IID_IContextMenu, (void**)&unk);
886 ok(hr == S_OK, "got (0x%08lx)\n", hr);
887 IUnknown_Release(unk);
889 unk = NULL;
890 hr = IShellView_GetItemObject(view, SVGIO_BACKGROUND, &IID_IDispatch, (void**)&unk);
891 ok(hr == S_OK || broken(hr == E_NOTIMPL) /* NT4 */, "got (0x%08lx)\n", hr);
892 if (unk) IUnknown_Release(unk);
894 unk = NULL;
895 hr = IShellView_GetItemObject(view, SVGIO_BACKGROUND, &IID_IPersistHistory, (void**)&unk);
896 todo_wine ok(hr == S_OK || broken(hr == E_NOTIMPL) /* W9x, NT4 */, "got (0x%08lx)\n", hr);
897 if (unk) IUnknown_Release(unk);
899 /* example of unsupported interface, base for IPersistHistory */
900 hr = IShellView_GetItemObject(view, SVGIO_BACKGROUND, &IID_IPersist, (void**)&unk);
901 ok(hr == E_NOINTERFACE || broken(hr == E_NOTIMPL) /* W2K */, "got (0x%08lx)\n", hr);
903 IShellView_Release(view);
904 IShellFolder_Release(desktop);
907 static void test_IShellFolderView(void)
909 IShellFolderView *folderview;
910 IShellFolder *desktop;
911 IShellView *view;
912 IDataObject *obj;
913 UINT i;
914 HRESULT hr;
916 hr = SHGetDesktopFolder(&desktop);
917 ok(hr == S_OK, "got (0x%08lx)\n", hr);
919 hr = IShellFolder_CreateViewObject(desktop, NULL, &IID_IShellView, (void**)&view);
920 ok(hr == S_OK, "got (0x%08lx)\n", hr);
922 hr = IShellView_QueryInterface(view, &IID_IShellFolderView, (void**)&folderview);
923 if (hr != S_OK)
925 win_skip("IShellView doesn't provide IShellFolderView on this platform\n");
926 IShellView_Release(view);
927 IShellFolder_Release(desktop);
928 return;
931 /* ::MoveIcons */
932 obj = IDataObjectImpl_Construct();
933 hr = IShellFolderView_MoveIcons(folderview, obj);
934 ok(hr == E_NOTIMPL || broken(hr == S_OK) /* W98 */, "got (0x%08lx)\n", hr);
935 IDataObject_Release(obj);
937 /* ::SetRedraw without list created */
938 hr = IShellFolderView_SetRedraw(folderview, TRUE);
939 ok(hr == S_OK, "got (0x%08lx)\n", hr);
941 /* ::QuerySupport */
942 hr = IShellFolderView_QuerySupport(folderview, NULL);
943 ok(hr == S_OK, "got (0x%08lx)\n", hr);
944 i = 0xdeadbeef;
945 hr = IShellFolderView_QuerySupport(folderview, &i);
946 ok(hr == S_OK, "got (0x%08lx)\n", hr);
947 ok(i == 0xdeadbeef, "got %d\n", i);
949 /* ::RemoveObject */
950 i = 0xdeadbeef;
951 hr = IShellFolderView_RemoveObject(folderview, NULL, &i);
952 ok(hr == S_OK || hr == E_FAIL, "got (0x%08lx)\n", hr);
953 if (hr == S_OK) ok(i == 0 || broken(i == 0xdeadbeef) /* Vista, 2k8 */,
954 "got %d\n", i);
956 IShellFolderView_Release(folderview);
958 IShellView_Release(view);
959 IShellFolder_Release(desktop);
962 static void test_IOleWindow(void)
964 IShellFolder *desktop;
965 IShellView *view;
966 IOleWindow *wnd;
967 HRESULT hr;
969 hr = SHGetDesktopFolder(&desktop);
970 ok(hr == S_OK, "got (0x%08lx)\n", hr);
972 hr = IShellFolder_CreateViewObject(desktop, NULL, &IID_IShellView, (void**)&view);
973 ok(hr == S_OK, "got (0x%08lx)\n", hr);
975 hr = IShellView_QueryInterface(view, &IID_IOleWindow, (void**)&wnd);
976 ok(hr == E_NOINTERFACE, "got (0x%08lx)\n", hr);
978 /* IShellView::ContextSensitiveHelp */
979 hr = IShellView_ContextSensitiveHelp(view, TRUE);
980 ok(hr == E_NOTIMPL, "got (0x%08lx)\n", hr);
981 hr = IShellView_ContextSensitiveHelp(view, FALSE);
982 ok(hr == E_NOTIMPL, "got (0x%08lx)\n", hr);
984 IShellView_Release(view);
985 IShellFolder_Release(desktop);
988 static const struct message folderview_setcurrentviewmode1_2_prevista[] = {
989 { LVM_SETVIEW, sent|wparam, LV_VIEW_ICON},
990 { LVM_SETIMAGELIST, sent|wparam, 0},
991 { LVM_SETIMAGELIST, sent|wparam, 1},
992 { 0x105a, sent},
993 { LVM_SETBKIMAGEW, sent|optional}, /* w2k3 */
994 { LVM_GETBKCOLOR, sent|optional}, /* w2k3 */
995 { LVM_GETTEXTBKCOLOR, sent|optional}, /* w2k3 */
996 { LVM_GETTEXTCOLOR, sent|optional}, /* w2k3 */
997 { LVM_SETEXTENDEDLISTVIEWSTYLE, sent|optional|wparam, 0xc8}, /* w2k3 */
998 { LVM_ARRANGE, sent },
999 { LVM_ARRANGE, sent|optional }, /* WinXP */
1000 { 0 }
1003 static const struct message folderview_setcurrentviewmode3_prevista[] = {
1004 { LVM_SETVIEW, sent|wparam, LV_VIEW_LIST},
1005 { LVM_SETIMAGELIST, sent|wparam, 0},
1006 { LVM_SETIMAGELIST, sent|wparam, 1},
1007 { 0x105a, sent},
1008 { LVM_SETBKIMAGEW, sent|optional}, /* w2k3 */
1009 { LVM_GETBKCOLOR, sent|optional}, /* w2k3 */
1010 { LVM_GETTEXTBKCOLOR, sent|optional}, /* w2k3 */
1011 { LVM_GETTEXTCOLOR, sent|optional}, /* w2k3 */
1012 { LVM_SETEXTENDEDLISTVIEWSTYLE, sent|optional|wparam, 0xc8}, /* w2k3 */
1013 { 0 }
1016 static const struct message folderview_setcurrentviewmode4_prevista[] = {
1017 { LVM_GETHEADER, sent},
1018 { LVM_GETITEMCOUNT, sent|optional },
1019 { LVM_SETSELECTEDCOLUMN, sent},
1020 { WM_NOTIFY, sent },
1021 { WM_NOTIFY, sent },
1022 { WM_NOTIFY, sent },
1023 { WM_NOTIFY, sent },
1024 { LVM_SETVIEW, sent|wparam, LV_VIEW_DETAILS},
1025 { LVM_SETIMAGELIST, sent|wparam, 0},
1026 { LVM_SETIMAGELIST, sent|wparam, 1},
1027 { 0x105a, sent},
1028 { LVM_SETBKIMAGEW, sent|optional}, /* w2k3 */
1029 { LVM_GETBKCOLOR, sent|optional}, /* w2k3 */
1030 { LVM_GETTEXTBKCOLOR, sent|optional}, /* w2k3 */
1031 { LVM_GETTEXTCOLOR, sent|optional}, /* w2k3 */
1032 { LVM_SETEXTENDEDLISTVIEWSTYLE, sent|optional|wparam, 0xc8}, /* w2k3 */
1033 { 0 }
1036 /* XP, SetCurrentViewMode(5)
1037 108e - LVM_SETVIEW (LV_VIEW_ICON);
1038 1036 - LVM_SETEXTEDEDLISTVIEWSTYLE (0x8000, 0)
1039 100c/104c repeated X times
1040 1003 - LVM_SETIMAGELIST
1041 1035 - LVM_SETICONSPACING
1042 1004 - LVM_GETITEMCOUNT
1043 105a - ?
1044 1016 - LVM_ARRANGE
1045 1016 - LVM_ARRANGE
1048 /* XP, SetCurrentViewMode(6)
1049 1036 - LVM_SETEXTENDEDLISTVIEWSTYLE (0x8000, 0)
1050 1035 - LVM_SETICONSPACING
1051 1003 - LVM_SETIMAGELIST
1052 1003 - LVM_SETIMAGELIST
1053 100c/104c repeated X times
1054 10a2 - LVM_SETTILEVIEWINFO
1055 108e - LVM_SETVIEW (LV_VIEW_TILE)
1056 1003 - LVM_SETIMAGELIST
1057 105a - ?
1058 1016 - LVM_ARRANGE
1059 1016 - LVM_ARRANGE
1062 /* XP, SetCurrentViewMode (7)
1063 10a2 - LVM_SETTILEVIEWINFO
1064 108e - LVM_SETVIEW (LV_VIEW_ICON)
1065 1004/10a4 (LVM_GETITEMCOUNT/LVM_SETTILEINFO) X times
1066 1016 - LVM_ARRANGE
1067 1016 - LVM_ARRANGE
1069 LVM_SETEXTENDEDLISTVIEWSTYLE (0x40000, 0x40000)
1071 LVM_SETEXTENDEDLISTVIEWSTYLE (0x8000, 0x8000)
1074 static void test_GetSetCurrentViewMode(void)
1076 IShellFolder *desktop;
1077 IShellView *sview;
1078 IFolderView *fview;
1079 IShellBrowser *browser;
1080 FOLDERSETTINGS fs;
1081 UINT viewmode;
1082 HWND hwnd;
1083 RECT rc = {0, 0, 10, 10};
1084 HRESULT hr;
1085 UINT i;
1086 static const int winxp_res[11] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
1087 static const int win2k3_res[11] = {0, 1, 2, 3, 4, 5, 6, 5, 8, 0, 0};
1088 static const int vista_res[11] = {0, 1, 5, 3, 4, 5, 6, 7, 7, 0, 0};
1089 static const int win7_res[11] = {1, 1, 1, 3, 4, 1, 6, 1, 8, 8, 8};
1091 hr = SHGetDesktopFolder(&desktop);
1092 ok(hr == S_OK, "got (0x%08lx)\n", hr);
1094 hr = IShellFolder_CreateViewObject(desktop, NULL, &IID_IShellView, (void**)&sview);
1095 ok(hr == S_OK, "got (0x%08lx)\n", hr);
1097 hr = IShellView_QueryInterface(sview, &IID_IFolderView, (void **)&fview);
1098 ok(hr == S_OK, "Got hr %#lx.\n", hr);
1100 viewmode = 0xdeadbeef;
1101 hr = IFolderView_GetCurrentViewMode(fview, &viewmode);
1102 ok(hr == S_OK, "Got hr %#lx.\n", hr);
1103 ok(viewmode == FVM_TILE || broken(viewmode == 0) /* pre win7 */, "Got view mode %u.\n", viewmode);
1105 fs.ViewMode = 1;
1106 fs.fFlags = 0;
1107 browser = IShellBrowserImpl_Construct();
1108 hr = IShellView_CreateViewWindow(sview, NULL, &fs, browser, &rc, &hwnd);
1109 ok(hr == S_OK || broken(hr == S_FALSE /*Win2k*/ ), "got (0x%08lx)\n", hr);
1111 if(SUCCEEDED(hr))
1113 HWND hwnd_lv;
1114 UINT count;
1116 if (0)
1118 /* Crashes under Win7/WinXP */
1119 IFolderView_GetCurrentViewMode(fview, NULL);
1122 hr = IFolderView_GetCurrentViewMode(fview, &viewmode);
1123 ok(hr == S_OK, "got (0x%08lx)\n", hr);
1124 ok(viewmode == 1, "ViewMode was %d\n", viewmode);
1126 hr = IFolderView_SetCurrentViewMode(fview, FVM_AUTO);
1127 ok(hr == S_OK, "got (0x%08lx)\n", hr);
1129 hr = IFolderView_SetCurrentViewMode(fview, 0);
1130 ok(hr == E_INVALIDARG || broken(hr == S_OK),
1131 "got (0x%08lx)\n", hr);
1133 hr = IFolderView_GetCurrentViewMode(fview, &viewmode);
1134 ok(hr == S_OK, "got (0x%08lx)\n", hr);
1136 for(i = 1; i < 9; i++)
1138 hr = IFolderView_SetCurrentViewMode(fview, i);
1139 ok(hr == S_OK || (i == 8 && hr == E_INVALIDARG /*Vista*/),
1140 "(%d) got (0x%08lx)\n", i, hr);
1142 hr = IFolderView_GetCurrentViewMode(fview, &viewmode);
1143 ok(hr == S_OK, "(%d) got (0x%08lx)\n", i, hr);
1145 /* Wine currently behaves like winxp here. */
1146 ok((viewmode == win7_res[i]) || (viewmode == vista_res[i]) ||
1147 (viewmode == win2k3_res[i]) || (viewmode == winxp_res[i]),
1148 "(%d) got %d\n",i , viewmode);
1151 hr = IFolderView_SetCurrentViewMode(fview, 9);
1152 ok(hr == E_INVALIDARG || broken(hr == S_OK),
1153 "got (0x%08lx)\n", hr);
1155 /* Test messages */
1156 hwnd_lv = subclass_listview(hwnd);
1157 ok(hwnd_lv != NULL, "Failed to subclass listview\n");
1158 if(hwnd_lv)
1160 /* Vista seems to set the viewmode by other means than
1161 sending messages. At least no related messages are
1162 captured by subclassing.
1164 BOOL vista_plus = FALSE;
1165 static const UINT vista_plus_msgs[] = {
1166 WM_SETREDRAW, WM_NOTIFY, WM_NOTIFYFORMAT, WM_QUERYUISTATE,
1167 WM_MENUCHAR, WM_WINDOWPOSCHANGING, WM_NCCALCSIZE, WM_WINDOWPOSCHANGED,
1168 WM_PARENTNOTIFY, LVM_GETHEADER, 0 };
1170 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1171 hr = IFolderView_SetCurrentViewMode(fview, 1);
1172 ok(hr == S_OK, "got 0x%08lx\n", hr);
1174 /* WM_SETREDRAW is not sent in versions before Vista. */
1175 vista_plus = get_msg_count(sequences, LISTVIEW_SEQ_INDEX, WM_SETREDRAW);
1176 if(vista_plus)
1177 verify_msgs_in(sequences[LISTVIEW_SEQ_INDEX], vista_plus_msgs);
1178 else
1179 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, folderview_setcurrentviewmode1_2_prevista,
1180 "IFolderView::SetCurrentViewMode(1)", TRUE);
1182 hr = IFolderView_SetCurrentViewMode(fview, 2);
1183 ok(hr == S_OK, "got 0x%08lx\n", hr);
1184 if(vista_plus)
1185 verify_msgs_in(sequences[LISTVIEW_SEQ_INDEX], vista_plus_msgs);
1186 else
1187 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, folderview_setcurrentviewmode1_2_prevista,
1188 "IFolderView::SetCurrentViewMode(2)", TRUE);
1190 hr = IFolderView_SetCurrentViewMode(fview, 3);
1191 ok(hr == S_OK, "got 0x%08lx\n", hr);
1192 if(vista_plus)
1193 verify_msgs_in(sequences[LISTVIEW_SEQ_INDEX], vista_plus_msgs);
1194 else
1195 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, folderview_setcurrentviewmode3_prevista,
1196 "IFolderView::SetCurrentViewMode(3)", TRUE);
1198 hr = IFolderView_SetCurrentViewMode(fview, 4);
1199 ok(hr == S_OK, "got 0x%08lx\n", hr);
1200 if(vista_plus)
1201 verify_msgs_in(sequences[LISTVIEW_SEQ_INDEX], vista_plus_msgs);
1202 else
1203 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, folderview_setcurrentviewmode4_prevista,
1204 "IFolderView::SetCurrentViewMode(4)", TRUE);
1206 hr = IFolderView_SetCurrentViewMode(fview, 5);
1207 ok(hr == S_OK, "got 0x%08lx\n", hr);
1208 todo_wine
1210 if(vista_plus)
1212 verify_msgs_in(sequences[LISTVIEW_SEQ_INDEX], vista_plus_msgs);
1214 else
1216 count = get_msg_count(sequences, LISTVIEW_SEQ_INDEX, LVM_SETVIEW);
1217 ok(count == 1, "LVM_SETVIEW sent %d times.\n", count);
1218 count = get_msg_count(sequences, LISTVIEW_SEQ_INDEX, LVM_SETEXTENDEDLISTVIEWSTYLE);
1219 ok(count == 1 || count == 2, "LVM_SETEXTENDEDLISTVIEWSTYLE sent %d times.\n", count);
1220 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1224 hr = IFolderView_SetCurrentViewMode(fview, 6);
1225 ok(hr == S_OK, "got 0x%08lx\n", hr);
1226 todo_wine
1228 if(vista_plus)
1230 verify_msgs_in(sequences[LISTVIEW_SEQ_INDEX], vista_plus_msgs);
1232 else
1234 count = get_msg_count(sequences, LISTVIEW_SEQ_INDEX, LVM_SETVIEW);
1235 ok(count == 1, "LVM_SETVIEW sent %d times.\n", count);
1236 count = get_msg_count(sequences, LISTVIEW_SEQ_INDEX, LVM_SETEXTENDEDLISTVIEWSTYLE);
1237 ok(count == 1 || count == 2, "LVM_SETEXTENDEDLISTVIEWSTYLE sent %d times.\n", count);
1238 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1242 hr = IFolderView_SetCurrentViewMode(fview, 7);
1243 ok(hr == S_OK, "got 0x%08lx\n", hr);
1244 todo_wine
1246 if(vista_plus)
1248 verify_msgs_in(sequences[LISTVIEW_SEQ_INDEX], vista_plus_msgs);
1250 else
1252 count = get_msg_count(sequences, LISTVIEW_SEQ_INDEX, LVM_SETVIEW);
1253 ok(count == 1, "LVM_SETVIEW sent %d times.\n", count);
1254 count = get_msg_count(sequences, LISTVIEW_SEQ_INDEX, LVM_SETEXTENDEDLISTVIEWSTYLE);
1255 ok(count == 2, "LVM_SETEXTENDEDLISTVIEWSTYLE sent %d times.\n", count);
1256 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1260 hr = IFolderView_SetCurrentViewMode(fview, 8);
1261 ok(hr == S_OK || broken(hr == E_INVALIDARG /* Vista */), "got 0x%08lx\n", hr);
1262 todo_wine
1264 if(vista_plus)
1266 verify_msgs_in(sequences[LISTVIEW_SEQ_INDEX], vista_plus_msgs);
1268 else
1270 count = get_msg_count(sequences, LISTVIEW_SEQ_INDEX, LVM_SETVIEW);
1271 ok(count == 1, "LVM_SETVIEW sent %d times.\n", count);
1272 count = get_msg_count(sequences, LISTVIEW_SEQ_INDEX, LVM_SETEXTENDEDLISTVIEWSTYLE);
1273 ok(count == 2, "LVM_SETEXTENDEDLISTVIEWSTYLE sent %d times.\n", count);
1274 flush_sequences(sequences, NUM_MSG_SEQUENCES);
1278 hr = IFolderView_GetCurrentViewMode(fview, &viewmode);
1279 ok(hr == S_OK, "Failed to get current viewmode.\n");
1280 ok_sequence(sequences, LISTVIEW_SEQ_INDEX, empty_seq,
1281 "IFolderView::GetCurrentViewMode", FALSE);
1284 IFolderView_Release(fview);
1286 else
1288 skip("No IFolderView for the desktop folder.\n");
1291 IShellBrowser_Release(browser);
1292 IShellView_DestroyViewWindow(sview);
1293 IShellView_Release(sview);
1294 IShellFolder_Release(desktop);
1297 static void test_IOleCommandTarget(void)
1299 IShellFolder *psf_desktop;
1300 IShellView *psv;
1301 IOleCommandTarget *poct;
1302 HRESULT hr;
1304 hr = SHGetDesktopFolder(&psf_desktop);
1305 ok(hr == S_OK, "got (0x%08lx)\n", hr);
1307 hr = IShellFolder_CreateViewObject(psf_desktop, NULL, &IID_IShellView, (void**)&psv);
1308 ok(hr == S_OK, "got (0x%08lx)\n", hr);
1309 if(SUCCEEDED(hr))
1311 hr = IShellView_QueryInterface(psv, &IID_IOleCommandTarget, (void**)&poct);
1312 ok(hr == S_OK || broken(hr == E_NOINTERFACE) /* Win95/NT4 */, "Got 0x%08lx\n", hr);
1313 if(SUCCEEDED(hr))
1315 OLECMD oc;
1317 hr = IOleCommandTarget_QueryStatus(poct, NULL, 0, NULL, NULL);
1318 ok(hr == E_INVALIDARG, "Got 0x%08lx\n", hr);
1320 oc.cmdID = 1;
1321 hr = IOleCommandTarget_QueryStatus(poct, NULL, 0, &oc, NULL);
1322 ok(hr == OLECMDERR_E_UNKNOWNGROUP, "Got 0x%08lx\n", hr);
1324 oc.cmdID = 1;
1325 hr = IOleCommandTarget_QueryStatus(poct, NULL, 1, &oc, NULL);
1326 ok(hr == OLECMDERR_E_UNKNOWNGROUP, "Got 0x%08lx\n", hr);
1328 hr = IOleCommandTarget_Exec(poct, NULL, 0, 0, NULL, NULL);
1329 ok(hr == OLECMDERR_E_UNKNOWNGROUP, "Got 0x%08lx\n", hr);
1331 IOleCommandTarget_Release(poct);
1334 IShellView_Release(psv);
1337 IShellFolder_Release(psf_desktop);
1340 static void test_SHCreateShellFolderView(void)
1342 IShellFolder *desktop;
1343 IShellView *psv;
1344 SFV_CREATE sfvc;
1345 ULONG refCount;
1346 IUnknown *unk;
1347 HRESULT hr;
1349 hr = SHGetDesktopFolder(&desktop);
1350 ok(hr == S_OK, "got (0x%08lx)\n", hr);
1352 if (0)
1354 /* crash on win7 */
1355 SHCreateShellFolderView(NULL, NULL);
1358 psv = (void *)0xdeadbeef;
1359 hr = SHCreateShellFolderView(NULL, &psv);
1360 ok(hr == E_INVALIDARG, "Got 0x%08lx\n", hr);
1361 ok(psv == NULL, "psv = %p\n", psv);
1363 memset(&sfvc, 0, sizeof(sfvc));
1364 psv = (void *)0xdeadbeef;
1365 hr = SHCreateShellFolderView(&sfvc, &psv);
1366 ok(hr == E_INVALIDARG, "Got 0x%08lx\n", hr);
1367 ok(psv == NULL, "psv = %p\n", psv);
1369 memset(&sfvc, 0, sizeof(sfvc));
1370 sfvc.cbSize = sizeof(sfvc) - 1;
1371 psv = (void *)0xdeadbeef;
1372 hr = SHCreateShellFolderView(&sfvc, &psv);
1373 ok(hr == E_INVALIDARG, "Got 0x%08lx\n", hr);
1374 ok(psv == NULL, "psv = %p\n", psv);
1376 memset(&sfvc, 0, sizeof(sfvc));
1377 sfvc.cbSize = sizeof(sfvc) + 1;
1378 psv = (void *)0xdeadbeef;
1379 hr = SHCreateShellFolderView(&sfvc, &psv);
1380 ok(hr == E_INVALIDARG, "Got 0x%08lx\n", hr);
1381 ok(psv == NULL, "psv = %p\n", psv);
1383 if (0)
1385 /* Crashes on NULL 'pshf' on XP/2k3 */
1386 memset(&sfvc, 0, sizeof(sfvc));
1387 sfvc.cbSize = sizeof(sfvc);
1388 psv = (void *)0xdeadbeef;
1389 hr = SHCreateShellFolderView(&sfvc, &psv);
1390 ok(hr == E_UNEXPECTED, "Got 0x%08lx\n", hr);
1391 ok(psv == NULL, "psv = %p\n", psv);
1393 memset(&sfvc, 0, sizeof(sfvc));
1394 sfvc.cbSize = sizeof(sfvc) - 1;
1395 sfvc.pshf = desktop;
1396 psv = (void *)0xdeadbeef;
1397 hr = SHCreateShellFolderView(&sfvc, &psv);
1398 ok(hr == E_INVALIDARG, "Got 0x%08lx\n", hr);
1399 ok(psv == NULL, "psv = %p\n", psv);
1401 memset(&sfvc, 0, sizeof(sfvc));
1402 sfvc.cbSize = sizeof(sfvc);
1403 sfvc.pshf = desktop;
1404 psv = NULL;
1405 hr = SHCreateShellFolderView(&sfvc, &psv);
1406 ok(hr == S_OK, "Got 0x%08lx\n", hr);
1407 ok(psv != NULL, "psv = %p\n", psv);
1409 hr = IShellView_QueryInterface(psv, &IID_CDefView, (void **)&unk);
1410 ok(hr == S_OK, "got (0x%08lx)\n", hr);
1411 ok(unk == (IUnknown *)psv, "got %p\n", unk);
1412 IUnknown_Release(unk);
1414 refCount = IShellView_Release(psv);
1415 ok(refCount == 0, "refCount = %lu\n", refCount);
1417 IShellFolder_Release(desktop);
1420 static void test_SHCreateShellFolderViewEx(void)
1422 IShellFolder *desktop;
1423 IShellView *psv;
1424 ULONG refCount;
1425 IUnknown *unk;
1426 HRESULT hr;
1427 CSFV csfv;
1429 hr = SHGetDesktopFolder(&desktop);
1430 ok(hr == S_OK, "got (0x%08lx)\n", hr);
1432 if (0)
1434 /* crash on win7 */
1435 SHCreateShellFolderViewEx(NULL, NULL);
1436 SHCreateShellFolderViewEx(NULL, &psv);
1437 SHCreateShellFolderViewEx(&csfv, NULL);
1440 memset(&csfv, 0, sizeof(csfv));
1441 csfv.pshf = desktop;
1442 psv = NULL;
1443 hr = SHCreateShellFolderViewEx(&csfv, &psv);
1444 ok(hr == S_OK, "Got 0x%08lx\n", hr);
1445 ok(psv != NULL, "psv = %p\n", psv);
1447 hr = IShellView_QueryInterface(psv, &IID_CDefView, (void **)&unk);
1448 ok(hr == S_OK, "got (0x%08lx)\n", hr);
1449 ok(unk == (IUnknown *)psv, "got %p\n", unk);
1450 IUnknown_Release(unk);
1452 refCount = IShellView_Release(psv);
1453 ok(refCount == 0, "refCount = %lu\n", refCount);
1455 if (0)
1457 /* Crashes on null shellfolder, on XP/2k3 */
1458 memset(&csfv, 0, sizeof(csfv));
1459 csfv.pshf = NULL;
1460 psv = (void *)0xdeadbeef;
1461 hr = SHCreateShellFolderViewEx(&csfv, &psv);
1462 ok(hr == E_UNEXPECTED, "Got 0x%08lx\n", hr);
1463 ok(psv == NULL, "psv = %p\n", psv);
1465 memset(&csfv, 0, sizeof(csfv));
1466 csfv.cbSize = sizeof(csfv);
1467 csfv.pshf = desktop;
1468 psv = NULL;
1469 hr = SHCreateShellFolderViewEx(&csfv, &psv);
1470 ok(hr == S_OK, "Got 0x%08lx\n", hr);
1471 ok(psv != NULL, "psv = %p\n", psv);
1472 if (psv)
1474 refCount = IShellView_Release(psv);
1475 ok(refCount == 0, "refCount = %lu\n", refCount);
1478 IShellFolder_Release(desktop);
1481 static void test_newmenu(void)
1483 IUnknown *unk, *unk2;
1484 HRESULT hr;
1486 hr = CoCreateInstance(&CLSID_NewMenu, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&unk);
1487 todo_wine
1488 ok(hr == S_OK, "Failed to create NewMenu object, hr %#lx.\n", hr);
1489 if (hr != S_OK)
1491 skip("NewMenu is not supported.\n");
1492 return;
1495 hr = IUnknown_QueryInterface(unk, &IID_IShellExtInit, (void **)&unk2);
1496 ok(hr == S_OK, "Failed to get IShellExtInit, hr %#lx.\n", hr);
1497 IUnknown_Release(unk2);
1499 hr = IUnknown_QueryInterface(unk, &IID_IContextMenu3, (void **)&unk2);
1500 ok(hr == S_OK, "Failed to get IContextMenu3, hr %#lx.\n", hr);
1501 IUnknown_Release(unk2);
1503 hr = IUnknown_QueryInterface(unk, &IID_IObjectWithSite, (void **)&unk2);
1504 ok(hr == S_OK, "Failed to get IObjectWithSite, hr %#lx.\n", hr);
1505 IUnknown_Release(unk2);
1507 IUnknown_Release(unk);
1510 START_TEST(shlview)
1512 OleInitialize(NULL);
1514 init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1516 test_CreateViewWindow();
1517 test_IFolderView();
1518 test_GetItemObject();
1519 test_IShellFolderView();
1520 test_IOleWindow();
1521 test_GetSetCurrentViewMode();
1522 test_IOleCommandTarget();
1523 test_SHCreateShellFolderView();
1524 test_SHCreateShellFolderViewEx();
1525 test_newmenu();
1527 OleUninitialize();