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