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 #include <versionhelpers.h>
15
_CreateDummyPidl()16 LPITEMIDLIST _CreateDummyPidl()
17 {
18 /* Create a tiny pidl with no contents */
19 LPITEMIDLIST testpidl = (LPITEMIDLIST)SHAlloc(3 * sizeof(WORD));
20 testpidl->mkid.cb = 2 * sizeof(WORD);
21 *(WORD*)((char*)testpidl + (int)(2 * sizeof(WORD))) = 0;
22
23 return testpidl;
24 }
25
TestUninitialized()26 VOID TestUninitialized()
27 {
28 CComPtr<IShellFolder> psf;
29 CComPtr<IEnumIDList> penum;
30 CComPtr<IDropTarget> pdt;
31 CComPtr<IContextMenu> pcm;
32 CComPtr<IShellView> psv;
33 LPITEMIDLIST retrievedPidl;
34 ULONG pceltFetched;
35 HRESULT hr;
36
37 /* Create a CFSFolder */
38 hr = CoCreateInstance(CLSID_ShellFSFolder, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellFolder, &psf));
39 ok(hr == S_OK, "hr = %lx\n", hr);
40
41 /* An uninitialized CFSFolder doesn't contain any items */
42 hr = psf->EnumObjects(NULL, 0, &penum);
43 ok(hr == S_OK, "hr = %lx\n", hr);
44 hr = penum->Next(0, &retrievedPidl, &pceltFetched);
45 ok(hr == S_FALSE, "hr = %lx\n", hr);
46 hr = penum->Next(1, &retrievedPidl, &pceltFetched);
47 ok(hr == S_FALSE, "hr = %lx\n", hr);
48
49 /* It supports viewing */
50 hr = psf->CreateViewObject(NULL, IID_PPV_ARG(IDropTarget, &pdt));
51 ok(hr == S_OK, "hr = %lx\n", hr);
52 hr = psf->CreateViewObject(NULL, IID_PPV_ARG(IContextMenu, &pcm));
53 ok(hr == S_OK, "hr = %lx\n", hr);
54 hr = psf->CreateViewObject(NULL, IID_PPV_ARG(IShellView, &psv));
55 ok(hr == S_OK, "hr = %lx\n", hr);
56
57 /* And its display name is ... "C:\Documents and Settings\<username>\Desktop" */
58 STRRET strretName;
59 hr = psf->GetDisplayNameOf(NULL,SHGDN_FORPARSING,&strretName);
60 ok(hr == S_OK, "hr = %lx\n", hr);
61 ok(strretName.uType == STRRET_WSTR, "strretName.uType == %x\n", strretName.uType);
62 ok((wcsncmp(strretName.pOleStr, L"C:\\Documents and Settings\\", 26) == 0) ||
63 (wcsncmp(strretName.pOleStr, L"C:\\Users\\", 9) == 0),
64 "wrong name, got: %S\n", strretName.pOleStr);
65 ok(wcscmp(strretName.pOleStr + wcslen(strretName.pOleStr) - 8, L"\\Desktop") == NULL,
66 "wrong name, got: %S\n", strretName.pOleStr);
67
68 hr = psf->GetDisplayNameOf(NULL,SHGDN_FORPARSING|SHGDN_INFOLDER,&strretName);
69 ok(hr == E_INVALIDARG, "hr = %lx\n", hr);
70
71
72
73
74 /* Use Initialize method with a dummy pidl and test the still non initialized CFSFolder */
75 CComPtr<IPersistFolder2> ppf2;
76 hr = psf->QueryInterface(IID_PPV_ARG(IPersistFolder2, &ppf2));
77 ok(hr == S_OK, "hr = %lx\n", hr);
78
79 LPITEMIDLIST testpidl = _CreateDummyPidl();
80
81 hr = ppf2->Initialize(testpidl);
82 ok(hr == S_OK, "hr = %lx\n", hr);
83
84 CComHeapPtr<ITEMIDLIST> pidl;
85 hr = ppf2->GetCurFolder(&pidl);
86 ok(hr == S_OK, "hr = %lx\n", hr);
87 ok(pidl->mkid.cb == 2 * sizeof(WORD), "got wrong pidl size, cb = %x\n", pidl->mkid.cb);
88
89 /* methods that worked before, now fail */
90 hr = psf->GetDisplayNameOf(NULL,SHGDN_FORPARSING,&strretName);
91 ok(hr == (IsWindows7OrGreater() ? E_INVALIDARG : E_FAIL), "hr = %lx\n", hr);
92 hr = psf->EnumObjects(NULL, 0, &penum);
93 ok(hr == (IsWindows7OrGreater() ? E_INVALIDARG : HRESULT_FROM_WIN32(ERROR_CANCELLED)), "hr = %lx\n", hr);
94
95 /* The following continue to work though */
96 hr = psf->CreateViewObject(NULL, IID_PPV_ARG(IDropTarget, &pdt));
97 ok(hr == S_OK, "hr = %lx\n", hr);
98 hr = psf->CreateViewObject(NULL, IID_PPV_ARG(IContextMenu, &pcm));
99 ok(hr == S_OK, "hr = %lx\n", hr);
100 hr = psf->CreateViewObject(NULL, IID_PPV_ARG(IShellView, &psv));
101 ok(hr == S_OK, "hr = %lx\n", hr);
102
103 }
104
TestInitialize()105 VOID TestInitialize()
106 {
107 HRESULT hr;
108 STRRET strretName;
109
110 /* Create a CFSFolder */
111 CComPtr<IShellFolder> psf;
112 hr = CoCreateInstance(CLSID_ShellFSFolder, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellFolder, &psf));
113 ok(hr == S_OK, "hr = %lx\n", hr);
114
115 CComPtr<IPersistFolder3> ppf3;
116 hr = psf->QueryInterface(IID_PPV_ARG(IPersistFolder3, &ppf3));
117 ok(hr == S_OK, "hr = %lx\n", hr);
118
119 LPITEMIDLIST testpidl = _CreateDummyPidl();
120 PERSIST_FOLDER_TARGET_INFO pfti = {0};
121 PERSIST_FOLDER_TARGET_INFO queriedPfti;
122 hr = ppf3->InitializeEx(NULL, NULL, NULL);
123 ok(hr == (IsWindows7OrGreater() ? E_INVALIDARG : E_OUTOFMEMORY), "hr = %lx\n", hr);
124
125 hr = ppf3->InitializeEx(NULL, NULL, &pfti);
126 ok(hr == (IsWindows7OrGreater() ? E_INVALIDARG : E_OUTOFMEMORY), "hr = %lx\n", hr);
127
128 wcscpy(pfti.szTargetParsingName, L"C:\\");
129 hr = ppf3->InitializeEx(NULL, NULL, &pfti);
130 ok(hr == (IsWindows7OrGreater() ? E_INVALIDARG : E_OUTOFMEMORY), "hr = %lx\n", hr);
131
132 hr = ppf3->InitializeEx(NULL, testpidl, NULL);
133 ok(hr == S_OK, "hr = %lx\n", hr);
134
135 hr = ppf3->GetFolderTargetInfo(&queriedPfti);
136 ok(hr == (IsWindows7OrGreater() ? E_FAIL : S_OK), "hr = %lx\n", hr);
137
138 hr = psf->GetDisplayNameOf(NULL,SHGDN_FORPARSING,&strretName);
139 ok(hr == (IsWindows7OrGreater() ? E_INVALIDARG : E_FAIL), "hr = %lx\n", hr);
140
141 pfti.szTargetParsingName[0] = 0;
142 hr = ppf3->InitializeEx(NULL, testpidl, &pfti);
143 ok(hr == S_OK, "hr = %lx\n", hr);
144
145 hr = ppf3->GetFolderTargetInfo(&queriedPfti);
146 ok(hr == S_OK, "hr = %lx\n", hr);
147 ok(wcscmp(queriedPfti.szTargetParsingName, L"") == 0, "wrong name, got: %S\n", queriedPfti.szTargetParsingName);
148
149 hr = psf->GetDisplayNameOf(NULL,SHGDN_FORPARSING,&strretName);
150 ok(hr == (IsWindows7OrGreater() ? E_INVALIDARG : E_FAIL), "hr = %lx\n", hr);
151
152 wcscpy(pfti.szTargetParsingName, L"C:\\");
153 hr = ppf3->InitializeEx(NULL, testpidl, &pfti);
154 ok(hr == S_OK, "hr = %lx\n", hr);
155
156 hr = ppf3->GetFolderTargetInfo(&queriedPfti);
157 ok(hr == S_OK, "hr = %lx\n", hr);
158 ok(wcscmp(queriedPfti.szTargetParsingName, L"C:\\") == 0, "wrong name, got: %S\n", queriedPfti.szTargetParsingName);
159
160 hr = psf->GetDisplayNameOf(NULL,SHGDN_FORPARSING,&strretName);
161 ok(hr == S_OK, "hr = %lx\n", hr);
162 ok(strretName.uType == STRRET_WSTR, "strretName.uType == %x\n", strretName.uType);
163 ok(wcscmp(strretName.pOleStr, L"C:\\") == 0, "wrong name, got: %S\n", strretName.pOleStr);
164 }
165
TestGetUIObjectOf()166 VOID TestGetUIObjectOf()
167 {
168 HRESULT hr;
169
170 /* Create a CFSFolder */
171 CComPtr<IShellFolder> psf;
172 hr = CoCreateInstance(CLSID_ShellFSFolder, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellFolder, &psf));
173 ok(hr == S_OK, "hr = %lx\n", hr);
174
175 /* test 0 cidl for IDataObject */
176 CComPtr<IDataObject> pdo;
177 hr = psf->GetUIObjectOf(NULL, 0, NULL, IID_NULL_PPV_ARG(IDataObject, &pdo));
178 ok(hr == E_INVALIDARG, "hr = %lx\n", hr);
179 }
180
START_TEST(CFSFolder)181 START_TEST(CFSFolder)
182 {
183 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
184
185 TestUninitialized();
186 TestInitialize();
187 TestGetUIObjectOf();
188 }
189