ReactOS  0.4.15-dev-1207-g698a8e6
EnumParentDir.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: Test the result of enumerating over a folder with a zip in it
5  * COPYRIGHT: Copyright 2020 Mark Jansen (mark.jansen@reactos.org)
6  */
7 
8 #include "precomp.h"
9 
10 struct FileInfo
11 {
14  bool Found;
15 };
16 
18 {
19  return GetModuleHandleA("zipfldr.dll") ? TRUE : FALSE;
20 }
21 
22 void FindExpectedFile(FileInfo* Array, size_t len, IShellFolder* pFolder, PCUITEMID_CHILD pidl, LPCWSTR& ExpectedName, SFGAOF& ExpectedAttributes)
23 {
24  ExpectedName = L"<WRONG FILE>";
25  ExpectedAttributes = (SFGAOF)~0;
26 
27  STRRET NameRet;
28  HRESULT hr;
29 
30  hr = pFolder->GetDisplayNameOf(pidl, SHGDN_NORMAL, &NameRet);
31  ok_hr(hr, S_OK);
32  if (!SUCCEEDED(hr))
33  return;
34 
35  WCHAR DisplayName[MAX_PATH];
36  hr = StrRetToBufW(&NameRet, pidl, DisplayName, RTL_NUMBER_OF(DisplayName));
37  ok_hr(hr, S_OK);
38  if (!SUCCEEDED(hr))
39  return;
40 
41  for (size_t n = 0; n < len; ++n)
42  {
43  if (!wcsicmp(Array[n].Name, DisplayName) && !Array[n].Found)
44  {
45  Array[n].Found = true;
46  ExpectedName = Array[n].Name;
47  ExpectedAttributes = Array[n].Attributes;
48  return;
49  }
50  }
51 }
52 
53 static void test_EnumDirFiles(const WCHAR* TestFolder)
54 {
55  CComPtr<IShellFolder> spFolder;
56  if (!InitializeShellFolder(TestFolder, spFolder))
57  return;
58 
59  CComPtr<IEnumIDList> spEnum;
61  HRESULT hr = spFolder->EnumObjects(NULL, SHCONTF_NONFOLDERS, &spEnum);
62  ok_hr(hr, S_OK);
63  if (!SUCCEEDED(hr))
64  return;
66 
67  SFGAOF BaseAttributes = SFGAO_FILESYSTEM;
68  FileInfo ExpectedFiles[] = {
69  { L"test.txt", BaseAttributes, false },
70  };
71 
72  ULONG totalFetched = 0;
73  do
74  {
75  CComHeapPtr<ITEMID_CHILD> child;
76  ULONG celtFetched = 0;
77  hr = spEnum->Next(1, &child, &celtFetched);
78  if (hr != S_OK)
79  break;
80  ok_int(celtFetched, 1);
81  if (celtFetched != 1)
82  break;
83 
84  LPCWSTR ExpectedName;
85  SFGAOF ExpectedAttributes;
86  FindExpectedFile(ExpectedFiles, RTL_NUMBER_OF(ExpectedFiles), spFolder, child, ExpectedName, ExpectedAttributes);
87 
88  totalFetched++;
89 
90  ok_displayname(spFolder, child, SHGDN_NORMAL, ExpectedName);
91 
92  SFGAOF Attributes = SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
93  hr = spFolder->GetAttributesOf(1, &child, &Attributes);
94  /* Just keep the ones we are interested in */
95  Attributes &= (SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR | SFGAO_STORAGEANCESTOR);
96  ok_hr(hr, S_OK);
97  ok_hex(Attributes, ExpectedAttributes);
98  } while (true);
99 
100  ok_int(totalFetched, RTL_NUMBER_OF(ExpectedFiles));
101  ok_hr(hr, S_FALSE);
103 }
104 
105 static void test_EnumDirDirs(const WCHAR* TestFolder)
106 {
107  CComPtr<IShellFolder> spFolder;
108  if (!InitializeShellFolder(TestFolder, spFolder))
109  return;
110 
111  CComPtr<IEnumIDList> spEnum;
113  HRESULT hr = spFolder->EnumObjects(NULL, SHCONTF_FOLDERS, &spEnum);
114  ok_hr(hr, S_OK);
115  if (!SUCCEEDED(hr))
116  return;
117 
119 
120  SFGAOF BaseAttributes = SFGAO_FILESYSTEM | SFGAO_FOLDER;
121  FileInfo ExpectedFiles[] = {
122  { L"TMP0.zip", BaseAttributes, false},
123  { L"ASUBFLD", BaseAttributes | SFGAO_FILESYSANCESTOR | SFGAO_STORAGEANCESTOR, false },
124  };
125 
126  bool bFoundZipfldr = false;
127 
128  ULONG totalFetched = 0;
129  do
130  {
131  CComHeapPtr<ITEMID_CHILD> child;
132  ULONG celtFetched = 0;
133  ok_int(zipfldr_loaded(), bFoundZipfldr ? TRUE : FALSE);
134  hr = spEnum->Next(1, &child, &celtFetched);
135  if (hr != S_OK)
136  break;
137  ok_int(celtFetched, 1);
138  if (celtFetched != 1)
139  break;
140 
141  ok_int(zipfldr_loaded(), bFoundZipfldr ? TRUE : FALSE);
142 
143  LPCWSTR ExpectedName;
144  SFGAOF ExpectedAttributes;
145  FindExpectedFile(ExpectedFiles, RTL_NUMBER_OF(ExpectedFiles), spFolder, child, ExpectedName, ExpectedAttributes);
146 
147  totalFetched++;
148 
149  ok_displayname(spFolder, child, SHGDN_NORMAL, ExpectedName);
150  trace("Current: %S\n", ExpectedName);
151 
152  SFGAOF Attributes = SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
153  hr = spFolder->GetAttributesOf(1, &child, &Attributes);
154  if ((ExpectedAttributes & SFGAO_FILESYSANCESTOR))
155  {
156  ok_int(zipfldr_loaded(), bFoundZipfldr ? TRUE : FALSE);
157  }
158  else
159  {
161  bFoundZipfldr = true;
162  }
163  /* Just keep the ones we are interested in */
164  Attributes &= (SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR | SFGAO_STORAGEANCESTOR);
165  ok_hr(hr, S_OK);
166  ok_hex(Attributes, ExpectedAttributes);
167  } while (true);
168 
169  ok_int(totalFetched, RTL_NUMBER_OF(ExpectedFiles));
170  ok_hr(hr, S_FALSE);
171 }
172 
173 
174 START_TEST(EnumParentDir)
175 {
177 
178  ok_hr(hr, S_OK);
179  if (!SUCCEEDED(hr))
180  return;
181 
182  WCHAR TestFolder[MAX_PATH], TestFile[MAX_PATH], SubFolder[MAX_PATH];
183  GetTempPathW(_countof(TestFolder), TestFolder);
184  PathAppendW(TestFolder, L"ZipDir");
185  PathAddBackslashW(TestFolder);
186 
187  CreateDirectoryW(TestFolder, NULL);
188 
189  WCHAR ZipTestFile[MAX_PATH];
190  if (!extract_resource(ZipTestFile, MAKEINTRESOURCEW(IDR_ZIP_TEST_FILE), TestFolder))
191  {
192  RemoveDirectoryW(TestFolder);
193  return;
194  }
195 
196  StringCchPrintfW(TestFile, _countof(TestFile), L"%stest.txt", TestFolder);
197 
199 
200  ok(hFile != INVALID_HANDLE_VALUE, "Error creating %S\n", TestFile);
202  {
203  StringCchPrintfW(SubFolder, _countof(SubFolder), L"%sASUBFLD", TestFolder);
204 
205  CreateDirectoryW(SubFolder, NULL);
206 
207  test_EnumDirFiles(TestFolder);
208  test_EnumDirDirs(TestFolder);
209 
210  RemoveDirectoryW(SubFolder);
211 
213  }
214 
215  DeleteFileW(ZipTestFile);
216  RemoveDirectoryW(TestFolder);
217  CoUninitialize();
218 }
#define ok_hr(status, expected)
Definition: ACListISF.cpp:30
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
SFGAOF Attributes
#define CloseHandle
Definition: compat.h:598
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TRUE
Definition: types.h:120
HRESULT WINAPI StrRetToBufW(LPSTRRET src, const ITEMIDLIST *pidl, LPWSTR dest, UINT len)
Definition: string.c:1522
#define ok_displayname(pFolder, pidl, Flags, Name)
Definition: precomp.h:31
static bool extract_resource(const WCHAR *Filename, LPCWSTR ResourceName)
Definition: db.cpp:1460
GLdouble n
Definition: glext.h:7729
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
const ITEMID_CHILD UNALIGNED * PCUITEMID_CHILD
Definition: shtypes.idl:70
static void test_EnumDirFiles(const WCHAR *TestFolder)
#define ok_hex(expression, result)
Definition: atltest.h:94
static HWND child
Definition: cursoricon.c:298
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
Definition: path.c:121
HRESULT GetDisplayNameOf([in] PCUITEMID_CHILD pidl, [in] SHGDNF uFlags, [out] STRRET *lpName)
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2079
#define FALSE
Definition: types.h:117
LPWSTR WINAPI PathAddBackslashW(LPWSTR lpszPath)
Definition: path.c:289
#define GENERIC_WRITE
Definition: nt_native.h:90
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
#define S_FALSE
Definition: winerror.h:2357
smooth NULL
Definition: ftsmooth.c:416
#define ok_int(expression, result)
Definition: atltest.h:134
return Found
Definition: dirsup.c:1270
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
START_TEST(EnumParentDir)
LONG HRESULT
Definition: typedefs.h:79
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
#define FILE_FLAG_DELETE_ON_CLOSE
Definition: disk.h:42
FileAttr Attributes
Definition: DriveVolume.h:58
#define wcsicmp
Definition: compat.h:15
LPCWSTR Name
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
_In_ HANDLE hFile
Definition: mswsock.h:90
wstring Name
Definition: DriveVolume.h:54
#define S_OK
Definition: intsafe.h:51
_Must_inspect_result_ _In_ USHORT _In_ PHIDP_PREPARSED_DATA _Out_writes_to_ LengthAttributes PHIDP_EXTENDED_ATTRIBUTES Attributes
Definition: hidpi.h:348
int zipfldr_loaded()
void FindExpectedFile(FileInfo *Array, size_t len, IShellFolder *pFolder, PCUITEMID_CHILD pidl, LPCWSTR &ExpectedName, SFGAOF &ExpectedAttributes)
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
#define ok(value,...)
Definition: atltest.h:57
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
#define InitializeShellFolder(Filename, pFolder)
Definition: precomp.h:25
#define CreateFileW
Definition: compat.h:600
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
static void test_EnumDirDirs(const WCHAR *TestFolder)
unsigned int ULONG
Definition: retypes.h:1
#define CREATE_NEW
Definition: disk.h:69
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define IDR_ZIP_TEST_FILE
Definition: resource.h:2
static IShellFolder IShellItem **static IBindCtx LPITEMIDLIST SFGAOF
Definition: ebrowser.c:83
#define SUCCEEDED(hr)
Definition: intsafe.h:49