ReactOS  0.4.15-dev-1374-g8d3e80e
SHCreateDataObject.cpp File Reference
#include "shelltest.h"
#include <ndk/rtlfuncs.h>
#include <stdio.h>
#include <shellutils.h>
#include <shlwapi.h>
Include dependency graph for SHCreateDataObject.cpp:

Go to the source code of this file.

Macros

#define ok_wstri(x, y)   ok(wcsicmp(x, y) == 0, "Wrong string. Expected '%S', got '%S'\n", y, x)
 

Typedefs

typedef HRESULT(WINAPItSHCreateDataObject) (PCIDLIST_ABSOLUTE pidlFolder, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, IDataObject *pdtInner, REFIID riid, void **ppv)
 

Functions

static void TestAdviseAndCanonical (PCIDLIST_ABSOLUTE pidlFolder, UINT cidl, PCUIDLIST_RELATIVE_ARRAY apidl)
 
static void TestHIDA (PVOID pData, SIZE_T Size, LPCWSTR ExpectRoot, LPCWSTR ExpectPath1, LPCWSTR ExpectPath2)
 
static void TestHDROP (PVOID pData, SIZE_T Size, LPCWSTR ExpectRoot, LPCWSTR ExpectPath1, LPCWSTR ExpectPath2)
 
static void TestFilenameA (PVOID pData, SIZE_T Size, LPCWSTR ExpectRoot, LPCWSTR ExpectPath1, LPCWSTR ExpectPath2)
 
static void TestFilenameW (PVOID pData, SIZE_T Size, LPCWSTR ExpectRoot, LPCWSTR ExpectPath1, LPCWSTR ExpectPath2)
 
static void TestDefaultFormat (PCIDLIST_ABSOLUTE pidlFolder, UINT cidl, PCUIDLIST_RELATIVE_ARRAY apidl)
 
static void TestSetAndGetExtraFormat (PCIDLIST_ABSOLUTE pidlFolder, UINT cidl, PCUIDLIST_RELATIVE_ARRAY apidl)
 
 START_TEST (SHCreateDataObject)
 

Variables

static DWORD g_WinVersion
 
static tSHCreateDataObject pSHCreateDataObject
 

Macro Definition Documentation

◆ ok_wstri

#define ok_wstri (   x,
  y 
)    ok(wcsicmp(x, y) == 0, "Wrong string. Expected '%S', got '%S'\n", y, x)

Definition at line 66 of file SHCreateDataObject.cpp.

Typedef Documentation

◆ tSHCreateDataObject

typedef HRESULT(WINAPI * tSHCreateDataObject) (PCIDLIST_ABSOLUTE pidlFolder, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, IDataObject *pdtInner, REFIID riid, void **ppv)

Definition at line 16 of file SHCreateDataObject.cpp.

Function Documentation

◆ START_TEST()

START_TEST ( SHCreateDataObject  )

Definition at line 401 of file SHCreateDataObject.cpp.

402 {
403  HRESULT hr;
404 
405  pSHCreateDataObject = (tSHCreateDataObject)GetProcAddress(GetModuleHandleA("shell32.dll"), "SHCreateDataObject");
406  if (!pSHCreateDataObject)
407  {
408  skip("shell32!SHCreateDataObject not exported\n");
409  return;
410  }
411 
413 
414  RTL_OSVERSIONINFOEXW rtlinfo = {0};
415 
416  rtlinfo.dwOSVersionInfoSize = sizeof(rtlinfo);
418  g_WinVersion = (rtlinfo.dwMajorVersion << 8) | rtlinfo.dwMinorVersion;
419 
420  CComHeapPtr<ITEMIDLIST_ABSOLUTE> pidlWindows;
421  CComHeapPtr<ITEMIDLIST_ABSOLUTE> pidlSystem32;
422  CComHeapPtr<ITEMIDLIST_ABSOLUTE> pidlResources;
423 
424  hr = SHGetFolderLocation(NULL, CSIDL_WINDOWS, NULL, 0, &pidlWindows);
425  ok_hex(hr, S_OK);
426  if (!SUCCEEDED(hr))
427  return;
428 
429  hr = SHGetFolderLocation(NULL, CSIDL_SYSTEM, NULL, 0, &pidlSystem32);
430  ok_hex(hr, S_OK);
431  if (!SUCCEEDED(hr))
432  return;
433 
434  hr = SHGetFolderLocation(NULL, CSIDL_RESOURCES, NULL, 0, &pidlResources);
435  ok_hex(hr, S_OK);
436  if (!SUCCEEDED(hr))
437  return;
438 
439  CComPtr<IShellFolder> shellFolder;
440  PCUITEMID_CHILD child1;
441  hr = SHBindToParent(pidlSystem32, IID_PPV_ARG(IShellFolder, &shellFolder), &child1);
442  ok_hex(hr, S_OK);
443  if (!SUCCEEDED(hr))
444  return;
445 
446  PCUITEMID_CHILD child2 = ILFindLastID(pidlResources);
447 
448  UINT cidl = 2;
449  PCUIDLIST_RELATIVE apidl[2] = {
450  child1, child2
451  };
452 
453  TestAdviseAndCanonical(pidlWindows, cidl, apidl);
454  TestDefaultFormat(pidlWindows, cidl, apidl);
455  TestSetAndGetExtraFormat(pidlWindows, cidl, apidl);
456 }
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:269
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:158
HRESULT hr
Definition: shlfolder.c:183
ULONG dwMinorVersion
Definition: rtltypes.h:271
const ITEMID_CHILD UNALIGNED * PCUITEMID_CHILD
Definition: shtypes.idl:70
#define IID_PPV_ARG(Itype, ppType)
#define ok_hex(expression, result)
Definition: atltest.h:94
ULONG dwMajorVersion
Definition: rtltypes.h:270
if SUCCEEDED(hr)
LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
Definition: pidl.c:189
#define CSIDL_WINDOWS
Definition: shlobj.h:2047
static DWORD g_WinVersion
LONG HRESULT
Definition: typedefs.h:79
static void TestAdviseAndCanonical(PCIDLIST_ABSOLUTE pidlFolder, UINT cidl, PCUIDLIST_RELATIVE_ARRAY apidl)
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
#define S_OK
Definition: intsafe.h:51
#define CSIDL_RESOURCES
Definition: shlobj.h:2064
static tSHCreateDataObject pSHCreateDataObject
HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
Definition: pidl.c:1337
static void TestDefaultFormat(PCIDLIST_ABSOLUTE pidlFolder, UINT cidl, PCUIDLIST_RELATIVE_ARRAY apidl)
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:2002
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define skip(...)
Definition: atltest.h:64
const ITEMIDLIST_RELATIVE UNALIGNED * PCUIDLIST_RELATIVE
Definition: shtypes.idl:57
#define GetProcAddress(x, y)
Definition: compat.h:612
HRESULT WINAPI SHGetFolderLocation(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwReserved, LPITEMIDLIST *ppidl)
Definition: shellpath.c:2741
#define CSIDL_SYSTEM
Definition: shlobj.h:2048
HRESULT(WINAPI * tSHCreateDataObject)(PCIDLIST_ABSOLUTE pidlFolder, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, IDataObject *pdtInner, REFIID riid, void **ppv)
static void TestSetAndGetExtraFormat(PCIDLIST_ABSOLUTE pidlFolder, UINT cidl, PCUIDLIST_RELATIVE_ARRAY apidl)

◆ TestAdviseAndCanonical()

static void TestAdviseAndCanonical ( PCIDLIST_ABSOLUTE  pidlFolder,
UINT  cidl,
PCUIDLIST_RELATIVE_ARRAY  apidl 
)
static

Definition at line 20 of file SHCreateDataObject.cpp.

21 {
22  CComPtr<IDataObject> spDataObj;
23  HRESULT hr = pSHCreateDataObject(pidlFolder, cidl, apidl, NULL, IID_PPV_ARG(IDataObject, &spDataObj));
24 
25  ok_hex(hr, S_OK);
26  if (!SUCCEEDED(hr))
27  return;
28 
29  hr = spDataObj->DAdvise(NULL, 0, NULL, NULL);
31 
32  hr = spDataObj->DUnadvise(0);
34 
35  hr = spDataObj->EnumDAdvise(NULL);
37 
38 
39  FORMATETC in = {1, (DVTARGETDEVICE*)2, 3, 4, 5};
40  FORMATETC out = {6, (DVTARGETDEVICE*)7, 8, 9, 10};
41 
42  hr = spDataObj->GetCanonicalFormatEtc(&in, &out);
44 
46  {
47  ok_int(out.cfFormat, 6);
48  ok_ptr(out.ptd, (void*)7);
49  ok_int(out.dwAspect, 8);
50  ok_int(out.lindex, 9);
51  ok_int(out.tymed, 10);
52  trace("out unmodified\n");
53  }
54  else
55  {
56  ok_int(out.cfFormat, in.cfFormat);
57  ok_ptr(out.ptd, NULL);
58  ok_int(out.dwAspect, (int)in.dwAspect);
59  ok_int(out.lindex, in.lindex);
60  ok_int(out.tymed, (int)in.tymed);
61  trace("in copied to out\n");
62  }
63 }
HRESULT hr
Definition: shlfolder.c:183
#define DATA_S_SAMEFORMATETC
Definition: winerror.h:2674
#define ok_ptr(expression, result)
Definition: atltest.h:108
#define IID_PPV_ARG(Itype, ppType)
#define ok_hex(expression, result)
Definition: atltest.h:94
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25
if SUCCEEDED(hr)
#define ok_int(expression, result)
Definition: atltest.h:134
static DWORD g_WinVersion
#define trace
Definition: atltest.h:70
LONG HRESULT
Definition: typedefs.h:79
static FILE * out
Definition: regtests2xml.c:44
#define OLE_E_ADVISENOTSUPPORTED
Definition: winerror.h:2617
#define S_OK
Definition: intsafe.h:51
static tSHCreateDataObject pSHCreateDataObject
GLuint in
Definition: glext.h:9616
#define NULL
Definition: types.h:112

Referenced by START_TEST().

◆ TestDefaultFormat()

static void TestDefaultFormat ( PCIDLIST_ABSOLUTE  pidlFolder,
UINT  cidl,
PCUIDLIST_RELATIVE_ARRAY  apidl 
)
static

Definition at line 144 of file SHCreateDataObject.cpp.

145 {
146  CComPtr<IDataObject> spDataObj;
147  HRESULT hr = pSHCreateDataObject(pidlFolder, cidl, apidl, NULL, IID_PPV_ARG(IDataObject, &spDataObj));
148 
149  ok_hex(hr, S_OK);
150  if (!SUCCEEDED(hr))
151  return;
152 
153  CComPtr<IEnumFORMATETC> pEnumFmt;
154  hr = spDataObj->EnumFormatEtc(DATADIR_GET, &pEnumFmt);
155 
156  ok_hex(hr, S_OK);
157  if (!SUCCEEDED(hr))
158  return;
159 
160  UINT Expected[4] = {
162  CF_HDROP,
164  RegisterClipboardFormatA("FileNameW"),
165  };
166 
167  UINT Count = 0;
168  FORMATETC fmt;
169  while (S_OK == (hr=pEnumFmt->Next(1, &fmt, NULL)))
170  {
171  char szGot[512], szExpected[512];
172  GetClipboardFormatNameA(fmt.cfFormat, szGot, sizeof(szGot));
173  ok(Count < _countof(Expected), "%u\n", Count);
174  if (Count < _countof(Expected))
175  {
176  GetClipboardFormatNameA(Expected[Count], szExpected, sizeof(szExpected));
177  ok(fmt.cfFormat == Expected[Count], "Got 0x%x(%s), expected 0x%x(%s) for %u\n",
178  fmt.cfFormat, szGot, Expected[Count], szExpected, Count);
179  }
180 
181  ok(fmt.ptd == NULL, "Got 0x%p, expected 0x%p for [%u].ptd\n", fmt.ptd, (void*)NULL, Count);
182  ok(fmt.dwAspect == DVASPECT_CONTENT, "Got 0x%lu, expected 0x%d for [%u].dwAspect\n", fmt.dwAspect, DVASPECT_CONTENT, Count);
183  ok(fmt.lindex == -1, "Got 0x%lx, expected 0x%x for [%u].lindex\n", fmt.lindex, -1, Count);
184  ok(fmt.tymed == TYMED_HGLOBAL, "Got 0x%lu, expected 0x%d for [%u].tymed\n", fmt.tymed, TYMED_HGLOBAL, Count);
185 
186  Count++;
187  }
188  trace("Got %u formats\n", Count);
189  ULONG ExpectedCount = (g_WinVersion < _WIN32_WINNT_WIN8) ? 1 : 4;
190  ok_int(Count, (int)ExpectedCount);
191  ok_hex(hr, S_FALSE);
192 
193  typedef void (*TestFunction)(PVOID pData, SIZE_T Size, LPCWSTR ExpectRoot, LPCWSTR ExpectPath1, LPCWSTR ExpectPath2);
194  TestFunction TestFormats[] = {
195  TestHIDA,
196  TestHDROP,
199  };
200 
201  WCHAR ExpectRoot[MAX_PATH], ExpectItem1[MAX_PATH], ExpectItem2[MAX_PATH];
202 
203  hr = SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, ExpectRoot);
204  ok_hex(hr, S_OK);
205  if (!SUCCEEDED(hr))
206  return;
207 
208  hr = SHGetFolderPathW(NULL, CSIDL_SYSTEM, NULL, 0, ExpectItem1);
209  ok_hex(hr, S_OK);
210  if (!SUCCEEDED(hr))
211  return;
212 
213  hr = SHGetFolderPathW(NULL, CSIDL_RESOURCES, NULL, 0, ExpectItem2);
214  ok_hex(hr, S_OK);
215  if (!SUCCEEDED(hr))
216  return;
217 
218 
219  /* The formats are not synthesized on request */
220  for (Count = 0; Count < _countof(Expected); ++Count)
221  {
222  STGMEDIUM medium = {0};
223  FORMATETC etc = { (CLIPFORMAT)Expected[Count], NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
224  char szExpected[512];
225 
226  GetClipboardFormatNameA(etc.cfFormat, szExpected, sizeof(szExpected));
227  hr = spDataObj->GetData(&etc, &medium);
228  HRESULT hr2 = spDataObj->QueryGetData(&etc);
229  ok_hex(hr2, SUCCEEDED(hr) ? S_OK : S_FALSE);
230 
231  if (Count < ExpectedCount)
232  {
233  ok(hr == S_OK, "0x%x (0x%x(%s))\n", (unsigned int)hr, Expected[Count], szExpected);
234  ok(medium.tymed == TYMED_HGLOBAL, "0x%lx (0x%x(%s))\n", medium.tymed, Expected[Count], szExpected);
235  if (hr == S_OK && medium.tymed == TYMED_HGLOBAL)
236  {
237  PVOID pData = GlobalLock(medium.hGlobal);
238  SIZE_T Size = GlobalSize(medium.hGlobal);
239  TestFormats[Count](pData, Size, ExpectRoot, ExpectItem1, ExpectItem2);
240  GlobalUnlock(medium.hGlobal);
241  }
242  }
243  else
244  {
246  ok(hr == E_INVALIDARG, "0x%x (0x%x(%s))\n", (unsigned int)hr, Expected[Count], szExpected);
247  else
248  ok(hr == DV_E_FORMATETC, "0x%x (0x%x(%s))\n", (unsigned int)hr, Expected[Count], szExpected);
249  }
250 
251  if (SUCCEEDED(hr))
252  ReleaseStgMedium(&medium);
253  }
254 
256  FORMATETC formatetc = { Format, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
257  STGMEDIUM medium;
258 
259  hr = spDataObj->GetData(&formatetc, &medium);
262  else
264 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
void WINAPI ReleaseStgMedium(STGMEDIUM *pmedium)
Definition: ole2.c:2033
UINT WINAPI RegisterClipboardFormatW(_In_ LPCWSTR)
const char * fmt
Definition: wsprintf.c:30
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
void TestFunction()
static void TestHIDA(PVOID pData, SIZE_T Size, LPCWSTR ExpectRoot, LPCWSTR ExpectPath1, LPCWSTR ExpectPath2)
#define IID_PPV_ARG(Itype, ppType)
#define ok_hex(expression, result)
Definition: atltest.h:94
SIZE_T NTAPI GlobalSize(HGLOBAL hMem)
Definition: heapmem.c:1090
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25
if SUCCEEDED(hr)
#define S_FALSE
Definition: winerror.h:2357
#define E_INVALIDARG
Definition: ddrawi.h:101
#define ok_int(expression, result)
Definition: atltest.h:134
#define CF_HDROP
Definition: constants.h:410
#define CSIDL_WINDOWS
Definition: shlobj.h:2047
#define _WIN32_WINNT_WIN8
Definition: sdkddkver.h:29
int Count
Definition: noreturn.cpp:7
static DWORD g_WinVersion
#define DV_E_FORMATETC
Definition: winerror.h:2633
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:79
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
static void TestHDROP(PVOID pData, SIZE_T Size, LPCWSTR ExpectRoot, LPCWSTR ExpectPath1, LPCWSTR ExpectPath2)
static const WCHAR CFSTR_PREFERREDDROPEFFECTW[]
Definition: shlobj.h:453
static void TestFilenameA(PVOID pData, SIZE_T Size, LPCWSTR ExpectRoot, LPCWSTR ExpectPath1, LPCWSTR ExpectPath2)
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
UINT WINAPI RegisterClipboardFormatA(_In_ LPCSTR)
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define S_OK
Definition: intsafe.h:51
#define CSIDL_RESOURCES
Definition: shlobj.h:2064
static tSHCreateDataObject pSHCreateDataObject
#define ok(value,...)
Definition: atltest.h:57
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2208
unsigned int ULONG
Definition: retypes.h:1
#define CFSTR_SHELLIDLISTA
Definition: shlobj.h:345
#define CFSTR_FILENAMEA
Definition: shlobj.h:352
#define CSIDL_SYSTEM
Definition: shlobj.h:2048
BOOLEAN Expected
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
Definition: dsound.c:943
static void TestFilenameW(PVOID pData, SIZE_T Size, LPCWSTR ExpectRoot, LPCWSTR ExpectPath1, LPCWSTR ExpectPath2)
int WINAPI GetClipboardFormatNameA(_In_ UINT format, _Out_writes_(cchMaxCount) LPSTR lpszFormatName, _In_ int cchMaxCount)
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char * Format
Definition: acpixf.h:1216

Referenced by START_TEST().

◆ TestFilenameA()

static void TestFilenameA ( PVOID  pData,
SIZE_T  Size,
LPCWSTR  ExpectRoot,
LPCWSTR  ExpectPath1,
LPCWSTR  ExpectPath2 
)
static

Definition at line 123 of file SHCreateDataObject.cpp.

124 {
125  LPCSTR FirstFile = (LPCSTR)pData;
126  LPWSTR FirstFileW;
127 
128  HRESULT hr = SHStrDupA(FirstFile, &FirstFileW);
129  ok_hex(hr, S_OK);
130  if (!SUCCEEDED(hr))
131  return;
132 
133  ok_wstri(ExpectPath1, FirstFileW);
134  CoTaskMemFree(FirstFileW);
135 }
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
HRESULT hr
Definition: shlfolder.c:183
#define ok_wstri(x, y)
#define ok_hex(expression, result)
Definition: atltest.h:94
HRESULT WINAPI SHStrDupA(LPCSTR lpszStr, LPWSTR *lppszDest)
Definition: string.c:1946
if SUCCEEDED(hr)
const char * LPCSTR
Definition: xmlstorage.h:183
LONG HRESULT
Definition: typedefs.h:79
#define S_OK
Definition: intsafe.h:51
WCHAR * LPWSTR
Definition: xmlstorage.h:184
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827

Referenced by TestDefaultFormat().

◆ TestFilenameW()

static void TestFilenameW ( PVOID  pData,
SIZE_T  Size,
LPCWSTR  ExpectRoot,
LPCWSTR  ExpectPath1,
LPCWSTR  ExpectPath2 
)
static

Definition at line 137 of file SHCreateDataObject.cpp.

138 {
139  LPCWSTR FirstFile = (LPCWSTR)pData;
140  ok_wstri(ExpectPath1, FirstFile);
141 }
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define ok_wstri(x, y)
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827

Referenced by TestDefaultFormat().

◆ TestHDROP()

static void TestHDROP ( PVOID  pData,
SIZE_T  Size,
LPCWSTR  ExpectRoot,
LPCWSTR  ExpectPath1,
LPCWSTR  ExpectPath2 
)
static

Definition at line 100 of file SHCreateDataObject.cpp.

101 {
102  DROPFILES* pDropFiles = (DROPFILES*)pData;
103  ok_int(pDropFiles->fWide, TRUE);
104 
105  LPCWSTR Expected[2] = { ExpectPath1, ExpectPath2 };
106 
107  SIZE_T offset = pDropFiles->pFiles;
108  UINT Count = 0;
109  for (;;Count++)
110  {
111  LPCWSTR ptr = (LPCWSTR)(((BYTE*)pDropFiles) + offset);
112  if (!*ptr)
113  break;
114 
115  if (Count < _countof(Expected))
117 
118  offset += (wcslen(ptr) + 1) * sizeof(WCHAR);
119  }
120  ok_int(Count, 2);
121 }
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define TRUE
Definition: types.h:120
#define ok_wstri(x, y)
static PVOID ptr
Definition: dispmode.c:27
#define ok_int(expression, result)
Definition: atltest.h:134
int Count
Definition: noreturn.cpp:7
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLintptr offset
Definition: glext.h:5920
#define _countof(array)
Definition: sndvol32.h:68
BOOL fWide
Definition: shlobj.h:2127
unsigned char BYTE
Definition: xxhash.c:193
ULONG_PTR SIZE_T
Definition: typedefs.h:80
unsigned int UINT
Definition: ndis.h:50
BOOLEAN Expected
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
DWORD pFiles
Definition: shlobj.h:2124
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by TestDefaultFormat().

◆ TestHIDA()

static void TestHIDA ( PVOID  pData,
SIZE_T  Size,
LPCWSTR  ExpectRoot,
LPCWSTR  ExpectPath1,
LPCWSTR  ExpectPath2 
)
static

Definition at line 69 of file SHCreateDataObject.cpp.

70 {
71  LPIDA pida = (LPIDA)pData;
72 
73  ok_int(pida->cidl, 2);
74  if (pida->cidl != 2)
75  return;
76 
77  WCHAR FolderPath[MAX_PATH], Item1[MAX_PATH], Item2[MAX_PATH];
78  BOOL bRet = SHGetPathFromIDListW(HIDA_GetPIDLFolder(pida), FolderPath);
79  ok_int(bRet, TRUE);
80  if (!bRet)
81  return;
82  ok_wstri(FolderPath, ExpectRoot);
83 
84  CComHeapPtr<ITEMIDLIST_ABSOLUTE> pidl1(ILCombine(HIDA_GetPIDLFolder(pida), HIDA_GetPIDLItem(pida, 0)));
85  CComHeapPtr<ITEMIDLIST_ABSOLUTE> pidl2(ILCombine(HIDA_GetPIDLFolder(pida), HIDA_GetPIDLItem(pida, 1)));
86 
87  bRet = SHGetPathFromIDListW(pidl1, Item1);
88  ok_int(bRet, TRUE);
89  if (!bRet)
90  return;
91  ok_wstri(Item1, ExpectPath1);
92 
93  bRet = SHGetPathFromIDListW(pidl2, Item2);
94  ok_int(bRet, TRUE);
95  if (!bRet)
96  return;
97  ok_wstri(Item2, ExpectPath2);
98 }
#define TRUE
Definition: types.h:120
#define ok_wstri(x, y)
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:699
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1294
static PCUIDLIST_RELATIVE HIDA_GetPIDLItem(CIDA const *pida, SIZE_T i)
Definition: shellutils.h:543
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok_int(expression, result)
Definition: atltest.h:134
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:34
struct CIDA * LPIDA
UINT cidl
Definition: shlobj.h:499
static PCUIDLIST_ABSOLUTE HIDA_GetPIDLFolder(CIDA const *pida)
Definition: shellutils.h:538
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
Definition: shlobj.h:498

Referenced by TestDefaultFormat().

◆ TestSetAndGetExtraFormat()

static void TestSetAndGetExtraFormat ( PCIDLIST_ABSOLUTE  pidlFolder,
UINT  cidl,
PCUIDLIST_RELATIVE_ARRAY  apidl 
)
static

Definition at line 267 of file SHCreateDataObject.cpp.

268 {
269  CComPtr<IDataObject> spDataObj;
270  HRESULT hr = pSHCreateDataObject(pidlFolder, cidl, apidl, NULL, IID_PPV_ARG(IDataObject, &spDataObj));
271 
272  ok_hex(hr, S_OK);
273  if (!SUCCEEDED(hr))
274  return;
275 
276  STGMEDIUM medium = {0};
277  medium.tymed = TYMED_HGLOBAL;
278  medium.hGlobal = GlobalAlloc(GHND, sizeof(DWORD));
279  ok(medium.hGlobal != NULL, "Download more ram\n");
280  PDWORD data = (PDWORD)GlobalLock(medium.hGlobal);
281  *data = 12345;
282  GlobalUnlock(medium.hGlobal);
283 
284  UINT flags = GlobalFlags(medium.hGlobal);
285  SIZE_T size = GlobalSize(medium.hGlobal);
286  ok_hex(flags, 0);
287  ok_size_t(size, sizeof(DWORD));
288 
289  FORMATETC etc = { (CLIPFORMAT)RegisterClipboardFormatA(CFSTR_INDRAGLOOPA), NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
290  FORMATETC etc2 = etc;
291 
292  /* Not supported! */
293  hr = spDataObj->SetData(&etc, &medium, FALSE);
296  else
297  ok_hex(hr, E_NOTIMPL);
298 
299  /* Object takes ownership! */
300  hr = spDataObj->SetData(&etc, &medium, TRUE);
301  ok_hex(hr, S_OK);
302  if (!SUCCEEDED(hr))
303  return;
304 
305  /* Does not touch the hGlobal! */
306  flags = GlobalFlags(medium.hGlobal);
307  size = GlobalSize(medium.hGlobal);
308  ok_hex(flags, 0);
309  ok_size_t(size, sizeof(DWORD));
310 
311  STGMEDIUM medium2 = {0};
312 
313  /* No conversion */
314  etc2.dwAspect = DVASPECT_DOCPRINT;
315  hr = spDataObj->GetData(&etc2, &medium2);
316  HRESULT hr2 = spDataObj->QueryGetData(&etc2);
317  ok_hex(hr2, SUCCEEDED(hr) ? S_OK : S_FALSE);
320  else
322 
323  etc2.dwAspect = DVASPECT_CONTENT;
324  etc2.tymed = TYMED_NULL;
325  hr = spDataObj->GetData(&etc2, &medium2);
326  hr2 = spDataObj->QueryGetData(&etc2);
327  ok_hex(hr2, SUCCEEDED(hr) ? S_OK : S_FALSE);
330  else
332  etc2.tymed = TYMED_HGLOBAL;
333 
334  ok_ptr(medium2.pUnkForRelease, NULL);
335  hr = spDataObj->GetData(&etc2, &medium2);
336  hr2 = spDataObj->QueryGetData(&etc2);
337  ok_hex(hr2, SUCCEEDED(hr) ? S_OK : S_FALSE);
338  ok_hex(hr, S_OK);
339  if (hr == S_OK)
340  {
341  ok_hex(medium2.tymed, TYMED_HGLOBAL);
343  {
344  /* The IDataObject is set as pUnkForRelease */
345  ok(medium2.pUnkForRelease == (IUnknown*)spDataObj, "Expected the data object (0x%p), got 0x%p\n",
346  (IUnknown*)spDataObj, medium2.pUnkForRelease);
347  ok(medium.hGlobal == medium2.hGlobal, "Pointers are not the same!, got 0x%p and 0x%p\n", medium.hGlobal, medium2.hGlobal);
348  }
349  else
350  {
351  ok_ptr(medium2.pUnkForRelease, NULL);
352  ok(medium.hGlobal != medium2.hGlobal, "Pointers are the same!\n");
353  }
354 
355  flags = GlobalFlags(medium2.hGlobal);
356  size = GlobalSize(medium2.hGlobal);
357  ok_hex(flags, 0);
358  ok_size_t(size, sizeof(DWORD));
359 
360  data = (PDWORD)GlobalLock(medium2.hGlobal);
361  if (data)
362  ok_int(*data, 12345);
363  else
364  ok(0, "GlobalLock: %lu\n", GetLastError());
365  GlobalUnlock(medium2.hGlobal);
366 
367  HGLOBAL backup = medium2.hGlobal;
368  ReleaseStgMedium(&medium2);
369 
373  {
374  /* Same object! just the pUnkForRelease was set, so original hGlobal is still valid */
375  ok_hex(flags, 0);
376  ok_size_t(size, sizeof(DWORD));
377  }
378  else
379  {
381  ok_size_t(size, 0);
382  }
383 
384  /* Original is still intact (but no longer ours!) */
385  flags = GlobalFlags(medium.hGlobal);
386  size = GlobalSize(medium.hGlobal);
387  ok_hex(flags, 0);
388  ok_size_t(size, sizeof(DWORD));
389  }
390 
391  HGLOBAL backup = medium.hGlobal;
392  spDataObj.Release();
393 
394  /* Now our hGlobal is deleted */
398  ok_size_t(size, 0);
399 }
static long backup()
Definition: maze.c:403
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
HRESULT hr
Definition: shlfolder.c:183
void WINAPI ReleaseStgMedium(STGMEDIUM *pmedium)
Definition: ole2.c:2033
#define TRUE
Definition: types.h:120
UINT NTAPI GlobalFlags(HGLOBAL hMem)
Definition: heapmem.c:520
#define CFSTR_INDRAGLOOPA
Definition: shlobj.h:360
#define GMEM_INVALID_HANDLE
Definition: winbase.h:305
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define ok_ptr(expression, result)
Definition: atltest.h:108
#define IID_PPV_ARG(Itype, ppType)
#define ok_hex(expression, result)
Definition: atltest.h:94
SIZE_T NTAPI GlobalSize(HGLOBAL hMem)
Definition: heapmem.c:1090
#define GHND
Definition: winbase.h:294
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25
#define FALSE
Definition: types.h:117
if SUCCEEDED(hr)
#define S_FALSE
Definition: winerror.h:2357
#define E_INVALIDARG
Definition: ddrawi.h:101
#define ok_int(expression, result)
Definition: atltest.h:134
#define _WIN32_WINNT_WIN8
Definition: sdkddkver.h:29
static DWORD g_WinVersion
GLsizeiptr size
Definition: glext.h:5919
#define DV_E_FORMATETC
Definition: winerror.h:2633
LONG HRESULT
Definition: typedefs.h:79
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLbitfield flags
Definition: glext.h:7161
#define ok_size_t(expression, result)
Definition: atltest.h:115
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
UINT WINAPI RegisterClipboardFormatA(_In_ LPCSTR)
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define S_OK
Definition: intsafe.h:51
static tSHCreateDataObject pSHCreateDataObject
#define ok(value,...)
Definition: atltest.h:57
#define E_NOTIMPL
Definition: ddrawi.h:99
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
DWORD * PDWORD
Definition: pedump.c:68

Referenced by START_TEST().

Variable Documentation

◆ g_WinVersion

DWORD g_WinVersion
static

◆ pSHCreateDataObject

tSHCreateDataObject pSHCreateDataObject
static