Removed W->A from DEFWND_ImmIsUIMessageW.
[wine] / dlls / shell32 / tests / shlfolder.c
1 /*
2  * Unit test of the IShellFolder functions.
3  *
4  * Copyright 2004 Vitaliy Margolen
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wtypes.h"
29 #include "shellapi.h"
30
31
32 #include "shlguid.h"
33 #include "shlobj.h"
34 #include "shobjidl.h"
35
36
37 #include "wine/unicode.h"
38 #include "wine/test.h"
39
40
41 IMalloc *ppM;
42
43 /* creates a file with the specified name for tests */
44 void CreateTestFile(CHAR *name)
45 {
46     HANDLE file;
47     DWORD written;
48
49     file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
50     if (file != INVALID_HANDLE_VALUE)
51     {
52         WriteFile(file, name, strlen(name), &written, NULL);
53         WriteFile(file, "\n", strlen("\n"), &written, NULL);
54         CloseHandle(file);
55     }
56 }
57
58
59 /* initializes the tests */
60 void CreateFilesFolders(void)
61 {
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 }
69
70 /* cleans after tests */
71 void Cleanup(void)
72 {
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");
79 }
80
81
82 /* perform test */
83 void test_EnumObjects(IShellFolder *iFolder)
84 {
85     IEnumIDList *iEnumList;
86     ITEMIDLIST *newPIDL, *(idlArr [5]);
87     ULONG NumPIDLs;
88     int i=0, j;
89     HRESULT nResult;
90
91     static const WORD iResults [5][5] =
92     {
93         { 0,-1,-1,-1,-1},
94         { 1, 0,-1,-1,-1},
95         { 1, 1, 0,-1,-1},
96         { 1, 1, 1, 0,-1},
97         { 1, 1, 1, 1, 0}
98     };
99
100     if SUCCEEDED(IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList))
101     {
102         while (IEnumIDList_Next(iEnumList, 1, &newPIDL, &NumPIDLs) == S_OK)
103         {
104             idlArr[i++] = newPIDL;
105         }
106         /* This fails on windows */
107         /* IEnumIDList_Release(iEnumList); */
108     
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)
112             {
113                 newPIDL = idlArr[i];
114                 idlArr[i] = idlArr[j];
115                 idlArr[j] = newPIDL;
116             }
117             
118         for (i=0;i<5;i++) for (j=0;j<5;j++)
119         {
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]);
122         }
123
124         for (i=0;i<5;i++)
125             IMalloc_Free(ppM, idlArr[i]);
126     }
127 }
128
129 START_TEST(shlfolder)
130 {
131     ITEMIDLIST *newPIDL;
132     IShellFolder *IDesktopFolder, *testIShellFolder;
133     WCHAR cCurrDirW [MAX_PATH];
134     static const WCHAR cTestDirW[] = {'\\','t','e','s','t','d','i','r',0};
135
136     
137     GetCurrentDirectoryW(MAX_PATH, cCurrDirW);
138     strcatW(cCurrDirW, cTestDirW);
139
140     
141     if(!SUCCEEDED(SHGetMalloc(&ppM)))
142         return;
143
144     CreateFilesFolders();
145     
146     if(!SUCCEEDED(SHGetDesktopFolder(&IDesktopFolder)))
147         return;
148
149     if (SUCCEEDED(IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0)))
150     {
151         if (SUCCEEDED(IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder)))
152         {
153             test_EnumObjects(testIShellFolder);
154             
155             /* This fails on windows */
156             /* IShellFolder_Release(newIShellFolder); */
157
158             IMalloc_Free(ppM, newPIDL);
159         }
160     }
161
162     Cleanup();
163 }