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(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);
70 /* cleans after tests */
73 DeleteFileA(".\\testdir\\test1.txt");
74 DeleteFileA(".\\testdir\\test2.txt");
75 DeleteFileA(".\\testdir\\test3.txt");
76 RemoveDirectoryA(".\\testdir\\test.txt");
77 RemoveDirectoryA(".\\testdir\\testdir2");
78 RemoveDirectoryA(".\\testdir");
83 void test_EnumObjects(IShellFolder *iFolder)
85 IEnumIDList *iEnumList;
86 ITEMIDLIST *newPIDL, *(idlArr [5]);
91 static const WORD iResults [5][5] =
100 if SUCCEEDED(IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList))
102 while (IEnumIDList_Next(iEnumList, 1, &newPIDL, &NumPIDLs) == S_OK)
104 idlArr[i++] = newPIDL;
106 /* This fails on windows */
107 /* IEnumIDList_Release(iEnumList); */
109 /* Sort them first in case of wrong order from system */
110 for (i=0;i<5;i++) for (j=0;j<5;j++)
111 if ((SHORT)IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]) < 0)
114 idlArr[i] = idlArr[j];
118 for (i=0;i<5;i++) for (j=0;j<5;j++)
120 nResult = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
121 ok(nResult == iResults[i][j], "Got %lx expected [%d]-[%d]=%x\n", nResult, i, j, iResults[i][j]);
125 IMalloc_Free(ppM, idlArr[i]);
129 START_TEST(shlfolder)
132 IShellFolder *IDesktopFolder, *testIShellFolder;
133 WCHAR cCurrDirW [MAX_PATH];
134 static const WCHAR cTestDirW[] = {'\\','t','e','s','t','d','i','r',0};
137 GetCurrentDirectoryW(MAX_PATH, cCurrDirW);
138 strcatW(cCurrDirW, cTestDirW);
141 if(!SUCCEEDED(SHGetMalloc(&ppM)))
144 CreateFilesFolders();
146 if(!SUCCEEDED(SHGetDesktopFolder(&IDesktopFolder)))
149 if (SUCCEEDED(IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0)))
151 if (SUCCEEDED(IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder)))
153 test_EnumObjects(testIShellFolder);
155 /* This fails on windows */
156 /* IShellFolder_Release(newIShellFolder); */
158 IMalloc_Free(ppM, newPIDL);