ReactOS 0.4.17-dev-1321-g5c122a9
CShellItem.cpp File Reference
#include "shelltest.h"
#include <shellutils.h>
#include <ntquery.h>
Include dependency graph for CShellItem.cpp:

Go to the source code of this file.

Macros

#define TestFailedDefVal(method, param, expected)
 

Functions

static IShellItem * CreateItem (PCWSTR pszPath=NULL)
 
static IShellItem2 * CreateItem2 (PCWSTR pszPath=NULL)
 
static void TestInterfaces ()
 
static void TestGetAttributes ()
 
static void TestShellItemPropSys ()
 
 START_TEST (CShellItem)
 

Variables

static const PROPERTYKEY PKEY_DoesNotExist = { { 0x071ED77F,0x6DEE,0x4800,0x94,0xE7,0x1F,0xDD,0x89,0x6B,0x43,0x66 }, 42 }
 
static const PROPERTYKEY PKEY_Size = { PSGUID_STORAGE, PID_STG_SIZE }
 
static const PROPERTYKEY PKEY_DateModified = { PSGUID_STORAGE, PID_STG_WRITETIME }
 

Macro Definition Documentation

◆ TestFailedDefVal

#define TestFailedDefVal (   method,
  param,
  expected 
)
Value:
{ \
pv.uhVal.QuadPart = (expected), pv.ulVal = ~(UINT)(expected); \
hr = pItem->method(PKEY_DoesNotExist, param); \
ok(FAILED(hr) && pv.uhVal.QuadPart == (expected), #method " failure value\n"); \
}
HRESULT hr
Definition: delayimp.cpp:582
method
Definition: dragdrop.c:54
GLfloat param
Definition: glext.h:5796
unsigned int UINT
Definition: sysinfo.c:13
#define FAILED(hr)
Definition: intsafe.h:51
static const PROPERTYKEY PKEY_DoesNotExist
Definition: CShellItem.cpp:12
BOOL expected
Definition: store.c:2000

Function Documentation

◆ CreateItem()

static IShellItem * CreateItem ( PCWSTR  pszPath = NULL)
static

Definition at line 16 of file CShellItem.cpp.

17{
19 if (!pszPath)
20 {
21 pszPath = szPath;
23 }
24
26 HRESULT hr = SHParseDisplayName(pszPath, NULL, &pidl, 0, NULL);
27 if (FAILED(hr))
28 return NULL;
29 IShellItem *pSI;
30 hr = SHCreateShellItem(NULL, NULL, pidl, &pSI);
31 ILFree(pidl);
32 return SUCCEEDED(hr) ? pSI : NULL;
33}
#define NULL
Definition: types.h:112
#define MAX_PATH
Definition: compat.h:34
HRESULT WINAPI SHCreateShellItem(PCIDLIST_ABSOLUTE pidlParent, IShellFolder *psfParent, PCUITEMID_CHILD pidl, IShellItem **ppsi)
Definition: CShellItem.cpp:433
#define SUCCEEDED(hr)
Definition: intsafe.h:50
LPCWSTR szPath
Definition: env.c:37
short WCHAR
Definition: pedump.c:58
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:1051
HRESULT WINAPI SHParseDisplayName(LPCWSTR pszName, IBindCtx *pbc, LPITEMIDLIST *ppidl, SFGAOF sfgaoIn, SFGAOF *psfgaoOut)
Definition: pidl.c:1548
#define _countof(array)
Definition: sndvol32.h:70
#define GetModuleFileName
Definition: winbase.h:3554

Referenced by CreateItem2(), TestGetAttributes(), and TestInterfaces().

◆ CreateItem2()

static IShellItem2 * CreateItem2 ( PCWSTR  pszPath = NULL)
static

Definition at line 35 of file CShellItem.cpp.

36{
37 IShellItem2 *pSI2;
38 CComPtr<IShellItem> pSI(CreateItem(pszPath));
39 HRESULT hr = pSI ? pSI->QueryInterface(IID_IShellItem2, (void**)&pSI2) : E_FAIL;
40 return SUCCEEDED(hr) ? pSI2 : NULL;
41}
#define E_FAIL
Definition: ddrawi.h:102
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
static IShellItem * CreateItem(PCWSTR pszPath=NULL)
Definition: CShellItem.cpp:16

Referenced by TestShellItemPropSys().

◆ START_TEST()

START_TEST ( CShellItem  )

Definition at line 169 of file CShellItem.cpp.

170{
171 CCoInit ComInit;
172
176}
static void TestShellItemPropSys()
Definition: CShellItem.cpp:118
static void TestGetAttributes()
Definition: CShellItem.cpp:94
static void TestInterfaces()
Definition: CShellItem.cpp:43

◆ TestGetAttributes()

static void TestGetAttributes ( )
static

Definition at line 94 of file CShellItem.cpp.

95{
97 HRESULT hr;
98 CComPtr<IShellItem> pItem(CreateItem());
99 if (!pItem)
100 {
101 skip("Unable to create IShellItem\n");
102 return;
103 }
104
105 query = SFGAO_FILESYSTEM;
106 hr = pItem->GetAttributes(query, (result = ~query, &result));
107 ok(hr == S_OK && query == result, "All matching is S_OK\n");
108
109 query = SFGAO_FILESYSTEM | SFGAO_COMPRESSED | SFGAO_ENCRYPTED | SFGAO_GHOSTED;
110 hr = pItem->GetAttributes(query, (result = ~query, &result));
111 ok(hr == S_FALSE && (query & result) != 0 && query > result, "Some matching is S_FALSE\n");
112
113 query = SFGAO_FOLDER | SFGAO_STREAM;
114 hr = pItem->GetAttributes(query, (result = ~query, &result));
115 ok(!(result & SFGAO_FILESYSTEM), "Filter away flags not in query\n");
116}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
static IShellFolder IShellItem **static IBindCtx LPITEMIDLIST SFGAOF
Definition: ebrowser.c:83
GLuint64EXT * result
Definition: glext.h:11304
#define S_OK
Definition: intsafe.h:52
#define S_FALSE
Definition: winerror.h:3451

Referenced by START_TEST().

◆ TestInterfaces()

static void TestInterfaces ( )
static

Definition at line 43 of file CShellItem.cpp.

44{
45 HRESULT hr;
46 CComPtr<IShellItem> pItem(CreateItem());
47 if (!pItem)
48 {
49 skip("Unable to create IShellItem\n");
50 return;
51 }
52
53#if 0 // Not sure when this exact change happened, don't test until it can be nailed down
54 CComPtr<IPersist> pPersist;
55 hr = pItem->QueryInterface(IID_PPV_ARG(IPersist, &pPersist));
56 if (LOBYTE(GetVersion()) >= 6 && !IsReactOS())
57 ok_hr(hr, S_OK);
58 else
59 ok_hr(hr, E_NOINTERFACE); // Windows incorrectly forgets to support QI for IPersist
60#endif
61
62 CComPtr<IPersistIDList> pPIL;
64 ok_hr(hr, S_OK);
65 if (SUCCEEDED(hr) && pPIL)
66 {
68 hr = pPIL->GetClassID(&clsid);
69 ok(hr == S_OK && clsid == CLSID_ShellItem, "ClassID\n");
70
71 hr = pPIL->SetIDList(NULL);
72 ok(FAILED(hr), "Can't set a NULL item\n");
73 }
74
75 CComPtr<IParentAndItem> pPAI;
77 ok_hr(hr, S_OK);
78 if (SUCCEEDED(hr) && pPAI)
79 {
80 hr = pPAI->GetParentAndItem(NULL, NULL, NULL);
81 ok(SUCCEEDED(hr), "Asking for nothing is allowed\n");
82
83 hr = pPAI->SetParentAndItem(NULL, NULL, NULL);
85 }
86
87 // Windows does not check these pointers
88 // ok(FAILED(hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, NULL)), "NULL output\n");
89 // ok(FAILED(hr = pItem->GetParent(NULL)), "NULL output\n");
90 // ok(FAILED(hr = pItem->GetAttributes(0, NULL)), "NULL output\n");
91 // ok(FAILED(hr = pItem->Compare(NULL, 0, NULL)), "NULL output\n");
92}
#define ok_hr(status, expected)
Definition: ACListISF.cpp:31
#define IID_PPV_ARG(Itype, ppType)
#define E_INVALIDARG
Definition: ddrawi.h:101
DWORD WINAPI GetVersion(void)
Definition: version.c:1458
#define LOBYTE(W)
Definition: jmemdos.c:487
const CLSID * clsid
Definition: msctf.cpp:50
#define E_NOINTERFACE
Definition: winerror.h:3479

Referenced by START_TEST().

◆ TestShellItemPropSys()

static void TestShellItemPropSys ( )
static

Definition at line 118 of file CShellItem.cpp.

119{
120 HRESULT hr;
121 PROPVARIANT pv;
124 WIN32_FIND_DATAW fd = {};
126
127 CComPtr<IShellItem2> pItem(CreateItem2(szPath));
128 if (!pItem)
129 {
130 if (LOBYTE(GetVersion()) >= 6)
131 skip("Unable to create IShellItem2 from %ls\n", szPath);
132 else
133 skip("IShellItem2 not supported\n");
134 return;
135 }
136
137 //ok_hr(pItem->GetInt32(PKEY_DoesNotExist, NULL), E_INVALIDARG); // Windows does not verify the pointer
138 ok_hr(pItem->GetUInt32(PKEY_DoesNotExist, &pv.ulVal), HResultFromWin32(ERROR_NOT_FOUND));
139
140 #define TestFailedDefVal(method, param, expected) \
141 { \
142 pv.uhVal.QuadPart = (expected), pv.ulVal = ~(UINT)(expected); \
143 hr = pItem->method(PKEY_DoesNotExist, param); \
144 ok(FAILED(hr) && pv.uhVal.QuadPart == (expected), #method " failure value\n"); \
145 }
146 TestFailedDefVal(GetUInt32, &pv.ulVal, 0);
147 TestFailedDefVal(GetInt32, (int*)&pv.lVal, 0);
148 TestFailedDefVal(GetUInt64, &pv.uhVal.QuadPart, 0);
149 TestFailedDefVal(GetBool, (BOOL*)&pv.lVal, FALSE);
150 TestFailedDefVal(GetFileTime, &pv.filetime, 0);
151 TestFailedDefVal(GetString, &pv.pwszVal, 0);
152 #undef TestFailedDefVal
153
154 pv.lVal = -1;
155 hr = pItem->GetUInt32(PKEY_Size, &pv.ulVal);
156 ok(hr == S_OK && pv.ulVal == fd.nFileSizeLow && fd.nFileSizeLow, "Size UInt32\n");
157 pv.lVal = -1;
158 hr = pItem->GetInt32(PKEY_Size, (int*)&pv.lVal);
159 ok(hr == S_OK && pv.ulVal == fd.nFileSizeLow && fd.nFileSizeLow, "Size Int32\n");
160 pv.lVal = -1;
161 hr = pItem->GetUInt64(PKEY_Size, &pv.uhVal.QuadPart);
162 ok(hr == S_OK && pv.uhVal.LowPart == fd.nFileSizeLow && fd.nFileSizeLow, "Size UInt64\n");
163
164 pv.lVal = -1;
165 hr = pItem->GetFileTime(PKEY_DateModified, &pv.filetime);
166 ok(hr == S_OK && pv.filetime.dwHighDateTime == fd.ftLastWriteTime.dwHighDateTime, "MDate\n"); // Only checking the high dword to avoid PIDL DOS time resolution
167}
static HRESULT GetString(ASSOCSTR Str, UINT Flags, LPCWSTR pszAssoc, LPCWSTR pszExtra, PWSTR Out, HKEY hProgId=NULL)
#define FALSE
Definition: types.h:117
BOOL WINAPI GetFileTime(IN HANDLE hFile, OUT LPFILETIME lpCreationTime OPTIONAL, OUT LPFILETIME lpLastAccessTime OPTIONAL, OUT LPFILETIME lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:881
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
unsigned int BOOL
Definition: ntddk_ex.h:94
#define HResultFromWin32
Definition: loader.cpp:14
#define TestFailedDefVal(method, param, expected)
static const PROPERTYKEY PKEY_Size
Definition: CShellItem.cpp:13
static const PROPERTYKEY PKEY_DateModified
Definition: CShellItem.cpp:14
static IShellItem2 * CreateItem2(PCWSTR pszPath=NULL)
Definition: CShellItem.cpp:35
static int fd
Definition: io.c:51
#define ERROR_NOT_FOUND
Definition: winerror.h:1014

Referenced by START_TEST().

Variable Documentation

◆ PKEY_DateModified

const PROPERTYKEY PKEY_DateModified = { PSGUID_STORAGE, PID_STG_WRITETIME }
static

Definition at line 14 of file CShellItem.cpp.

Referenced by TestShellItemPropSys().

◆ PKEY_DoesNotExist

const PROPERTYKEY PKEY_DoesNotExist = { { 0x071ED77F,0x6DEE,0x4800,0x94,0xE7,0x1F,0xDD,0x89,0x6B,0x43,0x66 }, 42 }
static

Definition at line 12 of file CShellItem.cpp.

Referenced by TestInterfaces(), and TestShellItemPropSys().

◆ PKEY_Size

const PROPERTYKEY PKEY_Size = { PSGUID_STORAGE, PID_STG_SIZE }
static

Definition at line 13 of file CShellItem.cpp.

Referenced by TestShellItemPropSys().