ReactOS 0.4.15-dev-7918-g2a2556c
EnumParentDir.cpp File Reference
#include "precomp.h"
Include dependency graph for EnumParentDir.cpp:

Go to the source code of this file.

Classes

struct  FileInfo
 

Functions

int zipfldr_loaded ()
 
void FindExpectedFile (FileInfo *Array, size_t len, IShellFolder *pFolder, PCUITEMID_CHILD pidl, LPCWSTR &ExpectedName, SFGAOF &ExpectedAttributes)
 
static void test_EnumDirFiles (const WCHAR *TestFolder, BOOL EnumFolders)
 
 START_TEST (EnumParentDir)
 

Variables

const SFGAOF BaseFileAttributes = SFGAO_FILESYSTEM
 
const SFGAOF BaseFolderAttributes = SFGAO_FILESYSTEM | SFGAO_FOLDER
 
FileInfo ExpectedFiles []
 
BOOL FoundZipfldr = FALSE
 

Function Documentation

◆ FindExpectedFile()

void FindExpectedFile ( FileInfo Array,
size_t  len,
IShellFolder pFolder,
PCUITEMID_CHILD  pidl,
LPCWSTR ExpectedName,
SFGAOF ExpectedAttributes 
)

Definition at line 22 of file EnumParentDir.cpp.

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}
#define ok_hr(status, expected)
Definition: ACListISF.cpp:31
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
return Found
Definition: dirsup.c:1270
#define MAX_PATH
Definition: compat.h:34
#define wcsicmp
Definition: compat.h:15
HRESULT WINAPI StrRetToBufW(LPSTRRET src, const ITEMIDLIST *pidl, LPWSTR dest, UINT len)
Definition: string.c:1530
static IShellFolder IShellItem **static IBindCtx LPITEMIDLIST SFGAOF
Definition: ebrowser.c:83
GLdouble n
Definition: glext.h:7729
GLenum GLsizei len
Definition: glext.h:6722
HRESULT GetDisplayNameOf([in] PCUITEMID_CHILD pidl, [in] SHGDNF uFlags, [out] STRRET *lpName)
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define L(x)
Definition: ntvdm.h:50
HRESULT hr
Definition: shlfolder.c:183
FileAttr Attributes
Definition: DriveVolume.h:58
wstring Name
Definition: DriveVolume.h:54
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by test_EnumDirFiles().

◆ START_TEST()

START_TEST ( EnumParentDir  )

Definition at line 123 of file EnumParentDir.cpp.

124{
126
127 ok_hr(hr, S_OK);
128 if (!SUCCEEDED(hr))
129 return;
130
132
133 WCHAR TestFolder[MAX_PATH], TestFile[MAX_PATH], SubFolder[MAX_PATH];
134 GetTempPathW(_countof(TestFolder), TestFolder);
135 PathAppendW(TestFolder, L"ZipDir");
136 PathAddBackslashW(TestFolder);
137
138 CreateDirectoryW(TestFolder, NULL);
139
140 WCHAR ZipTestFile[MAX_PATH];
141 if (!extract_resource(ZipTestFile, MAKEINTRESOURCEW(IDR_ZIP_TEST_FILE), TestFolder))
142 {
143 RemoveDirectoryW(TestFolder);
144 return;
145 }
146
147 StringCchPrintfW(TestFile, _countof(TestFile), L"%stest.txt", TestFolder);
148
150
151 ok(hFile != INVALID_HANDLE_VALUE, "Error creating %S\n", TestFile);
153 {
154 StringCchPrintfW(SubFolder, _countof(SubFolder), L"%sASUBFLD", TestFolder);
155
156 CreateDirectoryW(SubFolder, NULL);
157
158 winetest_push_context("Files");
159 test_EnumDirFiles(TestFolder, FALSE);
161 winetest_push_context("Folders");
162 test_EnumDirFiles(TestFolder, TRUE);
164
165 for (size_t n = 0; n < RTL_NUMBER_OF(ExpectedFiles); ++n)
166 {
167 ok(ExpectedFiles[n].Found, "Did not find %S\n", ExpectedFiles[n].Name);
168 }
169
170 RemoveDirectoryW(SubFolder);
171
173 }
174
175 DeleteFileW(ZipTestFile);
176 RemoveDirectoryW(TestFolder);
178}
int zipfldr_loaded()
FileInfo ExpectedFiles[]
static void test_EnumDirFiles(const WCHAR *TestFolder, BOOL EnumFolders)
#define ok(value,...)
Definition: atltest.h:57
#define ok_int(expression, result)
Definition: atltest.h:134
static bool extract_resource(const WCHAR *Filename, LPCWSTR ResourceName)
Definition: db.cpp:1447
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileW
Definition: compat.h:741
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2080
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
#define FILE_FLAG_DELETE_ON_CLOSE
Definition: disk.h:42
#define CREATE_NEW
Definition: disk.h:69
#define IDR_ZIP_TEST_FILE
Definition: resource.h:2
_In_ HANDLE hFile
Definition: mswsock.h:90
#define GENERIC_WRITE
Definition: nt_native.h:90
#define PathAddBackslashW
Definition: pathcch.h:301
#define PathAppendW
Definition: pathcch.h:309
void __winetest_cdecl winetest_push_context(const char *fmt,...)
void winetest_pop_context(void)
#define _countof(array)
Definition: sndvol32.h:68
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582

◆ test_EnumDirFiles()

static void test_EnumDirFiles ( const WCHAR TestFolder,
BOOL  EnumFolders 
)
static

Definition at line 63 of file EnumParentDir.cpp.

64{
65 CComPtr<IShellFolder> spFolder;
66 if (!InitializeShellFolder(TestFolder, spFolder))
67 return;
68
69 CComPtr<IEnumIDList> spEnum;
71 HRESULT hr = spFolder->EnumObjects(NULL, EnumFolders ? SHCONTF_FOLDERS : SHCONTF_NONFOLDERS, &spEnum);
72 ok_hr(hr, S_OK);
73 if (!SUCCEEDED(hr))
74 return;
76
77 do
78 {
79 CComHeapPtr<ITEMID_CHILD> child;
80 ULONG celtFetched = 0;
82 hr = spEnum->Next(1, &child, &celtFetched);
84 if (hr != S_OK)
85 break;
86 ok_int(celtFetched, 1);
87 if (celtFetched != 1)
88 break;
89
90 LPCWSTR ExpectedName;
91 SFGAOF ExpectedAttributes;
92 FindExpectedFile(ExpectedFiles, RTL_NUMBER_OF(ExpectedFiles), spFolder, child, ExpectedName, ExpectedAttributes);
93
95 ok_displayname(spFolder, child, SHGDN_NORMAL, ExpectedName);
97
98 SFGAOF Attributes = SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
99 hr = spFolder->GetAttributesOf(1, &child, &Attributes);
100
101 if (!wcsicmp(ExpectedName, L"TMP0.zip"))
102 {
103 // We allow both .zip files being a 'file' (2k3) or a 'folder' (win10)
104 if (Attributes & SFGAO_FOLDER)
105 ExpectedAttributes |= SFGAO_FOLDER;
106 // Only at this point (after calling GetAttributesOf) it will load zipfldr
108 trace("Found zip (%S)\n", ExpectedName);
109 }
111
112 /* Just keep the ones we are interested in */
113 Attributes &= (SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR | SFGAO_STORAGEANCESTOR);
114 ok_hr(hr, S_OK);
115 ok_hex(Attributes, ExpectedAttributes);
116 } while (true);
117
118 ok_hr(hr, S_FALSE);
120}
BOOL FoundZipfldr
void FindExpectedFile(FileInfo *Array, size_t len, IShellFolder *pFolder, PCUITEMID_CHILD pidl, LPCWSTR &ExpectedName, SFGAOF &ExpectedAttributes)
#define ok_hex(expression, result)
Definition: atltest.h:94
#define trace
Definition: atltest.h:70
#define InitializeShellFolder(Filename, pFolder)
Definition: precomp.h:25
#define ok_displayname(pFolder, pidl, Flags, Name)
Definition: precomp.h:31
static HWND child
Definition: cursoricon.c:298
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
#define S_FALSE
Definition: winerror.h:2357
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by START_TEST().

◆ zipfldr_loaded()

int zipfldr_loaded ( )

Definition at line 17 of file EnumParentDir.cpp.

18{
19 return GetModuleHandleA("zipfldr.dll") ? TRUE : FALSE;
20}
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812

Referenced by START_TEST(), and test_EnumDirFiles().

Variable Documentation

◆ BaseFileAttributes

const SFGAOF BaseFileAttributes = SFGAO_FILESYSTEM

Definition at line 53 of file EnumParentDir.cpp.

◆ BaseFolderAttributes

const SFGAOF BaseFolderAttributes = SFGAO_FILESYSTEM | SFGAO_FOLDER

Definition at line 54 of file EnumParentDir.cpp.

◆ ExpectedFiles

FileInfo ExpectedFiles[]
Initial value:
= {
{ L"test.txt", BaseFileAttributes, false },
{ L"TMP0.zip", BaseFileAttributes, false},
{ L"ASUBFLD", BaseFolderAttributes | SFGAO_FILESYSANCESTOR | SFGAO_STORAGEANCESTOR, false },
}
const SFGAOF BaseFolderAttributes
const SFGAOF BaseFileAttributes

Definition at line 55 of file EnumParentDir.cpp.

Referenced by START_TEST(), test_EnumDirFiles(), and test_EnumObjects_Files().

◆ FoundZipfldr

BOOL FoundZipfldr = FALSE

Definition at line 60 of file EnumParentDir.cpp.

Referenced by test_EnumDirFiles().