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