ReactOS 0.4.16-dev-816-g135a9a9
ItemIDList.cpp File Reference
#include "shelltest.h"
#include <shellutils.h>
Include dependency graph for ItemIDList.cpp:

Go to the source code of this file.

Classes

struct  FS95
 

Macros

#define TEST_CLSID(pidl, type, offset, clsid)
 

Enumerations

enum  { DIRBIT = 1 , FILEBIT = 2 , PT_COMPUTER_REGITEM = 0x2E }
 

Functions

static BYTE GetPIDLType (LPCITEMIDLIST pidl)
 
static int FileStruct_Att (LPCITEMIDLIST pidl)
 
 START_TEST (SHSimpleIDListFromPath)
 
 START_TEST (ILCreateFromPath)
 
 START_TEST (PIDL)
 
 START_TEST (ILIsEqual)
 

Macro Definition Documentation

◆ TEST_CLSID

#define TEST_CLSID (   pidl,
  type,
  offset,
  clsid 
)
Value:
do { \
ok_long(GetPIDLType(pidl), (type)); \
ok_int(*(CLSID*)((&pidl->mkid.abID[(offset) - sizeof(WORD)])) == clsid, TRUE); \
} while (0)
static BYTE GetPIDLType(LPCITEMIDLIST pidl)
Definition: ItemIDList.cpp:17
#define TRUE
Definition: types.h:120
unsigned short WORD
Definition: ntddk_ex.h:93
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLintptr offset
Definition: glext.h:5920
REFCLSID clsid
Definition: msctf.c:82

Definition at line 51 of file ItemIDList.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
DIRBIT 
FILEBIT 
PT_COMPUTER_REGITEM 

Definition at line 12 of file ItemIDList.cpp.

12 {
13 DIRBIT = 1, FILEBIT = 2,
15};
@ FILEBIT
Definition: ItemIDList.cpp:13
@ PT_COMPUTER_REGITEM
Definition: ItemIDList.cpp:14
@ DIRBIT
Definition: ItemIDList.cpp:13

Function Documentation

◆ FileStruct_Att()

static int FileStruct_Att ( LPCITEMIDLIST  pidl)
static

Definition at line 44 of file ItemIDList.cpp.

45{
46 C_ASSERT(FIELD_OFFSET(FS95, att) == 12);
47 FS95 *p = FS95::Validate(pidl);
48 return p ? p->att : (UINT(1) << 31);
49}
GLfloat GLfloat p
Definition: glext.h:8902
#define C_ASSERT(e)
Definition: intsafe.h:73
unsigned int UINT
Definition: ndis.h:50
static FS95 * Validate(LPCITEMIDLIST p)
Definition: ItemIDList.cpp:37
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255

Referenced by START_TEST().

◆ GetPIDLType()

static BYTE GetPIDLType ( LPCITEMIDLIST  pidl)
static

Definition at line 17 of file ItemIDList.cpp.

18{
19 // Return the type without the 0x80 flag
20 return pidl && pidl->mkid.cb >= 3 ? (pidl->mkid.abID[0] & 0x7F) : 0;
21}

◆ START_TEST() [1/4]

START_TEST ( ILCreateFromPath  )

Definition at line 159 of file ItemIDList.cpp.

160{
163
164 ok_ptr(ILCreateFromPathW(L"c:\\IDontExist"), NULL);
165
167 CComHeapPtr<ITEMIDLIST> pidlDir(ILCreateFromPathW(szPath));
168 if (szPath[1] != ':' || PathFindFileNameW(szPath) <= szPath)
169 {
170 skip("Not a local directory %ls\n", szPath);
171 }
172 else if (!(LPITEMIDLIST)pidlDir)
173 {
174 skip("?\n");
175 }
176 else
177 {
178 item = ILFindLastID(pidlDir);
179 ok_long(item->mkid.abID[0] & 0x73, 0x30 | DIRBIT);
180 ok_int(*(UINT*)(&item->mkid.abID[2]), 0); // No size
181 }
182 PathAppendW(szPath, L"kernel32.dll");
183 CComHeapPtr<ITEMIDLIST> pidlFile(ILCreateFromPathW(szPath));
184 if (!(LPITEMIDLIST)pidlFile)
185 {
186 skip("?\n");
187 }
188 else
189 {
190 item = ILFindLastID(pidlFile);
191 ok_long(item->mkid.abID[0] & 0x73, 0x30 | FILEBIT);
192 ok_int(*(UINT*)(&item->mkid.abID[2]) > 1024 * 42, TRUE); // At least this large
193 }
194}
#define ok_long(expression, result)
Definition: atltest.h:133
#define skip(...)
Definition: atltest.h:64
#define ok_int(expression, result)
Definition: atltest.h:134
#define ok_ptr(expression, result)
Definition: atltest.h:108
#define NULL
Definition: types.h:112
#define MAX_PATH
Definition: compat.h:34
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2313
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:394
LPCWSTR szPath
Definition: env.c:37
static ATOM item
Definition: dde.c:856
#define L(x)
Definition: ntvdm.h:50
#define PathAppendW
Definition: pathcch.h:309
LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
Definition: pidl.c:198
LPITEMIDLIST WINAPI ILCreateFromPathW(LPCWSTR path)
Definition: pidl.c:1101
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define _countof(array)
Definition: sndvol32.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ START_TEST() [2/4]

START_TEST ( ILIsEqual  )

Definition at line 215 of file ItemIDList.cpp.

216{
217 LPITEMIDLIST p1, p2, pidl;
218
219 p1 = p2 = NULL;
220 ok_int(ILIsEqual(p1, p2), TRUE);
221
222 ITEMIDLIST emptyitem = {}, emptyitem2 = {};
223 ok_int(ILIsEqual(&emptyitem, &emptyitem2), TRUE);
224
225 ok_int(ILIsEqual(NULL, &emptyitem), FALSE); // These two are not equal for some reason
226
229 if (p1 && p2)
230 {
231 ok_int(ILIsEqual(p1, p2), TRUE);
232 p1->mkid.abID[0] = PT_COMPUTER_REGITEM; // RegItem in wrong parent
233 ok_int(ILIsEqual(p1, p2), FALSE);
234 }
235 else
236 {
237 skip("Unable to initialize test\n");
238 }
239 ILFree(p1);
240 ILFree(p2);
241
242 // ILIsParent must compare like ILIsEqual
243 p1 = SHSimpleIDListFromPath(L"c:\\");
244 p2 = SHSimpleIDListFromPath(L"c:\\dir\\file");
245 if (p1 && p2)
246 {
247 ok_int(ILIsParent(NULL, p1, FALSE), FALSE); // NULL is always false
248 ok_int(ILIsParent(p1, NULL, FALSE), FALSE); // NULL is always false
249 ok_int(ILIsParent(NULL, NULL, FALSE), FALSE); // NULL is always false
250 ok_int(ILIsParent(p1, p1, FALSE), TRUE); // I'm my own parent
251 ok_int(ILIsParent(p1, p1, TRUE), FALSE); // Self is not immediate
252 ok_int(ILIsParent(p1, p2, FALSE), TRUE); // Grandchild
253 ok_int(ILIsParent(p1, p2, TRUE), FALSE); // Grandchild is not immediate
254 ok_ptr(ILFindChild(p1, p2), ILGetNext(ILGetNext(p2))); // Child is "dir\\file", skip MyComputer and C:
255 ok_int(ILIsEmpty(pidl = ILFindChild(p1, p1)) && pidl, TRUE); // Self
256 ILRemoveLastID(p2);
257 ok_int(ILIsParent(p1, p2, TRUE), TRUE); // Immediate child
258
259 p1->mkid.abID[0] = PT_COMPUTER_REGITEM; // RegItem in wrong parent
260 ok_int(ILIsParent(p1, p2, FALSE), FALSE);
261 }
262 else
263 {
264 skip("Unable to initialize test\n");
265 }
266 ILFree(p1);
267 ILFree(p2);
268}
#define FALSE
Definition: types.h:117
LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner, int nFolder, BOOL fCreate)
Definition: pidl.c:445
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:1044
BOOL WINAPI ILIsParent(LPCITEMIDLIST pidlParent, LPCITEMIDLIST pidlChild, BOOL bImmediate)
Definition: pidl.c:697
BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
Definition: pidl.c:221
LPITEMIDLIST WINAPI ILGetNext(LPCITEMIDLIST pidl)
Definition: pidl.c:970
PUIDLIST_RELATIVE WINAPI ILFindChild(PIDLIST_ABSOLUTE pidl1, PCIDLIST_ABSOLUTE pidl2)
Definition: pidl.c:750
BOOL WINAPI ILIsEqual(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:582
static BOOL ILIsEmpty(_In_opt_ PCUIDLIST_RELATIVE pidl)
Definition: shlobj.h:2519
PIDLIST_ABSOLUTE WINAPI SHSimpleIDListFromPath(PCWSTR)
#define CSIDL_DRIVES
Definition: shlobj.h:2189

◆ START_TEST() [3/4]

START_TEST ( PIDL  )

Definition at line 196 of file ItemIDList.cpp.

197{
198 LPITEMIDLIST pidl;
199
201 if (pidl)
202 TEST_CLSID(ILFindLastID(pidl), 0x1f, 4, CLSID_MyComputer);
203 else
204 skip("?\n");
205 ILFree(pidl);
206
208 if (pidl)
209 TEST_CLSID(ILFindLastID(pidl), 0x71, 14, CLSID_Printers);
210 else
211 skip("?\n");
212 ILFree(pidl);
213}
#define TEST_CLSID(pidl, type, offset, clsid)
Definition: ItemIDList.cpp:51
#define CSIDL_PRINTERS
Definition: shlobj.h:2177

◆ START_TEST() [4/4]

START_TEST ( SHSimpleIDListFromPath  )

Definition at line 57 of file ItemIDList.cpp.

58{
59 HRESULT hr;
62
63 // We compare pidl1 and pidl2
64 CComHeapPtr<ITEMIDLIST> pidl1(SHSimpleIDListFromPath(szPath));
65 CComHeapPtr<ITEMIDLIST> pidl2(ILCreateFromPathW(szPath));
66
67 // Yes, they are equal logically
68 LPITEMIDLIST pidl1Last = ILFindLastID(pidl1), pidl2Last = ILFindLastID(pidl2);
69 ok_int(ILIsEqual(pidl1, pidl2), TRUE);
70 ok_int(ILIsEqual(pidl1Last, pidl2Last), TRUE);
71
72 // Bind to parent
73 CComPtr<IShellFolder> psf1, psf2;
75 ok_long(hr, S_OK);
77 ok_long(hr, S_OK);
78
79 // Get attributes
80 DWORD attrs1 = SFGAO_FOLDER, attrs2 = SFGAO_FOLDER;
81 hr = (psf1 ? psf1->GetAttributesOf(1, &pidl1Last, &attrs1) : E_UNEXPECTED);
82 ok_long(hr, S_OK);
83 hr = (psf2 ? psf2->GetAttributesOf(1, &pidl2Last, &attrs2) : E_UNEXPECTED);
84 ok_long(hr, S_OK);
85
86 // There is the difference in attributes because SHSimpleIDListFromPath
87 // cannot create PIDLs to folders, only files and drives:
88 ok_long((attrs1 & SFGAO_FOLDER), 0);
89 ok_long((attrs2 & SFGAO_FOLDER), SFGAO_FOLDER);
90
91
92 // Make sure the internal details match Windows NT5+
95 CComHeapPtr<ITEMIDLIST> pidlSys32(SHSimpleIDListFromPath(szPath));
96 if (szPath[1] != ':' || PathFindFileNameW(szPath) <= szPath)
97 {
98 skip("Not a local directory %ls\n", szPath);
99 }
100 else if (!(LPITEMIDLIST)pidlSys32)
101 {
102 skip("?\n");
103 }
104 else
105 {
106 item = ILFindLastID(pidlSys32);
107 ok_long(item->mkid.abID[0] & 0x73, 0x30 | FILEBIT); // This is actually a file PIDL
108 ok_long(FileStruct_Att(item), 0); // Simple PIDL without attributes
109 ok_int(*(UINT*)(&item->mkid.abID[2]), 0); // No size
110
111 ILRemoveLastID(pidlSys32); // Now we should have "c:\Windows"
112 item = ILFindLastID(pidlSys32);
113 ok_long(item->mkid.abID[0] & 0x73, 0x30 | DIRBIT);
114 ok_int(*(UINT*)(&item->mkid.abID[2]), 0); // No size
115 }
116
117 WCHAR drive[4] = { szPath[0], szPath[1], L'\\', L'\0' };
118 CComHeapPtr<ITEMIDLIST> pidlDrive(SHSimpleIDListFromPath(drive));
119 if (drive[1] != ':')
120 {
121 skip("Not a local drive %ls\n", drive);
122 }
123 else if (!(LPITEMIDLIST)pidlDrive)
124 {
125 skip("?\n");
126 }
127 else
128 {
129 item = ILFindLastID(pidlDrive);
130 ok_long(item->mkid.abID[0] & 0x70, 0x20); // Something in My Computer
131 ok_char(item->mkid.abID[1] | 32, drive[0] | 32);
132 }
133
134 CComHeapPtr<ITEMIDLIST> pidlVirt(SHSimpleIDListFromPath(L"x:\\IDontExist"));
135 if (!(LPITEMIDLIST)pidlVirt)
136 {
137 skip("?\n");
138 }
139 else
140 {
141 item = ILFindLastID(pidlVirt);
142 ok_long(item->mkid.abID[0] & 0x73, 0x30 | FILEBIT); // Yes, a file
143 ok_long(FileStruct_Att(item), 0); // Simple PIDL, no attributes
144 ok_int(*(UINT*)(&item->mkid.abID[2]), 0); // No size
145
146 ILRemoveLastID(pidlVirt); // "x:\"
147 item = ILFindLastID(pidlVirt);
148 ok_long(item->mkid.abID[0] & 0x70, 0x20); // Something in My Computer
149 ok_char(item->mkid.abID[1] | 32, 'x' | 32); // x:
150 }
151
152 LPITEMIDLIST pidl;
153 ok_int((pidl = SHSimpleIDListFromPath(L"c:")) != NULL, TRUE);
154 ILFree(pidl);
155 ok_int((pidl = SHSimpleIDListFromPath(L"c:\\")) != NULL, TRUE);
156 ILFree(pidl);
157}
static int FileStruct_Att(LPCITEMIDLIST pidl)
Definition: ItemIDList.cpp:44
#define ok_char(expression, result)
Definition: atltest.h:122
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2352
unsigned long DWORD
Definition: ntddk_ex.h:95
#define S_OK
Definition: intsafe.h:52
HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
Definition: pidl.c:1462
HRESULT hr
Definition: shlfolder.c:183
#define E_UNEXPECTED
Definition: winerror.h:2456
#define IID_PPV_ARG(Itype, ppType)