ReactOS 0.4.15-dev-7659-ga55345b
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-2023 Mark Jansen (mark.jansen@reactos.org)
6 */
7
8#include "precomp.h"
9
10struct FileInfo
11{
14 bool Found;
15};
16
18{
19 return GetModuleHandleA("zipfldr.dll") ? TRUE : FALSE;
20}
21
22void 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
53const SFGAOF BaseFileAttributes = SFGAO_FILESYSTEM;
54const SFGAOF BaseFolderAttributes = SFGAO_FILESYSTEM | SFGAO_FOLDER;
56 { L"test.txt", BaseFileAttributes, false },
57 { L"TMP0.zip", BaseFileAttributes, false}, // 2k3 Shows this as a file, newer shows this as a folder
58 { L"ASUBFLD", BaseFolderAttributes | SFGAO_FILESYSANCESTOR | SFGAO_STORAGEANCESTOR, false },
59};
61
62static void
63test_EnumDirFiles(const WCHAR *TestFolder, BOOL EnumFolders)
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}
121
122
123START_TEST(EnumParentDir)
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}
#define ok_hr(status, expected)
Definition: ACListISF.cpp:31
const SFGAOF BaseFolderAttributes
BOOL FoundZipfldr
int zipfldr_loaded()
FileInfo ExpectedFiles[]
const SFGAOF BaseFileAttributes
static void test_EnumDirFiles(const WCHAR *TestFolder, BOOL EnumFolders)
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
#define ok_hex(expression, result)
Definition: atltest.h:94
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
return Found
Definition: dirsup.c:1270
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 MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FILE_SHARE_READ
Definition: compat.h:136
#define wcsicmp
Definition: compat.h:15
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
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
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
HRESULT WINAPI StrRetToBufW(LPSTRRET src, const ITEMIDLIST *pidl, LPWSTR dest, UINT len)
Definition: string.c:1522
static IShellFolder IShellItem **static IBindCtx LPITEMIDLIST SFGAOF
Definition: ebrowser.c:83
unsigned int BOOL
Definition: ntddk_ex.h:94
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 FILE_FLAG_DELETE_ON_CLOSE
Definition: disk.h:42
#define CREATE_NEW
Definition: disk.h:69
#define InitializeShellFolder(Filename, pFolder)
Definition: precomp.h:25
#define ok_displayname(pFolder, pidl, Flags, Name)
Definition: precomp.h:31
#define IDR_ZIP_TEST_FILE
Definition: resource.h:2
static HWND child
Definition: cursoricon.c:298
_In_ HANDLE hFile
Definition: mswsock.h:90
#define GENERIC_WRITE
Definition: nt_native.h:90
#define L(x)
Definition: ntvdm.h:50
#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)
HRESULT hr
Definition: shlfolder.c:183
const ITEMID_CHILD UNALIGNED * PCUITEMID_CHILD
Definition: shtypes.idl:70
#define _countof(array)
Definition: sndvol32.h:68
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
SFGAOF Attributes
LPCWSTR Name
FileAttr Attributes
Definition: DriveVolume.h:58
wstring Name
Definition: DriveVolume.h:54
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
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185