2 * Unit test of the IShellFolder functions.
4 * Copyright 2004 Vitaliy Margolen
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 #include "wine/unicode.h"
38 #include "wine/test.h"
43 /* creates a file with the specified name for tests */
44 void CreateTestFile(const CHAR *name)
49 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
50 if (file != INVALID_HANDLE_VALUE)
52 WriteFile(file, name, strlen(name), &written, NULL);
53 WriteFile(file, "\n", strlen("\n"), &written, NULL);
59 /* initializes the tests */
60 void CreateFilesFolders(void)
62 CreateDirectoryA(".\\testdir", NULL);
63 CreateDirectoryA(".\\testdir\\test.txt", NULL);
64 CreateTestFile (".\\testdir\\test1.txt ");
65 CreateTestFile (".\\testdir\\test2.txt ");
66 CreateTestFile (".\\testdir\\test3.txt ");
67 CreateDirectoryA(".\\testdir\\testdir2 ", NULL);
68 CreateDirectoryA(".\\testdir\\testdir2\\subdir", NULL);
71 /* cleans after tests */
74 DeleteFileA(".\\testdir\\test1.txt");
75 DeleteFileA(".\\testdir\\test2.txt");
76 DeleteFileA(".\\testdir\\test3.txt");
77 RemoveDirectoryA(".\\testdir\\test.txt");
78 RemoveDirectoryA(".\\testdir\\testdir2\\subdir");
79 RemoveDirectoryA(".\\testdir\\testdir2");
80 RemoveDirectoryA(".\\testdir");
85 void test_EnumObjects(IShellFolder *iFolder)
87 IEnumIDList *iEnumList;
88 ITEMIDLIST *newPIDL, *(idlArr [5]);
93 static const WORD iResults [5][5] =
102 /* Just test SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR for now */
103 static const ULONG attrs[5] =
105 SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
106 SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
112 hr = IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
113 ok(hr == S_OK, "EnumObjects failed %08lx\n", hr);
115 while (IEnumIDList_Next(iEnumList, 1, &newPIDL, &NumPIDLs) == S_OK)
117 idlArr[i++] = newPIDL;
120 hr = IEnumIDList_Release(iEnumList);
121 ok(hr == S_OK, "IEnumIDList_Release failed %08lx\n", hr);
123 /* Sort them first in case of wrong order from system */
124 for (i=0;i<5;i++) for (j=0;j<5;j++)
125 if ((SHORT)IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]) < 0)
128 idlArr[i] = idlArr[j];
132 for (i=0;i<5;i++) for (j=0;j<5;j++)
134 hr = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
135 ok(hr == iResults[i][j], "Got %lx expected [%d]-[%d]=%x\n", hr, i, j, iResults[i][j]);
139 for (i = 0; i < 5; i++)
142 flags = SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR;
143 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
144 flags &= SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR;
145 ok(hr == S_OK, "GetAttributesOf returns %08lx\n", hr);
146 ok(flags == attrs[i], "GetAttributesOf gets attrs %08lx, expects %08lx\n", flags, attrs[i]);
150 IMalloc_Free(ppM, idlArr[i]);
154 START_TEST(shlfolder)
157 IShellFolder *IDesktopFolder, *testIShellFolder;
158 WCHAR cCurrDirW [MAX_PATH];
159 static const WCHAR cTestDirW[] = {'\\','t','e','s','t','d','i','r',0};
162 GetCurrentDirectoryW(MAX_PATH, cCurrDirW);
163 strcatW(cCurrDirW, cTestDirW);
167 hr = SHGetMalloc(&ppM);
168 ok(hr == S_OK, "SHGetMalloc failed %08lx\n", hr);
170 CreateFilesFolders();
172 hr = SHGetDesktopFolder(&IDesktopFolder);
173 ok(hr == S_OK, "SHGetDesktopfolder failed %08lx\n", hr);
175 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
176 ok(hr == S_OK, "ParseDisplayName failed %08lx\n", hr);
178 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
179 ok(hr == S_OK, "BindToObject failed %08lx\n", hr);
181 test_EnumObjects(testIShellFolder);
183 hr = IShellFolder_Release(testIShellFolder);
184 ok(hr == S_OK, "IShellFolder_Release failed %08lx\n", hr);
186 IMalloc_Free(ppM, newPIDL);