ReactOS  0.4.14-dev-323-g6fe6a88
CFSFolder.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 CMyComputer
5  * PROGRAMMER: Giannis Adamopoulos
6  */
7 
8 #include "shelltest.h"
9 
10 #define NDEBUG
11 #include <debug.h>
12 #include <stdio.h>
13 #include <shellutils.h>
14 
16 {
17  /* Create a tiny pidl with no contents */
18  LPITEMIDLIST testpidl = (LPITEMIDLIST)SHAlloc(3 * sizeof(WORD));
19  testpidl->mkid.cb = 2 * sizeof(WORD);
20  *(WORD*)((char*)testpidl + (int)(2 * sizeof(WORD))) = 0;
21 
22  return testpidl;
23 }
24 
26 {
27  CComPtr<IShellFolder> psf;
28  CComPtr<IEnumIDList> penum;
29  CComPtr<IDropTarget> pdt;
30  CComPtr<IContextMenu> pcm;
31  CComPtr<IShellView> psv;
32  LPITEMIDLIST retrievedPidl;
33  ULONG pceltFetched;
34  HRESULT hr;
35 
36  /* Create a CFSFolder */
37  hr = CoCreateInstance(CLSID_ShellFSFolder, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellFolder, &psf));
38  ok(hr == S_OK, "hr = %lx\n", hr);
39 
40  /* An uninitialized CFSFolder doesn't contain any items */
41  hr = psf->EnumObjects(NULL, 0, &penum);
42  ok(hr == S_OK, "hr = %lx\n", hr);
43  hr = penum->Next(0, &retrievedPidl, &pceltFetched);
44  ok(hr == S_FALSE, "hr = %lx\n", hr);
45  hr = penum->Next(1, &retrievedPidl, &pceltFetched);
46  ok(hr == S_FALSE, "hr = %lx\n", hr);
47 
48  /* It supports viewing */
49  hr = psf->CreateViewObject(NULL, IID_PPV_ARG(IDropTarget, &pdt));
50  ok(hr == S_OK, "hr = %lx\n", hr);
51  hr = psf->CreateViewObject(NULL, IID_PPV_ARG(IContextMenu, &pcm));
52  ok(hr == S_OK, "hr = %lx\n", hr);
53  hr = psf->CreateViewObject(NULL, IID_PPV_ARG(IShellView, &psv));
54  ok(hr == S_OK, "hr = %lx\n", hr);
55 
56  /* And its display name is ... "C:\Documents and Settings\" */
57  STRRET strretName;
58  hr = psf->GetDisplayNameOf(NULL,SHGDN_FORPARSING,&strretName);
59  ok(hr == S_OK, "hr = %lx\n", hr);
60  ok(strretName.uType == STRRET_WSTR, "strretName.uType == %x\n", strretName.uType);
61  ok(wcscmp(strretName.pOleStr, L"C:\\Documents and Settings\\") == 0, "wrong name, got: %S\n", strretName.pOleStr);
62 
63  hr = psf->GetDisplayNameOf(NULL,SHGDN_FORPARSING|SHGDN_INFOLDER,&strretName);
64  ok(hr == E_INVALIDARG, "hr = %lx\n", hr);
65 
66 
67 
68 
69  /* Use Initialize method with a dummy pidl and test the still non initialized CFSFolder */
70  CComPtr<IPersistFolder2> ppf2;
71  hr = psf->QueryInterface(IID_PPV_ARG(IPersistFolder2, &ppf2));
72  ok(hr == S_OK, "hr = %lx\n", hr);
73 
74  LPITEMIDLIST testpidl = _CreateDummyPidl();
75 
76  hr = ppf2->Initialize(testpidl);
77  ok(hr == S_OK, "hr = %lx\n", hr);
78 
79  CComHeapPtr<ITEMIDLIST> pidl;
80  hr = ppf2->GetCurFolder(&pidl);
81  ok(hr == S_OK, "hr = %lx\n", hr);
82  ok(pidl->mkid.cb == 2 * sizeof(WORD), "got wrong pidl size, cb = %x\n", pidl->mkid.cb);
83 
84  /* methods that worked before, now fail */
85  hr = psf->GetDisplayNameOf(NULL,SHGDN_FORPARSING,&strretName);
86  ok(hr == E_FAIL, "hr = %lx\n", hr);
87  hr = psf->EnumObjects(NULL, 0, &penum);
88  ok(hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "hr = %lx\n", hr);
89 
90  /* The following continue to work though */
91  hr = psf->CreateViewObject(NULL, IID_PPV_ARG(IDropTarget, &pdt));
92  ok(hr == S_OK, "hr = %lx\n", hr);
93  hr = psf->CreateViewObject(NULL, IID_PPV_ARG(IContextMenu, &pcm));
94  ok(hr == S_OK, "hr = %lx\n", hr);
95  hr = psf->CreateViewObject(NULL, IID_PPV_ARG(IShellView, &psv));
96  ok(hr == S_OK, "hr = %lx\n", hr);
97 
98 }
99 
101 {
102  HRESULT hr;
103  STRRET strretName;
104 
105  /* Create a CFSFolder */
106  CComPtr<IShellFolder> psf;
107  hr = CoCreateInstance(CLSID_ShellFSFolder, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellFolder, &psf));
108  ok(hr == S_OK, "hr = %lx\n", hr);
109 
110  CComPtr<IPersistFolder3> ppf3;
111  hr = psf->QueryInterface(IID_PPV_ARG(IPersistFolder3, &ppf3));
112  ok(hr == S_OK, "hr = %lx\n", hr);
113 
114  LPITEMIDLIST testpidl = _CreateDummyPidl();
115  PERSIST_FOLDER_TARGET_INFO pfti = {0};
116  PERSIST_FOLDER_TARGET_INFO queriedPfti;
117  hr = ppf3->InitializeEx(NULL, NULL, NULL);
118  ok(hr == E_INVALIDARG, "hr = %lx\n", hr);
119 
120  hr = ppf3->InitializeEx(NULL, NULL, &pfti);
121  ok(hr == E_INVALIDARG, "hr = %lx\n", hr);
122 
123  wcscpy(pfti.szTargetParsingName, L"C:\\");
124  hr = ppf3->InitializeEx(NULL, NULL, &pfti);
125  ok(hr == E_INVALIDARG, "hr = %lx\n", hr);
126 
127  hr = ppf3->InitializeEx(NULL, testpidl, NULL);
128  ok(hr == S_OK, "hr = %lx\n", hr);
129 
130  hr = ppf3->GetFolderTargetInfo(&queriedPfti);
131  ok(hr == E_FAIL, "hr = %lx\n", hr);
132 
133  hr = psf->GetDisplayNameOf(NULL,SHGDN_FORPARSING,&strretName);
134  ok(hr == E_FAIL, "hr = %lx\n", hr);
135 
136  pfti.szTargetParsingName[0] = 0;
137  hr = ppf3->InitializeEx(NULL, testpidl, &pfti);
138  ok(hr == S_OK, "hr = %lx\n", hr);
139 
140  hr = ppf3->GetFolderTargetInfo(&queriedPfti);
141  ok(hr == S_OK, "hr = %lx\n", hr);
142  ok(wcscmp(queriedPfti.szTargetParsingName, L"") == 0, "wrong name, got: %S\n", queriedPfti.szTargetParsingName);
143 
144  hr = psf->GetDisplayNameOf(NULL,SHGDN_FORPARSING,&strretName);
145  ok(hr == E_FAIL, "hr = %lx\n", hr);
146 
147  wcscpy(pfti.szTargetParsingName, L"C:\\");
148  hr = ppf3->InitializeEx(NULL, testpidl, &pfti);
149  ok(hr == S_OK, "hr = %lx\n", hr);
150 
151  hr = ppf3->GetFolderTargetInfo(&queriedPfti);
152  ok(hr == S_OK, "hr = %lx\n", hr);
153  ok(wcscmp(queriedPfti.szTargetParsingName, L"C:\\") == 0, "wrong name, got: %S\n", queriedPfti.szTargetParsingName);
154 
155  hr = psf->GetDisplayNameOf(NULL,SHGDN_FORPARSING,&strretName);
156  ok(hr == S_OK, "hr = %lx\n", hr);
157  ok(strretName.uType == STRRET_WSTR, "strretName.uType == %x\n", strretName.uType);
158  ok(wcscmp(strretName.pOleStr, L"C:\\") == 0, "wrong name, got: %S\n", strretName.pOleStr);
159 }
160 
162 {
163  HRESULT hr;
164 
165  /* Create a CFSFolder */
166  CComPtr<IShellFolder> psf;
167  hr = CoCreateInstance(CLSID_ShellFSFolder, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellFolder, &psf));
168  ok(hr == S_OK, "hr = %lx\n", hr);
169 
170  /* test 0 cidl for IDataObject */
171  CComPtr<IDataObject> pdo;
172  hr = psf->GetUIObjectOf(NULL, 0, NULL, IID_NULL_PPV_ARG(IDataObject, &pdo));
173  ok(hr == E_INVALIDARG, "hr = %lx\n", hr);
174 }
175 
177 {
179 
181  TestInitialize();
183 }
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
VOID TestInitialize()
Definition: CFSFolder.cpp:100
HRESULT hr
Definition: shlfolder.c:183
VOID TestUninitialized()
Definition: CFSFolder.cpp:25
VOID TestGetUIObjectOf()
Definition: CFSFolder.cpp:161
LPWSTR pOleStr
Definition: shtypes.idl:96
#define IID_PPV_ARG(Itype, ppType)
#define E_FAIL
Definition: ddrawi.h:102
LPITEMIDLIST _CreateDummyPidl()
Definition: CFSFolder.cpp:15
#define S_FALSE
Definition: winerror.h:2357
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
#define IID_NULL_PPV_ARG(Itype, ppType)
LONG HRESULT
Definition: typedefs.h:77
START_TEST(CFSFolder)
Definition: CFSFolder.cpp:176
unsigned short WORD
Definition: ntddk_ex.h:93
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define S_OK
Definition: intsafe.h:59
#define ERROR_CANCELLED
Definition: winerror.h:726
#define ok(value,...)
Definition: atltest.h:57
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:2002
unsigned int ULONG
Definition: retypes.h:1
UINT uType
Definition: shtypes.idl:93
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
LPVOID WINAPI SHAlloc(SIZE_T len)
Definition: shellole.c:309
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31